/* -*- mode: C++; indent-tabs-mode: nil; -*-
* This file is a part of LEMON, a generic C++ optimization library.
* Copyright (C) 2003-2008
* 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
///\brief Implementation of the LEMON-CPLEX mip solver interface.
#include <lemon/mip_cplex.h>
#include <ilcplex/cplex.h>
//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);
CPXchgprobtype( env, lp, CPXPROB_MILP);
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.
ctype[0]=CPX_INTEGER;//'I'
ctype[0]=CPX_CONTINUOUS ;//'C'
CPXchgctype (env, lp, 1, indices, ctype);
MipCplex::ColTypes MipCplex::_colType(int i) const {
CPXgetctype (env, lp, ctype, i, i);
LpCplex::SolveExitStatus MipCplex::_solve(){
status = CPXmipopt (env, lp);
LpCplex::SolutionStatus MipCplex::_getMipStatus() const {
int stat = CPXgetstat(env, lp);
//Fortunately, MIP statuses did not change for cplex 8.0
// Optimal integer solution has been found.
// Optimal soluton with the tolerance defined by epgap or epagap has
//This also exists in later issues
// case CPXMIP_UNBOUNDED:
//Unboundedness not treated well: the following is from cplex 9.0 doc
// 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) const {
CPXgetmipx(env, lp, &x, i, i);
MipCplex::Value MipCplex::_getPrimalValue() const {
CPXgetmipobjval(env, lp, &objval);
} //END OF NAMESPACE LEMON