athos@1299: #include"lp_solver_skeleton.h"
athos@1299: #include"lp_cplex.h"
athos@1299: #include<lemon/list_graph.h>
athos@1299: 
athos@1299: using namespace lemon;
athos@1299: 
athos@1299: void lpTest(LpSolverBase & lp)
athos@1299: {
athos@1299:   typedef LpSolverBase LP;
athos@1299: 
athos@1299:   std::vector<LP::Col> x;
athos@1299:   for(int i=0;i<10;i++) x.push_back(lp.addCol());
athos@1299: 
athos@1299:   std::vector<LP::Col> y(10);
athos@1299:   lp.addColSet(y);
athos@1299: 
athos@1299:   std::map<int,LP::Col> z;
athos@1299:   
athos@1299:   z.insert(std::make_pair(12,INVALID));
athos@1299:   z.insert(std::make_pair(2,INVALID));
athos@1299:   z.insert(std::make_pair(7,INVALID));
athos@1299:   z.insert(std::make_pair(5,INVALID));
athos@1299:   
athos@1299:   lp.addColSet(z);
athos@1299: 
athos@1299: 
athos@1299:   LP::Expr e,f,g;
athos@1299:   LP::Col p1,p2,p3,p4,p5;
athos@1299:   LP::Constr c;
athos@1299:   
athos@1299:   e[p1]=2;
athos@1299:   e.constComp()=12;
athos@1299:   e[p1]+=2;
athos@1299:   e.constComp()+=12;
athos@1299:   e[p1]-=2;
athos@1299:   e.constComp()-=12;
athos@1299:   
athos@1299:   e=2;
athos@1299:   e=2.2;
athos@1299:   e=p1;
athos@1299:   e=f;
athos@1299: 
athos@1299:   e+=2;
athos@1299:   e+=2.2;
athos@1299:   e+=p1;
athos@1299:   e+=f;
athos@1299: 
athos@1299:   e-=2;
athos@1299:   e-=2.2;
athos@1299:   e-=p1;
athos@1299:   e-=f;
athos@1299: 
athos@1299:   e*=2;
athos@1299:   e*=2.2;
athos@1299:   e/=2;
athos@1299:   e/=2.2;
athos@1299: 
athos@1299:   e=((p1+p2)+(p1-p2)+(p1+12)+(12+p1)+(p1-12)+(12-p1)+
athos@1299:       (f+12)+(12+f)+(p1+f)+(f+p1)+(f+g)+
athos@1299:       (f-12)+(12-f)+(p1-f)+(f-p1)+(f-g)+
athos@1299:       2.2*f+f*2.2+f/2.2+
athos@1299:       2*f+f*2+f/2+
athos@1299:       2.2*p1+p1*2.2+p1/2.2+
athos@1299:       2*p1+p1*2+p1/2
athos@1299:      );
athos@1299:   
athos@1299: 
athos@1299:   c = (e  <= f  );
athos@1299:   c = (e  <= 2.2);
athos@1299:   c = (e  <= 2  );
athos@1299:   c = (e  <= p1 );
athos@1299:   c = (2.2<= f  );
athos@1299:   c = (2  <= f  );
athos@1299:   c = (p1 <= f  );
athos@1299:   c = (p1 <= p2 );
athos@1299:   c = (p1 <= 2.2);
athos@1299:   c = (p1 <= 2  );
athos@1299:   c = (2.2<= p2 );
athos@1299:   c = (2  <= p2 );
athos@1299: 
athos@1299:   c = (e  >= f  );
athos@1299:   c = (e  >= 2.2);
athos@1299:   c = (e  >= 2  );
athos@1299:   c = (e  >= p1 );
athos@1299:   c = (2.2>= f  );
athos@1299:   c = (2  >= f  );
athos@1299:   c = (p1 >= f  );
athos@1299:   c = (p1 >= p2 );
athos@1299:   c = (p1 >= 2.2);
athos@1299:   c = (p1 >= 2  );
athos@1299:   c = (2.2>= p2 );
athos@1299:   c = (2  >= p2 );
athos@1299: 
athos@1299:   c = (e  == f  );
athos@1299:   c = (e  == 2.2);
athos@1299:   c = (e  == 2  );
athos@1299:   c = (e  == p1 );
athos@1299:   c = (2.2== f  );
athos@1299:   c = (2  == f  );
athos@1299:   c = (p1 == f  );
athos@1299:   //c = (p1 == p2 );
athos@1299:   c = (p1 == 2.2);
athos@1299:   c = (p1 == 2  );
athos@1299:   c = (2.2== p2 );
athos@1299:   c = (2  == p2 );
athos@1299: 
athos@1299:   c = (2 <= e <= 3);
athos@1299:   c = (2 <= p1<= 3);
athos@1299: 
athos@1299:   c = (2 >= e >= 3);
athos@1299:   c = (2 >= p1>= 3);
athos@1299: 
athos@1299:   e[x[3]]=2;
athos@1299:   e[x[3]]=4;
athos@1299:   e[x[3]]=1;
athos@1299:   e.constComp()=12;
athos@1299:   
athos@1299:   lp.addRow(LP::INF,e,23);
athos@1299:   lp.addRow(LP::INF,3.0*(p1+p2)-p3,23);
athos@1299:   lp.addRow(LP::INF,3.0*(x[1]+x[2]/2)-x[3],23);
athos@1299:   lp.addRow(LP::INF,3.0*(p1+p2*2-5*p3+12-p4/3)+2*p4-4,23);
athos@1299:   lp.addRow(LP::INF,3.0*(x[1]+x[2]*2-5*x[3]+12-x[4]/3)+2*x[4]-4,23);
athos@1299: 
athos@1299:   lp.addRow(x[1]+x[3]<=x[5]-3);
athos@1299:   lp.addRow(-7<=x[1]+x[3]-12<=3);
athos@1299:   //lp.addRow(x[1]<=x[5]);
athos@1299: 
athos@1299: }
athos@1299: 
athos@1299: 
athos@1299: template<class G,class C>
athos@1299: double maxFlow(const G &g,const C &cap,typename G::Node s,typename G::Node t)
athos@1299: {
athos@1299:   LpGlpk lp;
athos@1299:   
athos@1299:   typedef G Graph;
athos@1299:   typedef typename G::Node Node;
athos@1299:   typedef typename G::NodeIt NodeIt;
athos@1299:   typedef typename G::Edge Edge;
athos@1299:   typedef typename G::EdgeIt EdgeIt;
athos@1299:   typedef typename G::OutEdgeIt OutEdgeIt;
athos@1299:   typedef typename G::InEdgeIt InEdgeIt;
athos@1299:   
athos@1299:   typename G::EdgeMap<LpGlpk::Col> x(g);
athos@1299:   lp.addColSet(x);
athos@1299:    //for(EdgeIt e(g);e!=INVALID;++e) x[e]=lp.addCol();
athos@1299:   
athos@1299:   for(EdgeIt e(g);e!=INVALID;++e) {
athos@1299:     lp.setColUpperBound(x[e],cap[e]);
athos@1299:     lp.setColLowerBound(x[e],0);
athos@1299:   }
athos@1299: 
athos@1299:   for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) {
athos@1299:     LpGlpk::Expr ex;
athos@1299:     for(InEdgeIt  e(g,n);e!=INVALID;++e) ex+=x[e];
athos@1299:     for(OutEdgeIt e(g,n);e!=INVALID;++e) ex-=x[e];
athos@1299:     lp.addRow(0,ex,0);
athos@1299:   }
athos@1299:   {
athos@1299:     LpGlpk::Expr ex;
athos@1299:     for(InEdgeIt  e(g,t);e!=INVALID;++e) ex+=x[e];
athos@1299:     for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e];
athos@1299:     lp.setObj(ex);
athos@1299:   }
athos@1299: 
athos@1299:   lp.solve();
athos@1299: 
athos@1299:   return 0;
athos@1299: }
athos@1299: 
athos@1299: int main() 
athos@1299: {
athos@1299:   LpSolverSkeleton lp_skel;
athos@1299:   LpGlpk lp_glpk;
athos@1299:   LpCplex lp_cplex;
athos@1299: 
athos@1299:   lpTest(lp_skel);
athos@1299:   lpTest(lp_cplex);
athos@1299: 
athos@1299:   ListGraph g;
athos@1299:   ListGraph::EdgeMap<double> cap(g);
athos@1299:   
athos@1299:   maxFlow(g,cap,ListGraph::NodeIt(g),ListGraph::NodeIt(g));
athos@1299: 
athos@1299: }