1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/test/lp_test.cc Wed Apr 06 07:24:48 2005 +0000
1.3 @@ -0,0 +1,139 @@
1.4 +#include<lemon/lp_solver_skeleton.h>
1.5 +#include<lemon/lp_glpk.h>
1.6 +
1.7 +using namespace lemon;
1.8 +
1.9 +void lpTest(LpSolverBase & lp)
1.10 +{
1.11 + typedef LpSolverBase LP;
1.12 +
1.13 + std::vector<LP::Col> x(10);
1.14 + // for(int i=0;i<10;i++) x.push_back(lp.addCol());
1.15 + lp.addColSet(x);
1.16 +
1.17 + std::vector<LP::Col> y(10);
1.18 + lp.addColSet(y);
1.19 +
1.20 + std::map<int,LP::Col> z;
1.21 +
1.22 + z.insert(std::make_pair(12,INVALID));
1.23 + z.insert(std::make_pair(2,INVALID));
1.24 + z.insert(std::make_pair(7,INVALID));
1.25 + z.insert(std::make_pair(5,INVALID));
1.26 +
1.27 + lp.addColSet(z);
1.28 +
1.29 +
1.30 + LP::Expr e,f,g;
1.31 + LP::Col p1,p2,p3,p4,p5;
1.32 + LP::Constr c;
1.33 +
1.34 + e[p1]=2;
1.35 + e.constComp()=12;
1.36 + e[p1]+=2;
1.37 + e.constComp()+=12;
1.38 + e[p1]-=2;
1.39 + e.constComp()-=12;
1.40 +
1.41 + e=2;
1.42 + e=2.2;
1.43 + e=p1;
1.44 + e=f;
1.45 +
1.46 + e+=2;
1.47 + e+=2.2;
1.48 + e+=p1;
1.49 + e+=f;
1.50 +
1.51 + e-=2;
1.52 + e-=2.2;
1.53 + e-=p1;
1.54 + e-=f;
1.55 +
1.56 + e*=2;
1.57 + e*=2.2;
1.58 + e/=2;
1.59 + e/=2.2;
1.60 +
1.61 + e=((p1+p2)+(p1-p2)+(p1+12)+(12+p1)+(p1-12)+(12-p1)+
1.62 + (f+12)+(12+f)+(p1+f)+(f+p1)+(f+g)+
1.63 + (f-12)+(12-f)+(p1-f)+(f-p1)+(f-g)+
1.64 + 2.2*f+f*2.2+f/2.2+
1.65 + 2*f+f*2+f/2+
1.66 + 2.2*p1+p1*2.2+p1/2.2+
1.67 + 2*p1+p1*2+p1/2
1.68 + );
1.69 +
1.70 +
1.71 + c = (e <= f );
1.72 + c = (e <= 2.2);
1.73 + c = (e <= 2 );
1.74 + c = (e <= p1 );
1.75 + c = (2.2<= f );
1.76 + c = (2 <= f );
1.77 + c = (p1 <= f );
1.78 + c = (p1 <= p2 );
1.79 + c = (p1 <= 2.2);
1.80 + c = (p1 <= 2 );
1.81 + c = (2.2<= p2 );
1.82 + c = (2 <= p2 );
1.83 +
1.84 + c = (e >= f );
1.85 + c = (e >= 2.2);
1.86 + c = (e >= 2 );
1.87 + c = (e >= p1 );
1.88 + c = (2.2>= f );
1.89 + c = (2 >= f );
1.90 + c = (p1 >= f );
1.91 + c = (p1 >= p2 );
1.92 + c = (p1 >= 2.2);
1.93 + c = (p1 >= 2 );
1.94 + c = (2.2>= p2 );
1.95 + c = (2 >= p2 );
1.96 +
1.97 + c = (e == f );
1.98 + c = (e == 2.2);
1.99 + c = (e == 2 );
1.100 + c = (e == p1 );
1.101 + c = (2.2== f );
1.102 + c = (2 == f );
1.103 + c = (p1 == f );
1.104 + //c = (p1 == p2 );
1.105 + c = (p1 == 2.2);
1.106 + c = (p1 == 2 );
1.107 + c = (2.2== p2 );
1.108 + c = (2 == p2 );
1.109 +
1.110 + c = (2 <= e <= 3);
1.111 + c = (2 <= p1<= 3);
1.112 +
1.113 + c = (2 >= e >= 3);
1.114 + c = (2 >= p1>= 3);
1.115 +
1.116 + e[x[3]]=2;
1.117 + e[x[3]]=4;
1.118 + e[x[3]]=1;
1.119 + e.constComp()=12;
1.120 +
1.121 + lp.addRow(LP::INF,e,23);
1.122 + lp.addRow(LP::INF,3.0*(x[1]+x[2]/2)-x[3],23);
1.123 + lp.addRow(LP::INF,3.0*(x[1]+x[2]*2-5*x[3]+12-x[4]/3)+2*x[4]-4,23);
1.124 +
1.125 + lp.addRow(x[1]+x[3]<=x[5]-3);
1.126 + lp.addRow(-7<=x[1]+x[3]-12<=3);
1.127 + lp.addRow(x[1]<=x[5]);
1.128 +
1.129 +
1.130 +
1.131 +}
1.132 +
1.133 +int main()
1.134 +{
1.135 + LpSolverSkeleton lp_skel;
1.136 + LpGlpk lp_glpk;
1.137 +
1.138 + lpTest(lp_skel);
1.139 + lpTest(lp_glpk);
1.140 +
1.141 + return 0;
1.142 +}