test/mip_test.cc
changeset 1209 4a170261cc54
parent 1105 62dba6c90f35
equal deleted inserted replaced
14:aae4cbc23f3e 15:b0d75fb6ed11
    59     check(std::abs(mip.solValue()-exp_opt) < 1e-3, sbuf.str());
    59     check(std::abs(mip.solValue()-exp_opt) < 1e-3, sbuf.str());
    60     //+ecvt(exp_opt,2)
    60     //+ecvt(exp_opt,2)
    61   }
    61   }
    62 }
    62 }
    63 
    63 
    64 void aTest(MipSolver& mip)
    64 void aTest(MipSolver& mip, bool solve_empty=true)
    65 {
    65 {
    66   //The following example is very simple
    66   //The following example is very simple
    67 
    67 
    68 
    68 
    69   typedef MipSolver::Row Row;
    69   typedef MipSolver::Row Row;
    78   mip.obj(x1);
    78   mip.obj(x1);
    79 
    79 
    80   mip.max();
    80   mip.max();
    81 
    81 
    82   //Unconstrained optimization
    82   //Unconstrained optimization
    83   mip.solve();
    83   if(solve_empty)
       
    84     mip.solve();
    84   //Check it out!
    85   //Check it out!
    85 
    86 
    86   //Constraints
    87   //Constraints
    87   mip.addRow(2 * x1 + x2 <= 2);
    88   mip.addRow(2 * x1 + x2 <= 2);
    88   Row y2 = mip.addRow(x1 - 2 * x2 <= 0);
    89   Row y2 = mip.addRow(x1 - 2 * x2 <= 0);
   133 {
   134 {
   134 
   135 
   135 #ifdef LEMON_HAVE_MIP
   136 #ifdef LEMON_HAVE_MIP
   136   {
   137   {
   137     Mip mip1;
   138     Mip mip1;
       
   139 #if LEMON_DEFAULT_MIP==LEMON_CBC_
       
   140     aTest(mip1, false);
       
   141 #else
   138     aTest(mip1);
   142     aTest(mip1);
       
   143 #endif
   139     cloneTest<Mip>();
   144     cloneTest<Mip>();
   140   }
   145   }
   141 #endif
   146 #endif
   142 
   147 
   143 #ifdef LEMON_HAVE_GLPK
   148 #ifdef LEMON_HAVE_GLPK
   159 #endif
   164 #endif
   160 
   165 
   161 #ifdef LEMON_HAVE_CBC
   166 #ifdef LEMON_HAVE_CBC
   162   {
   167   {
   163     CbcMip mip1;
   168     CbcMip mip1;
   164     aTest(mip1);
   169     aTest(mip1, false);
   165     cloneTest<CbcMip>();
   170     cloneTest<CbcMip>();
   166   }
   171   }
   167 #endif
   172 #endif
   168 
   173 
   169   return 0;
   174   return 0;