src/work/athos/pf_demo.cc
author marci
Mon, 01 Mar 2004 12:06:56 +0000
changeset 138 c6297c121409
parent 77 69b2d279c8f0
child 201 b9158a014fe8
permissions -rw-r--r--
.
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@77
    26
  
athos@77
    27
  //Marci példája
athos@77
    28
  ListGraph flowG;
athos@77
    29
athos@77
    30
  NodeIt s=flowG.addNode();
athos@77
    31
  NodeIt v1=flowG.addNode();
athos@77
    32
  NodeIt v2=flowG.addNode();
athos@77
    33
  NodeIt v3=flowG.addNode();
athos@77
    34
  NodeIt v4=flowG.addNode();
athos@77
    35
  NodeIt t=flowG.addNode();
athos@77
    36
  
athos@77
    37
athos@77
    38
  EdgeIt s_v1=flowG.addEdge(s, v1);
athos@77
    39
  EdgeIt s_v2=flowG.addEdge(s, v2);
athos@77
    40
  EdgeIt v1_v2=flowG.addEdge(v1, v2);
athos@77
    41
  EdgeIt v2_v1=flowG.addEdge(v2, v1);
athos@77
    42
  EdgeIt v1_v3=flowG.addEdge(v1, v3);
athos@77
    43
  EdgeIt v3_v2=flowG.addEdge(v3, v2);
athos@77
    44
  EdgeIt v2_v4=flowG.addEdge(v2, v4);
athos@77
    45
  EdgeIt v4_v3=flowG.addEdge(v4, v3);
athos@77
    46
  EdgeIt v3_t=flowG.addEdge(v3, t);
athos@77
    47
  EdgeIt v4_t=flowG.addEdge(v4, t);
athos@77
    48
athos@77
    49
  ListGraph::EdgeMap<int> cap(flowG);
athos@77
    50
athos@77
    51
  cap.set(s_v1, 16);
athos@77
    52
  cap.set(s_v2, 13);
athos@77
    53
  cap.set(v1_v2, 10);
athos@77
    54
  cap.set(v2_v1, 4);
athos@77
    55
  cap.set(v1_v3, 12);
athos@77
    56
  cap.set(v3_v2, 9);
athos@77
    57
  cap.set(v2_v4, 14);
athos@77
    58
  cap.set(v4_v3, 7);
athos@77
    59
  cap.set(v3_t, 20);
athos@77
    60
  cap.set(v4_t, 4);
athos@77
    61
athos@77
    62
athos@77
    63
athos@77
    64
athos@77
    65
athos@77
    66
athos@77
    67
athos@77
    68
  /*
athos@36
    69
  //Ahuja könyv példája
athos@36
    70
  node_iterator s=flow_test.add_node();
athos@77
    71
  NodeIt v2=flow_test.add_node();
athos@77
    72
  NodeIt v3=flow_test.add_node();
athos@77
    73
  NodeIt v4=flow_test.add_node();
athos@77
    74
  NodeIt v5=flow_test.add_node();
athos@77
    75
  NodeIt t=flow_test.add_node();
athos@36
    76
  
athos@36
    77
  node_property_vector<list_graph, std::string> node_name(flow_test);
athos@36
    78
  node_name.put(s, "s");  
athos@36
    79
  node_name.put(v2, "v2");
athos@36
    80
  node_name.put(v3, "v3");
athos@36
    81
  node_name.put(v4, "v4");
athos@36
    82
  node_name.put(v5, "v5");
athos@36
    83
  node_name.put(t, "t");
athos@36
    84
athos@36
    85
  
athos@36
    86
  edge_iterator s_v2=flow_test.add_edge(s, v2);
athos@36
    87
  edge_iterator s_v3=flow_test.add_edge(s, v3);
athos@36
    88
  
athos@36
    89
  edge_iterator v2_v4=flow_test.add_edge(v2, v4);
athos@36
    90
  edge_iterator v2_v5=flow_test.add_edge(v2, v5);
athos@36
    91
athos@36
    92
  edge_iterator v3_v5=flow_test.add_edge(v3, v5);
athos@36
    93
athos@36
    94
  edge_iterator v4_t=flow_test.add_edge(v4, t);
athos@36
    95
  edge_iterator v5_t=flow_test.add_edge(v5, t);
athos@36
    96
  
athos@36
    97
  //Kis modositas
athos@36
    98
  edge_iterator v2_s=flow_test.add_edge(v2, s);
athos@36
    99
athos@36
   100
  edge_property_vector<list_graph, int> cap(flow_test);  
athos@36
   101
  cap.put(s_v2, 10);
athos@36
   102
  cap.put(s_v3, 10);
athos@36
   103
  cap.put(v2_v4, 5);
athos@36
   104
  cap.put(v2_v5, 8);
athos@36
   105
  cap.put(v3_v5, 5);
athos@36
   106
  cap.put(v4_t, 8);
athos@36
   107
  cap.put(v5_t, 8);
athos@36
   108
athos@36
   109
  //Kis modositas
athos@36
   110
  cap.put(v2_s, 100);
athos@36
   111
athos@36
   112
  //Kis modositas
athos@36
   113
  //edge_iterator t_s=flow_test.add_edge(t, s);
athos@36
   114
  //cap.put(t_s, 20);
athos@36
   115
athos@77
   116
  */
