1.1 --- a/src/work/jacint/dijkstra.hh Mon Feb 16 15:57:59 2004 +0000
1.2 +++ b/src/work/jacint/dijkstra.hh Mon Feb 16 16:15:58 2004 +0000
1.3 @@ -1,11 +1,11 @@
1.4 /*
1.5 *dijkstra
1.6 *by jacint
1.7 - *Performs Dijkstra's algorithm from node s.
1.8 + *Performs Dijkstra's algorithm from Node s.
1.9 *
1.10 *Constructor:
1.11 *
1.12 - *dijkstra(graph_type& G, node_iterator s, edge_property_vector& distance)
1.13 + *dijkstra(graph_type& G, NodeIt s, EdgeMap& distance)
1.14 *
1.15 *
1.16 *
1.17 @@ -16,17 +16,17 @@
1.18 * The following function should be used after run() was already run.
1.19 *
1.20 *
1.21 - *T dist(node_iterator v) : returns the distance from s to v.
1.22 + *T dist(NodeIt v) : returns the distance from s to v.
1.23 * It is 0 if v is not reachable from s.
1.24 *
1.25 *
1.26 - *edge_iterator pred(node_iterator v)
1.27 - * Returns the last edge of a shortest s-v path.
1.28 + *EdgeIt pred(NodeIt v)
1.29 + * Returns the last Edge of a shortest s-v path.
1.30 * Returns an invalid iterator if v=s or v is not
1.31 * reachable from s.
1.32 *
1.33 *
1.34 - *bool reach(node_iterator v) : true if v is reachable from s
1.35 + *bool reach(NodeIt v) : true if v is reachable from s
1.36 *
1.37 *
1.38 *
1.39 @@ -48,7 +48,7 @@
1.40 #include <algorithm>
1.41
1.42 #include <marci_graph_traits.hh>
1.43 -#include <marci_property_vector.hh>
1.44 +#include <marciMap.hh>
1.45
1.46
1.47 namespace std {
1.48 @@ -60,37 +60,37 @@
1.49
1.50 template <typename graph_type, typename T>
1.51 class dijkstra{
1.52 - typedef typename graph_traits<graph_type>::node_iterator node_iterator;
1.53 - typedef typename graph_traits<graph_type>::edge_iterator edge_iterator;
1.54 - typedef typename graph_traits<graph_type>::each_node_iterator each_node_iterator;
1.55 - typedef typename graph_traits<graph_type>::in_edge_iterator in_edge_iterator;
1.56 - typedef typename graph_traits<graph_type>::out_edge_iterator out_edge_iterator;
1.57 + typedef typename graph_traits<graph_type>::NodeIt NodeIt;
1.58 + typedef typename graph_traits<graph_type>::EdgeIt EdgeIt;
1.59 + typedef typename graph_traits<graph_type>::EachNodeIt EachNodeIt;
1.60 + typedef typename graph_traits<graph_type>::InEdgeIt InEdgeIt;
1.61 + typedef typename graph_traits<graph_type>::OutEdgeIt OutEdgeIt;
1.62
1.63
1.64 graph_type& G;
1.65 - node_iterator s;
1.66 - node_property_vector<graph_type, edge_iterator> predecessor;
1.67 - node_property_vector<graph_type, T> distance;
1.68 - edge_property_vector<graph_type, T> length;
1.69 - node_property_vector<graph_type, bool> reached;
1.70 + NodeIt s;
1.71 + NodeMap<graph_type, EdgeIt> predecessor;
1.72 + NodeMap<graph_type, T> distance;
1.73 + EdgeMap<graph_type, T> length;
1.74 + NodeMap<graph_type, bool> reached;
1.75
1.76 public :
1.77
1.78 /*
1.79 - The distance of all the nodes is 0.
1.80 + The distance of all the Nodes is 0.
1.81 */
1.82 - dijkstra(graph_type& _G, node_iterator _s, edge_property_vector<graph_type, T>& _length) :
1.83 + dijkstra(graph_type& _G, NodeIt _s, EdgeMap<graph_type, T>& _length) :
1.84 G(_G), s(_s), predecessor(G, 0), distance(G, 0), length(_length), reached(G, false) { }
1.85
1.86
1.87
1.88 /*By Misi.*/
1.89 - struct node_dist_comp
1.90 + struct Node_dist_comp
1.91 {
1.92 - node_property_vector<graph_type, T> &d;
1.93 - node_dist_comp(node_property_vector<graph_type, T> &_d) : d(_d) {}
1.94 + NodeMap<graph_type, T> &d;
1.95 + Node_dist_comp(NodeMap<graph_type, T> &_d) : d(_d) {}
1.96
1.97 - bool operator()(const node_iterator& u, const node_iterator& v) const
1.98 + bool operator()(const NodeIt& u, const NodeIt& v) const
1.99 { return d.get(u) < d.get(v); }
1.100 };
1.101
1.102 @@ -98,23 +98,23 @@
1.103
1.104 void run() {
1.105
1.106 - node_property_vector<graph_type, bool> scanned(G, false);
1.107 - std::priority_queue<node_iterator, vector<node_iterator>, node_dist_comp>
1.108 - heap(( node_dist_comp(distance) ));
1.109 + NodeMap<graph_type, bool> scanned(G, false);
1.110 + std::priority_queue<NodeIt, vector<NodeIt>, Node_dist_comp>
1.111 + heap(( Node_dist_comp(distance) ));
1.112
1.113 heap.push(s);
1.114 reached.put(s, true);
1.115
1.116 while (!heap.empty()) {
1.117
1.118 - node_iterator v=heap.top();
1.119 + NodeIt v=heap.top();
1.120 heap.pop();
1.121
1.122
1.123 if (!scanned.get(v)) {
1.124
1.125 - for(out_edge_iterator e=G.first_out_edge(v); e.valid(); ++e) {
1.126 - node_iterator w=G.head(e);
1.127 + for(OutEdgeIt e=G.template first<OutEdgeIt>(v); e.valid(); ++e) {
1.128 + NodeIt w=G.head(e);
1.129
1.130 if (!scanned.get(w)) {
1.131 if (!reached.get(w)) {
1.132 @@ -147,29 +147,29 @@
1.133
1.134
1.135 /*
1.136 - *Returns the distance of the node v.
1.137 - *It is 0 for the root and for the nodes not
1.138 + *Returns the distance of the Node v.
1.139 + *It is 0 for the root and for the Nodes not
1.140 *reachable form the root.
1.141 */
1.142 - T dist(node_iterator v) {
1.143 + T dist(NodeIt v) {
1.144 return -distance.get(v);
1.145 }
1.146
1.147
1.148
1.149 /*
1.150 - * Returns the last edge of a shortest s-v path.
1.151 + * Returns the last Edge of a shortest s-v path.
1.152 * Returns an invalid iterator if v=root or v is not
1.153 * reachable from the root.
1.154 */
1.155 - edge_iterator pred(node_iterator v) {
1.156 + EdgeIt pred(NodeIt v) {
1.157 if (v!=s) { return predecessor.get(v);}
1.158 - else {return edge_iterator();}
1.159 + else {return EdgeIt();}
1.160 }
1.161
1.162
1.163
1.164 - bool reach(node_iterator v) {
1.165 + bool reach(NodeIt v) {
1.166 return reached.get(v);
1.167 }
1.168