1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
20 ///\brief Implementation of the LEMON-CPLEX mip solver interface.
22 #include <lemon/mip_cplex.h>
25 #include <ilcplex/cplex.h>
30 MipCplex::MipCplex() {
31 //This is unnecessary: setting integrality constraints on
32 //variables will set this, too
34 ///\todo The constant CPXPROB_MIP is
35 ///called CPXPROB_MILP in later versions
37 CPXchgprobtype( env, lp, CPXPROB_MIP);
39 CPXchgprobtype( env, lp, CPXPROB_MILP);
44 void MipCplex::_colType(int i, MipCplex::ColTypes col_type){
46 // Note If a variable is to be changed to binary, a call to CPXchgbds
47 // should also be made to change the bounds to 0 and 1.
54 ctype[0]=CPX_INTEGER;//'I'
57 ctype[0]=CPX_CONTINUOUS ;//'C'
62 CPXchgctype (env, lp, 1, indices, ctype);
65 MipCplex::ColTypes MipCplex::_colType(int i) const {
68 CPXgetctype (env, lp, ctype, i, i);
81 LpCplex::SolveExitStatus MipCplex::_solve(){
83 status = CPXmipopt (env, lp);
92 LpCplex::SolutionStatus MipCplex::_getMipStatus() const {
94 int stat = CPXgetstat(env, lp);
96 //Fortunately, MIP statuses did not change for cplex 8.0
100 // Optimal integer solution has been found.
101 case CPXMIP_OPTIMAL_TOL:
102 // Optimal soluton with the tolerance defined by epgap or epagap has
105 //This also exists in later issues
106 // case CPXMIP_UNBOUNDED:
108 case CPXMIP_INFEASIBLE:
113 //Unboundedness not treated well: the following is from cplex 9.0 doc
114 // About Unboundedness
116 // The treatment of models that are unbounded involves a few
117 // subtleties. Specifically, a declaration of unboundedness means that
118 // ILOG CPLEX has determined that the model has an unbounded
119 // ray. Given any feasible solution x with objective z, a multiple of
120 // the unbounded ray can be added to x to give a feasible solution
121 // with objective z-1 (or z+1 for maximization models). Thus, if a
122 // feasible solution exists, then the optimal objective is
123 // unbounded. Note that ILOG CPLEX has not necessarily concluded that
124 // a feasible solution exists. Users can call the routine CPXsolninfo
125 // to determine whether ILOG CPLEX has also concluded that the model
126 // has a feasible solution.
130 MipCplex::Value MipCplex::_getPrimal(int i) const {
132 CPXgetmipx(env, lp, &x, i, i);
136 MipCplex::Value MipCplex::_getPrimalValue() const {
138 CPXgetmipobjval(env, lp, &objval);
141 } //END OF NAMESPACE LEMON