- lp_test is made working.
authoralpar
Tue, 14 Jun 2005 13:55:28 +0000
changeset 1484a3484f00a5f0
parent 1483 e427615afb48
child 1485 3a1c6678fa23
- lp_test is made working.
- some more 'const' for those who like them..
lemon/lp_base.h
test/lp_test.cc
     1.1 --- a/lemon/lp_base.h	Tue Jun 14 10:26:37 2005 +0000
     1.2 +++ b/lemon/lp_base.h	Tue Jun 14 13:55:28 2005 +0000
     1.3 @@ -47,12 +47,12 @@
     1.4  
     1.5      ///\param n is a floating id
     1.6      ///\return the corresponding fix id
     1.7 -    int fixId(int n) {return cross[n];}
     1.8 +    int fixId(int n) const {return cross[n];}
     1.9      ///Convert a fix id to a floating one
    1.10  
    1.11      ///\param n is a fix id
    1.12      ///\return the corresponding floating id
    1.13 -    int floatingId(int n) { return index[n];}
    1.14 +    int floatingId(int n) const { return index[n];}
    1.15      ///Add a new floating id.
    1.16  
    1.17      ///\param n is a floating id
     2.1 --- a/test/lp_test.cc	Tue Jun 14 10:26:37 2005 +0000
     2.2 +++ b/test/lp_test.cc	Tue Jun 14 13:55:28 2005 +0000
     2.3 @@ -40,6 +40,12 @@
     2.4      LP::Col p1,p2,p3,p4,p5;
     2.5      LP::Constr c;
     2.6      
     2.7 +    p1=lp.addCol();
     2.8 +    p2=lp.addCol();
     2.9 +    p3=lp.addCol();
    2.10 +    p4=lp.addCol();
    2.11 +    p5=lp.addCol();
    2.12 +    
    2.13      e[p1]=2;
    2.14      e.constComp()=12;
    2.15      e[p1]+=2;
    2.16 @@ -199,11 +205,15 @@
    2.17    lp.max();
    2.18    lp.solve();
    2.19  
    2.20 -
    2.21 +  double opt=122.0/9.0;
    2.22 +  
    2.23    if (lp.primalStatus()==LpSolverBase::OPTIMAL){
    2.24 -    printf("Z = %g; x1 = %g; x2 = %g\n", 
    2.25 -	   lp.primalValue(), 
    2.26 -	   lp.primal(x1), lp.primal(x2));
    2.27 +    std::cout<< "Z = "<<lp.primalValue()
    2.28 +	     << " (error = " << lp.primalValue()-opt
    2.29 +	     << "); x1 = "<<lp.primal(x1)
    2.30 +	     << "; x2 = "<<lp.primal(x2)
    2.31 +	     <<std::endl;
    2.32 +    
    2.33    }
    2.34    else{
    2.35      std::cout<<"Optimal solution not found!"<<std::endl;
    2.36 @@ -211,8 +221,8 @@
    2.37  
    2.38    check(lp.primalStatus()==LpSolverBase::OPTIMAL,"Primalstatus should be OPTIMAL");
    2.39  
    2.40 -  double opt=123/9;
    2.41 -  check(lp.primalValue()==opt,"The optimum value is 122/9");
    2.42 +  check(std::abs(lp.primalValue()-opt)<1e-3,
    2.43 +	"Wrong optimal value: the right optimum is 122/9 (13.555555...)");
    2.44  
    2.45  
    2.46  }
    2.47 @@ -224,9 +234,9 @@
    2.48    lpTest(lp_skel);
    2.49  
    2.50  #ifdef HAVE_GLPK
    2.51 -  LpGlpk lp_glpk;
    2.52 -  lpTest(lp_glpk);
    2.53 -  aTest(lp_glpk);
    2.54 +  LpGlpk lp_glpk1,lp_glpk2;
    2.55 +  lpTest(lp_glpk1);
    2.56 +  aTest(lp_glpk2);
    2.57  #endif
    2.58  
    2.59  #ifdef HAVE_CPLEX