maxflow_pp.h

00001 //==========================================================================
00002 //
00003 //   maxflow_pp.h
00004 //
00005 //==========================================================================
00006 // $Id: maxflow_pp.h,v 1.5 2003/01/31 08:15:05 chris Exp $
00007 
00008 #ifndef GTL_MAXFLOW_PP_H
00009 #define GTL_MAXFLOW_PP_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 #include <queue>
00018 
00019 __GTL_BEGIN_NAMESPACE
00020 
00024 class GTL_EXTERN maxflow_pp : public algorithm
00025 {
00026 public:
00033     maxflow_pp();
00034 
00040     virtual ~maxflow_pp();
00041 
00049     void set_vars(const edge_map<double>& edge_capacity);
00050 
00058     void set_vars(
00059         const edge_map<double>& edge_capacity, 
00060         const node& net_source, const node& net_target);
00061 
00080     virtual int check(graph& G);
00081 
00090     int run(graph& G);
00091 
00098     double get_max_flow(const edge& e) const;
00099 
00105     double get_max_flow() const;
00106 
00113     double get_rem_cap(const edge& e) const;
00114 
00120     virtual void reset();
00121 protected:
00125     enum {TARGET_FROM_SOURCE_REACHABLE = 2, TARGET_FROM_SOURCE_NOT_REACHABLE = 3};
00126 
00130     bool artif_source_target;
00131 
00135     bool set_vars_executed;
00136 
00140     double max_graph_flow;
00141 
00145     node net_source;
00146 
00150     node net_target;
00151 
00155     list<edge> edges_not_org;
00156 
00160     edge_map<bool> edge_org;
00161 
00165     edge_map<bool> back_edge_exists;
00166 
00170     edge_map<edge> back_edge;
00171 
00175     edge_map<double> edge_capacity;
00176 
00180     edge_map<double> edge_max_flow;
00181 
00185     edge_map<double> flow_update;
00186 
00190     list<edge> full_edges;
00191                 
00195     list<node> temp_unvisible_nodes;
00196                 
00200     list<edge> temp_unvisible_edges;
00201                 
00205     void create_artif_source_target(graph& G);
00206 
00210     void prepare_run(const graph& G);
00211 
00215     int leveling(graph& G);
00216 
00220     void hide_unreachable_nodes(graph& G);
00221 
00225     void store_temp_unvisible_edges(const node& cur_node);
00226 
00230     void min_throughput_node(const graph& G, node& min_tp_node, double& min_value);
00231 
00235     double comp_min_throughput(const node cur_node) const;
00236 
00240     void get_sp_ahead(const graph& G, const node& start_node, 
00241         node_map<edge>& last_edge);
00242 
00246     void get_sp_backwards(const graph& G, const node& start_node, 
00247         node_map<edge>& prev_edge);
00248 
00252     void push(graph& G, const node& start_node, const double flow_value);
00253 
00257     void pull(graph& G, const node& start_node, const double flow_value);
00258 
00262     void comp_rem_net(graph& G);
00263 
00267     void single_edge_update(graph& G, edge cur_edge);
00268 
00272     double extra_charge_ahead(const node& start_node, const 
00273         node_map<edge>& last_edge) const;
00274 
00278     double extra_charge_backwards(const node& start_node, 
00279         const node_map<edge>& prev_edge) const;
00280 
00284     void create_back_edge(graph& G, const edge& org_edge);
00285 
00289     void comp_max_flow(const graph& G);
00290 
00294     void restore_graph(graph& G);
00295 private:
00296 };
00297 
00298 __GTL_END_NAMESPACE
00299 
00300 #endif // GTL_MAXFLOW_PP_H
00301 
00302 //--------------------------------------------------------------------------
00303 //   end of file
00304 //--------------------------------------------------------------------------