The main difficulty is that in order to make the graph representation compact and efficient, we have chosen a data structure which is not modifiable. Once you constructs a graph, you cannot change it (except for the node/edge attributes) without building a new graph.
As a consequence, the creation of the graph must be split into
two phases: in the first you must create an instance of the
class ARGLoader
, which gathers all the information needed
to build the graph (for instance, by loading data from
a file), and then in the second phase you create an instance of the
class Graph
, passing the ARGLoader
to its constructor,
in order to actually build the graph. Both Graph
and
ARGLoader
are declared in the include file argraph.h
.
ARGLoader
is an abstract class, from which the user should
derive its own loader class to implement the desired way to
load or to generate the graphs. In VFLib we have provided
some simple implementations of ARGLoader
to perform
generation and loading of graphs using a not very sophisticated
file format.
One of these classes is ARGEdit
, declared in argedit.h
,
which implements some simple graph editing operations. For instance,
the user may generate the graph by successive node and edge
insertions, and then use the ARGEdit
to initialize a Graph
object.
For example, suppose you want to generate a complete 4 nodes graph.
You have first to create an ARGEdit
, then you have to insert the
four nodes, and finally for each pair of nodes you have to insert the
corresponding edge. The code performing this operation would be:
#include "argraph.h"
#include "argedit.h"
int main()
{ ARGEdit ed; // The object used to create the graph
int i,j;
// Insert the four nodes
for(i=0; i<4; i++)
ed.InsertNode(NULL); // The inserted node will have index i.
// NULL stands for no semantic attribute.
// Insert the edges
for(i=0; i<4; i++)
for(j=0; j<4; j++)
if (i!=j)
ed.InsertEdge(i, j, NULL); // NULL stands for no sem. attribute.
// Now the Graph can be constructed...
Graph g(&ed);
// To be continued...
In a later subsection, some other ARGLoader
implementations
will be presented which can be used to load a graph from a
file.