COIN-OR::LEMON - Graph Library

Changeset 2149:b437bdee6fd0 in lemon-0.x


Ignore:
Timestamp:
07/18/06 13:11:54 (18 years ago)
Author:
athos
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2863
Message:

Some tests added to the test file mip_test.cc. One problem is the verbosity of the mip solver in glpk which I couldn't find how to kill.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/mip_glpk.cc

    r2148 r2149  
    3131  }
    3232
    33   void MipGlpk::_colType(int i, ColTypes col_type){
     33  void MipGlpk::_colType(int i, MipGlpk::ColTypes col_type){
    3434    switch (col_type){
    3535      case INTEGER:
     
    3939        lpx_set_col_kind(lp,i,LPX_CV);
    4040        break;
    41       default:
     41    default:;
    4242        //FIXME problem
    4343    }
    4444  }
    4545 
    46   ColTypes MipGlpk::_colType(int i){
     46  MipGlpk::ColTypes MipGlpk::_colType(int i){
    4747    switch (lpx_get_col_kind(lp,i)){
    4848    case LPX_IV:
  • test/mip_test.cc

    r2147 r2149  
    11#include <lemon/lp.h>
     2#include "test_tools.h"
    23
    34using namespace lemon;
    45
    5 int main(){
     6void solveAndCheck(Mip& lp, LpSolverBase::SolutionStatus stat,
     7                   double exp_opt) {
     8  using std::string;
     9  lp.solve();
     10  //int decimal,sign;
     11  std::ostringstream buf;
     12  buf << "Primalstatus should be: " << int(stat)<<" and it is "<<int(lp.primalStatus());
     13
     14  //  itoa(stat,buf1, 10);
     15  check(lp.primalStatus()==stat, buf.str());
     16
     17  if (stat ==  LpSolverBase::OPTIMAL) {
     18    std::ostringstream buf;
     19    buf << "Wrong optimal value: the right optimum is " << exp_opt;
     20    check(std::abs(lp.primalValue()-exp_opt) < 1e-3, buf.str());
     21    //+ecvt(exp_opt,2)
     22  }
     23}
     24
     25void aTest(Mip& mip)
     26{
     27 //The following example is very simple
     28
     29  typedef Mip::Row Row;
     30  typedef Mip::Col Col;
    631
    732
     33  Col x1 = mip.addCol();
     34  Col x2 = mip.addCol();
     35
     36
     37
     38  //Constraints
     39  mip.addRow(2*x1+x2 <=2); 
     40  mip.addRow(x1-2*x2 <=0); 
     41
     42  //Nonnegativity of the variable x1
     43  mip.colLowerBound(x1, 0);
     44
     45
     46
     47  //Objective function
     48  mip.setObj(x1);
     49
     50  mip.max();
     51
     52
     53  //Maximization of x1
     54  //over the triangle with vertices
     55  double expected_opt=4.0/5.0;
     56  solveAndCheck(mip, Mip::OPTIMAL, expected_opt);
     57
     58  //Restrict x2 to integer
     59  mip.colType(x2,Mip::INTEGER); 
     60  expected_opt=1.0/2.0;
     61  solveAndCheck(mip, Mip::OPTIMAL, expected_opt);
     62
     63
     64  //Restrict both to integer
     65  mip.colType(x1,Mip::INTEGER); 
     66  expected_opt=0;
     67  solveAndCheck(mip, Mip::OPTIMAL, expected_opt);
     68
     69 
     70
     71}
     72
     73
     74int main()
     75{
     76
    877#ifdef HAVE_GLPK
    9   //This needs some thinking
     78  MipGlpk mip1;
     79  aTest(mip1);
    1080#endif
    1181
Note: See TracChangeset for help on using the changeset viewer.