[Lemon-commits] [lemon_svn] jacint: r1497 - hugo/trunk/src/test

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:45:52 CET 2006


Author: jacint
Date: Thu Jan 27 17:11:54 2005
New Revision: 1497

Modified:
   hugo/trunk/src/test/max_matching_test.cc

Log:


Modified: hugo/trunk/src/test/max_matching_test.cc
==============================================================================
--- hugo/trunk/src/test/max_matching_test.cc	(original)
+++ hugo/trunk/src/test/max_matching_test.cc	Thu Jan 27 17:11:54 2005
@@ -15,6 +15,7 @@
  */
 
 #include <iostream>
+#include <vector>
 #include <queue>
 #include <math.h>
 #include <cstdlib>
@@ -23,8 +24,6 @@
 #include <lemon/invalid.h>
 #include <lemon/list_graph.h>
 #include <lemon/max_matching.h>
-//temporarily
-#include <work/jacint/graph_gen.h>
 
 using namespace std;
 using namespace lemon;
@@ -39,68 +38,89 @@
   typedef Graph::NodeIt NodeIt;
   typedef Graph::Node Node;
    
-  Graph G;
-
-  random_init(); 
-  randomGraph(G, random(5000), random(20000) );  
+  Graph g;
+  g.clear();
 
-  MaxMatching<Graph> max_matching(G);
+  std::vector<Graph::Node> nodes;
+  for (int i=0; i<13; ++i)
+      nodes.push_back(g.addNode());
+
+  g.addEdge(nodes[0], nodes[0]);
+  g.addEdge(nodes[6], nodes[10]);
+  g.addEdge(nodes[5], nodes[10]);
+  g.addEdge(nodes[4], nodes[10]);
+  g.addEdge(nodes[3], nodes[11]);  
+  g.addEdge(nodes[1], nodes[6]);
+  g.addEdge(nodes[4], nodes[7]);  
+  g.addEdge(nodes[1], nodes[8]);
+  g.addEdge(nodes[0], nodes[8]);
+  g.addEdge(nodes[3], nodes[12]);
+  g.addEdge(nodes[6], nodes[9]);
+  g.addEdge(nodes[9], nodes[11]);
+  g.addEdge(nodes[2], nodes[10]);
+  g.addEdge(nodes[10], nodes[8]);
+  g.addEdge(nodes[5], nodes[8]);
+  g.addEdge(nodes[6], nodes[3]);
+  g.addEdge(nodes[0], nodes[5]);
+  g.addEdge(nodes[6], nodes[12]);
+  
+  MaxMatching<Graph> max_matching(g);
   max_matching.runEdmonds(0);
   
   int s=0;
-  Graph::NodeMap<Node> mate(G,INVALID);
+  Graph::NodeMap<Node> mate(g,INVALID);
   max_matching.writeNMapNode(mate);
