src/work/athos/pf_demo.cc
author jacint
Sat, 20 Mar 2004 20:08:24 +0000
changeset 221 d8a67c5b26d1
parent 105 a3c73e9b9b2e
child 331 f5461f8bc59b
permissions -rw-r--r--
map.get(v) <- map[v] csere
athos@36
     1
#include <iostream>
athos@36
     2
#include <vector>
athos@36
     3
#include <string>
athos@36
     4
athos@77
     5
#include "list_graph.hh"
athos@36
     6
#include "marci_graph_traits.hh"
athos@77
     7
//#include "marci_property_vector.hh"
athos@36
     8
#include "preflow_push.hh"
athos@36
     9
alpar@105
    10
using namespace hugo;
athos@36
    11
athos@36
    12
athos@36
    13
int main (int, char*[])
athos@36
    14
{
athos@36
    15
athos@36
    16
  
athos@77
    17
  typedef ListGraph::NodeIt NodeIt;
athos@77
    18
  typedef ListGraph::EdgeIt EdgeIt;
athos@77
    19
  /*
athos@77
    20
  typedef ListGraph::EachNodeIt EachNodeIt;
athos@77
    21
  typedef ListGraph::EachEdgeIt EachEdgeIt;
athos@77
    22
  typedef ListGraph::OutEdgeIt OutEdgeIt;
athos@77
    23
  typedef ListGraph::InEdgeIt InEdgeIt;
athos@77
    24
  typedef ListGraph::SymEdgeIt SymEdgeIt;
athos@77
    25
  */
athos@201
    26
  ListGraph flowG;
athos@201
    27
athos@201
    28
  /*
athos@77
    29
  //Marci példája
athos@201
    30
athos@77
    31
athos@77
    32
  NodeIt s=flowG.addNode();
athos@77
    33
  NodeIt v1=flowG.addNode();
athos@77
    34
  NodeIt v2=flowG.addNode();
athos@77
    35
  NodeIt v3=flowG.addNode();
athos@77
    36
  NodeIt v4=flowG.addNode();
athos@77
    37
  NodeIt t=flowG.addNode();
athos@77
    38
  
athos@77
    39
athos@77
    40
  EdgeIt s_v1=flowG.addEdge(s, v1);
athos@77
    41
  EdgeIt s_v2=flowG.addEdge(s, v2);
athos@77
    42
  EdgeIt v1_v2=flowG.addEdge(v1, v2);
athos@77
    43
  EdgeIt v2_v1=flowG.addEdge(v2, v1);
athos@77
    44
  EdgeIt v1_v3=flowG.addEdge(v1, v3);
athos@77
    45
  EdgeIt v3_v2=flowG.addEdge(v3, v2);
athos@77
    46
  EdgeIt v2_v4=flowG.addEdge(v2, v4);
athos@77
    47
  EdgeIt v4_v3=flowG.addEdge(v4, v3);
athos@77
    48
  EdgeIt v3_t=flowG.addEdge(v3, t);
athos@77
    49
  EdgeIt v4_t=flowG.addEdge(v4, t);
athos@77
    50
athos@77
    51
  ListGraph::EdgeMap<int> cap(flowG);
athos@77
    52
athos@77
    53
  cap.set(s_v1, 16);
athos@77
    54
  cap.set(s_v2, 13);
athos@77
    55
  cap.set(v1_v2, 10);
athos@77
    56
  cap.set(v2_v1, 4);
athos@77
    57
  cap.set(v1_v3, 12);
athos@77
    58
  cap.set(v3_v2, 9);
athos@77
    59
  cap.set(v2_v4, 14);
athos@77
    60
  cap.set(v4_v3, 7);
athos@77
    61
  cap.set(v3_t, 20);
athos@77
    62
  cap.set(v4_t, 4);
athos@201
    63
  */
athos@77
    64
athos@77
    65
athos@201
    66
  //Ahuja könyv példája
athos@77
    67
athos@201
    68
  NodeIt s=flowG.addNode();
athos@201
    69
  NodeIt v2=flowG.addNode();
athos@201
    70
  NodeIt v3=flowG.addNode();
athos@201
    71
  NodeIt v4=flowG.addNode();
athos@201
    72
  NodeIt v5=flowG.addNode();
athos@201
    73
  NodeIt t=flowG.addNode();
athos@77
    74
athos@201
    75
  EdgeIt s_v2=flowG.addEdge(s, v2);
athos@201
    76
  EdgeIt s_v3=flowG.addEdge(s, v3);
athos@201
    77
  EdgeIt v2_v4=flowG.addEdge(v2, v4);
athos@201
    78
  EdgeIt v2_v5=flowG.addEdge(v2, v5);
athos@201
    79
  EdgeIt v3_v5=flowG.addEdge(v3, v5);
athos@201
    80
  EdgeIt v4_t=flowG.addEdge(v4, t);
athos@201
    81
  EdgeIt v5_t=flowG.addEdge(v5, t);
athos@36
    82
  
athos@36
    83
  //Kis modositas
athos@201
    84
  //edge_iterator v2_s=flowG.add_edge(v2, s);
athos@36
    85
athos@201
    86
  ListGraph::EdgeMap<int> cap(flowG);
athos@201
    87
athos@201
    88
  cap.set(s_v2, 10);
athos@201
    89
  cap.set(s_v3, 10);
athos@201
    90
  cap.set(v2_v4, 5);
athos@201
    91
  cap.set(v2_v5, 8);
athos@201
    92
  cap.set(v3_v5, 5);
athos@201
    93
  cap.set(v4_t, 8);
athos@201
    94
  cap.set(v5_t, 8);
athos@36
    95
athos@36
    96
  //Kis modositas
athos@201
    97
  //cap.put(v2_s, 100);
athos@201
    98
 
athos@36
    99
athos@77
   100
athos@77
   101
athos@36
   102
  /*Egyszerű példa
athos@77
   103
  NodeIt s=flow_test.add_node();
athos@77
   104
  NodeIt v1=flow_test.add_node();
athos@77
   105
  NodeIt v2=flow_test.add_node();
athos@77
   106
  NodeIt t=flow_test.add_node();
athos@36
   107
  
athos@36
   108
  node_property_vector<list_graph, std::string> node_name(flow_test);
athos@36
   109
  node_name.put(s, "s");
athos@36
   110
  node_name.put(v1, "v1");
athos@36
   111
  node_name.put(v2, "v2");
athos@36
   112
  node_name.put(t, "t");
athos@36
   113
athos@36
   114
  edge_iterator s_v1=flow_test.add_edge(s, v1);
athos@36
   115
  edge_iterator v1_v2=flow_test.add_edge(v1, v2);
athos@36
   116
  edge_iterator v2_t=flow_test.add_edge(v2, t);
athos@36
   117
athos@36
   118
  edge_property_vector<list_graph, int> cap(flow_test); 
athos@36
   119
    
athos@36
   120
  cap.put(s_v1, 16);
athos@36
   121
  cap.put(v1_v2, 10);
athos@36
   122
  cap.put(v2_t, 4);
athos@36
   123
  */
athos@36
   124
athos@36
   125
  std::cout << "preflow-push algorithm test..." << std::endl;
athos@77
   126
athos@77
   127
  /*
athos@36
   128
  std::cout << "on directed graph graph" << std::endl; //<< flow_test;
athos@36
   129
  std::cout << "names and capacity values" << std::endl; 
athos@77
   130
  for(EachNodeIt i=flow_test.first_node(); i.valid(); ++i) { 
athos@36
   131
    std::cout << node_name.get(i) << ": ";
athos@36
   132
    std::cout << "out edges: ";
athos@36
   133
    for(out_edge_iterator j=flow_test.first_out_edge(i); j.valid(); ++j) 
athos@36
   134
      std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " ";
athos@36
   135
    std::cout << "in edges: ";
athos@36
   136
    for(in_edge_iterator j=flow_test.first_in_edge(i); j.valid(); ++j) 
athos@36
   137
      std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " ";
athos@36
   138
    std::cout << std::endl;
athos@36
   139
  }
athos@77
   140
  */
athos@36
   141
  
athos@77
   142
  //for(each_NodeIt i=flow_test.first_node(); i.valid(); ++i) { 
athos@36
   143
  //  std::cout << i << " ";
athos@36
   144
  //}
athos@36
   145
  
athos@77
   146
  preflow_push<ListGraph, int> preflow_push_test(flowG, s, t, cap);
athos@36
   147
  cout << preflow_push_test.run()<<endl;
athos@36
   148
athos@36
   149
  //cap.put(v5_t, 9);
athos@36
   150
  //cout << preflow_push_test.run()<<endl;
athos@36
   151
athos@36
   152
  return 0;
athos@36
   153
}
athos@36
   154
athos@36
   155
athos@36
   156
athos@36
   157
athos@36
   158
athos@36
   159
athos@36
   160
athos@36
   161
athos@36
   162