COIN-OR::LEMON - Graph Library

Changeset 1473:876c7b7f4dae in lemon-0.x for test


Ignore:
Timestamp:
06/10/05 14:50:43 (19 years ago)
Author:
athos
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1953
Message:

Some tests have been developed, bugs got fixed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/lp_test.cc

    r1445 r1473  
    11#include<lemon/lp_skeleton.h>
     2#include "test_tools.h"
    23
    34#ifdef HAVE_CONFIG_H
     
    171172}
    172173
     174void aTest(LpSolverBase & lp)
     175{
     176  typedef LpSolverBase LP;
     177
     178 //The following example is taken from the book by Gáspár and Temesi, page 39.
     179
     180  typedef LpSolverBase::Row Row;
     181  typedef LpSolverBase::Col Col;
     182
     183
     184  Col x1 = lp.addCol();
     185  Col x2 = lp.addCol();
     186
     187
     188  //Constraints
     189  lp.addRow(3*x1+2*x2 >=6); 
     190  lp.addRow(-1*x1+x2<=4); 
     191  lp.addRow(5*x1+8*x2<=40); 
     192  lp.addRow(x1-2*x2<=4); 
     193  //Nonnegativity of the variables
     194  lp.colLowerBound(x1, 0);
     195  lp.colLowerBound(x2, 0);
     196  //Objective function
     197  lp.setObj(2*x1+x2);
     198
     199  lp.max();
     200  lp.solve();
     201
     202
     203  if (lp.primalStatus()==LpSolverBase::OPTIMAL){
     204    printf("Z = %g; x1 = %g; x2 = %g\n",
     205           lp.primalValue(),
     206           lp.primal(x1), lp.primal(x2));
     207  }
     208  else{
     209    std::cout<<"Optimal solution not found!"<<std::endl;
     210  }
     211
     212  check(lp.primalStatus()==LpSolverBase::OPTIMAL,"Primalstatus should be OPTIMAL");
     213
     214  double opt=123/9;
     215  check(lp.primalValue()==opt,"The optimum value is 122/9");
     216
     217
     218}
     219
     220
    173221int main()
    174222{
     
    179227  LpGlpk lp_glpk;
    180228  lpTest(lp_glpk);
     229  aTest(lp_glpk);
    181230#endif
    182231
    183232#ifdef HAVE_CPLEX
    184 //  LpCplex lp_cplex;
    185 //  lpTest(lp_cplex);
     233  LpCplex lp_cplex;
     234  lpTest(lp_cplex);
    186235#endif
    187236
Note: See TracChangeset for help on using the changeset viewer.