-  for(NodeIt v(G); v!=INVALID; ++v) {
+  for(NodeIt v(g); v!=INVALID; ++v) {
     if ( mate[v]!=INVALID ) ++s;
   }
   int size=(int)s/2;  //size will be used as the size of a maxmatching
 
-  for(NodeIt v(G); v!=INVALID; ++v) {
+  for(NodeIt v(g); v!=INVALID; ++v) {
     max_matching.mate(v);
   }
 
   check ( size == max_matching.size(), "mate() returns a different size matching than max_matching.size()" );
 
-  Graph::NodeMap<MaxMatching<Graph>::pos_enum> pos0(G);
+  Graph::NodeMap<MaxMatching<Graph>::pos_enum> pos0(g);
   max_matching.writePos(pos0);
   
   max_matching.resetMatching();
   max_matching.runEdmonds(1);
   s=0;
   max_matching.writeNMapNode(mate);
-  for(NodeIt v(G); v!=INVALID; ++v) {
+  for(NodeIt v(g); v!=INVALID; ++v) {
     if ( mate[v]!=INVALID ) ++s;
   }
   check ( (int)s/2 == size, "The size does not equal!" );
 
-  Graph::NodeMap<MaxMatching<Graph>::pos_enum> pos1(G);
+  Graph::NodeMap<MaxMatching<Graph>::pos_enum> pos1(g);
   max_matching.writePos(pos1);
 
   max_matching.run();
   s=0;
   max_matching.writeNMapNode(mate);
-  for(NodeIt v(G); v!=INVALID; ++v) {
+  for(NodeIt v(g); v!=INVALID; ++v) {
     if ( mate[v]!=INVALID ) ++s;
   }
   check ( (int)s/2 == size, "The size does not equal!" ); 
   
-  Graph::NodeMap<MaxMatching<Graph>::pos_enum> pos2(G);
+  Graph::NodeMap<MaxMatching<Graph>::pos_enum> pos2(g);
   max_matching.writePos(pos2);
 
   max_matching.resetMatching();
   max_matching.run();
   s=0;
   max_matching.writeNMapNode(mate);
-  for(NodeIt v(G); v!=INVALID; ++v) {
+  for(NodeIt v(g); v!=INVALID; ++v) {
     if ( mate[v]!=INVALID ) ++s;
   }
   check ( (int)s/2 == size, "The size does not equal!" ); 
   
-  Graph::NodeMap<MaxMatching<Graph>::pos_enum> pos(G);
+  Graph::NodeMap<MaxMatching<Graph>::pos_enum> pos(g);
   max_matching.writePos(pos);
    
   bool ismatching=true;
-  for(NodeIt v(G); v!=INVALID; ++v) {
+  for(NodeIt v(g); v!=INVALID; ++v) {
     if ( mate[v]!=INVALID ) {
       Node u=mate[v];
       if (mate[u]!=v) ismatching=false; 
@@ -109,7 +129,7 @@
   check ( ismatching, "It is not a matching!" );
 
   bool coincide=true;
-  for(NodeIt v(G); v!=INVALID; ++v) {
+  for(NodeIt v(g); v!=INVALID; ++v) {
    if ( pos0[v] != pos1[v] || pos1[v]!=pos2[v] || pos2[v]!=pos[v] ) {
      coincide=false;
     }
@@ -117,17 +137,17 @@
   check ( coincide, "The decompositions do not coincide! " );
 
   bool noedge=true;
-  for(UndirEdgeIt e(G); e!=INVALID; ++e) {
-   if ( (pos[G.target(e)]==max_matching.C && pos[G.source(e)]==max_matching.D) || 
-	 (pos[G.target(e)]==max_matching.D && pos[G.source(e)]==max_matching.C) )
+  for(UndirEdgeIt e(g); e!=INVALID; ++e) {
+   if ( (pos[g.target(e)]==max_matching.C && pos[g.source(e)]==max_matching.D) || 
+	 (pos[g.target(e)]==max_matching.D && pos[g.source(e)]==max_matching.C) )
       noedge=false; 
   }
   check ( noedge, "There are edges between D and C!" );
   
   bool oddcomp=true;
-  Graph::NodeMap<bool> todo(G,true);
+  Graph::NodeMap<bool> todo(g,true);
   int num_comp=0;
-  for(NodeIt v(G); v!=INVALID; ++v) {
+  for(NodeIt v(g); v!=INVALID; ++v) {
    if ( pos[v]==max_matching.D && todo[v] ) {
       int comp_size=1;
       ++num_comp;
@@ -137,8 +157,8 @@
       while (!Q.empty()) {
 	Node w=Q.front();	
 	Q.pop();
-	for(IncEdgeIt e(G,w); e!=INVALID; ++e) {
-	  Node u=G.target(e);
+	for(IncEdgeIt e(g,w); e!=INVALID; ++e) {
+	  Node u=g.target(e);
 	  if ( pos[u]==max_matching.D && todo[u] ) {
 	    ++comp_size;
 	    Q.push(u);
@@ -149,43 +169,14 @@
       if ( !(comp_size % 2) ) oddcomp=false;  
     }
   }
-  check ( oddcomp, "A component of G[D] is not odd." );
+  check ( oddcomp, "A component of g[D] is not odd." );
 
   int barrier=0;
-  for(NodeIt v(G); v!=INVALID; ++v) {
+  for(NodeIt v(g); v!=INVALID; ++v) {
     if ( pos[v]==max_matching.A ) ++barrier;
   }
-  int expected_size=(int)( countNodes(G)-num_comp+barrier)/2;
+  int expected_size=(int)( countNodes(g)-num_comp+barrier)/2;
   check ( size==expected_size, "The size of the matching is wrong." );
   
   return 0;
 }
-
-
-void random_init()
-{
-  unsigned int seed = getpid();
-  seed |= seed << 15;
-  seed ^= time(0);
-  
-  srand(seed);
-}
-
-
-int random(int m)
-{
-  return int( double(m) * rand() / (RAND_MAX + 1.0) );
-}
-
-
-/// Generates a random graph with n nodes and m edges.
-/// Before generating the random graph, \c g.clear() is called.
-template<typename Graph>
-void randomGraph(Graph& g, int n, int m) {
-  g.clear();
-  std::vector<typename Graph::Node> nodes;
-  for (int i=0; i<n; ++i)
-    nodes.push_back(g.addNode());
-  for (int i=0; i<m; ++i) 
-    g.addEdge(nodes[random(n)], nodes[random(n)]);
-}



More information about the Lemon-commits mailing list