/* -*- C++ -*- * * This file is a part of LEMON, a generic C++ optimization library * * Copyright (C) 2003-2006 * 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 * purpose. * */ #ifndef LEMON_MIP_GLPK_CC #define LEMON_MIP_GLPK_CC ///\file ///\brief Implementation of the LEMON-GLPK mip solver interface. #include namespace lemon { MipGlpk::MipGlpk() { lpx_set_class(lp,LPX_MIP); } void MipGlpk::_colType(int i, MipGlpk::ColTypes col_type){ switch (col_type){ case LEMON_INTEGER: lpx_set_col_kind(lp,i,LPX_IV); break; case REAL: lpx_set_col_kind(lp,i,LPX_CV); break; default:; //FIXME problem } } MipGlpk::ColTypes MipGlpk::_colType(int i){ switch (lpx_get_col_kind(lp,i)){ case LPX_IV: return LEMON_INTEGER;//Or binary case LPX_CV: return REAL; default: return REAL;//Error! } } LpGlpk::SolveExitStatus MipGlpk::_solve(){ int result = lpx_simplex(lp); // if (lpx_get_status(lp)==LPX_OPT){ //Maybe we could try the routine lpx_intopt(lp), a revised //version of lpx_integer result = lpx_integer(lp); switch (result){ case LPX_E_OK: return SOLVED; default: return UNSOLVED; } } return UNSOLVED; } LpGlpk::SolutionStatus MipGlpk::_getMipStatus(){ if (lpx_get_status(lp)==LPX_OPT){ //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is //infeasible, akkor ez is, de ez lehet maskepp is infeasible. int stat= lpx_mip_status(lp); switch (stat) { case LPX_I_UNDEF://Undefined (no solve has been run yet) return UNDEFINED; case LPX_I_NOFEAS://There is no feasible integral solution return INFEASIBLE; // case LPX_UNBND://Unbounded // return INFINITE; case LPX_I_FEAS://Feasible return FEASIBLE; case LPX_I_OPT://Feasible return OPTIMAL; default: return UNDEFINED; //to avoid gcc warning //FIXME error } } else return UNDEFINED; //Maybe we could refine this: what does the LP //relaxation look like } MipGlpk::Value MipGlpk::_getPrimal(int i){ return lpx_mip_col_val(lp,i); } MipGlpk::Value MipGlpk::_getPrimalValue(){ return lpx_mip_obj_val(lp); } } //END OF NAMESPACE LEMON #endif //END OF MIP_GLPK_CC