1.1 --- a/src/lemon/suurballe.h Thu Oct 07 17:21:27 2004 +0000
1.2 +++ b/src/lemon/suurballe.h Fri Oct 08 13:07:51 2004 +0000
1.3 @@ -68,14 +68,16 @@
1.4
1.5 typedef ConstMap<Edge,int> ConstMap;
1.6
1.7 - //Input
1.8 const Graph& G;
1.9
1.10 + Node s;
1.11 + Node t;
1.12 +
1.13 //Auxiliary variables
1.14 //This is the capacity map for the mincostflow problem
1.15 ConstMap const1map;
1.16 //This MinCostFlow instance will actually solve the problem
1.17 - MinCostFlow<Graph, LengthMap, ConstMap> mincost_flow;
1.18 + MinCostFlow<Graph, LengthMap, ConstMap> min_cost_flow;
1.19
1.20 //Container to store found paths
1.21 std::vector< std::vector<Edge> > paths;
1.22 @@ -83,39 +85,40 @@
1.23 public :
1.24
1.25
1.26 - /// The constructor of the class.
1.27 + /*! \brief The constructor of the class.
1.28
1.29 - ///\param _G The directed graph the algorithm runs on.
1.30 - ///\param _length The length (weight or cost) of the edges.
1.31 - Suurballe(Graph& _G, LengthMap& _length) : G(_G),
1.32 - const1map(1), mincost_flow(_G, _length, const1map){}
1.33 + \param _G The directed graph the algorithm runs on.
1.34 + \param _length The length (weight or cost) of the edges.
1.35 + \param _s Source node.
1.36 + \param _t Target node.
1.37 + */
1.38 + Suurballe(Graph& _G, LengthMap& _length, Node _s, Node _t) :
1.39 + G(_G), s(_s), t(_t), const1map(1),
1.40 + min_cost_flow(_G, _length, const1map, _s, _t) { }
1.41
1.42 ///Runs the algorithm.
1.43
1.44 ///Runs the algorithm.
1.45 ///Returns k if there are at least k edge-disjoint paths from s to t.
1.46 - ///Otherwise it returns the number of found edge-disjoint paths from s to t.
1.47 + ///Otherwise it returns the number of edge-disjoint paths found
1.48 + ///from s to t.
1.49 ///
1.50 - ///\param s The source node.
1.51 - ///\param t The target node.
1.52 ///\param k How many paths are we looking for?
1.53 ///
1.54 - int run(Node s, Node t, int k) {
1.55 -
1.56 - int i = mincost_flow.run(s,t,k);
1.57 -
1.58 + int run(int k) {
1.59 + int i = min_cost_flow.run(k);
1.60
1.61 //Let's find the paths
1.62 //We put the paths into stl vectors (as an inner representation).
1.63 //In the meantime we lose the information stored in 'reversed'.
1.64 //We suppose the lengths to be positive now.
1.65
1.66 - //We don't want to change the flow of mincost_flow, so we make a copy
1.67 + //We don't want to change the flow of min_cost_flow, so we make a copy
1.68 //The name here suggests that the flow has only 0/1 values.
1.69 EdgeIntMap reversed(G);
1.70
1.71 for(typename Graph::EdgeIt e(G); e!=INVALID; ++e)
1.72 - reversed[e] = mincost_flow.getFlow()[e];
1.73 + reversed[e] = min_cost_flow.getFlow()[e];
1.74
1.75 paths.clear();
1.76 //total_length=0;
1.77 @@ -143,39 +146,32 @@
1.78 }
1.79
1.80
1.81 - ///Returns the total length of the paths
1.82 + ///Returns the total length of the paths.
1.83
1.84 ///This function gives back the total length of the found paths.
1.85 - ///\pre \ref run() must
1.86 - ///be called before using this function.
1.87 Length totalLength(){
1.88 - return mincost_flow.totalLength();
1.89 + return min_cost_flow.totalLength();
1.90 }
1.91
1.92 ///Returns the found flow.
1.93
1.94 ///This function returns a const reference to the EdgeMap \c flow.
1.95 - ///\pre \ref run() must
1.96 - ///be called before using this function.
1.97 - const EdgeIntMap &getFlow() const { return mincost_flow.flow;}
1.98 + const EdgeIntMap &getFlow() const { return min_cost_flow.flow;}
1.99
1.100 /// Returns the optimal dual solution
1.101
1.102 ///This function returns a const reference to the NodeMap
1.103 ///\c potential (the dual solution).
1.104 - /// \pre \ref run() must be called before using this function.
1.105 - const EdgeIntMap &getPotential() const { return mincost_flow.potential;}
1.106 + const EdgeIntMap &getPotential() const { return min_cost_flow.potential;}
1.107
1.108 ///Checks whether the complementary slackness holds.
1.109
1.110 ///This function checks, whether the given solution is optimal.
1.111 - ///It should return true after calling \ref run()
1.112 ///Currently this function only checks optimality,
1.113 ///doesn't bother with feasibility
1.114 ///It is meant for testing purposes.
1.115 - ///
1.116 bool checkComplementarySlackness(){
1.117 - return mincost_flow.checkComplementarySlackness();
1.118 + return min_cost_flow.checkComplementarySlackness();
1.119 }
1.120
1.121 ///Read the found paths.