athos@2219: /* -*- C++ -*- athos@2219: * athos@2219: * This file is a part of LEMON, a generic C++ optimization library athos@2219: * athos@2219: * Copyright (C) 2003-2006 athos@2219: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport athos@2219: * (Egervary Research Group on Combinatorial Optimization, EGRES). athos@2219: * athos@2219: * Permission to use, modify and distribute this software is granted athos@2219: * provided that this copyright notice appears in all copies. For athos@2219: * precise terms see the accompanying LICENSE file. athos@2219: * athos@2219: * This software is provided "AS IS" with no warranty of any kind, athos@2219: * express or implied, and with no claim as to its suitability for any athos@2219: * purpose. athos@2219: * athos@2219: */ athos@2219: athos@2219: #ifndef LEMON_MIP_CPLEX_CC athos@2219: #define LEMON_MIP_CPLEX_CC athos@2219: athos@2219: ///\file athos@2219: ///\brief Implementation of the LEMON-CPLEX mip solver interface. athos@2219: athos@2219: #include athos@2219: athos@2219: namespace lemon { athos@2219: athos@2219: MipCplex::MipCplex() { athos@2219: //This is unnecessary: setting integrality constraints on athos@2219: //variables will set this, too athos@2219: athos@2219: ///\todo The constant CPXPROB_MIP is athos@2219: ///called CPXPROB_MILP in later versions athos@2219: CPXchgprobtype( env, lp, CPXPROB_MIP); athos@2219: } athos@2219: athos@2219: void MipCplex::_colType(int i, MipCplex::ColTypes col_type){ athos@2219: athos@2219: // Note If a variable is to be changed to binary, a call to CPXchgbds athos@2219: // should also be made to change the bounds to 0 and 1. athos@2219: athos@2219: int indices[1]; athos@2219: indices[0]=i; athos@2219: char ctype[1]; athos@2219: switch (col_type){ athos@2219: case LEMON_INTEGER: athos@2219: ctype[0]=CPX_INTEGER;//'I' athos@2219: break; athos@2219: case REAL: athos@2219: ctype[0]=CPX_CONTINUOUS ;//'C' athos@2219: break; athos@2219: default:; athos@2219: //FIXME problem athos@2219: } athos@2219: CPXchgctype (env, lp, 1, indices, ctype); athos@2219: } athos@2219: athos@2219: MipCplex::ColTypes MipCplex::_colType(int i){ athos@2219: athos@2219: char ctype[1]; athos@2219: status = CPXgetctype (env, lp, ctype, i, i); athos@2219: switch (ctype[0]){ athos@2219: athos@2219: case CPX_INTEGER: athos@2219: return LEMON_INTEGER; athos@2219: case CPX_CONTINUOUS: athos@2219: return REAL; athos@2219: default: athos@2219: return REAL;//Error! athos@2219: } athos@2219: athos@2219: } athos@2219: athos@2219: LpCplex::SolveExitStatus MipCplex::_solve(){ athos@2219: athos@2219: status = CPXmipopt (env, lp); athos@2219: if (status==0) athos@2219: return SOLVED; athos@2219: else athos@2219: return UNSOLVED; athos@2219: athos@2219: } athos@2219: athos@2219: athos@2219: LpCplex::SolutionStatus MipCplex::_getMipStatus(){ athos@2219: athos@2219: int stat = CPXgetstat(env, lp); athos@2219: athos@2219: //Fortunately, MIP statuses did not change for cplex 8.0 athos@2219: switch (stat) athos@2219: { athos@2219: case CPXMIP_OPTIMAL: athos@2219: return OPTIMAL; athos@2219: //This also exists in later issues athos@2219: // case CPXMIP_UNBOUNDED: athos@2219: //return INFINITE; athos@2219: case CPXMIP_INFEASIBLE: athos@2219: return INFEASIBLE; athos@2219: default: athos@2219: return UNDEFINED; athos@2219: } athos@2219: //Unboundedness not treated well: the following is from cplex 9.0 doc athos@2219: // About Unboundedness athos@2219: athos@2219: // The treatment of models that are unbounded involves a few athos@2219: // subtleties. Specifically, a declaration of unboundedness means that athos@2219: // ILOG CPLEX has determined that the model has an unbounded athos@2219: // ray. Given any feasible solution x with objective z, a multiple of athos@2219: // the unbounded ray can be added to x to give a feasible solution athos@2219: // with objective z-1 (or z+1 for maximization models). Thus, if a athos@2219: // feasible solution exists, then the optimal objective is athos@2219: // unbounded. Note that ILOG CPLEX has not necessarily concluded that athos@2219: // a feasible solution exists. Users can call the routine CPXsolninfo athos@2219: // to determine whether ILOG CPLEX has also concluded that the model athos@2219: // has a feasible solution. athos@2219: athos@2219: } athos@2219: athos@2219: MipCplex::Value MipCplex::_getPrimal(int i){ athos@2219: Value x; athos@2219: CPXgetmipx(env, lp, &x, i, i); athos@2219: return x; athos@2219: } athos@2219: athos@2219: MipCplex::Value MipCplex::_getPrimalValue(){ athos@2219: Value objval; athos@2219: status = CPXgetmipobjval(env, lp, &objval); athos@2219: return objval; athos@2219: } athos@2219: } //END OF NAMESPACE LEMON athos@2219: athos@2219: #endif //END OF MIP_CPLEX_CC