# HG changeset patch # User athos # Date 1159174236 0 # Node ID c263168e09642dfadbf69adb2b1d34ef1d087578 # Parent 50f1a780a5ff10bafbadc99febf50966d3650b9d Missing cplex files: sorry. diff -r 50f1a780a5ff -r c263168e0964 lemon/mip_cplex.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lemon/mip_cplex.cc Mon Sep 25 08:50:36 2006 +0000 @@ -0,0 +1,133 @@ +/* -*- C++ -*- + * + * This file is a part of LEMON, a generic C++ optimization library + * + * Copyright (C) 2003-2006 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#ifndef LEMON_MIP_CPLEX_CC +#define LEMON_MIP_CPLEX_CC + +///\file +///\brief Implementation of the LEMON-CPLEX mip solver interface. + +#include + +namespace lemon { + + MipCplex::MipCplex() { + //This is unnecessary: setting integrality constraints on + //variables will set this, too + + ///\todo The constant CPXPROB_MIP is + ///called CPXPROB_MILP in later versions + CPXchgprobtype( env, lp, CPXPROB_MIP); + } + + void MipCplex::_colType(int i, MipCplex::ColTypes col_type){ + + // Note If a variable is to be changed to binary, a call to CPXchgbds + // should also be made to change the bounds to 0 and 1. + + int indices[1]; + indices[0]=i; + char ctype[1]; + switch (col_type){ + case LEMON_INTEGER: + ctype[0]=CPX_INTEGER;//'I' + break; + case REAL: + ctype[0]=CPX_CONTINUOUS ;//'C' + break; + default:; + //FIXME problem + } + CPXchgctype (env, lp, 1, indices, ctype); + } + + MipCplex::ColTypes MipCplex::_colType(int i){ + + char ctype[1]; + status = CPXgetctype (env, lp, ctype, i, i); + switch (ctype[0]){ + + case CPX_INTEGER: + return LEMON_INTEGER; + case CPX_CONTINUOUS: + return REAL; + default: + return REAL;//Error! + } + + } + + LpCplex::SolveExitStatus MipCplex::_solve(){ + + status = CPXmipopt (env, lp); + if (status==0) + return SOLVED; + else + return UNSOLVED; + + } + + + LpCplex::SolutionStatus MipCplex::_getMipStatus(){ + + int stat = CPXgetstat(env, lp); + + //Fortunately, MIP statuses did not change for cplex 8.0 + switch (stat) + { + case CPXMIP_OPTIMAL: + return OPTIMAL; + //This also exists in later issues + // case CPXMIP_UNBOUNDED: + //return INFINITE; + case CPXMIP_INFEASIBLE: + return INFEASIBLE; + default: + return UNDEFINED; + } + //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. + + } + + MipCplex::Value MipCplex::_getPrimal(int i){ + Value x; + CPXgetmipx(env, lp, &x, i, i); + return x; + } + + MipCplex::Value MipCplex::_getPrimalValue(){ + Value objval; + status = CPXgetmipobjval(env, lp, &objval); + return objval; + } +} //END OF NAMESPACE LEMON + +#endif //END OF MIP_CPLEX_CC diff -r 50f1a780a5ff -r c263168e0964 lemon/mip_cplex.cc~ --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lemon/mip_cplex.cc~ Mon Sep 25 08:50:36 2006 +0000 @@ -0,0 +1,135 @@ +/* -*- C++ -*- + * + * This file is a part of LEMON, a generic C++ optimization library + * + * Copyright (C) 2003-2006 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#ifndef LEMON_MIP_CPLEX_CC +#define LEMON_MIP_CPLEX_CC + +///\file +///\brief Implementation of the LEMON-CPLEX mip solver interface. + +#include + +namespace lemon { + + MipCplex::MipCplex() { + //This is unnecessary: setting integrality constraints on + //variables will set this, too + + ///\todo The constant CPXPROB_MIP is + ///called CPXPROB_MILP in later versions + CPXchgprobtype( env, lp, CPXPROB_MIP); + } + + void MipCplex::_colType(int i, MipCplex::ColTypes col_type){ + + // Note If a variable is to be changed to binary, a call to CPXchgbds + // should also be made to change the bounds to 0 and 1. + + int indices[1]; + indices[0]=i; + char ctype[1]; + switch (col_type){ + case INTEGER: + ctype[0]=CPX_INTEGER;//'I' + break; + case REAL: + ctype[0]=CPX_CONTINUOUS ;//'C' + break; + default:; + //FIXME problem + } + CPXchgctype (env, lp, 1, indices, ctype); + } + + MipCplex::ColTypes MipCplex::_colType(int i){ + + char ctype[1]; + status = CPXgetctype (env, lp, ctype, i, i); + std::cout<<"Kukucska: "< + +namespace lemon { + + /// \brief Interface for the CPLEX MIP solver + /// + /// This class implements an interface for the CPLEX MIP solver. + ///\ingroup gen_opt_group + class MipCplex : public MipSolverBase, public LpCplex{ + + public: + + typedef MipSolverBase ParentMip; + typedef LpCplex ParentLp; + + MipCplex(); + //~MipCplex(); + + + + + protected: + + virtual ColTypes _colType(int col); + virtual void _colType(int col, ColTypes col_type); + + virtual LpCplex::SolveExitStatus _solve(); + virtual LpCplex::SolutionStatus _getMipStatus(); + virtual ParentLp::Value _getPrimal(int i); + virtual ParentLp::Value _getPrimalValue(); + }; + +} //END OF NAMESPACE LEMON + +#endif // END OF LEMON_MIP_CPLEX_H diff -r 50f1a780a5ff -r c263168e0964 lemon/mip_cplex.h~ --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lemon/mip_cplex.h~ Mon Sep 25 08:50:36 2006 +0000 @@ -0,0 +1,59 @@ +/* -*- C++ -*- + * + * This file is a part of LEMON, a generic C++ optimization library + * + * Copyright (C) 2003-2006 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#ifndef LEMON_MIP_CPLEX_H +#define LEMON_MIP_CPLEX_H + +///\file +///\brief Header of the LEMON-CPLEX mip solver interface. +///\ingroup gen_opt_group + + +#include + +namespace lemon { + /// \brief Interface for the CPLEX MIP solver + /// + /// This class implements an interface for the CPLEX MIP solver. + ///\ingroup gen_opt_group + class MipCplex : public MipSolverBase, public LpCplex{ + + public: + + typedef MipSolverBase ParentMip; + typedef LpCplex ParentLp; + + MipCplex(); + //~MipCplex(); + + + + protected: + + virtual ColTypes _colType(int col); + virtual void _colType(int col, ColTypes col_type); + + virtual LpCplex::SolveExitStatus _solve(); + virtual LpCplex::SolutionStatus _getMipStatus(); + virtual ParentLp::Value _getPrimal(int i); + virtual ParentLp::Value _getPrimalValue(); + }; + +} //END OF NAMESPACE LEMON + +#endif // END OF LEMON_MIP_CPLEX_H