min_weight_tree — minimum weight spanning tree
t = min_weight_tree([i],g)
integer, node number of the root of the tree
row vector of integer numbers of the arcs of the tree if it exists
min_weight_tree
tries to find a minimum weight
spanning tree for the graph g
. The optional argument
i
is the number of the root node of the tree; its
default value is node number 1. This node is meaningless for an
undirected graph.
The weights are given by the weight
field of the
graph edges_data_structure. If its value is not
given, it is assumed to be equal to 0 on each edge. Weigths can
be positive, equal to 0 or negative. To compute a spanning tree
without dealing with weights, give to weights a value of 0 on each
edge.
min_weight_tree
returns the tree t
as
a row vector of the arc numbers (directed graph) or edge numbers
(undirected graph) if it exists or the empty vector
[]
otherwise. If the tree exists, the dimension of
t
is the number of nodes less 1. If
t(i)
is the root of the tree: - for j < i,
t(j)
is the number of the arc in the tree after node
t(j)
- for j > i, t(j)
is the number
of the arc in the tree before node t(j)
ta=[1 1 2 2 2 3 4 5 5 7 8 8 9 10 10 10 11 12 13 13 13 14 15 16 16 17 17]; he=[2 10 3 5 7 4 2 4 6 8 6 9 7 7 11 15 12 13 9 10 14 11 16 1 17 14 15]; g=make_graph('foo',1,17,ta,he); g.nodes.graphics.x=[117,57,7,4,57,57,112,111,145,167,227,232,195,287,291,354,296]; g.nodes.graphics.y=[5,42,87,134,89,135,86,137,191,46,80,135,189,197,69,51,126]; g.nodes.graphics.type(1)=2; show_graph(g); t=min_weight_tree(1,g); g.edges.graphics.foreground(t)=color('red'); show_graph(g);