'make doc' is now working also in case of external build.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
20 #include <lemon/lp_skeleton.h>
21 #include "test_tools.h"
29 #include <lemon/lp_glpk.h>
33 #include <lemon/lp_cplex.h>
36 using namespace lemon;
38 void lpTest(LpSolverBase & lp)
43 typedef LpSolverBase LP;
45 std::vector<LP::Col> x(10);
46 // for(int i=0;i<10;i++) x.push_back(lp.addCol());
48 lp.colLowerBound(x,1);
49 lp.colUpperBound(x,1);
53 std::vector<LP::Col> y(10);
56 lp.colLowerBound(y,1);
57 lp.colUpperBound(y,1);
60 std::map<int,LP::Col> z;
62 z.insert(std::make_pair(12,INVALID));
63 z.insert(std::make_pair(2,INVALID));
64 z.insert(std::make_pair(7,INVALID));
65 z.insert(std::make_pair(5,INVALID));
69 lp.colLowerBound(z,1);
70 lp.colUpperBound(z,1);
75 LP::Col p1,p2,p3,p4,p5;
111 e=((p1+p2)+(p1-p2)+(p1+12)+(12+p1)+(p1-12)+(12-p1)+
112 (f+12)+(12+f)+(p1+f)+(f+p1)+(f+g)+
113 (f-12)+(12-f)+(p1-f)+(f-p1)+(f-g)+
116 2.2*p1+p1*2.2+p1/2.2+
171 lp.addRow(LP::INF,e,23);
172 lp.addRow(LP::INF,3.0*(x[1]+x[2]/2)-x[3],23);
173 lp.addRow(LP::INF,3.0*(x[1]+x[2]*2-5*x[3]+12-x[4]/3)+2*x[4]-4,23);
175 lp.addRow(x[1]+x[3]<=x[5]-3);
176 lp.addRow(-7<=x[1]+x[3]-12<=3);
177 lp.addRow(x[1]<=x[5]);
182 LP::Row p1,p2,p3,p4,p5;
207 2.2*p1+p1*2.2+p1/2.2+
215 void solveAndCheck(LpSolverBase& lp, LpSolverBase::SolutionStatus stat,
220 std::ostringstream buf;
221 buf << "Primalstatus should be: " << int(stat);
223 // itoa(stat,buf1, 10);
224 check(lp.primalStatus()==stat, buf.str());
226 if (stat == LpSolverBase::OPTIMAL) {
227 std::ostringstream buf;
228 buf << "Wrong optimal value: the right optimum is " << exp_opt;
229 check(std::abs(lp.primalValue()-exp_opt) < 1e-3, buf.str());
234 void aTest(LpSolverBase & lp)
236 typedef LpSolverBase LP;
238 //The following example is very simple
240 typedef LpSolverBase::Row Row;
241 typedef LpSolverBase::Col Col;
244 Col x1 = lp.addCol();
245 Col x2 = lp.addCol();
249 Row upright=lp.addRow(x1+x2 <=1);
250 lp.addRow(x1+x2 >=-1);
251 lp.addRow(x1-x2 <=1);
252 lp.addRow(x1-x2 >=-1);
253 //Nonnegativity of the variables
254 lp.colLowerBound(x1, 0);
255 lp.colLowerBound(x2, 0);
261 //Maximization of x1+x2
262 //over the triangle with vertices (0,0) (0,1) (1,0)
263 double expected_opt=1;
264 solveAndCheck(lp, LpSolverBase::OPTIMAL, expected_opt);
269 solveAndCheck(lp, LpSolverBase::OPTIMAL, expected_opt);
271 //Vertex (-1,0) instead of (0,0)
272 lp.colLowerBound(x1, -LpSolverBase::INF);
274 solveAndCheck(lp, LpSolverBase::OPTIMAL, expected_opt);
276 //Erase one constraint and return to maximization
277 lp.eraseRow(upright);
279 expected_opt=LpSolverBase::INF;
280 solveAndCheck(lp, LpSolverBase::INFINITE, expected_opt);
283 lp.addRow(x1+x2 <=-2);
284 solveAndCheck(lp, LpSolverBase::INFEASIBLE, expected_opt);
286 //Change problem and forget to solve
288 check(lp.primalStatus()==LpSolverBase::UNDEFINED,"Primalstatus should be UNDEFINED");
291 // if (lp.primalStatus()==LpSolverBase::OPTIMAL){
292 // std::cout<< "Z = "<<lp.primalValue()
293 // << " (error = " << lp.primalValue()-expected_opt
294 // << "); x1 = "<<lp.primal(x1)
295 // << "; x2 = "<<lp.primal(x2)
300 // std::cout<<lp.primalStatus()<<std::endl;
301 // std::cout<<"Optimal solution not found!"<<std::endl;
315 LpGlpk lp_glpk1,lp_glpk2;
321 LpCplex lp_cplex1,lp_cplex2;