Removed some unnecessary files.
2 * src/test/max_matching_test.cc - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
22 #include "test_tools.h"
23 #include <lemon/invalid.h>
24 #include <lemon/list_graph.h>
25 #include <lemon/max_matching.h>
27 #include <work/jacint/graph_gen.h>
30 using namespace lemon;
34 typedef UndirListGraph Graph;
36 typedef Graph::Edge Edge;
37 typedef Graph::UndirEdgeIt UndirEdgeIt;
38 typedef Graph::IncEdgeIt IncEdgeIt;
39 typedef Graph::NodeIt NodeIt;
40 typedef Graph::Node Node;
45 randomGraph(G, random(5000), random(20000) );
47 MaxMatching<Graph> max_matching(G);
48 max_matching.runEdmonds(0);
51 Graph::NodeMap<Node> mate(G,INVALID);
52 max_matching.writeNMapNode(mate);
53 for(NodeIt v(G); v!=INVALID; ++v) {
54 if ( mate[v]!=INVALID ) ++s;
56 int size=(int)s/2; //size will be used as the size of a maxmatching
58 for(NodeIt v(G); v!=INVALID; ++v) {
62 check ( size == max_matching.size(), "mate() returns a different size matching than max_matching.size()" );
64 Graph::NodeMap<MaxMatching<Graph>::pos_enum> pos0(G);
65 max_matching.writePos(pos0);
67 max_matching.resetMatching();
68 max_matching.runEdmonds(1);
70 max_matching.writeNMapNode(mate);
71 for(NodeIt v(G); v!=INVALID; ++v) {
72 if ( mate[v]!=INVALID ) ++s;
74 check ( (int)s/2 == size, "The size does not equal!" );
76 Graph::NodeMap<MaxMatching<Graph>::pos_enum> pos1(G);
77 max_matching.writePos(pos1);
81 max_matching.writeNMapNode(mate);
82 for(NodeIt v(G); v!=INVALID; ++v) {
83 if ( mate[v]!=INVALID ) ++s;
85 check ( (int)s/2 == size, "The size does not equal!" );
87 Graph::NodeMap<MaxMatching<Graph>::pos_enum> pos2(G);
88 max_matching.writePos(pos2);
90 max_matching.resetMatching();
93 max_matching.writeNMapNode(mate);
94 for(NodeIt v(G); v!=INVALID; ++v) {
95 if ( mate[v]!=INVALID ) ++s;
97 check ( (int)s/2 == size, "The size does not equal!" );
99 Graph::NodeMap<MaxMatching<Graph>::pos_enum> pos(G);
100 max_matching.writePos(pos);
102 bool ismatching=true;
103 for(NodeIt v(G); v!=INVALID; ++v) {
104 if ( mate[v]!=INVALID ) {
106 if (mate[u]!=v) ismatching=false;
109 check ( ismatching, "It is not a matching!" );
112 for(NodeIt v(G); v!=INVALID; ++v) {
113 if ( pos0[v] != pos1[v] || pos1[v]!=pos2[v] || pos2[v]!=pos[v] ) {
117 check ( coincide, "The decompositions do not coincide! " );
120 for(UndirEdgeIt e(G); e!=INVALID; ++e) {
121 if ( (pos[G.target(e)]==max_matching.C && pos[G.source(e)]==max_matching.D) ||
122 (pos[G.target(e)]==max_matching.D && pos[G.source(e)]==max_matching.C) )
125 check ( noedge, "There are edges between D and C!" );
128 Graph::NodeMap<bool> todo(G,true);
130 for(NodeIt v(G); v!=INVALID; ++v) {
131 if ( pos[v]==max_matching.D && todo[v] ) {
140 for(IncEdgeIt e(G,w); e!=INVALID; ++e) {
142 if ( pos[u]==max_matching.D && todo[u] ) {
149 if ( !(comp_size % 2) ) oddcomp=false;
152 check ( oddcomp, "A component of G[D] is not odd." );
155 for(NodeIt v(G); v!=INVALID; ++v) {
156 if ( pos[v]==max_matching.A ) ++barrier;
158 int expected_size=(int)( countNodes(G)-num_comp+barrier)/2;
159 check ( size==expected_size, "The size of the matching is wrong." );
167 unsigned int seed = getpid();
177 return int( double(m) * rand() / (RAND_MAX + 1.0) );
181 /// Generates a random graph with n nodes and m edges.
182 /// Before generating the random graph, \c g.clear() is called.
183 template<typename Graph>
184 void randomGraph(Graph& g, int n, int m) {
186 std::vector<typename Graph::Node> nodes;
187 for (int i=0; i<n; ++i)
188 nodes.push_back(g.addNode());
189 for (int i=0; i<m; ++i)
190 g.addEdge(nodes[random(n)], nodes[random(n)]);