athos@2144: /* -*- C++ -*- athos@2144: * athos@2144: * This file is a part of LEMON, a generic C++ optimization library athos@2144: * athos@2144: * Copyright (C) 2003-2006 athos@2144: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport athos@2144: * (Egervary Research Group on Combinatorial Optimization, EGRES). athos@2144: * athos@2144: * Permission to use, modify and distribute this software is granted athos@2144: * provided that this copyright notice appears in all copies. For athos@2144: * precise terms see the accompanying LICENSE file. athos@2144: * athos@2144: * This software is provided "AS IS" with no warranty of any kind, athos@2144: * express or implied, and with no claim as to its suitability for any athos@2144: * purpose. athos@2144: * athos@2144: */ athos@2144: athos@2144: #ifndef LEMON_ILP_GLPK_CC athos@2144: #define LEMON_ILP_GLPK_CC athos@2144: athos@2144: ///\file athos@2144: ///\brief Implementation of the LEMON-GLPK lp solver interface. athos@2144: athos@2144: #include athos@2144: athos@2144: namespace lemon { athos@2144: athos@2144: MipGlpk::MipGlpk() { athos@2144: lpx_set_class(lp,LPX_MIP); athos@2144: } athos@2148: athos@2149: void MipGlpk::_colType(int i, MipGlpk::ColTypes col_type){ athos@2148: switch (col_type){ athos@2148: case INTEGER: athos@2148: lpx_set_col_kind(lp,i,LPX_IV); athos@2148: break; athos@2148: case REAL: athos@2148: lpx_set_col_kind(lp,i,LPX_CV); athos@2148: break; athos@2149: default:; athos@2148: //FIXME problem athos@2144: } athos@2144: } athos@2144: athos@2149: MipGlpk::ColTypes MipGlpk::_colType(int i){ athos@2148: switch (lpx_get_col_kind(lp,i)){ athos@2148: case LPX_IV: athos@2148: return INTEGER;//Or binary athos@2148: case LPX_CV: athos@2148: return REAL; athos@2148: default: athos@2148: return REAL;//Error! athos@2144: } athos@2148: athos@2144: } athos@2144: athos@2144: LpGlpk::SolveExitStatus MipGlpk::_solve(){ athos@2144: int result = lpx_simplex(lp); athos@2144: result = lpx_integer(lp); athos@2144: switch (result){ athos@2144: case LPX_E_OBJLL: athos@2144: case LPX_E_OBJUL: athos@2144: case LPX_E_ITLIM: athos@2144: case LPX_E_TMLIM: athos@2144: case LPX_E_OK: athos@2144: return SOLVED; athos@2144: default: athos@2144: return UNSOLVED; athos@2144: } athos@2144: } athos@2185: athos@2185: athos@2185: LpGlpk::SolutionStatus MipGlpk::_getMipStatus(){ athos@2185: athos@2185: //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is athos@2185: //infeasible, akkor ez is, de ez lehet maskepp is infeasible. athos@2185: int stat= lpx_mip_status(lp); athos@2185: switch (stat) { athos@2185: case LPX_I_UNDEF://Undefined (no solve has been run yet) athos@2185: return UNDEFINED; athos@2185: case LPX_I_NOFEAS://There is no feasible integral solution (primal, I guess) athos@2185: return INFEASIBLE; athos@2185: // case LPX_UNBND://Unbounded athos@2185: // return INFINITE; athos@2185: case LPX_I_FEAS://Feasible athos@2185: return FEASIBLE; athos@2185: case LPX_I_OPT://Feasible athos@2185: return OPTIMAL; athos@2185: default: athos@2185: return UNDEFINED; //to avoid gcc warning athos@2185: //FIXME error athos@2185: } athos@2185: } athos@2185: athos@2144: MipGlpk::Value MipGlpk::_getPrimal(int i){ athos@2144: return lpx_mip_col_val(lp,i); athos@2144: } athos@2144: athos@2144: MipGlpk::Value MipGlpk::_getPrimalValue(){ athos@2144: return lpx_mip_obj_val(lp); athos@2144: } athos@2144: } //END OG NAMESPACE LEMON athos@2144: athos@2144: #endif