next up previous contents index
Next: 2.2 Loading and saving Up: 2. Managing graphs Previous: 2. Managing graphs

  
2.1 Creating graphs

The standard function for making a graph list is make_graph. The first argument is the name of the graph, the second argument is a flag which can be 1 (directed graph) or 0 (undirected graph), the third argument is the number of nodes of the graph, and the last two arguments are the tail and head vectors of the graph.

We have already seen that the graph named ``foo'' in figure 1 can be created by the command:

g=make_graph('foo',1,4,[1 1 2 3],[2 3 1 3]);

The simplest graph we can create in Metanet is:

g=make_graph('min',1,1,[1],[1]);
It is directed, has one node and one loop arc on this node and can be seen in figure 3.
  
Figure 3: Smallest directed graph
\begin{figure}\begin{center}%
\begin{picture}
(0,0)%
\epsfig{file=min.pstex} %
\...
...oup %
\begin{picture}
(491,596)(2548,108)
\end{picture}\end{center} \end{figure}

The following graph shown in figure 4 is the same as the first graph we have created, but it is undirected:

g=make_graph('ufoo',0,4,[1 1 2 3],[2 3 1 3]);


  
Figure 4: Small undirected graph
\begin{figure}\begin{center}%
\begin{picture}
(0,0)%
\epsfig{file=ufoo.pstex} %
...
...p %
\begin{picture}
(2281,1431)(753,-787)
\end{picture}\end{center} \end{figure}

You can also give 0 as the third argument of make_graph (number of nodes). This means that make_graph will compute itself from its last arguments, the tail and head vectors, the number of nodes of the graph. So, this graph has no isolated node and the nodes names are taken from the numbers in tail and head vectors. For instance, if you enter

g=make_graph('foo1',1,0,[1 1 4 3],[4 3 1 3]);
the graph (shown in figure 5) has three nodes with names 1, 3 and 4, no isolated node and four edges. Note the difference with the graph of figure 1.


  
Figure 5: Directed graph
\begin{figure}\begin{center}%
\begin{picture}
(0,0)%
\epsfig{file=foo1.pstex} %
...
...p %
\begin{picture}
(2105,1295)(753,-787)
\end{picture}\end{center} \end{figure}

The other elements of the graph list (see 1.1) can be entered by using the names of the elements. For instance, to give graph ``foo'' coordinates for the nodes, you can enter:

g=make_graph('foo',1,4,[1 1 2 3],[2 3 1 3]);
g('node_x')=[42 108 176 162];
g('node_y')=[36 134  36  93];

Another simple example: if you want to transform the directed graph g into an undirected graph, you only have to do:

g('directed')=0;

There is a wizard way to create a graph list ``by hands'' without using the make_graph function. This can be useful when writing your own Scilab functions. You can use the Scilab function glist which must have as many arguments as the elements of the graph list (see 1.1). This way can lead to errors, because the list is somehow long. You can use the check_graph function to check if the graph list is correct.


next up previous contents index
Next: 2.2 Loading and saving Up: 2. Managing graphs Previous: 2. Managing graphs
Scilab Group