dijkstra.h

00001 //==========================================================================
00002 //
00003 //   dijkstra.h
00004 //
00005 //==========================================================================
00006 // $Id: dijkstra.h,v 1.8 2003/02/25 09:18:19 chris Exp $
00007 
00008 #ifndef GTL_DIJKSTRA_H
00009 #define GTL_DIJKSTRA_H
00010 
00011 #include <GTL/GTL.h>
00012 #include <GTL/graph.h>
00013 #include <GTL/node_map.h>
00014 #include <GTL/edge_map.h>
00015 #include <GTL/algorithm.h>
00016 
00017 __GTL_BEGIN_NAMESPACE
00018 
00029 class GTL_EXTERN dijkstra : public algorithm
00030 {
00031 public:
00035     typedef list<node>::const_iterator shortest_path_node_iterator;
00036 
00040     typedef list<edge>::const_iterator shortest_path_edge_iterator;
00041 
00045     enum node_color {white, grey, black};
00046 
00054     dijkstra();
00055 
00061     virtual ~dijkstra();
00062 
00072     void source(const node& n);
00073 
00083     void target(const node& n);
00084 
00092     void weights(const edge_map<double>& weight);
00093     
00105     void store_preds(bool set);
00106 
00125     virtual int check(graph& G);
00126             
00141     int run(graph& G);
00142 
00148     node source() const;
00149 
00155     node target() const;
00156 
00164     bool store_preds() const;
00165 
00173     bool reached(const node& n) const;
00174 
00182     double distance(const node& n) const;
00183 
00201     node predecessor_node(const node& n) const;
00202 
00220     edge predecessor_edge(const node& n) const;
00221 
00236     shortest_path_node_iterator shortest_path_nodes_begin(const node& dest);
00237 
00252     shortest_path_node_iterator shortest_path_nodes_end(const node& dest);
00253 
00268     shortest_path_edge_iterator shortest_path_edges_begin(const node& dest);
00269 
00284     shortest_path_edge_iterator shortest_path_edges_end(const node& dest);
00285 
00296     virtual void reset();
00297 private:
00304     node s;
00305 
00312     node t;
00313 
00320     bool weights_set;
00321 
00328     bool preds_set;
00329 
00336     edge_map<double> weight;
00337 
00345     node_map<edge> pred;
00346 
00352     node_map<int> mark;
00353 
00361     node_map<double> dist;
00362 
00373     node_map<list<node> > shortest_path_node_list;
00374 
00385     node_map<list<edge> > shortest_path_edge_list;
00386 
00391     void reset_algorithm();
00392     
00397     void init(graph& G);
00398 
00404     void fill_node_list(const node& t);
00405 
00411     void fill_edge_list(const node& t);
00412 };
00413 
00414 __GTL_END_NAMESPACE
00415 
00416 #endif // GTL_DIJKSTRA_H
00417 
00418 //--------------------------------------------------------------------------
00419 //   end of file
00420 //--------------------------------------------------------------------------