[Lemon-commits] [lemon_svn] athos: r908 - in hugo/trunk/src/work: . athos
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:42:10 CET 2006
Author: athos
Date: Wed Jun 2 11:45:50 2004
New Revision: 908
Modified:
hugo/trunk/src/work/athos/min_cost_flow.cc
hugo/trunk/src/work/athos/mincostflow.h
hugo/trunk/src/work/makefile
Log:
Seems to work. More tests required.
Modified: hugo/trunk/src/work/athos/min_cost_flow.cc
==============================================================================
--- hugo/trunk/src/work/athos/min_cost_flow.cc (original)
+++ hugo/trunk/src/work/athos/min_cost_flow.cc Wed Jun 2 11:45:50 2004
@@ -11,7 +11,7 @@
bool passed = true;
-/*
+
void check(bool rc, char *msg="") {
passed = passed && rc;
if(!rc) {
@@ -20,7 +20,7 @@
}
}
-*/
+
int main()
@@ -90,6 +90,7 @@
min_cost_flow_test.run();
//int k=1;
+ check(min_cost_flow_test.checkOptimality(), "Is the primal-dual solution pair really optimal?");
/*
check( min_cost_flow_test.run(s,t,k) == 1 && min_cost_flow_test.totalLength() == 19,"One path, total cost should be 19");
@@ -109,10 +110,10 @@
check(min_cost_flow_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
-
+ */
cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
<< endl;
return passed ? 0 : 1;
- */
+
}
Modified: hugo/trunk/src/work/athos/mincostflow.h
==============================================================================
--- hugo/trunk/src/work/athos/mincostflow.h (original)
+++ hugo/trunk/src/work/athos/mincostflow.h Wed Jun 2 11:45:50 2004
@@ -99,8 +99,6 @@
//To store the potential (dual variables)
typedef typename Graph::template NodeMap<Cost> PotentialMap;
PotentialMap potential;
- //To store excess-deficit values
- SupplyDemandMap excess_deficit;
Cost total_cost;
@@ -114,8 +112,7 @@
cost(_cost),
supply_demand(_supply_demand),
flow(_graph),
- potential(_graph),
- excess_deficit(_graph){ }
+ potential(_graph){ }
///Runs the algorithm.
@@ -126,9 +123,13 @@
/// feasible primal-dual solution pair as well.
void run() {
+ //To store excess-deficit values
+ SupplyDemandMap excess_deficit(graph);
+
//Resetting variables from previous runs
//total_cost = 0;
+
typedef typename Graph::template NodeMap<int> HeapMap;
typedef BinHeap< Node, SupplyDemand, typename Graph::template NodeMap<int>,
std::greater<SupplyDemand> > HeapType;
@@ -196,6 +197,7 @@
//Let's construct the sugraph consisting only of the abundant edges
typedef ConstMap< typename Graph::Node, bool > ConstNodeMap;
+
ConstNodeMap const_true_map(true);
typedef SubGraphWrapper< const Graph, ConstNodeMap,
typename Graph::template EdgeMap<bool> >
@@ -320,7 +322,7 @@
Node s = excess_nodes.top();
- SupplyDemand max_excess = excess_nodes[s];
+ max_excess = excess_nodes[s];
Node t = deficit_nodes.top();
if (max_excess < deficit_nodes[t]){
max_excess = deficit_nodes[t];
@@ -370,7 +372,7 @@
//Update the excess_nodes heap
- if (delta >= excess_nodes[s]){
+ if (delta > excess_nodes[s]){
if (delta > excess_nodes[s])
deficit_nodes.push(s,delta - excess_nodes[s]);
excess_nodes.pop();
@@ -380,7 +382,7 @@
excess_nodes.set(s, excess_nodes[s] - delta);
}
//Update the deficit_nodes heap
- if (delta >= deficit_nodes[t]){
+ if (delta > deficit_nodes[t]){
if (delta > deficit_nodes[t])
excess_nodes.push(t,delta - deficit_nodes[t]);
deficit_nodes.pop();
@@ -444,7 +446,7 @@
///This function checks, whether the given solution is optimal
///Running after a \c run() should return with true
- ///In this "state of the art" this only check optimality, doesn't bother with feasibility
+ ///In this "state of the art" this only checks optimality, doesn't bother with feasibility
///
///\todo Is this OK here?
bool checkComplementarySlackness(){
@@ -455,20 +457,52 @@
mod_pot = cost[e]-potential[graph.head(e)]+potential[graph.tail(e)];
fl_e = flow[e];
// std::cout << fl_e << std::endl;
- if (0<fl_e && fl_e<capacity[e]){
- if (mod_pot != 0)
- return false;
+ if (mod_pot > 0 && fl_e != 0)
+ return false;
+
+ }
+ return true;
+ }
+
+ /*
+ //For testing purposes only
+ //Lists the node_properties
+ void write_property_vector(const SupplyDemandMap& a,
+ char* prop_name="property"){
+ FOR_EACH_LOC(typename Graph::NodeIt, i, graph){
+ cout<<"Node id.: "<<graph.id(i)<<", "<<prop_name<<" value: "<<a[i]<<endl;
+ }
+ cout<<endl;
+ }
+ */
+ bool checkFeasibility(){
+ SupplyDemandMap supdem(graph);
+ FOR_EACH_LOC(typename Graph::EdgeIt, e, graph){
+
+ if ( flow[e] < 0){
+
+ return false;
}
- else{
- if (mod_pot > 0 && fl_e != 0)
- return false;
- if (mod_pot < 0 && fl_e != capacity[e])
- return false;
+ supdem[graph.tail(e)] += flow[e];
+ supdem[graph.head(e)] -= flow[e];
+ }
+ //write_property_vector(supdem, "supdem");
+ //write_property_vector(supply_demand, "supply_demand");
+
+ FOR_EACH_LOC(typename Graph::NodeIt, n, graph){
+
+ if ( supdem[n] != supply_demand[n]){
+ //cout<<"Node id.: "<<graph.id(n)<<" : "<<supdem[n]<<", should be: "<<supply_demand[n]<<endl;
+ return false;
}
}
+
return true;
}
-
+
+ bool checkOptimality(){
+ return checkFeasibility() && checkComplementarySlackness();
+ }
}; //class MinCostFlow
Modified: hugo/trunk/src/work/makefile
==============================================================================
--- hugo/trunk/src/work/makefile (original)
+++ hugo/trunk/src/work/makefile Wed Jun 2 11:45:50 2004
@@ -1,5 +1,5 @@
INCLUDEDIRS ?= -I.. -I. -I./{marci,jacint,alpar,klao,akos}
-CXXFLAGS = -g -O3 -W -Wall $(INCLUDEDIRS) -ansi -pedantic
+CXXFLAGS = -g -W -Wall $(INCLUDEDIRS) -ansi -pedantic
BINARIES ?= bin_heap_demo
More information about the Lemon-commits
mailing list