[Gambas-user] Graph classes

Tobias Boege taboege at ...626...
Sat Sep 13 05:36:21 CEST 2014


Hi list,

with #6468, it is finally possible to use Graphs from gb.data. You have a
base "Graph" class from which all implementations inherit. It also acts
like a driver/dispatcher for implementation functions. (Little) more on
that below.

GraphMatrix is a concrete graph implementation in gb.data based on an
adjacency matrix (a full n*n one at the moment -- I may go for sparse
matrices later). More implementations may follow as I have time.

You can also create your own graph classes in Gambas. It's more
complicated than you might want it to be but you don't invent new graph
classes on a daily basis, right? That's mainly because I made excessive
use of virtual classes to have a nice interface without additional memory
usage.

At least the process of creating your own graph class is convoluted enough
that I cannot explain it now, so either self-study or wait for the tutorial/
GambasMag article (depends on how fast December approaches) :-)

Attached are three projects:

  - ConnectivityMatrix: shows how to use GraphMatrix. It (sort of) computes
    the connected components of a graph, but by taking the sum over powers
    of the adjacency matrix (using gb.gsl).

  - custom-graph: a very quickly written project which implements a
    "DirectoryGraph", i.e. a graph which represents a directory hierarchy
    where "being contained in a directory" and (symbolic) links are edges.

    The class is written in Gambas and rather minimal. The project creates
    a (graphviz) dot file and its png of the graph of /usr/lib/gambas3/*so*.

  - GraphFloodFill: is a more sophisticated project. At its heart it
    interprets an Image object as a graph by implicitly taking the pixels
    as vertices and defining edges between pixels of the same colour (or
    from any colour to white or transparent).

    The BreadthFirstSearch class implements a BFS for a general Graph object.
    ImageGraph contains just enough functionality to allow a BFS on it. This
    together allows to do a flood fill on the backing Image object.

    There is also a neat little colour chooser because the traditional one
    from gb.form was too bulky for the form.

Questions?

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ConnectivityMatrix-0.1.1.tar.gz
Type: application/octet-stream
Size: 4754 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20140913/af082743/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: custom-graph-0.0.1.tar.gz
Type: application/octet-stream
Size: 4771 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20140913/af082743/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GraphFloodfill-0.2.1.tar.gz
Type: application/octet-stream
Size: 8419 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20140913/af082743/attachment-0002.obj>


More information about the User mailing list