[Lemon-commits] [lemon_svn] marci: r1404 - hugo/trunk/src/work/marci/lp
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:45:09 CET 2006
Author: marci
Date: Sat Nov 20 15:23:27 2004
New Revision: 1404
Modified:
hugo/trunk/src/work/marci/lp/lp_solver_wrapper.h
hugo/trunk/src/work/marci/lp/makefile
hugo/trunk/src/work/marci/lp/max_flow_by_lp.cc
Log:
Modifications for hugo 0.2
Modified: hugo/trunk/src/work/marci/lp/lp_solver_wrapper.h
==============================================================================
--- hugo/trunk/src/work/marci/lp/lp_solver_wrapper.h (original)
+++ hugo/trunk/src/work/marci/lp/lp_solver_wrapper.h Sat Nov 20 15:23:27 2004
@@ -10,7 +10,9 @@
#include <stdlib.h>
// #include <stdio>
//#include <stdlib>
+extern "C" {
#include "glpk.h"
+}
#include <iostream>
#include <vector>
Modified: hugo/trunk/src/work/marci/lp/makefile
==============================================================================
--- hugo/trunk/src/work/marci/lp/makefile (original)
+++ hugo/trunk/src/work/marci/lp/makefile Sat Nov 20 15:23:27 2004
@@ -5,7 +5,7 @@
CXXFLAGS = -g -O2 -W -Wall $(INCLUDEDIRS) -ansi -pedantic
LDFLAGS = -L$(GLPKROOT)/lib -lglpk
-BINARIES = max_flow_by_lp sample sample2 sample11 sample15
+BINARIES = max_flow_by_lp# sample sample2 sample11 sample15
#include ../makefile
Modified: hugo/trunk/src/work/marci/lp/max_flow_by_lp.cc
==============================================================================
--- hugo/trunk/src/work/marci/lp/max_flow_by_lp.cc (original)
+++ hugo/trunk/src/work/marci/lp/max_flow_by_lp.cc Sat Nov 20 15:23:27 2004
@@ -2,15 +2,14 @@
#include <iostream>
#include <fstream>
-#include <sage_graph.h>
#include <lemon/smart_graph.h>
+#include <lemon/list_graph.h>
#include <lemon/dimacs.h>
#include <lemon/time_measure.h>
//#include <graph_wrapper.h>
-#include <lemon/max_flow.h>
+#include <lemon/preflow.h>
#include <augmenting_flow.h>
//#include <preflow_res.h>
-#include <for_each_macros.h>
#include <lp_solver_wrapper.h>
using namespace lemon;
@@ -33,9 +32,8 @@
int main(int, char **) {
- typedef SageGraph MutableGraph;
- //typedef SmartGraph Graph;
- typedef SageGraph Graph;
+ typedef ListGraph MutableGraph;
+ typedef SmartGraph Graph;
typedef Graph::Node Node;
typedef Graph::EdgeIt EdgeIt;
@@ -47,7 +45,7 @@
readDimacs(std::cin, g, cap, s, t);
Timer ts;
Graph::EdgeMap<int> flow(g); //0 flow
- MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
+ Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
max_flow_test(g, s, t, cap, flow);
AugmentingFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
augmenting_flow_test(g, s, t, cap, flow);
@@ -60,9 +58,9 @@
max_flow_test.run();
std::cout << "elapsed time: " << ts << std::endl;
std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
- max_flow_test.actMinCut(cut);
+ max_flow_test.minCut(cut);
- FOR_EACH_LOC(Graph::EdgeIt, e, g) {
+ for (Graph::EdgeIt e(g); e!=INVALID; ++e) {
if (cut[g.source(e)] && !cut[g.target(e)] && !flow[e]==cap[e])
std::cout << "Slackness does not hold!" << std::endl;
if (!cut[g.source(e)] && cut[g.target(e)] && flow[e]>0)
@@ -74,7 +72,7 @@
// std::cout << "preflow ..." << std::endl;
// FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
// ts.reset();
-// max_flow_test.preflow(MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >::GEN_FLOW);
+// max_flow_test.preflow(Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >::GEN_FLOW);
// std::cout << "elapsed time: " << ts << std::endl;
// std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
@@ -97,7 +95,7 @@
{
std::cout << "physical blocking flow augmentation ..." << std::endl;
- FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
+ for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
ts.reset();
int i=0;
while (augmenting_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
@@ -105,7 +103,7 @@
std::cout << "number of augmentation phases: " << i << std::endl;
std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
- FOR_EACH_LOC(Graph::EdgeIt, e, g) {
+ for (Graph::EdgeIt e(g); e!=INVALID; ++e) {
if (cut[g.source(e)] && !cut[g.target(e)] && !flow[e]==cap[e])
std::cout << "Slackness does not hold!" << std::endl;
if (!cut[g.source(e)] && cut[g.target(e)] && flow[e]>0)
@@ -126,7 +124,7 @@
{
std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
- FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
+ for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
ts.reset();
int i=0;
while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; }
@@ -134,7 +132,7 @@
std::cout << "number of augmentation phases: " << i << std::endl;
std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
- FOR_EACH_LOC(Graph::EdgeIt, e, g) {
+ for (Graph::EdgeIt e(g); e!=INVALID; ++e) {
if (cut[g.source(e)] && !cut[g.target(e)] && !flow[e]==cap[e])
std::cout << "Slackness does not hold!" << std::endl;
if (!cut[g.source(e)] && cut[g.target(e)] && flow[e]>0)
@@ -186,37 +184,28 @@
typedef Graph::EdgeMap<ColIt> EdgeIndexMap;
EdgeIndexMap edge_index_map(g);
PrimalMap<Graph::Edge, EdgeIndexMap> lp_flow(lp, edge_index_map);
- Graph::EdgeIt e;
- for (g.first(e); g.valid(e); g.next(e)) {
+ for (Graph::EdgeIt e(g); e!=INVALID; ++e) {
ColIt col_it=lp.addCol();
edge_index_map.set(e, col_it);
lp.setColBounds(col_it, LPX_DB, 0.0, cap[e]);
}
- Graph::NodeIt n;
- for (g.first(n); g.valid(n); g.next(n)) {
+ for (Graph::NodeIt n(g); n!=INVALID; ++n) {
if (n!=s) {
//hurokelek miatt
Graph::EdgeMap<int> coeffs(g, 0);
- {
- Graph::InEdgeIt e;
- for (g.first(e, n); g.valid(e); g.next(e)) coeffs.set(e, coeffs[e]+1);
- }
- {
- Graph::OutEdgeIt e;
- for (g.first(e, n); g.valid(e); g.next(e)) coeffs.set(e, coeffs[e]-1);
- }
+ for (Graph::InEdgeIt e(g, n); e!=INVALID; ++e)
+ coeffs.set(e, coeffs[e]+1);
+ for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e)
+ coeffs.set(e, coeffs[e]-1);
if (n==t) {
- Graph::EdgeIt e;
- //std::vector< std::pair<ColIt, double> > row;
- for (g.first(e); g.valid(e); g.next(e)) {
+ for (Graph::EdgeIt e(g); e!=INVALID; ++e) {
if (coeffs[e]!=0)
lp.setObjCoef(edge_index_map[e], coeffs[e]);
}
} else {
RowIt row_it=lp.addRow();
- Graph::EdgeIt e;
std::vector< std::pair<ColIt, double> > row;
- for (g.first(e); g.valid(e); g.next(e)) {
+ for (Graph::EdgeIt e(g); e!=INVALID; ++e) {
if (coeffs[e]!=0)
row.push_back(std::make_pair(edge_index_map[e], coeffs[e]));
}
More information about the Lemon-commits
mailing list