Lemon Graph Format uses label instead of id named map.
2 #include <lemon/lp_skeleton.h>
3 #include "test_tools.h"
11 #include <lemon/lp_glpk.h>
15 #include <lemon/lp_cplex.h>
18 using namespace lemon;
20 void lpTest(LpSolverBase & lp)
25 typedef LpSolverBase LP;
27 std::vector<LP::Col> x(10);
28 // for(int i=0;i<10;i++) x.push_back(lp.addCol());
30 lp.colLowerBound(x,1);
31 lp.colUpperBound(x,1);
35 std::vector<LP::Col> y(10);
38 lp.colLowerBound(y,1);
39 lp.colUpperBound(y,1);
42 std::map<int,LP::Col> z;
44 z.insert(std::make_pair(12,INVALID));
45 z.insert(std::make_pair(2,INVALID));
46 z.insert(std::make_pair(7,INVALID));
47 z.insert(std::make_pair(5,INVALID));
51 lp.colLowerBound(z,1);
52 lp.colUpperBound(z,1);
57 LP::Col p1,p2,p3,p4,p5;
93 e=((p1+p2)+(p1-p2)+(p1+12)+(12+p1)+(p1-12)+(12-p1)+
94 (f+12)+(12+f)+(p1+f)+(f+p1)+(f+g)+
95 (f-12)+(12-f)+(p1-f)+(f-p1)+(f-g)+
153 lp.addRow(LP::INF,e,23);
154 lp.addRow(LP::INF,3.0*(x[1]+x[2]/2)-x[3],23);
155 lp.addRow(LP::INF,3.0*(x[1]+x[2]*2-5*x[3]+12-x[4]/3)+2*x[4]-4,23);
157 lp.addRow(x[1]+x[3]<=x[5]-3);
158 lp.addRow(-7<=x[1]+x[3]-12<=3);
159 lp.addRow(x[1]<=x[5]);
164 LP::Row p1,p2,p3,p4,p5;
189 2.2*p1+p1*2.2+p1/2.2+
197 void solveAndCheck(LpSolverBase& lp, LpSolverBase::SolutionStatus stat,
202 std::ostringstream buf;
203 buf << "Primalstatus should be: " << int(stat);
205 // itoa(stat,buf1, 10);
206 check(lp.primalStatus()==stat, buf.str());
208 if (stat == LpSolverBase::OPTIMAL) {
209 std::ostringstream buf;
210 buf << "Wrong optimal value: the right optimum is " << exp_opt;
211 check(std::abs(lp.primalValue()-exp_opt) < 1e-3, buf.str());
216 void aTest(LpSolverBase & lp)
218 typedef LpSolverBase LP;
220 //The following example is very simple
222 typedef LpSolverBase::Row Row;
223 typedef LpSolverBase::Col Col;
226 Col x1 = lp.addCol();
227 Col x2 = lp.addCol();
231 Row upright=lp.addRow(x1+x2 <=1);
232 lp.addRow(x1+x2 >=-1);
233 lp.addRow(x1-x2 <=1);
234 lp.addRow(x1-x2 >=-1);
235 //Nonnegativity of the variables
236 lp.colLowerBound(x1, 0);
237 lp.colLowerBound(x2, 0);
243 //Maximization of x1+x2
244 //over the triangle with vertices (0,0) (0,1) (1,0)
245 double expected_opt=1;
246 solveAndCheck(lp, LpSolverBase::OPTIMAL, expected_opt);
251 solveAndCheck(lp, LpSolverBase::OPTIMAL, expected_opt);
253 //Vertex (-1,0) instead of (0,0)
254 lp.colLowerBound(x1, -LpSolverBase::INF);
256 solveAndCheck(lp, LpSolverBase::OPTIMAL, expected_opt);
258 //Erase one constraint and return to maximization
259 lp.eraseRow(upright);
261 expected_opt=LpSolverBase::INF;
262 solveAndCheck(lp, LpSolverBase::INFINITE, expected_opt);
265 lp.addRow(x1+x2 <=-2);
266 solveAndCheck(lp, LpSolverBase::INFEASIBLE, expected_opt);
268 //Change problem and forget to solve
270 check(lp.primalStatus()==LpSolverBase::UNDEFINED,"Primalstatus should be UNDEFINED");
273 // if (lp.primalStatus()==LpSolverBase::OPTIMAL){
274 // std::cout<< "Z = "<<lp.primalValue()
275 // << " (error = " << lp.primalValue()-expected_opt
276 // << "); x1 = "<<lp.primal(x1)
277 // << "; x2 = "<<lp.primal(x2)
282 // std::cout<<lp.primalStatus()<<std::endl;
283 // std::cout<<"Optimal solution not found!"<<std::endl;
297 LpGlpk lp_glpk1,lp_glpk2;
303 LpCplex lp_cplex1,lp_cplex2;