[Lemon-commits] [lemon_svn] athos: r2952 - in hugo/trunk: lemon test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 21:51:26 CET 2006
Author: athos
Date: Thu Sep 21 16:46:28 2006
New Revision: 2952
Modified:
hugo/trunk/lemon/Makefile.am
hugo/trunk/lemon/lp.h
hugo/trunk/lemon/lp_base.h
hugo/trunk/lemon/lp_cplex.cc
hugo/trunk/lemon/lp_cplex.h
hugo/trunk/lemon/mip_glpk.cc
hugo/trunk/lemon/mip_glpk.h
hugo/trunk/test/mip_test.cc
Log:
Interface to the cplex MIP solver: it is little, a bit sour but it is ours.
Modified: hugo/trunk/lemon/Makefile.am
==============================================================================
--- hugo/trunk/lemon/Makefile.am (original)
+++ hugo/trunk/lemon/Makefile.am Thu Sep 21 16:46:28 2006
@@ -25,6 +25,7 @@
if HAVE_CPLEX
lemon_libemon_la_SOURCES += lemon/lp_cplex.cc
+lemon_libemon_la_SOURCES += lemon/mip_cplex.cc
endif
lemon_HEADERS += \
@@ -78,6 +79,7 @@
lemon/min_cost_flow.h \
lemon/min_cut.h \
lemon/mip_glpk.h \
+ lemon/mip_cplex.h \
lemon/path.h \
lemon/polynomial.h \
lemon/preflow.h \
Modified: hugo/trunk/lemon/lp.h
==============================================================================
--- hugo/trunk/lemon/lp.h (original)
+++ hugo/trunk/lemon/lp.h Thu Sep 21 16:46:28 2006
@@ -21,18 +21,20 @@
#include<lemon/config.h>
+
#ifdef HAVE_GLPK
#include <lemon/lp_glpk.h>
#include <lemon/mip_glpk.h>
#elif HAVE_CPLEX
#include <lemon/lp_cplex.h>
+#include <lemon/mip_cplex.h>
#endif
///\file
///\brief Defines a default LP solver
///\ingroup gen_opt_group
namespace lemon {
-
+
#ifdef DOXYGEN
///The default LP solver identifier
@@ -72,6 +74,7 @@
#elif HAVE_CPLEX
#define DEFAULT_LP CPLEX
typedef LpCplex Lp;
+ typedef MipCplex Mip;
const char default_solver_name[]="CPLEX";
#endif
#endif
Modified: hugo/trunk/lemon/lp_base.h
==============================================================================
--- hugo/trunk/lemon/lp_base.h (original)
+++ hugo/trunk/lemon/lp_base.h Thu Sep 21 16:46:28 2006
@@ -75,8 +75,10 @@
}
return cross[n];
}
- ///\todo Create an own exception type.
- else throw LogicError(); //floatingId-s must form a continuous range;
+ else {
+ ///\todo Create an own exception type.
+ throw LogicError(); //floatingId-s must form a continuous range;
+ }
}
///Remove a fix id.
@@ -1169,7 +1171,10 @@
///Continuous variable
REAL = 0,
///Integer variable
- INTEGER = 1
+
+ ///Unfortunately, cplex 7.5 somewhere writes something like
+ ///#define INTEGER 'I'
+ LEMON_INTEGER = 1
///\todo No support for other types yet.
};
@@ -1192,7 +1197,7 @@
///Sets the type of the given Col to integer or remove that property.
void integer(Col c, bool enable) {
if (enable)
- colType(c,INTEGER);
+ colType(c,LEMON_INTEGER);
else
colType(c,REAL);
}
@@ -1202,7 +1207,7 @@
///Gives back the type of the column.
///\return true if the column has integer type and false if not.
bool integer(Col c){
- return (colType(c)==INTEGER);
+ return (colType(c)==LEMON_INTEGER);
}
/// The status of the MIP problem
Modified: hugo/trunk/lemon/lp_cplex.cc
==============================================================================
--- hugo/trunk/lemon/lp_cplex.cc (original)
+++ hugo/trunk/lemon/lp_cplex.cc Thu Sep 21 16:46:28 2006
@@ -269,7 +269,7 @@
//CPX_PARAM_LPMETHOD
status = CPXlpopt(env, lp);
//status = CPXprimopt(env, lp);
-#if CPX_VERSION >= 900
+#if CPX_VERSION >= 800
if (status)
{
return UNSOLVED;
@@ -416,8 +416,23 @@
LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
{
+ //Unboundedness not treated well: the following is from cplex 9.0 doc
+ // About Unboundedness
+
+ // The treatment of models that are unbounded involves a few
+ // subtleties. Specifically, a declaration of unboundedness means that
+ // ILOG CPLEX has determined that the model has an unbounded
+ // ray. Given any feasible solution x with objective z, a multiple of
+ // the unbounded ray can be added to x to give a feasible solution
+ // with objective z-1 (or z+1 for maximization models). Thus, if a
+ // feasible solution exists, then the optimal objective is
+ // unbounded. Note that ILOG CPLEX has not necessarily concluded that
+ // a feasible solution exists. Users can call the routine CPXsolninfo
+ // to determine whether ILOG CPLEX has also concluded that the model
+ // has a feasible solution.
+
int stat = CPXgetstat(env, lp);
-#if CPX_VERSION >= 900
+#if CPX_VERSION >= 800
switch (stat)
{
case CPX_STAT_OPTIMAL:
@@ -485,7 +500,7 @@
LpCplex::SolutionStatus LpCplex::_getDualStatus()
{
int stat = CPXgetstat(env, lp);
-#if CPX_VERSION >= 900
+#if CPX_VERSION >= 800
switch (stat)
{
case CPX_STAT_OPTIMAL:
@@ -514,7 +529,7 @@
LpCplex::ProblemTypes LpCplex::_getProblemType()
{
int stat = CPXgetstat(env, lp);
-#if CPX_VERSION >= 900
+#if CPX_VERSION >= 800
switch (stat)
{
case CPX_STAT_OPTIMAL:
Modified: hugo/trunk/lemon/lp_cplex.h
==============================================================================
--- hugo/trunk/lemon/lp_cplex.h (original)
+++ hugo/trunk/lemon/lp_cplex.h Thu Sep 21 16:46:28 2006
@@ -34,7 +34,7 @@
/// \brief Interface for the CPLEX solver
///
/// This class implements an interface for the CPLEX LP solver.
- class LpCplex : public LpSolverBase {
+ class LpCplex :virtual public LpSolverBase {
public:
Modified: hugo/trunk/lemon/mip_glpk.cc
==============================================================================
--- hugo/trunk/lemon/mip_glpk.cc (original)
+++ hugo/trunk/lemon/mip_glpk.cc Thu Sep 21 16:46:28 2006
@@ -16,11 +16,11 @@
*
*/
-#ifndef LEMON_ILP_GLPK_CC
-#define LEMON_ILP_GLPK_CC
+#ifndef LEMON_MIP_GLPK_CC
+#define LEMON_MIP_GLPK_CC
///\file
-///\brief Implementation of the LEMON-GLPK lp solver interface.
+///\brief Implementation of the LEMON-GLPK mip solver interface.
#include <lemon/mip_glpk.h>
@@ -32,7 +32,7 @@
void MipGlpk::_colType(int i, MipGlpk::ColTypes col_type){
switch (col_type){
- case INTEGER:
+ case LEMON_INTEGER:
lpx_set_col_kind(lp,i,LPX_IV);
break;
case REAL:
@@ -46,7 +46,7 @@
MipGlpk::ColTypes MipGlpk::_colType(int i){
switch (lpx_get_col_kind(lp,i)){
case LPX_IV:
- return INTEGER;//Or binary
+ return LEMON_INTEGER;//Or binary
case LPX_CV:
return REAL;
default:
@@ -110,6 +110,6 @@
MipGlpk::Value MipGlpk::_getPrimalValue(){
return lpx_mip_obj_val(lp);
}
-} //END OG NAMESPACE LEMON
+} //END OF NAMESPACE LEMON
-#endif
+#endif //END OF MIP_GLPK_CC
Modified: hugo/trunk/lemon/mip_glpk.h
==============================================================================
--- hugo/trunk/lemon/mip_glpk.h (original)
+++ hugo/trunk/lemon/mip_glpk.h Thu Sep 21 16:46:28 2006
@@ -16,20 +16,20 @@
*
*/
-#ifndef LEMON_ILP_GLPK_H
-#define LEMON_ILP_GLPK_H
+#ifndef LEMON_MIP_GLPK_H
+#define LEMON_MIP_GLPK_H
///\file
-///\brief Header of the LEMON-GLPK lp solver interface.
+///\brief Header of the LEMON-GLPK mip solver interface.
///\ingroup gen_opt_group
#include <lemon/lp_glpk.h>
namespace lemon {
- /// \brief Interface for the GLPK ILP solver
+ /// \brief Interface for the GLPK MIP solver
///
- /// This class implements an interface for the GLPK ILP solver.
+ /// This class implements an interface for the GLPK MIP solver.
///\ingroup gen_opt_group
class MipGlpk : public MipSolverBase, public LpGlpk{
@@ -56,4 +56,4 @@
} //END OF NAMESPACE LEMON
-#endif // END OF LEMON_ILP_GLPK_H
+#endif // END OF LEMON_MIP_GLPK_H
Modified: hugo/trunk/test/mip_test.cc
==============================================================================
--- hugo/trunk/test/mip_test.cc (original)
+++ hugo/trunk/test/mip_test.cc Thu Sep 21 16:46:28 2006
@@ -1,20 +1,26 @@
-#include <lemon/lp.h>
#include "test_tools.h"
+
+#include <lemon/mip_cplex.h>
+#include <lemon/mip_glpk.h>
+#include<lemon/config.h>
+
using namespace lemon;
-void solveAndCheck(Mip& lp, LpSolverBase::SolutionStatus stat,
+void solveAndCheck(MipSolverBase& lp, MipSolverBase::SolutionStatus stat,
double exp_opt) {
using std::string;
+
lp.solve();
//int decimal,sign;
std::ostringstream buf;
buf << "Primalstatus should be: " << int(stat)<<" and it is "<<int(lp.primalStatus());
+
// itoa(stat,buf1, 10);
check(lp.mipStatus()==stat, buf.str());
- if (stat == LpSolverBase::OPTIMAL) {
+ if (stat == MipSolverBase::OPTIMAL) {
std::ostringstream buf;
buf << "Wrong optimal value: the right optimum is " << exp_opt;
check(std::abs(lp.primalValue()-exp_opt) < 1e-3, buf.str());
@@ -22,20 +28,18 @@
}
}
-void aTest(Mip& mip)
+void aTest(MipSolverBase& mip)
{
//The following example is very simple
- typedef Mip::Row Row;
- typedef Mip::Col Col;
-
-
- Col x1 = mip.addCol();
- Col x2 = mip.addCol();
+ typedef MipSolverBase::Row Row;
+ typedef MipSolverBase::Col Col;
+ Col x1 = mip.addCol();
+ Col x2 = mip.addCol();
//Objective function
@@ -60,18 +64,18 @@
//Maximization of x1
//over the triangle with vertices
double expected_opt=4.0/5.0;
- solveAndCheck(mip, Mip::OPTIMAL, expected_opt);
+ solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);
//Restrict x2 to integer
- mip.colType(x2,Mip::INTEGER);
+ mip.colType(x2,MipSolverBase::LEMON_INTEGER);
expected_opt=1.0/2.0;
- solveAndCheck(mip, Mip::OPTIMAL, expected_opt);
+ solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);
//Restrict both to integer
- mip.colType(x1,Mip::INTEGER);
+ mip.colType(x1,MipSolverBase::LEMON_INTEGER);
expected_opt=0;
- solveAndCheck(mip, Mip::OPTIMAL, expected_opt);
+ solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);
@@ -86,6 +90,14 @@
aTest(mip1);
#endif
+
+
+#ifdef HAVE_CPLEX
+ //std::cout<<ATTILA<<INTEGER;
+ MipCplex mip2;
+ aTest(mip2);
+#endif
+
return 0;
}
More information about the Lemon-commits
mailing list