next up previous contents index
Next: 2.3 Plotting graphs Up: 2. Managing graphs Previous: 2.1 Creating graphs

  
2.2 Loading and saving graphs

Graphs are saved in ASCII files, called graph files . A graph file has the extension .graph. The structure of a graph file is given below:


GRAPH TYPE (0 = UNDIRECTED, 1 = DIRECTED), DEFAULTS (NODEDIAMETER, NODE BORDER,

        first line continuing ARC WIDTH, HILITED ARC WIDTH, FONTSIZE):
<one line with above values>
NUMBER OF ARCS:
<one line with the number of arcs>
NUMBER OF NODES:
<one line with the number of nodes>
****************************************
DESCRIPTION OF ARCS:
ARC NAME, TAIL NODE NAME, HEAD NODE NAME, COLOR, WIDTH, HIWIDTH, FONTSIZE
COST, MIN CAP, CAP, MAX CAP, LENGTH, Q WEIGHT, Q ORIGIN, WEIGHT
<one blank line>
<two lines for each arc>
****************************************
DESCRIPTION OF NODES:
NODE NAME, POSSIBLE TYPE (1 = SINK, 2 = SOURCE)
X, Y, COLOR, DIAMETER, BORDER, FONTSIZE
DEMAND
<one blank line>
<three lines for each node>

For an undirected graph, ARC is replaced by EDGE. Moreover, the values of NODE DIAMETER, NODE BORDER, ARC WIDTH, HILITED ARC WIDTH and FONTSIZE for the graph, COLOR, WIDTH, HIWIDTH and FONTSIZE for the arcs, and POSSIBLE TYPE, COLOR, DIAMETER, BORDER and FONTSIZE for the nodes can be omitted or equal to 0, then the default is used (see 1.1).

It is possible to create by hands a graph file and to load it into Scilab, but it is a very cumbersome job. Programs are given to generate graphs (see 4).

To load a graph into Scilab, use the load_graph function. Its argument is the absolute or relative pathname of the graph file; if the .graph extension is missing, it is assumed. load_graph returns the corresponding graph list.

For instance, to load the graph foo, which is in the current directory, and put the corresponding graph list in the Scilab variable g, do:
g=load_graph('foo'); or g=load_graph('foo.graph');.
To load the graph mesh100 given in the Scilab distribution, do:
g=load_graph(SCI+'/demos/metanet/mesh100.graph');


To save a graph, use the save_graph function. Its first argument is the graph list, and its second argument is the name or the pathname of the graph file; if the .graph extension is missing, it is assumed. If the path is the name of a directory, the name of the graph is used as the name of the file.

For instance, the following command saves the graph g into the graph file foo.graph:
save_graph(g,'foo.graph');


next up previous contents index
Next: 2.3 Plotting graphs Up: 2. Managing graphs Previous: 2.1 Creating graphs
Scilab Group