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@2218: #ifndef LEMON_MIP_GLPK_CC athos@2218: #define LEMON_MIP_GLPK_CC athos@2144: athos@2144: ///\file athos@2218: ///\brief Implementation of the LEMON-GLPK mip 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@2218: case LEMON_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@2218: return LEMON_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@2213: // athos@2213: if (lpx_get_status(lp)==LPX_OPT){ athos@2213: //Maybe we could try the routine lpx_intopt(lp), a revised athos@2213: //version of lpx_integer athos@2213: result = lpx_integer(lp); athos@2213: switch (result){ athos@2144: case LPX_E_OK: athos@2213: return SOLVED; athos@2144: default: athos@2213: return UNSOLVED; athos@2213: } athos@2213: athos@2144: } athos@2213: return UNSOLVED; athos@2144: } athos@2185: athos@2185: athos@2185: LpGlpk::SolutionStatus MipGlpk::_getMipStatus(){ athos@2185: athos@2213: if (lpx_get_status(lp)==LPX_OPT){ athos@2213: //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is athos@2213: //infeasible, akkor ez is, de ez lehet maskepp is infeasible. athos@2213: int stat= lpx_mip_status(lp); athos@2213: athos@2213: switch (stat) { athos@2213: case LPX_I_UNDEF://Undefined (no solve has been run yet) athos@2213: return UNDEFINED; athos@2213: case LPX_I_NOFEAS://There is no feasible integral solution athos@2213: return INFEASIBLE; athos@2213: // case LPX_UNBND://Unbounded athos@2213: // return INFINITE; athos@2213: case LPX_I_FEAS://Feasible athos@2213: return FEASIBLE; athos@2213: case LPX_I_OPT://Feasible athos@2213: return OPTIMAL; athos@2213: default: athos@2185: return UNDEFINED; //to avoid gcc warning athos@2185: //FIXME error athos@2213: } athos@2185: } athos@2213: else athos@2213: return UNDEFINED; //Maybe we could refine this: what does the LP athos@2213: //relaxation look like athos@2213: 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@2218: } //END OF NAMESPACE LEMON athos@2144: athos@2218: #endif //END OF MIP_GLPK_CC