[Lemon-commits] [lemon_svn] athos: r2941 - in hugo/trunk: lemon test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 21:51:22 CET 2006
Author: athos
Date: Fri Sep 8 17:51:32 2006
New Revision: 2941
Modified:
hugo/trunk/lemon/mip_glpk.cc
hugo/trunk/test/mip_test.cc
Log:
Some corrections.
Modified: hugo/trunk/lemon/mip_glpk.cc
==============================================================================
--- hugo/trunk/lemon/mip_glpk.cc (original)
+++ hugo/trunk/lemon/mip_glpk.cc Fri Sep 8 17:51:32 2006
@@ -57,40 +57,50 @@
LpGlpk::SolveExitStatus MipGlpk::_solve(){
int result = lpx_simplex(lp);
- result = lpx_integer(lp);
- switch (result){
- case LPX_E_OBJLL:
- case LPX_E_OBJUL:
- case LPX_E_ITLIM:
- case LPX_E_TMLIM:
+ //
+ if (lpx_get_status(lp)==LPX_OPT){
+ //Maybe we could try the routine lpx_intopt(lp), a revised
+ //version of lpx_integer
+ result = lpx_integer(lp);
+ switch (result){
case LPX_E_OK:
- return SOLVED;
+ return SOLVED;
default:
- return UNSOLVED;
+ return UNSOLVED;
+ }
+
}
+ return UNSOLVED;
}
LpGlpk::SolutionStatus MipGlpk::_getMipStatus(){
- //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is
- //infeasible, akkor ez is, de ez lehet maskepp is infeasible.
- int stat= lpx_mip_status(lp);
- switch (stat) {
- case LPX_I_UNDEF://Undefined (no solve has been run yet)
- return UNDEFINED;
- case LPX_I_NOFEAS://There is no feasible integral solution (primal, I guess)
- return INFEASIBLE;
-// case LPX_UNBND://Unbounded
-// return INFINITE;
- case LPX_I_FEAS://Feasible
- return FEASIBLE;
- case LPX_I_OPT://Feasible
- return OPTIMAL;
- default:
+ if (lpx_get_status(lp)==LPX_OPT){
+ //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is
+ //infeasible, akkor ez is, de ez lehet maskepp is infeasible.
+ int stat= lpx_mip_status(lp);
+
+ switch (stat) {
+ case LPX_I_UNDEF://Undefined (no solve has been run yet)
+ return UNDEFINED;
+ case LPX_I_NOFEAS://There is no feasible integral solution
+ return INFEASIBLE;
+ // case LPX_UNBND://Unbounded
+ // return INFINITE;
+ case LPX_I_FEAS://Feasible
+ return FEASIBLE;
+ case LPX_I_OPT://Feasible
+ return OPTIMAL;
+ default:
return UNDEFINED; //to avoid gcc warning
//FIXME error
+ }
}
+ else
+ return UNDEFINED; //Maybe we could refine this: what does the LP
+ //relaxation look like
+
}
MipGlpk::Value MipGlpk::_getPrimal(int i){
Modified: hugo/trunk/test/mip_test.cc
==============================================================================
--- hugo/trunk/test/mip_test.cc (original)
+++ hugo/trunk/test/mip_test.cc Fri Sep 8 17:51:32 2006
@@ -12,7 +12,7 @@
buf << "Primalstatus should be: " << int(stat)<<" and it is "<<int(lp.primalStatus());
// itoa(stat,buf1, 10);
- check(lp.primalStatus()==stat, buf.str());
+ check(lp.mipStatus()==stat, buf.str());
if (stat == LpSolverBase::OPTIMAL) {
std::ostringstream buf;
@@ -35,12 +35,6 @@
- //Constraints
- mip.addRow(2*x1+x2 <=2);
- mip.addRow(x1-2*x2 <=0);
-
- //Nonnegativity of the variable x1
- mip.colLowerBound(x1, 0);
@@ -50,8 +44,21 @@
mip.max();
+ //Unconstrained optimization
+ mip.solve();
+ //Check it out!
+
+ //Constraints
+ mip.addRow(2*x1+x2 <=2);
+ mip.addRow(x1-2*x2 <=0);
+
+ //Nonnegativity of the variable x1
+ mip.colLowerBound(x1, 0);
+
+
+
//Maximization of x1
- //over the triangle with vertices
+ //over the triangle with vertices
double expected_opt=4.0/5.0;
solveAndCheck(mip, Mip::OPTIMAL, expected_opt);
More information about the Lemon-commits
mailing list