src/work/athos/dijkstra_at.h
author alpar
Thu, 31 Mar 2005 13:30:27 +0000
changeset 1282 81e89e2b90d1
parent 250 81a3d0abe5f3
permissions -rw-r--r--
length() returns int istead of size_t
athos@250
     1
/*
athos@250
     2
Egy pontból összes többibe vezető legrövidebb utak irányított gráfban
athos@250
     3
athos@250
     4
Preconditions:
athos@250
     5
A gráf típus tud:
athos@250
     6
- pontból kimenő éleket sorban visszaadni
athos@250
     7
A T számtípus, ami tud összehasonlítást, összedást
athos@250
     8
A bemenetre:
athos@250
     9
weight nemnegatív
athos@250
    10
athos@250
    11
*/
athos@250
    12
#ifndef DIJKSTRA_AT_H
athos@250
    13
#define DIJKSTRA_AT_H
athos@250
    14
athos@250
    15
athos@250
    16
athos@250
    17
//#include <algorithm>
athos@250
    18
//#include <deque>
athos@250
    19
//#include <vector>
athos@250
    20
//#include "pf_hiba.hh"
athos@250
    21
//#include <marci_list_graph.hh>
athos@250
    22
//#include <marci_graph_traits.hh>
athos@250
    23
athos@250
    24
athos@250
    25
using namespace std;
athos@250
    26
alpar@921
    27
namespace lemon {
athos@250
    28
athos@250
    29
  template <typename graph_type, typename T>
athos@250
    30
  class dijkstra_at {
athos@250
    31
athos@250
    32
    //Hasznos typedef-ek
athos@250
    33
    typedef typename graph_type::NodeIt NodeIt;
athos@250
    34
    typedef typename graph_type::EdgeIt EdgeIt;
athos@250
    35
    typedef typename graph_type::EachNodeIt EachNodeIt;
athos@250
    36
    typedef typename graph_type::EachEdgeIt EachEdgeIt;
athos@250
    37
    typedef typename graph_type::OutEdgeIt OutEdgeIt;
athos@250
    38
    typedef typename graph_type::InEdgeIt InEdgeIt;
athos@250
    39
    typedef typename graph_type::SymEdgeIt SymEdgeIt;
athos@250
    40
athos@250
    41
athos@250
    42
athos@250
    43
    //---------------------------------------------
athos@250
    44
    //Parameters of the algorithm
athos@250
    45
    //---------------------------------------------
athos@250
    46
athos@250
    47
    //---------------------------------------------
athos@250
    48
    //Parameters of the algorithm
athos@250
    49
    //---------------------------------------------
athos@250
    50
 
athos@250
    51
  private:
athos@250
    52
    //input
athos@250
    53
    graph_type& G;
athos@250
    54
    NodeIt s;
athos@250
    55
    typename graph_type::EdgeMap<T> &weight;
athos@250
    56
    //typename graph_type::EdgeMap<T>  &capacity;
athos@250
    57
    //output
athos@250
    58
    //typename graph_type::EdgeMap<T>  
athos@250
    59
    //    typename graph_type::EdgeMap<T> preflow;
athos@250
    60
      
athos@250
    61
    //auxiliary variables for computation
athos@250
    62
    deque<NodeIt> next_to_reach;
athos@250
    63
    
athos@250
    64
    
athos@250
    65
    typename graph_type::NodeMap<bool> reached;
athos@250
    66
athos@250
    67
    //Variables holding output
athos@250
    68
    //Predessors in the shortest paths arborescence
athos@250
    69
    typename graph_type::NodeMap<NodeIt> pred;
athos@250
    70
athos@250
    71
athos@250
    72
  public:
athos@250
    73
  
athos@250
    74
athos@250
    75
    dijkstra_at(
athos@250
    76
		      graph_type& _G, 
athos@250
    77
		      NodeIt _s, 
athos@250
    78
		      typename graph_type::EdgeMap<T> & _weight)
athos@250
    79
      : G(_G), s(_s),
athos@250
    80
      weight(_weight),
athos@250
    81
      next_to_reach(),
athos@250
    82
      reached(_G),
athos@250
    83
      pred(G)
athos@250
    84
     	
athos@250
    85
    { 
athos@250
    86
    }
athos@250
    87
      /*By Misi.*/
athos@250
    88
      struct Node_dist_comp
athos@250
    89
      {
athos@250
    90
	NodeMap<graph_type, T> &d;
athos@250
    91
	Node_dist_comp(NodeMap<graph_type, T> &_d) : d(_d) {} 
athos@250
    92
	
athos@250
    93
	bool operator()(const NodeIt& u, const NodeIt& v) const 
athos@250
    94
	{ return d.get(u) < d.get(v); }
athos@250
    95
      };
athos@250
    96
athos@250
    97
athos@250
    98
      
athos@250
    99
      void run() {
athos@250
   100
	
athos@250
   101
	NodeMap<graph_type, bool> scanned(G, false);
athos@250
   102
	std::priority_queue<NodeIt, vector<NodeIt>, Node_dist_comp> 
athos@250
   103
	  heap(( Node_dist_comp(distance) ));
athos@250
   104
	
athos@250
   105
	heap.push(s);
athos@250
   106
	reached.set(s, true);
athos@250
   107
	
athos@250
   108
      }
athos@250
   109
athos@250
   110
      
athos@250
   111
    };
athos@250
   112
  
athos@250
   113
athos@250
   114
athos@250
   115
athos@250
   116
athos@250
   117
 
athos@250
   118
  };  //class dijkstra_at  
athos@250
   119
athos@250
   120
alpar@921
   121
}//namespace lemon
athos@250
   122
athos@250
   123
#endif //DIJKSTRA_AT