COIN-OR::LEMON - Graph Library

Ignore:
Timestamp:
08/23/04 13:06:00 (20 years ago)
Author:
marci
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1031
Message:

stGraphWrapper modifications

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/work/marci/bipartite_matching_try_3.cc

    r762 r768  
    1818using namespace hugo;
    1919
     20using std::cout;
     21using std::endl;
     22
    2023int main() {
    2124  //typedef UndirListGraph Graph;
     
    3134
    3235  int a;
    33   std::cout << "number of nodes in the first color class=";
     36  cout << "number of nodes in the first color class=";
    3437  std::cin >> a;
    3538  int b;
    36   std::cout << "number of nodes in the second color class=";
     39  cout << "number of nodes in the second color class=";
    3740  std::cin >> b;
    3841  int m;
    39   std::cout << "number of edges=";
     42  cout << "number of edges=";
    4043  std::cin >> m;
    4144 
    42   std::cout << "Generatig a random bipartite graph..." << std::endl;
     45  cout << "Generatig a random bipartite graph..." << endl;
    4346  random_init();
    4447  randomBipartiteGraph(g, a, b, m);
    4548
    46 //   std::cout << "Edges of the bipartite graph:" << std::endl;
    47 //   FOR_EACH_LOC(EdgeIt, e, g) std::cout << e << " ";
    48 //   std::cout << std::endl;
     49//   cout << "Edges of the bipartite graph:" << endl;
     50//   FOR_EACH_LOC(EdgeIt, e, g) cout << e << " ";
     51//   cout << endl;
    4952
    50 //   std::cout << "Nodes:" << std::endl;
    51 //   FOR_EACH_LOC(Graph::NodeIt, v, g) std::cout << v << " ";
    52 //   std::cout << std::endl;
    53 //   std::cout << "Nodes in T:" << std::endl;
    54 //   FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) std::cout << v << " ";
    55 //   std::cout << std::endl;
    56 //   std::cout << "Nodes in S:" << std::endl;
    57 //   FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) std::cout << v << " ";
    58 //   std::cout << std::endl;
     53//   cout << "Nodes:" << endl;
     54//   FOR_EACH_LOC(Graph::NodeIt, v, g) cout << v << " ";
     55//   cout << endl;
     56//   cout << "Nodes in T:" << endl;
     57//   FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " ";
     58//   cout << endl;
     59//   cout << "Nodes in S:" << endl;
     60//   FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " ";
     61//   cout << endl;
    5962
    60 //   std::cout << "Erasing the first node..." << std::endl;
     63//   cout << "Erasing the first node..." << endl;
    6164//   NodeIt n;
    6265//   g.first(n);
    6366//   g.erase(n);
    64 //   std::cout << "Nodes of the bipartite graph:" << std::endl;
    65 //   FOR_EACH_GLOB(n, g) std::cout << n << " ";
    66 //   std::cout << std::endl;
     67//   cout << "Nodes of the bipartite graph:" << endl;
     68//   FOR_EACH_GLOB(n, g) cout << n << " ";
     69//   cout << endl;
    6770
    68 //   std::cout << "Nodes in T:" << std::endl;
    69 //   FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) std::cout << v << " ";
    70 //   std::cout << std::endl;
    71 //   std::cout << "Nodes in S:" << std::endl;
    72 //   FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) std::cout << v << " ";
    73 //   std::cout << std::endl;
     71//   cout << "Nodes in T:" << endl;
     72//   FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " ";
     73//   cout << endl;
     74//   cout << "Nodes in S:" << endl;
     75//   FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " ";
     76//   cout << endl;
    7477
    75   typedef stGraphWrapper<Graph> stGW;
     78  typedef stBipartiteGraphWrapper<Graph> stGW;
    7679  stGW stgw(g);
    7780  ConstMap<stGW::Edge, int> const1map(1);
    7881
    7982  Timer ts;
     83  cout << "max bipartite matching with stGraphWrapper..." << endl;
    8084  ts.reset();
    8185  stGW::EdgeMap<int> flow(stgw);
     
    8791//  while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
    8892//  while (max_flow_test.augmentOnBlockingFlow2()) {
    89 //   std::cout << max_flow_test.flowValue() << std::endl;
     93//   cout << max_flow_test.flowValue() << endl;
    9094//  }
    91   std::cout << "max flow value: " << max_flow_test.flowValue() << std::endl;
    92   std::cout << "elapsed time: " << ts << std::endl;
     95  cout << "matching value: " << max_flow_test.flowValue() << endl;
     96  cout << "elapsed time: " << ts << endl;
    9397//   FOR_EACH_LOC(stGW::EdgeIt, e, stgw) {
    94 //     if (flow[e]) std::cout << e << std::endl;
     98//     if (flow[e]) cout << e << endl;
    9599//   }
    96   std::cout << std::endl;
     100  cout << endl;
    97101
    98102  typedef ConstMap<Graph::Edge, int> EdgeCap;
     
    105109  NodeFlow gnf(g); //0
    106110
    107   typedef stGraphWrapper<Graph>::EdgeMapWrapper<EdgeCap, NodeCap> CapMap;
    108   typedef stGraphWrapper<Graph>::EdgeMapWrapper<EdgeFlow, NodeFlow> FlowMap;
     111  typedef stGW::EdgeMapWrapper<EdgeCap, NodeCap> CapMap;
     112  typedef stGW::EdgeMapWrapper<EdgeFlow, NodeFlow> FlowMap;
    109113  CapMap cm(ge1, gn1);
    110114  FlowMap fm(gef, gnf);
    111115
    112116  //Timer ts;
     117  cout << "max bipartite matching with stGraphWrapper..." << endl;
    113118  ts.reset();
    114119  //stGW::EdgeMap<int> flow(stgw);
     
    120125//  while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
    121126//  while (max_flow_test.augmentOnBlockingFlow2()) {
    122 //   std::cout << max_flow_test.flowValue() << std::endl;
     127//   cout << max_flow_test.flowValue() << endl;
    123128//  }
    124   std::cout << "max flow value: " << max_flow_test1.flowValue() << std::endl;
    125   std::cout << "elapsed time: " << ts << std::endl;
     129  cout << "matching value: " << max_flow_test1.flowValue() << endl;
     130  cout << "elapsed time: " << ts << endl;
    126131//   FOR_EACH_LOC(Graph::EdgeIt, e, g) {
    127 //     if (gef[e]) std::cout << e << std::endl;
     132//     if (gef[e]) cout << e << endl;
    128133//   }
    129   std::cout << std::endl;
     134  cout << endl;
    130135
     136  cout << "max bipartite matching with stGraphWrapper..." << endl;
    131137  ts.reset();
    132138  FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0);
     
    137143  matching_test.run();
    138144
    139   std::cout << "max flow value: " << matching_test.matchingValue() << std::endl;
    140   std::cout << "elapsed time: " << ts << std::endl;
     145  cout << "matching value: " << matching_test.matchingValue() << endl;
     146  cout << "elapsed time: " << ts << endl;
    141147//   FOR_EACH_LOC(Graph::EdgeIt, e, g) {
    142 //     if (gef[e]) std::cout << e << std::endl;
     148//     if (gef[e]) cout << e << endl;
    143149//   }
    144   std::cout << std::endl;
     150  cout << endl;
    145151
     152  cout << "max bipartite matching with MaxBipartiteMatching..." << endl;
    146153  ts.reset();
    147154  FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0);
    148155  //FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0);
    149   MaxBipartiteMatching<Graph, ConstMap<Graph::Edge, int>, ConstMap<Graph::Node, int>,
    150     Graph::EdgeMap<int>, Graph::NodeMap<int> >
    151     matching_test_1(g, ge1, gn1, gef/*, gnf*/);
     156  typedef MaxBipartiteMatching<Graph, ConstMap<Graph::Edge, int>,
     157    ConstMap<Graph::Node, int>,
     158    Graph::EdgeMap<int>, Graph::NodeMap<int> > MaxBipartiteMatching;
     159  MaxBipartiteMatching matching_test_1(g, ge1, gn1, gef/*, gnf*/);
    152160  matching_test_1.run();
    153161
    154   std::cout << "max flow value: " << matching_test_1.matchingValue() << std::endl;
    155   std::cout << "elapsed time: " << ts << std::endl;
     162  cout << "matching value: " << matching_test_1.matchingValue() << endl;
     163  cout << "elapsed time: " << ts << endl;
    156164//   FOR_EACH_LOC(Graph::EdgeIt, e, g) {
    157 //     if (gef[e]) std::cout << e << std::endl;
     165//     if (gef[e]) cout << e << endl;
    158166//   }
    159   std::cout << std::endl;
     167  cout << endl;
     168
     169  cout << "testing optimality with MaxBipartiteMatching..." << endl;
     170  ts.reset();
     171  matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING);
     172  cout << "matching value: " << matching_test_1.matchingValue() << endl;
     173  cout << "elapsed time: " << ts << endl;
     174
     175  cout << "testing optimality with MaxBipartiteMatching..." << endl;
     176  ts.reset();
     177  matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING_WITH_GOOD_NODE_FLOW);
     178  cout << "matching value: " << matching_test_1.matchingValue() << endl;
     179  cout << "elapsed time: " << ts << endl;
    160180
    161181  return 0;
Note: See TracChangeset for help on using the changeset viewer.