Several changes. \n If new map is added to mapstorage it emits signal with the name of the new map. This was important, because from now on not only tha mapwin should be updated. \n Furthermore algobox gets a pointer to mapstorage instead of only the mapnames from it. This is important because without it it would be complicated to pass all of the required maps to algobox.
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());
33 std::vector<LP::Col> y(10);
36 std::map<int,LP::Col> z;
38 z.insert(std::make_pair(12,INVALID));
39 z.insert(std::make_pair(2,INVALID));
40 z.insert(std::make_pair(7,INVALID));
41 z.insert(std::make_pair(5,INVALID));
47 LP::Col p1,p2,p3,p4,p5;
83 e=((p1+p2)+(p1-p2)+(p1+12)+(12+p1)+(p1-12)+(12-p1)+
84 (f+12)+(12+f)+(p1+f)+(f+p1)+(f+g)+
85 (f-12)+(12-f)+(p1-f)+(f-p1)+(f-g)+
143 lp.addRow(LP::INF,e,23);
144 lp.addRow(LP::INF,3.0*(x[1]+x[2]/2)-x[3],23);
145 lp.addRow(LP::INF,3.0*(x[1]+x[2]*2-5*x[3]+12-x[4]/3)+2*x[4]-4,23);
147 lp.addRow(x[1]+x[3]<=x[5]-3);
148 lp.addRow(-7<=x[1]+x[3]-12<=3);
149 lp.addRow(x[1]<=x[5]);
154 LP::Row p1,p2,p3,p4,p5;
179 2.2*p1+p1*2.2+p1/2.2+
187 void solveAndCheck(LpSolverBase& lp, LpSolverBase::SolutionStatus stat,
192 std::ostringstream buf;
193 buf << "Primalstatus should be: " << int(stat);
195 // itoa(stat,buf1, 10);
196 check(lp.primalStatus()==stat, buf.str());
198 if (stat == LpSolverBase::OPTIMAL) {
199 std::ostringstream buf;
200 buf << "Wrong optimal value: the right optimum is " << exp_opt;
201 check(std::abs(lp.primalValue()-exp_opt) < 1e-3, buf.str());
206 void aTest(LpSolverBase & lp)
208 typedef LpSolverBase LP;
210 //The following example is very simple
212 typedef LpSolverBase::Row Row;
213 typedef LpSolverBase::Col Col;
216 Col x1 = lp.addCol();
217 Col x2 = lp.addCol();
221 Row upright=lp.addRow(x1+x2 <=1);
222 lp.addRow(x1+x2 >=-1);
223 lp.addRow(x1-x2 <=1);
224 lp.addRow(x1-x2 >=-1);
225 //Nonnegativity of the variables
226 lp.colLowerBound(x1, 0);
227 lp.colLowerBound(x2, 0);
233 //Maximization of x1+x2
234 //over the triangle with vertices (0,0) (0,1) (1,0)
235 double expected_opt=1;
236 solveAndCheck(lp, LpSolverBase::OPTIMAL, expected_opt);
241 solveAndCheck(lp, LpSolverBase::OPTIMAL, expected_opt);
243 //Vertex (-1,0) instead of (0,0)
244 lp.colLowerBound(x1, -LpSolverBase::INF);
246 solveAndCheck(lp, LpSolverBase::OPTIMAL, expected_opt);
248 //Erase one constraint and return to maximization
249 lp.eraseRow(upright);
251 expected_opt=LpSolverBase::INF;
252 solveAndCheck(lp, LpSolverBase::INFINITE, expected_opt);
255 lp.addRow(x1+x2 <=-2);
256 solveAndCheck(lp, LpSolverBase::INFEASIBLE, expected_opt);
258 //Change problem and forget to solve
260 check(lp.primalStatus()==LpSolverBase::UNDEFINED,"Primalstatus should be UNDEFINED");
263 // if (lp.primalStatus()==LpSolverBase::OPTIMAL){
264 // std::cout<< "Z = "<<lp.primalValue()
265 // << " (error = " << lp.primalValue()-expected_opt
266 // << "); x1 = "<<lp.primal(x1)
267 // << "; x2 = "<<lp.primal(x2)
272 // std::cout<<lp.primalStatus()<<std::endl;
273 // std::cout<<"Optimal solution not found!"<<std::endl;
287 LpGlpk lp_glpk1,lp_glpk2;
293 LpCplex lp_cplex1,lp_cplex2;