equal
deleted
inserted
replaced
37 |
37 |
38 { |
38 { |
39 LP::Expr e,f,g; |
39 LP::Expr e,f,g; |
40 LP::Col p1,p2,p3,p4,p5; |
40 LP::Col p1,p2,p3,p4,p5; |
41 LP::Constr c; |
41 LP::Constr c; |
|
42 |
|
43 p1=lp.addCol(); |
|
44 p2=lp.addCol(); |
|
45 p3=lp.addCol(); |
|
46 p4=lp.addCol(); |
|
47 p5=lp.addCol(); |
42 |
48 |
43 e[p1]=2; |
49 e[p1]=2; |
44 e.constComp()=12; |
50 e.constComp()=12; |
45 e[p1]+=2; |
51 e[p1]+=2; |
46 e.constComp()+=12; |
52 e.constComp()+=12; |
197 lp.setObj(2*x1+x2); |
203 lp.setObj(2*x1+x2); |
198 |
204 |
199 lp.max(); |
205 lp.max(); |
200 lp.solve(); |
206 lp.solve(); |
201 |
207 |
202 |
208 double opt=122.0/9.0; |
|
209 |
203 if (lp.primalStatus()==LpSolverBase::OPTIMAL){ |
210 if (lp.primalStatus()==LpSolverBase::OPTIMAL){ |
204 printf("Z = %g; x1 = %g; x2 = %g\n", |
211 std::cout<< "Z = "<<lp.primalValue() |
205 lp.primalValue(), |
212 << " (error = " << lp.primalValue()-opt |
206 lp.primal(x1), lp.primal(x2)); |
213 << "); x1 = "<<lp.primal(x1) |
|
214 << "; x2 = "<<lp.primal(x2) |
|
215 <<std::endl; |
|
216 |
207 } |
217 } |
208 else{ |
218 else{ |
209 std::cout<<"Optimal solution not found!"<<std::endl; |
219 std::cout<<"Optimal solution not found!"<<std::endl; |
210 } |
220 } |
211 |
221 |
212 check(lp.primalStatus()==LpSolverBase::OPTIMAL,"Primalstatus should be OPTIMAL"); |
222 check(lp.primalStatus()==LpSolverBase::OPTIMAL,"Primalstatus should be OPTIMAL"); |
213 |
223 |
214 double opt=123/9; |
224 check(std::abs(lp.primalValue()-opt)<1e-3, |
215 check(lp.primalValue()==opt,"The optimum value is 122/9"); |
225 "Wrong optimal value: the right optimum is 122/9 (13.555555...)"); |
216 |
226 |
217 |
227 |
218 } |
228 } |
219 |
229 |
220 |
230 |
222 { |
232 { |
223 LpSkeleton lp_skel; |
233 LpSkeleton lp_skel; |
224 lpTest(lp_skel); |
234 lpTest(lp_skel); |
225 |
235 |
226 #ifdef HAVE_GLPK |
236 #ifdef HAVE_GLPK |
227 LpGlpk lp_glpk; |
237 LpGlpk lp_glpk1,lp_glpk2; |
228 lpTest(lp_glpk); |
238 lpTest(lp_glpk1); |
229 aTest(lp_glpk); |
239 aTest(lp_glpk2); |
230 #endif |
240 #endif |
231 |
241 |
232 #ifdef HAVE_CPLEX |
242 #ifdef HAVE_CPLEX |
233 // LpCplex lp_cplex; |
243 // LpCplex lp_cplex; |
234 // lpTest(lp_cplex); |
244 // lpTest(lp_cplex); |