/* -*- mode: C++; indent-tabs-mode: nil; -*-
* This file is a part of LEMON, a generic C++ optimization library.
* Copyright (C) 2003-2008
* 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
///\brief Implementation of the LEMON-GLPK mip solver interface.
#include <lemon/mip_glpk.h>
#if GLP_MAJOR_VERSION > 4 || (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15)
#define LEMON_glp(func) (glp_##func)
#define LEMON_lpx(func) (lpx_##func)
#define LEMON_GLP(def) (GLP_##def)
#define LEMON_LPX(def) (LPX_##def)
#define LEMON_glp(func) (lpx_##func)
#define LEMON_lpx(func) (lpx_##func)
#define LEMON_GLP(def) (LPX_##def)
#define LEMON_LPX(def) (LPX_##def)
#if !(GLP_MAJOR_VERSION > 4 || \
(GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15))
LEMON_lpx(set_class)(lp,LEMON_GLP(MIP));
void MipGlpk::_colType(int i, MipGlpk::ColTypes col_type){
LEMON_glp(set_col_kind)(lp,i,LEMON_GLP(IV));
LEMON_glp(set_col_kind)(lp,i,LEMON_GLP(CV));
MipGlpk::ColTypes MipGlpk::_colType(int i) const {
switch (LEMON_glp(get_col_kind)(lp,i)){
LpGlpk::SolveExitStatus MipGlpk::_solve() {
int result = LEMON_lpx(simplex)(lp);
// hack: mip does not contain integer variable
#if GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION == 16
if (LEMON_glp(get_num_int(lp)) == 0) {
tmp = LEMON_lpx(add_cols)(lp, 1);
LEMON_glp(set_col_bnds)(lp, tmp, LEMON_GLP(FX), 0.0, 0.0);
LEMON_glp(set_col_kind)(lp, tmp, LEMON_GLP(IV));
if (LEMON_lpx(get_status)(lp)==LEMON_LPX(OPT)) {
//Maybe we could try the routine lpx_intopt(lp), a revised
result = LEMON_lpx(integer)(lp);
#if GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION == 16
LEMON_lpx(del_cols)(lp, 1, tmpa);
return solved ? SOLVED : UNSOLVED;
LpGlpk::SolutionStatus MipGlpk::_getMipStatus() const {
if (LEMON_lpx(get_status)(lp)==LEMON_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= LEMON_lpx(mip_status)(lp);
case LEMON_LPX(I_UNDEF):
//Undefined (no solve has been run yet)
case LEMON_LPX(I_NOFEAS):
//There is no feasible integral solution
// case LEMON_LPX(UNBND)://Unbounded
case LEMON_LPX(I_FEAS):
//Feasible
case LEMON_LPX(I_OPT):
//Feasible
return UNDEFINED; //to avoid gcc warning
return UNDEFINED; //Maybe we could refine this: what does the LP
MipGlpk::Value MipGlpk::_getPrimal(int i) const {
return LEMON_glp(mip_col_val)(lp,i);
MipGlpk::Value MipGlpk::_getPrimalValue() const {
return LEMON_glp(mip_obj_val)(lp);
} //END OF NAMESPACE LEMON