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