athos@36
   117
athos@77
   118
athos@77
   119
athos@36
   120
  /*Egyszerű példa
athos@77
   121
  NodeIt s=flow_test.add_node();
athos@77
   122
  NodeIt v1=flow_test.add_node();
athos@77
   123
  NodeIt v2=flow_test.add_node();
athos@77
   124
  NodeIt t=flow_test.add_node();
athos@36
   125
  
athos@36
   126
  node_property_vector<list_graph, std::string> node_name(flow_test);
athos@36
   127
  node_name.put(s, "s");
athos@36
   128
  node_name.put(v1, "v1");
athos@36
   129
  node_name.put(v2, "v2");
athos@36
   130
  node_name.put(t, "t");
athos@36
   131
athos@36
   132
  edge_iterator s_v1=flow_test.add_edge(s, v1);
athos@36
   133
  edge_iterator v1_v2=flow_test.add_edge(v1, v2);
athos@36
   134
  edge_iterator v2_t=flow_test.add_edge(v2, t);
athos@36
   135
athos@36
   136
  edge_property_vector<list_graph, int> cap(flow_test); 
athos@36
   137
    
athos@36
   138
  cap.put(s_v1, 16);
athos@36
   139
  cap.put(v1_v2, 10);
athos@36
   140
  cap.put(v2_t, 4);
athos@36
   141
  */
athos@36
   142
athos@36
   143
  std::cout << "preflow-push algorithm test..." << std::endl;
athos@77
   144
athos@77
   145
  /*
athos@36
   146
  std::cout << "on directed graph graph" << std::endl; //<< flow_test;
athos@36
   147
  std::cout << "names and capacity values" << std::endl; 
athos@77
   148
  for(EachNodeIt i=flow_test.first_node(); i.valid(); ++i) { 
athos@36
   149
    std::cout << node_name.get(i) << ": ";
athos@36
   150
    std::cout << "out edges: ";
athos@36
   151
    for(out_edge_iterator j=flow_test.first_out_edge(i); j.valid(); ++j) 
athos@36
   152
      std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " ";
athos@36
   153
    std::cout << "in edges: ";
athos@36
   154
    for(in_edge_iterator j=flow_test.first_in_edge(i); j.valid(); ++j) 
athos@36
   155
      std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " ";
athos@36
   156
    std::cout << std::endl;
athos@36
   157
  }
athos@77
   158
  */
athos@36
   159
  
athos@77
   160
  //for(each_NodeIt i=flow_test.first_node(); i.valid(); ++i) { 
athos@36
   161
  //  std::cout << i << " ";
athos@36
   162
  //}
athos@36
   163
  
athos@77
   164
  preflow_push<ListGraph, int> preflow_push_test(flowG, s, t, cap);
athos@36
   165
  cout << preflow_push_test.run()<<endl;
athos@36
   166
athos@36
   167
  //cap.put(v5_t, 9);
athos@36
   168
  //cout << preflow_push_test.run()<<endl;
athos@36
   169
athos@36
   170
  return 0;
athos@36
   171
}
athos@36
   172
athos@36
   173
athos@36
   174
athos@36
   175
athos@36
   176
athos@36
   177
athos@36
   178
athos@36
   179
athos@36
   180