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