src/work/athos/pf_demo.cc
changeset 331 f5461f8bc59b
parent 201 b9158a014fe8
child 921 818510fa3d99
     1.1 --- a/src/work/athos/pf_demo.cc	Thu Apr 15 14:41:20 2004 +0000
     1.2 +++ b/src/work/athos/pf_demo.cc	Thu Apr 15 17:03:44 2004 +0000
     1.3 @@ -2,8 +2,8 @@
     1.4  #include <vector>
     1.5  #include <string>
     1.6  
     1.7 -#include "list_graph.hh"
     1.8 -#include "marci_graph_traits.hh"
     1.9 +#include "list_graph.h"
    1.10 +//#include "marci_graph_traits.hh"
    1.11  //#include "marci_property_vector.hh"
    1.12  #include "preflow_push.hh"
    1.13  
    1.14 @@ -13,137 +13,88 @@
    1.15  int main (int, char*[])
    1.16  {
    1.17  
    1.18 -  
    1.19 -  typedef ListGraph::NodeIt NodeIt;
    1.20 -  typedef ListGraph::EdgeIt EdgeIt;
    1.21 -  /*
    1.22 -  typedef ListGraph::EachNodeIt EachNodeIt;
    1.23 -  typedef ListGraph::EachEdgeIt EachEdgeIt;
    1.24 -  typedef ListGraph::OutEdgeIt OutEdgeIt;
    1.25 -  typedef ListGraph::InEdgeIt InEdgeIt;
    1.26 -  typedef ListGraph::SymEdgeIt SymEdgeIt;
    1.27 -  */
    1.28 -  ListGraph flowG;
    1.29 +  typedef ListGraph::Node Node;
    1.30 +  typedef ListGraph::Edge Edge;
    1.31 +
    1.32 +  ListGraph graph;
    1.33  
    1.34    /*
    1.35    //Marci példája
    1.36  
    1.37  
    1.38 -  NodeIt s=flowG.addNode();
    1.39 -  NodeIt v1=flowG.addNode();
    1.40 -  NodeIt v2=flowG.addNode();
    1.41 -  NodeIt v3=flowG.addNode();
    1.42 -  NodeIt v4=flowG.addNode();
    1.43 -  NodeIt t=flowG.addNode();
    1.44 +  NodeIt s=graph.addNode();
    1.45 +  NodeIt v1=graph.addNode();
    1.46 +  NodeIt v2=graph.addNode();
    1.47 +  NodeIt v3=graph.addNode();
    1.48 +  NodeIt v4=graph.addNode();
    1.49 +  NodeIt t=graph.addNode();
    1.50    
    1.51  
    1.52 -  EdgeIt s_v1=flowG.addEdge(s, v1);
    1.53 -  EdgeIt s_v2=flowG.addEdge(s, v2);
    1.54 -  EdgeIt v1_v2=flowG.addEdge(v1, v2);
    1.55 -  EdgeIt v2_v1=flowG.addEdge(v2, v1);
    1.56 -  EdgeIt v1_v3=flowG.addEdge(v1, v3);
    1.57 -  EdgeIt v3_v2=flowG.addEdge(v3, v2);
    1.58 -  EdgeIt v2_v4=flowG.addEdge(v2, v4);
    1.59 -  EdgeIt v4_v3=flowG.addEdge(v4, v3);
    1.60 -  EdgeIt v3_t=flowG.addEdge(v3, t);
    1.61 -  EdgeIt v4_t=flowG.addEdge(v4, t);
    1.62 +  EdgeIt s_v1=graph.addEdge(s, v1);
    1.63 +  EdgeIt s_v2=graph.addEdge(s, v2);
    1.64 +  EdgeIt v1_v2=graph.addEdge(v1, v2);
    1.65 +  EdgeIt v2_v1=graph.addEdge(v2, v1);
    1.66 +  EdgeIt v1_v3=graph.addEdge(v1, v3);
    1.67 +  EdgeIt v3_v2=graph.addEdge(v3, v2);
    1.68 +  EdgeIt v2_v4=graph.addEdge(v2, v4);
    1.69 +  EdgeIt v4_v3=graph.addEdge(v4, v3);
    1.70 +  EdgeIt v3_t=graph.addEdge(v3, t);
    1.71 +  EdgeIt v4_t=graph.addEdge(v4, t);
    1.72  
    1.73 -  ListGraph::EdgeMap<int> cap(flowG);
    1.74 +  ListGraph::EdgeMap<int> length(graph);
    1.75  
    1.76 -  cap.set(s_v1, 16);
    1.77 -  cap.set(s_v2, 13);
    1.78 -  cap.set(v1_v2, 10);
    1.79 -  cap.set(v2_v1, 4);
    1.80 -  cap.set(v1_v3, 12);
    1.81 -  cap.set(v3_v2, 9);
    1.82 -  cap.set(v2_v4, 14);
    1.83 -  cap.set(v4_v3, 7);
    1.84 -  cap.set(v3_t, 20);
    1.85 -  cap.set(v4_t, 4);
    1.86 +  length.set(s_v1, 16);
    1.87 +  length.set(s_v2, 13);
    1.88 +  length.set(v1_v2, 10);
    1.89 +  length.set(v2_v1, 4);
    1.90 +  length.set(v1_v3, 12);
    1.91 +  length.set(v3_v2, 9);
    1.92 +  length.set(v2_v4, 14);
    1.93 +  length.set(v4_v3, 7);
    1.94 +  length.set(v3_t, 20);
    1.95 +  length.set(v4_t, 4);
    1.96    */
    1.97  
    1.98  
    1.99    //Ahuja könyv példája
   1.100  
   1.101 -  NodeIt s=flowG.addNode();
   1.102 -  NodeIt v2=flowG.addNode();
   1.103 -  NodeIt v3=flowG.addNode();
   1.104 -  NodeIt v4=flowG.addNode();
   1.105 -  NodeIt v5=flowG.addNode();
   1.106 -  NodeIt t=flowG.addNode();
   1.107 +  Node s=graph.addNode();
   1.108 +  Node v2=graph.addNode();
   1.109 +  Node v3=graph.addNode();
   1.110 +  Node v4=graph.addNode();
   1.111 +  Node v5=graph.addNode();
   1.112 +  Node t=graph.addNode();
   1.113  
   1.114 -  EdgeIt s_v2=flowG.addEdge(s, v2);
   1.115 -  EdgeIt s_v3=flowG.addEdge(s, v3);
   1.116 -  EdgeIt v2_v4=flowG.addEdge(v2, v4);
   1.117 -  EdgeIt v2_v5=flowG.addEdge(v2, v5);
   1.118 -  EdgeIt v3_v5=flowG.addEdge(v3, v5);
   1.119 -  EdgeIt v4_t=flowG.addEdge(v4, t);
   1.120 -  EdgeIt v5_t=flowG.addEdge(v5, t);
   1.121 +  Edge s_v2=graph.addEdge(s, v2);
   1.122 +  Edge s_v3=graph.addEdge(s, v3);
   1.123 +  Edge v2_v4=graph.addEdge(v2, v4);
   1.124 +  Edge v2_v5=graph.addEdge(v2, v5);
   1.125 +  Edge v3_v5=graph.addEdge(v3, v5);
   1.126 +  Edge v4_t=graph.addEdge(v4, t);
   1.127 +  Edge v5_t=graph.addEdge(v5, t);
   1.128    
   1.129    //Kis modositas
   1.130 -  //edge_iterator v2_s=flowG.add_edge(v2, s);
   1.131 +  //edge_iterator v2_s=graph.add_edge(v2, s);
   1.132  
   1.133 -  ListGraph::EdgeMap<int> cap(flowG);
   1.134 +  ListGraph::EdgeMap<int> length(graph);
   1.135  
   1.136 -  cap.set(s_v2, 10);
   1.137 -  cap.set(s_v3, 10);
   1.138 -  cap.set(v2_v4, 5);
   1.139 -  cap.set(v2_v5, 8);
   1.140 -  cap.set(v3_v5, 5);
   1.141 -  cap.set(v4_t, 8);
   1.142 -  cap.set(v5_t, 8);
   1.143 +  length.set(s_v2, 10);
   1.144 +  length.set(s_v3, 10);
   1.145 +  length.set(v2_v4, 5);
   1.146 +  length.set(v2_v5, 8);
   1.147 +  length.set(v3_v5, 5);
   1.148 +  length.set(v4_t, 8);
   1.149 +  length.set(v5_t, 8);
   1.150  
   1.151    //Kis modositas
   1.152 -  //cap.put(v2_s, 100);
   1.153 - 
   1.154 +  //length.put(v2_s, 100);
   1.155  
   1.156  
   1.157  
   1.158 -  /*Egyszerű példa
   1.159 -  NodeIt s=flow_test.add_node();
   1.160 -  NodeIt v1=flow_test.add_node();
   1.161 -  NodeIt v2=flow_test.add_node();
   1.162 -  NodeIt t=flow_test.add_node();
   1.163 -  
   1.164 -  node_property_vector<list_graph, std::string> node_name(flow_test);
   1.165 -  node_name.put(s, "s");
   1.166 -  node_name.put(v1, "v1");
   1.167 -  node_name.put(v2, "v2");
   1.168 -  node_name.put(t, "t");
   1.169 -
   1.170 -  edge_iterator s_v1=flow_test.add_edge(s, v1);
   1.171 -  edge_iterator v1_v2=flow_test.add_edge(v1, v2);
   1.172 -  edge_iterator v2_t=flow_test.add_edge(v2, t);
   1.173 -
   1.174 -  edge_property_vector<list_graph, int> cap(flow_test); 
   1.175 -    
   1.176 -  cap.put(s_v1, 16);
   1.177 -  cap.put(v1_v2, 10);
   1.178 -  cap.put(v2_t, 4);
   1.179 -  */
   1.180 -
   1.181    std::cout << "preflow-push algorithm test..." << std::endl;
   1.182  
   1.183 -  /*
   1.184 -  std::cout << "on directed graph graph" << std::endl; //<< flow_test;
   1.185 -  std::cout << "names and capacity values" << std::endl; 
   1.186 -  for(EachNodeIt i=flow_test.first_node(); i.valid(); ++i) { 
   1.187 -    std::cout << node_name.get(i) << ": ";
   1.188 -    std::cout << "out edges: ";
   1.189 -    for(out_edge_iterator j=flow_test.first_out_edge(i); j.valid(); ++j) 
   1.190 -      std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " ";
   1.191 -    std::cout << "in edges: ";
   1.192 -    for(in_edge_iterator j=flow_test.first_in_edge(i); j.valid(); ++j) 
   1.193 -      std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " ";
   1.194 -    std::cout << std::endl;
   1.195 -  }
   1.196 -  */
   1.197    
   1.198 -  //for(each_NodeIt i=flow_test.first_node(); i.valid(); ++i) { 
   1.199 -  //  std::cout << i << " ";
   1.200 -  //}
   1.201 -  
   1.202 -  preflow_push<ListGraph, int> preflow_push_test(flowG, s, t, cap);
   1.203 +  preflow_push<ListGraph, int> preflow_push_test(graph, s, t, length);
   1.204    cout << preflow_push_test.run()<<endl;
   1.205  
   1.206    //cap.put(v5_t, 9);
   1.207 @@ -151,12 +102,3 @@
   1.208  
   1.209    return 0;
   1.210  }
   1.211 -
   1.212 -
   1.213 -
   1.214 -
   1.215 -
   1.216 -
   1.217 -
   1.218 -
   1.219 -