Update contrib.
1 //=======================================================================
2 // Copyright (c) 2005 Aaron Windsor
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 //=======================================================================
11 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
15 #include <boost/graph/adjacency_list.hpp>
16 #include <boost/graph/max_cardinality_matching.hpp>
23 #include "std_log_result.h"
24 #define LOG_FILENAME_LINE __FILE__, __LINE__
27 #include <boost/test/minimal.hpp>
29 using namespace boost;
31 typedef adjacency_list<vecS, vecS, undirectedS> my_graph;
33 int test_main(int argc, char* argv[])
37 // Create the following graph: (it'll look better when output
38 // to the terminal in a fixed width font...)
40 const int n_vertices = 18;
42 std::vector<std::string> ascii_graph;
44 ascii_graph.push_back(" 0 1---2 3 ");
45 ascii_graph.push_back(" \\ / \\ / ");
46 ascii_graph.push_back(" 4---5 6---7 ");
47 ascii_graph.push_back(" | | | | ");
48 ascii_graph.push_back(" 8---9 10---11 ");
49 ascii_graph.push_back(" / \\ / \\ ");
50 ascii_graph.push_back(" 12 13 14---15 16 17 ");
52 // It has a perfect matching of size 8. There are two isolated
53 // vertices that we'll use later...
55 my_graph g(n_vertices);
57 // our vertices are stored in a vector, so we can refer to vertices
58 // by integers in the range 0..15
78 std::vector<graph_traits<my_graph>::vertex_descriptor> mate(n_vertices);
80 // find the maximum cardinality matching. we'll use a checked version
81 // of the algorithm, which takes a little longer than the unchecked
82 // version, but has the advantage that it will return "false" if the
83 // matching returned is not actually a maximum cardinality matching
88 bool success = checked_edmonds_maximum_cardinality_matching(g, &mate[0]);
92 std::cout << "In the following graph:" << std::endl << std::endl;
94 for(std::vector<std::string>::iterator itr = ascii_graph.begin(); itr != ascii_graph.end(); ++itr)
95 std::cout << *itr << std::endl;
97 std::cout << std::endl << "Found a matching of size " << matching_size(g, &mate[0]) << std::endl;
99 std::cout << "The matching is:" << std::endl;
101 graph_traits<my_graph>::vertex_iterator vi, vi_end;
102 for(tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
103 if (mate[*vi] != graph_traits<my_graph>::null_vertex() && *vi < mate[*vi])
104 std::cout << "{" << *vi << ", " << mate[*vi] << "}" << std::endl;
106 std::cout << std::endl;
108 //now we'll add two edges, and the perfect matching has size 9
110 ascii_graph.pop_back();
111 ascii_graph.push_back(" 12---13 14---15 16---17 ");
116 #ifndef __SYMBIAN32__
117 success = checked_edmonds_maximum_cardinality_matching(g, &mate[0]);
121 std::cout << "In the following graph:" << std::endl << std::endl;
123 for(std::vector<std::string>::iterator itr = ascii_graph.begin(); itr != ascii_graph.end(); ++itr)
124 std::cout << *itr << std::endl;
126 std::cout << std::endl << "Found a matching of size " << matching_size(g, &mate[0]) << std::endl;
128 std::cout << "The matching is:" << std::endl;
130 for(tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
131 if (mate[*vi] != graph_traits<my_graph>::null_vertex() && *vi < mate[*vi])
132 std::cout << "{" << *vi << ", " << mate[*vi] << "}" << std::endl;
136 std_log(LOG_FILENAME_LINE,"[End Test Case ]");
137 testResultXml("matching_example");