1.1 --- a/test/mip_test.cc Thu Apr 02 19:29:56 2009 +0200
1.2 +++ b/test/mip_test.cc Wed Apr 01 22:58:58 2009 +0200
1.3 @@ -18,7 +18,6 @@
1.4
1.5 #include "test_tools.h"
1.6
1.7 -
1.8 #ifdef HAVE_CONFIG_H
1.9 #include <lemon/config.h>
1.10 #endif
1.11 @@ -31,6 +30,10 @@
1.12 #include <lemon/glpk.h>
1.13 #endif
1.14
1.15 +#ifdef HAVE_CBC
1.16 +#include <lemon/cbc.h>
1.17 +#endif
1.18 +
1.19
1.20 using namespace lemon;
1.21
1.22 @@ -57,14 +60,13 @@
1.23
1.24 void aTest(MipSolver& mip)
1.25 {
1.26 - //The following example is very simple
1.27 + //The following example is very simple
1.28
1.29
1.30 typedef MipSolver::Row Row;
1.31 typedef MipSolver::Col Col;
1.32
1.33
1.34 -
1.35 Col x1 = mip.addCol();
1.36 Col x2 = mip.addCol();
1.37
1.38 @@ -74,23 +76,24 @@
1.39
1.40 mip.max();
1.41
1.42 -
1.43 //Unconstrained optimization
1.44 mip.solve();
1.45 //Check it out!
1.46
1.47 //Constraints
1.48 - mip.addRow(2*x1+x2 <=2);
1.49 - mip.addRow(x1-2*x2 <=0);
1.50 + mip.addRow(2 * x1 + x2 <= 2);
1.51 + Row y2 = mip.addRow(x1 - 2 * x2 <= 0);
1.52
1.53 //Nonnegativity of the variable x1
1.54 mip.colLowerBound(x1, 0);
1.55
1.56 +
1.57 //Maximization of x1
1.58 //over the triangle with vertices (0,0),(4/5,2/5),(0,2)
1.59 double expected_opt=4.0/5.0;
1.60 solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
1.61
1.62 +
1.63 //Restrict x2 to integer
1.64 mip.colType(x2,MipSolver::INTEGER);
1.65 expected_opt=1.0/2.0;
1.66 @@ -102,10 +105,15 @@
1.67 expected_opt=0;
1.68 solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
1.69
1.70 -
1.71 + //Erase a variable
1.72 + mip.erase(x2);
1.73 + mip.rowUpperBound(y2, 8);
1.74 + expected_opt=1;
1.75 + solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
1.76
1.77 }
1.78
1.79 +
1.80 template<class MIP>
1.81 void cloneTest()
1.82 {
1.83 @@ -144,6 +152,14 @@
1.84 }
1.85 #endif
1.86
1.87 +#ifdef HAVE_CBC
1.88 + {
1.89 + CbcMip mip1;
1.90 + aTest(mip1);
1.91 + cloneTest<CbcMip>();
1.92 + }
1.93 +#endif
1.94 +
1.95 return 0;
1.96
1.97 }