[Lemon-commits] [lemon_svn] alpar: r1748 - in hugo/trunk/src: demo test work/athos/lp

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:47:19 CET 2006


Author: alpar
Date: Wed Apr  6 09:24:48 2005
New Revision: 1748

Added:
   hugo/trunk/src/demo/lp_demo.cc
   hugo/trunk/src/test/lp_test.cc
      - copied, changed from r1747, /hugo/trunk/src/work/athos/lp/lp_test.cc
Removed:
   hugo/trunk/src/work/athos/lp/lp_test.cc
Modified:
   hugo/trunk/src/test/Makefile.am

Log:
lp_test added
WARNING: Overall glpk dependency! (we should avoid)

Added: hugo/trunk/src/demo/lp_demo.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/demo/lp_demo.cc	Wed Apr  6 09:24:48 2005
@@ -0,0 +1,61 @@
+#include<lemon/lp_glpk.h>
+#include<lemon/graph_reader.h>
+#include<lemon/list_graph.h>
+
+using namespace lemon;
+
+template<class G,class C>
+double maxFlow(const G &g,const C &cap,typename G::Node s,typename G::Node t)
+{
+  LpGlpk lp;
+  
+  typedef G Graph;
+  typedef typename G::Node Node;
+  typedef typename G::NodeIt NodeIt;
+  typedef typename G::Edge Edge;
+  typedef typename G::EdgeIt EdgeIt;
+  typedef typename G::OutEdgeIt OutEdgeIt;
+  typedef typename G::InEdgeIt InEdgeIt;
+  
+  typename G::template EdgeMap<LpGlpk::Col> x(g);
+  lp.addColSet(x);
+  
+  for(EdgeIt e(g);e!=INVALID;++e) {
+    lp.colUpperBound(x[e],cap[e]);
+    lp.colLowerBound(x[e],0);
+  }
+
+  for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) {
+    LpGlpk::Expr ex;
+    for(InEdgeIt  e(g,n);e!=INVALID;++e) ex+=x[e];
+    for(OutEdgeIt e(g,n);e!=INVALID;++e) ex-=x[e];
+    lp.addRow(ex==0);
+  }
+  {
+    LpGlpk::Expr ex;
+    for(InEdgeIt  e(g,t);e!=INVALID;++e) ex+=x[e];
+    for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e];
+    lp.setObj(ex);
+  }
+
+  lp.solve();
+
+  return 0;
+}
+
+int main() 
+{
+  LpGlpk lp_glpk;
+
+  ListGraph g;
+  ListGraph::Node s=g.addNode();
+  ListGraph::Node t=g.addNode();
+
+  ListGraph::EdgeMap<double> cap(g);
+  
+  GraphReader<ListGraph> reader(std::cin,g);
+  reader.addEdgeMap("capacity",cap).run();
+  
+  maxFlow(g,cap,s,t);
+
+}

Modified: hugo/trunk/src/test/Makefile.am
==============================================================================
--- hugo/trunk/src/test/Makefile.am	(original)
+++ hugo/trunk/src/test/Makefile.am	Wed Apr  6 09:24:48 2005
@@ -1,4 +1,5 @@
 AM_CPPFLAGS = -I$(top_srcdir)/src
+LDADD = $(top_builddir)/src/lemon/libemon.la -lglpk
 
 EXTRA_DIST = preflow_graph.dim dijkstra_test.lgf
 noinst_HEADERS = \
@@ -17,6 +18,7 @@
 	graph_wrapper_test \
 	graph_utils_test \
 	kruskal_test \
+	lp_test \
         max_matching_test \
         maps_test \
 	min_cost_flow_test \
@@ -41,6 +43,7 @@
 graph_utils_test_SOURCES = graph_utils_test.cc
 graph_wrapper_test_SOURCES = graph_wrapper_test.cc
 kruskal_test_SOURCES = kruskal_test.cc
+lp_test_SOURCES = lp_test.cc
 maps_test_SOURCES = maps_test.cc
 min_cost_flow_test_SOURCES = min_cost_flow_test.cc
 max_matching_test_SOURCES = max_matching_test.cc

Copied: hugo/trunk/src/test/lp_test.cc (from r1747, /hugo/trunk/src/work/athos/lp/lp_test.cc)
==============================================================================
--- /hugo/trunk/src/work/athos/lp/lp_test.cc	(original)
+++ hugo/trunk/src/test/lp_test.cc	Wed Apr  6 09:24:48 2005
@@ -1,6 +1,5 @@
-#include"lp_solver_skeleton.h"
-#include"lp_glpk.h"
-#include<lemon/list_graph.h>
+#include<lemon/lp_solver_skeleton.h>
+#include<lemon/lp_glpk.h>
 
 using namespace lemon;
 
@@ -8,8 +7,9 @@
 {
   typedef LpSolverBase LP;
 
-  std::vector<LP::Col> x;
-  for(int i=0;i<10;i++) x.push_back(lp.addCol());
+  std::vector<LP::Col> x(10);
+  //  for(int i=0;i<10;i++) x.push_back(lp.addCol());
+  lp.addColSet(x);
 
   std::vector<LP::Col> y(10);
   lp.addColSet(y);
@@ -123,46 +123,8 @@
   lp.addRow(-7<=x[1]+x[3]-12<=3);
   lp.addRow(x[1]<=x[5]);
 
-}
-
 
-template<class G,class C>
-double maxFlow(const G &g,const C &cap,typename G::Node s,typename G::Node t)
-{
-  LpGlpk lp;
-  
-  typedef G Graph;
-  typedef typename G::Node Node;
-  typedef typename G::NodeIt NodeIt;
-  typedef typename G::Edge Edge;
-  typedef typename G::EdgeIt EdgeIt;
-  typedef typename G::OutEdgeIt OutEdgeIt;
-  typedef typename G::InEdgeIt InEdgeIt;
-  
-  typename G::template EdgeMap<LpGlpk::Col> x(g);
-  lp.addColSet(x);
   
-  for(EdgeIt e(g);e!=INVALID;++e) {
-    lp.colUpperBound(x[e],cap[e]);
-    lp.colLowerBound(x[e],0);
-  }
-
-  for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) {
-    LpGlpk::Expr ex;
-    for(InEdgeIt  e(g,n);e!=INVALID;++e) ex+=x[e];
-    for(OutEdgeIt e(g,n);e!=INVALID;++e) ex-=x[e];
-    lp.addRow(ex==0);
-  }
-  {
-    LpGlpk::Expr ex;
-    for(InEdgeIt  e(g,t);e!=INVALID;++e) ex+=x[e];
-    for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e];
-    lp.setObj(ex);
-  }
-
-  lp.solve();
-
-  return 0;
 }
 
 int main() 
@@ -173,12 +135,5 @@
   lpTest(lp_skel);
   lpTest(lp_glpk);
 
-  ListGraph g;
-  ListGraph::Node s=g.addNode();
-  ListGraph::Node t=g.addNode();
-
-  ListGraph::EdgeMap<double> cap(g);
-  
-  maxFlow(g,cap,s,t);
-
+  return 0;
 }



More information about the Lemon-commits mailing list