Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bellman_ford.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file bellman_ford.h
1 /* This software is distributed under the GNU Lesser General Public License */
2 //==========================================================================
3 //
4 // bellman_ford.h
5 //
6 //==========================================================================
7 // $Id: bellman_ford.h,v 1.5 2003/03/24 15:58:54 raitner Exp $
8 
9 #ifndef GTL_BELLMAN_FORD_H
10 #define GTL_BELLMAN_FORD_H
11 
12 #include <GTL/GTL.h>
13 #include <GTL/algorithm.h>
14 #include <GTL/node_map.h>
15 #include <GTL/edge_map.h>
16 
18 
19 
34 {
35 public:
36 
40  bellman_ford();
41 
45  virtual ~bellman_ford();
46 
58  int check (graph& G);
59 
60  int run (graph& G);
61 
68  void reset ();
69 
79  void source (const node& n) {s = n;}
80 
86  node source () const {return s;}
87 
95  void weights (const edge_map<double>& weight) {w = weight; vars_set = true; }
96 
107  void store_preds (bool set);
108 
117  bool store_preds () const {return preds != 0;}
118 
124  bool reached (const node& n) const {return !inf[n];}
125 
131  double distance (const node& n) const {return d[n];}
132 
147  edge predecessor_edge (const node& n) const
148  {assert (preds); return (*preds)[n];}
149 
164  node predecessor_node (const node& n) const
165  {edge e = predecessor_edge(n); return e == edge() ? node() : e.opposite(n); }
166 
171  bool negative_cycle() const
172  {return cycle;}
173 
174 private:
175 
176 
182  void relax (const edge& e, bool dir);
183 
190 
197 
203  bool vars_set;
204 
211 
218 
225 
232  bool cycle;
233 };
234 
236 
237 #endif // GTL_BELLMAN_FORD_H