test/lp_test.cc
changeset 2630 d239741cfd44
parent 2571 f5c6e63f51d1
child 2637 bafe730864da
equal deleted inserted replaced
24:9f98a60ff590 25:64b0240ea3ef
    18 
    18 
    19 #include <sstream>
    19 #include <sstream>
    20 #include <lemon/lp_skeleton.h>
    20 #include <lemon/lp_skeleton.h>
    21 #include "test_tools.h"
    21 #include "test_tools.h"
    22 #include <lemon/tolerance.h>
    22 #include <lemon/tolerance.h>
       
    23 #include <lemon/lp_utils.h>
    23 
    24 
    24 #ifdef HAVE_CONFIG_H
    25 #ifdef HAVE_CONFIG_H
    25 #include <lemon/config.h>
    26 #include <lemon/config.h>
    26 #endif
    27 #endif
    27 
    28 
   214 
   215 
   215   }
   216   }
   216   
   217   
   217   {
   218   {
   218     LP::DualExpr e,f,g;
   219     LP::DualExpr e,f,g;
   219     LP::Row p1,p2,p3,p4,p5;
   220     LP::Row p1 = INVALID, p2 = INVALID, p3 = INVALID, 
       
   221       p4 = INVALID, p5 = INVALID;
   220     
   222     
   221     e[p1]=2;
   223     e[p1]=2;
   222     e[p1]+=2;
   224     e[p1]+=2;
   223     e[p1]-=2;
   225     e[p1]-=2;
   224     
   226     
   293   //Objective function
   295   //Objective function
   294   lp.obj(x1+x2);
   296   lp.obj(x1+x2);
   295 
   297 
   296   lp.max();
   298   lp.max();
   297 
   299 
   298 
       
   299   //Testing the problem retrieving routines
   300   //Testing the problem retrieving routines
   300   check(lp.objCoeff(x1)==1,"First term should be 1 in the obj function!");
   301   check(lp.objCoeff(x1)==1,"First term should be 1 in the obj function!");
   301   check(lp.isMax(),"This is a maximization!");
   302   check(lp.isMax(),"This is a maximization!");
   302   check(lp.coeff(upright,x1)==1,"The coefficient in question is 1!");
   303   check(lp.coeff(upright,x1)==1,"The coefficient in question is 1!");
   303   //  std::cout<<lp.colLowerBound(x1)<<std::endl;
   304   //  std::cout<<lp.colLowerBound(x1)<<std::endl;
   305   check(  lp.colUpperBound(x1)==LpSolverBase::INF,"The upper bound for variable x1 should be infty.");
   306   check(  lp.colUpperBound(x1)==LpSolverBase::INF,"The upper bound for variable x1 should be infty.");
   306   LpSolverBase::Value lb,ub;
   307   LpSolverBase::Value lb,ub;
   307   lp.getRowBounds(upright,lb,ub);
   308   lp.getRowBounds(upright,lb,ub);
   308   check(  lb==-LpSolverBase::INF,"The lower bound for the first row should be -infty.");
   309   check(  lb==-LpSolverBase::INF,"The lower bound for the first row should be -infty.");
   309   check(  ub==1,"The upper bound for the first row should be 1.");
   310   check(  ub==1,"The upper bound for the first row should be 1.");
   310 
   311   LpSolverBase::Expr e = lp.row(upright);
       
   312   check(  e.size() == 2, "The row retrieval gives back wrong expression.");
       
   313   check(  e[x1] == 1, "The first coefficient should 1.");
       
   314   check(  e[x2] == 1, "The second coefficient should 1.");
       
   315 
       
   316   LpSolverBase::DualExpr de = lp.col(x1);
       
   317   check(  de.size() == 4, "The col retrieval gives back wrong expression.");
       
   318   check(  de[upright] == 1, "The first coefficient should 1.");
       
   319 
       
   320   LpSolverBase* clp = lp.copyLp();
       
   321 
       
   322   //Testing the problem retrieving routines
       
   323   check(clp->objCoeff(x1)==1,"First term should be 1 in the obj function!");
       
   324   check(clp->isMax(),"This is a maximization!");
       
   325   check(clp->coeff(upright,x1)==1,"The coefficient in question is 1!");
       
   326   //  std::cout<<lp.colLowerBound(x1)<<std::endl;
       
   327   check(  clp->colLowerBound(x1)==0,"The lower bound for variable x1 should be 0.");
       
   328   std::cerr << clp->colUpperBound(x1) << std::endl;
       
   329   check(  clp->colUpperBound(x1)==LpSolverBase::INF,"The upper bound for variable x1 should be infty.");
       
   330 
       
   331   clp->getRowBounds(upright,lb,ub);
       
   332   check(  lb==-LpSolverBase::INF,"The lower bound for the first row should be -infty.");
       
   333   check(  ub==1,"The upper bound for the first row should be 1.");
       
   334   e = clp->row(upright);
       
   335   check(  e.size() == 2, "The row retrieval gives back wrong expression.");
       
   336   check(  e[x1] == 1, "The first coefficient should 1.");
       
   337   check(  e[x2] == 1, "The second coefficient should 1.");
       
   338 
       
   339   de = clp->col(x1);
       
   340   check(  de.size() == 4, "The col retrieval gives back wrong expression.");
       
   341   check(  de[upright] == 1, "The first coefficient should 1.");
       
   342   
       
   343   delete clp;
   311 
   344 
   312   //Maximization of x1+x2
   345   //Maximization of x1+x2
   313   //over the triangle with vertices (0,0) (0,1) (1,0)
   346   //over the triangle with vertices (0,0) (0,1) (1,0)
   314   double expected_opt=1;
   347   double expected_opt=1;
   315   solveAndCheck(lp, LpSolverBase::OPTIMAL, expected_opt);
   348   solveAndCheck(lp, LpSolverBase::OPTIMAL, expected_opt);
   335   solveAndCheck(lp, LpSolverBase::INFEASIBLE, expected_opt);
   368   solveAndCheck(lp, LpSolverBase::INFEASIBLE, expected_opt);
   336 
   369 
   337   //Change problem and forget to solve
   370   //Change problem and forget to solve
   338   lp.min();
   371   lp.min();
   339   check(lp.primalStatus()==LpSolverBase::UNDEFINED,"Primalstatus should be UNDEFINED");
   372   check(lp.primalStatus()==LpSolverBase::UNDEFINED,"Primalstatus should be UNDEFINED");
       
   373 
   340 
   374 
   341 //   lp.solve();
   375 //   lp.solve();
   342 //   if (lp.primalStatus()==LpSolverBase::OPTIMAL){
   376 //   if (lp.primalStatus()==LpSolverBase::OPTIMAL){
   343 //     std::cout<< "Z = "<<lp.primalValue()
   377 //     std::cout<< "Z = "<<lp.primalValue()
   344 // 	     << " (error = " << lp.primalValue()-expected_opt
   378 // 	     << " (error = " << lp.primalValue()-expected_opt