<< add_edge_data Edges - Arcs arc_number >>

metanet >> metanet > Edges - Arcs > adj_lists

adj_lists

computes adjacency lists

Calling Sequence

[lp,la,ls] = adj_lists(g)
[lp,la,ls] = adj_lists(directed,n,tail,head)

Parameters

g

:a graph (see graph_data_structure).

directed

integer, 0 (undirected graph) or 1 (directed graph)

n

integer, the number of nodes of the graph

tail

the row vector of the numbers of the tail nodes of the graph (its size is the number of edges of the graph)

head

the row vector of the numbers of the head nodes of the graph (its size is the number of edges of the graph)

lp

row vector, pointer array of the adjacency lists description of the graph (its size is the number of nodes of the graph + 1)

la

row vector, arc array of the adjacency lists description of the graph (its size is the number of edges of the graph)

ls

row vector, node array of the adjacency lists description of the graph (its size is the number of edges of the graph)

Description

adj_lists computes the row vectors of the adjacency lists description of the graph g. It is also possible to give adj_lists the description of the graph given by the number of nodes n and the row vectors tail and head.

For a node numbered k, the connected edges are given by la(lp(k):(lp(k+1)-1)), while the other bounds of these edges are connected to nodes ls((lp(k):(lp(k+1)-1))).

Examples

ta=[2 3 3 5 3 4 4 5 8];
he=[1 2 4 2 6 6 7 7 4];
g=make_graph('foo',1,8,ta,he);
g.nodes.graphics.x=[129 200 283 281 128 366 122 333];
g.nodes.graphics.y=[61 125 129 189 173 135 236 249];
g.nodes.graphics.display='number';
g.edges.graphics.display='number';

show_graph(g);
//directed graph
[lp,la,ls]=adj_lists(g)
[lp,la,ls]=adj_lists(1,g.nodes.number,ta,he)
for k=1:node_number(g)
  sel=lp(k):(lp(k+1)-1);
  g1=g;
  g1.nodes.graphics.colors(2,k)=color('red');
  g1.edges.graphics.foreground(la(sel))=color('green');
  g1.nodes.graphics.colors(1,ls(sel))=color('red');
  show_graph(g1);
  halt() 
end

//non directed graph
g.directed=0;
[lp,la,ls]=adj_lists(g);
for k=1:node_number(g)
  sel=lp(k):(lp(k+1)-1);
  g1=g;
  g1.nodes.graphics.colors(2,k)=color('red');
  g1.edges.graphics.foreground(la(sel))=color('green');
  g1.nodes.graphics.colors(1,ls(sel))=color('red');
  show_graph(g1);
  halt()
end

See Also


<< add_edge_data Edges - Arcs arc_number >>