COIN-OR::LEMON - Graph Library

Changeset 1309:b3ce42a4d7d2 in lemon-0.x


Ignore:
Timestamp:
04/06/05 09:24:48 (15 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1748
Message:

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

Location:
src
Files:
1 added
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/test/Makefile.am

    r1235 r1309  
    11AM_CPPFLAGS = -I$(top_srcdir)/src
     2LDADD = $(top_builddir)/src/lemon/libemon.la -lglpk
    23
    34EXTRA_DIST = preflow_graph.dim dijkstra_test.lgf
     
    1819        graph_utils_test \
    1920        kruskal_test \
     21        lp_test \
    2022        max_matching_test \
    2123        maps_test \
     
    4244graph_wrapper_test_SOURCES = graph_wrapper_test.cc
    4345kruskal_test_SOURCES = kruskal_test.cc
     46lp_test_SOURCES = lp_test.cc
    4447maps_test_SOURCES = maps_test.cc
    4548min_cost_flow_test_SOURCES = min_cost_flow_test.cc
  • src/test/lp_test.cc

    r1295 r1309  
    1 #include"lp_solver_skeleton.h"
    2 #include"lp_glpk.h"
    3 #include<lemon/list_graph.h>
     1#include<lemon/lp_solver_skeleton.h>
     2#include<lemon/lp_glpk.h>
    43
    54using namespace lemon;
     
    98  typedef LpSolverBase LP;
    109
    11   std::vector<LP::Col> x;
    12   for(int i=0;i<10;i++) x.push_back(lp.addCol());
     10  std::vector<LP::Col> x(10);
     11  //  for(int i=0;i<10;i++) x.push_back(lp.addCol());
     12  lp.addColSet(x);
    1313
    1414  std::vector<LP::Col> y(10);
     
    124124  lp.addRow(x[1]<=x[5]);
    125125
    126 }
    127126
    128 
    129 template<class G,class C>
    130 double maxFlow(const G &g,const C &cap,typename G::Node s,typename G::Node t)
    131 {
    132   LpGlpk lp;
    133127 
    134   typedef G Graph;
    135   typedef typename G::Node Node;
    136   typedef typename G::NodeIt NodeIt;
    137   typedef typename G::Edge Edge;
    138   typedef typename G::EdgeIt EdgeIt;
    139   typedef typename G::OutEdgeIt OutEdgeIt;
    140   typedef typename G::InEdgeIt InEdgeIt;
    141  
    142   typename G::template EdgeMap<LpGlpk::Col> x(g);
    143   lp.addColSet(x);
    144  
    145   for(EdgeIt e(g);e!=INVALID;++e) {
    146     lp.colUpperBound(x[e],cap[e]);
    147     lp.colLowerBound(x[e],0);
    148   }
    149 
    150   for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) {
    151     LpGlpk::Expr ex;
    152     for(InEdgeIt  e(g,n);e!=INVALID;++e) ex+=x[e];
    153     for(OutEdgeIt e(g,n);e!=INVALID;++e) ex-=x[e];
    154     lp.addRow(ex==0);
    155   }
    156   {
    157     LpGlpk::Expr ex;
    158     for(InEdgeIt  e(g,t);e!=INVALID;++e) ex+=x[e];
    159     for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e];
    160     lp.setObj(ex);
    161   }
    162 
    163   lp.solve();
    164 
    165   return 0;
    166128}
    167129
     
    174136  lpTest(lp_glpk);
    175137
    176   ListGraph g;
    177   ListGraph::Node s=g.addNode();
    178   ListGraph::Node t=g.addNode();
    179 
    180   ListGraph::EdgeMap<double> cap(g);
    181  
    182   maxFlow(g,cap,s,t);
    183 
     138  return 0;
    184139}
Note: See TracChangeset for help on using the changeset viewer.