test/lp_test.cc
changeset 528 9db62975c32b
parent 462 9b082b3fb33f
child 530 fc6c7aab4b8d
equal deleted inserted replaced
4:c3384384d7e0 7:c388ecf73a08
   195     tolerance=0.02;
   195     tolerance=0.02;
   196     e.simplify(tolerance);
   196     e.simplify(tolerance);
   197     buf << "Coeff. of p2 should be 0";
   197     buf << "Coeff. of p2 should be 0";
   198     check(const_cast<const LpSolver::Expr&>(e)[p2]==0, buf.str());
   198     check(const_cast<const LpSolver::Expr&>(e)[p2]==0, buf.str());
   199 
   199 
       
   200     //Test for clone/new
       
   201     LP* lpnew = lp.newSolver();
       
   202     LP* lpclone = lp.cloneSolver();
       
   203     delete lpnew;
       
   204     delete lpclone;
   200 
   205 
   201   }
   206   }
   202 
   207 
   203   {
   208   {
   204     LP::DualExpr e,f,g;
   209     LP::DualExpr e,f,g;
   245 
   250 
   246   check(lp.primalType()==stat, buf.str());
   251   check(lp.primalType()==stat, buf.str());
   247 
   252 
   248   if (stat ==  LpSolver::OPTIMAL) {
   253   if (stat ==  LpSolver::OPTIMAL) {
   249     std::ostringstream sbuf;
   254     std::ostringstream sbuf;
   250     sbuf << "Wrong optimal value: the right optimum is " << exp_opt;
   255     sbuf << "Wrong optimal value (" << lp.primal() <<") with "
       
   256          << lp.solverName() <<"\n     the right optimum is " << exp_opt;
   251     check(std::abs(lp.primal()-exp_opt) < 1e-3, sbuf.str());
   257     check(std::abs(lp.primal()-exp_opt) < 1e-3, sbuf.str());
   252   }
   258   }
   253 }
   259 }
   254 
   260 
   255 void aTest(LpSolver & lp)
   261 void aTest(LpSolver & lp)
   353   lp.addRow(x1+x2 <=-2);
   359   lp.addRow(x1+x2 <=-2);
   354   solveAndCheck(lp, LpSolver::INFEASIBLE, expected_opt);
   360   solveAndCheck(lp, LpSolver::INFEASIBLE, expected_opt);
   355 
   361 
   356 }
   362 }
   357 
   363 
       
   364 template<class LP>
       
   365 void cloneTest()
       
   366 {
       
   367   //Test for clone/new
       
   368   
       
   369   LP* lp = new LP();
       
   370   LP* lpnew = lp->newSolver();
       
   371   LP* lpclone = lp->cloneSolver();
       
   372   delete lp;
       
   373   delete lpnew;
       
   374   delete lpclone;
       
   375 }
       
   376 
   358 int main()
   377 int main()
   359 {
   378 {
   360   LpSkeleton lp_skel;
   379   LpSkeleton lp_skel;
   361   lpTest(lp_skel);
   380   lpTest(lp_skel);
   362 
   381 
   363 #ifdef HAVE_GLPK
   382 #ifdef HAVE_GLPK
   364   {
   383   {
   365     GlpkLp lp_glpk1,lp_glpk2;
   384     GlpkLp lp_glpk1,lp_glpk2;
   366     lpTest(lp_glpk1);
   385     lpTest(lp_glpk1);
   367     aTest(lp_glpk2);
   386     aTest(lp_glpk2);
       
   387     cloneTest<GlpkLp>();
   368   }
   388   }
   369 #endif
   389 #endif
   370 
   390 
   371 #ifdef HAVE_CPLEX
   391 #ifdef HAVE_CPLEX
   372   try {
   392   try {
   379 #else
   399 #else
   380     std::cerr << error.what() << std::endl;
   400     std::cerr << error.what() << std::endl;
   381     std::cerr << "Cplex license check failed, lp check skipped" << std::endl;
   401     std::cerr << "Cplex license check failed, lp check skipped" << std::endl;
   382 #endif
   402 #endif
   383   }
   403   }
       
   404     cloneTest<CplexLp>();
   384 #endif
   405 #endif
   385 
   406 
   386 #ifdef HAVE_SOPLEX
   407 #ifdef HAVE_SOPLEX
   387   {
   408   {
   388     SoplexLp lp_soplex1,lp_soplex2;
   409     SoplexLp lp_soplex1,lp_soplex2;
   389     lpTest(lp_soplex1);
   410     lpTest(lp_soplex1);
   390     aTest(lp_soplex2);
   411     aTest(lp_soplex2);
       
   412     cloneTest<SoplexLp>();
   391   }
   413   }
   392 #endif
   414 #endif
   393 
   415 
   394 #ifdef HAVE_CLP
   416 #ifdef HAVE_CLP
   395   {
   417   {
   396     ClpLp lp_clp1,lp_clp2;
   418     ClpLp lp_clp1,lp_clp2;
   397     lpTest(lp_clp1);
   419     lpTest(lp_clp1);
   398     aTest(lp_clp2);
   420     aTest(lp_clp2);
       
   421     cloneTest<ClpLp>();
   399   }
   422   }
   400 #endif
   423 #endif
   401 
   424 
   402   return 0;
   425   return 0;
   403 }
   426 }