src/work/marci/bipartite_graph_wrapper_test.cc
author klao
Sun, 09 Jan 2005 20:08:53 +0000
changeset 1064 5f0a20861a77
parent 921 818510fa3d99
permissions -rw-r--r--
Doxyfile: minor changes
     1 // -*- c++ -*-
     2 #include <iostream>
     3 #include <fstream>
     4 #include <vector>
     5 
     6 //#include <sage_graph.h>
     7 #include <lemon/smart_graph.h>
     8 //#include <dimacs.h>
     9 #include <lemon/time_measure.h>
    10 //#include <for_each_macros.h>
    11 #include <bfs_dfs.h>
    12 #include <lemon/graph_wrapper.h>
    13 #include <bipartite_graph_wrapper.h>
    14 #include <lemon/maps.h>
    15 #include <lemon/preflow.h>
    16 #include <augmenting_flow.h>
    17 
    18 using std::cout;
    19 using std::endl;
    20 
    21 using namespace lemon;
    22 
    23 int main() {
    24   //typedef UndirSageGraph Graph; 
    25   typedef SmartGraph Graph;
    26   typedef Graph::Node Node;
    27   typedef Graph::NodeIt NodeIt;
    28   typedef Graph::Edge Edge;
    29   typedef Graph::EdgeIt EdgeIt;
    30   typedef Graph::OutEdgeIt OutEdgeIt;
    31 
    32   Graph g;
    33 //   std::vector<Graph::Node> s_nodes;
    34 //   std::vector<Graph::Node> t_nodes;
    35 //   for (int i=0; i<3; ++i) s_nodes.push_back(g.addNode());
    36 //   for (int i=0; i<3; ++i) t_nodes.push_back(g.addNode());
    37 //   g.addEdge(s_nodes[0], t_nodes[2]);
    38 //   g.addEdge(t_nodes[1], s_nodes[2]);
    39 //   g.addEdge(s_nodes[0], t_nodes[1]);
    40   
    41 //   Graph::NodeMap<int> ref_map(g, -1);
    42 //   IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
    43 //   for (int i=0; i<3; ++i) bipartite_map.insert(s_nodes[i], false);
    44 //   for (int i=0; i<3; ++i) bipartite_map.insert(t_nodes[i], true);
    45 
    46   std::vector<Graph::Node> nodes;
    47   for (int i=0; i<3; ++i) nodes.push_back(g.addNode());
    48   for (int i=3; i<6; ++i) nodes.push_back(g.addNode());
    49   g.addEdge(nodes[0], nodes[3+2]);
    50   g.addEdge(nodes[3+1], nodes[2]);
    51   g.addEdge(nodes[0], nodes[3+1]);
    52   
    53   Graph::NodeMap<int> ref_map(g, -1);
    54   IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
    55   for (int i=0; i<3; ++i) bipartite_map.insert(nodes[i], false);
    56   for (int i=3; i<6; ++i) bipartite_map.insert(nodes[i], true);
    57 
    58   Graph::Node u;
    59   cout << "These nodes will be in S:" << endl;
    60   //FIXME azert kellene ++, es invalid vizsgalat u-bol, hogy ezt le lehessen 
    61   //irni 1etlen FOR_EACH-csel.
    62   for (bipartite_map.first(u, false); u!=INVALID; bipartite_map.next(u)) 
    63     cout << g.id(u) << " ";
    64   cout << endl;
    65   cout << "These nodes will be in T:" << endl;
    66   for (bipartite_map.first(u, true); u!=INVALID; bipartite_map.next(u)) 
    67     cout << g.id(u) << " ";
    68   cout << endl;
    69 
    70   typedef BipartiteGraphWrapper<Graph> BGW;
    71   BGW bgw(g, bipartite_map);
    72 
    73   cout << "Nodes by NodeIt:" << endl;
    74   for (BGW::NodeIt n(bgw); n!=INVALID; ++n)
    75     cout << g.id(n) << " ";
    76   cout << endl;
    77 
    78   cout << "Nodes in S by ClassNodeIt:" << endl;
    79   for (BGW::ClassNodeIt n(bgw, bgw.S_CLASS); n!=INVALID; ++n)
    80     cout << g.id(n) << " ";
    81   cout << endl;
    82 
    83   cout << "Nodes in T by ClassNodeIt:" << endl;
    84   for (BGW::ClassNodeIt n(bgw, bgw.T_CLASS); n!=INVALID; ++n)
    85     cout << g.id(n) << " ";
    86   cout << endl;
    87 
    88   cout << "Edges of the bipartite graph:" << endl;
    89   for (BGW::EdgeIt e(bgw); e!=INVALID; ++e)
    90     cout << g.id(bgw.source(e)) << "->" << g.id(bgw.target(e)) << endl;
    91 
    92   BGW::NodeMap<int> dbyj(bgw);
    93   BGW::EdgeMap<int> dbyxcj(bgw);
    94 
    95 //   typedef stBipartiteGraphWrapper<BGW> stGW;
    96 //   stGW stgw(bgw);
    97 //   ConstMap<stGW::Edge, int> const1map(1);
    98 //   stGW::NodeMap<int> ize(stgw);
    99 //   stGW::EdgeMap<int> flow(stgw);
   100 
   101 //   BfsIterator< BGW, BGW::NodeMap<bool> > bfs(bgw);
   102 //   Graph::NodeIt si;
   103 //   Graph::Node s; 
   104 //   s=g.first(si);
   105 //   bfs.pushAndSetReached(BGW::Node(s));
   106 //   while (!bfs.finished()) { ++bfs; }
   107 
   108 //   FOR_EACH_LOC(stGW::NodeIt, n, stgw) { 
   109 //     cout << "out-edges of " << n << ":" << endl; 
   110 //     FOR_EACH_INC_LOC(stGW::OutEdgeIt, e, stgw, n) { 
   111 //       cout << " " << e << endl;
   112 //       cout << " aNode: " << stgw.aNode(e) << endl;
   113 //       cout << " bNode: " << stgw.bNode(e) << endl;      
   114 //     }
   115 //     cout << "in-edges of " << n << ":" << endl; 
   116 //     FOR_EACH_INC_LOC(stGW::InEdgeIt, e, stgw, n) { 
   117 //       cout << " " << e << endl;
   118 //       cout << " aNode: " << stgw.aNode(e) << endl;
   119 //       cout << " bNode: " << stgw.bNode(e) << endl;     
   120 //     }
   121 //   }
   122 //   cout << "Edges of the stGraphWrapper:" << endl; 
   123 //   FOR_EACH_LOC(stGW::EdgeIt, n, stgw) { 
   124 //     cout << " " << n << endl;
   125 //   }
   126 
   127 //   stGW::NodeMap<bool> b(stgw);
   128 //   FOR_EACH_LOC(stGW::NodeIt, n, stgw) { 
   129 //     cout << n << ": " << b[n] << endl;
   130 //   }
   131 
   132 //   cout << "Bfs from s:" << endl;
   133 //   BfsIterator< stGW, stGW::NodeMap<bool> > bfs_stgw(stgw);
   134 //   bfs_stgw.pushAndSetReached(stgw.S_NODE);
   135 //   while (!bfs_stgw.finished()) { 
   136 //     cout << " " << stGW::OutEdgeIt(bfs_stgw) << endl;
   137 //     ++bfs_stgw; 
   138 //   }
   139   
   140 //   AugmentingFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> > 
   141 //     max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow);
   142 //   while (max_flow_test.augmentOnShortestPath()) { }
   143 
   144 //   cout << max_flow_test.flowValue() << std::endl;
   145 
   146   return 0;
   147 }