1 // Copyright (C) 2012, Michele Caini.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // Two Graphs Common Spanning Trees Algorithm
7 // Based on academic article of Mint, Read and Tarjan
8 // Efficient Algorithm for Common Spanning Tree Problem
9 // Electron. Lett., 28 April 1983, Volume 19, Issue 9, p.346-347
12 #include <boost/graph/adjacency_list.hpp>
13 #include <boost/graph/two_graphs_common_spanning_trees.hpp>
23 boost::vecS
, // OutEdgeList
24 boost::vecS
, // VertexList
25 boost::undirectedS
, // Directed
26 boost::no_property
, // VertexProperties
27 boost::no_property
, // EdgeProperties
28 boost::no_property
, // GraphProperties
29 boost::listS
// EdgeList
35 boost::graph_traits
<Graph
>::vertex_descriptor
39 boost::graph_traits
<Graph
>::edge_descriptor
43 boost::graph_traits
<Graph
>::vertex_iterator
47 boost::graph_traits
<Graph
>::edge_iterator
51 int main(int argc
, char **argv
)
54 vector
< edge_descriptor
> iG_o
;
55 vector
< edge_descriptor
> vG_o
;
57 iG_o
.push_back(boost::add_edge(0, 1, iG
).first
);
58 iG_o
.push_back(boost::add_edge(0, 2, iG
).first
);
59 iG_o
.push_back(boost::add_edge(0, 3, iG
).first
);
60 iG_o
.push_back(boost::add_edge(0, 4, iG
).first
);
61 iG_o
.push_back(boost::add_edge(1, 2, iG
).first
);
62 iG_o
.push_back(boost::add_edge(3, 4, iG
).first
);
64 vG_o
.push_back(boost::add_edge(1, 2, vG
).first
);
65 vG_o
.push_back(boost::add_edge(2, 0, vG
).first
);
66 vG_o
.push_back(boost::add_edge(2, 3, vG
).first
);
67 vG_o
.push_back(boost::add_edge(4, 3, vG
).first
);
68 vG_o
.push_back(boost::add_edge(0, 3, vG
).first
);
69 vG_o
.push_back(boost::add_edge(0, 4, vG
).first
);
71 vector
<bool> inL(iG_o
.size(), false);
73 std::vector
< std::vector
<bool> > coll
;
74 boost::tree_collector
<
75 std::vector
< std::vector
<bool> >,
77 > tree_collector(coll
);
78 boost::two_graphs_common_spanning_trees
88 std::vector
< std::vector
<bool> >::iterator it
;
89 for(it
= coll
.begin(); it
!= coll
.end(); ++it
) {
90 // Here you can play with the trees that the algorithm has found.