1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
20 ///\brief Implementation of the LEMON-GLPK mip solver interface.
22 #include <lemon/mip_glpk.h>
28 #if GLP_MAJOR_VERSION > 4 || (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15)
29 #define LEMON_glp(func) (glp_##func)
30 #define LEMON_lpx(func) (lpx_##func)
32 #define LEMON_GLP(def) (GLP_##def)
33 #define LEMON_LPX(def) (LPX_##def)
37 #define LEMON_glp(func) (lpx_##func)
38 #define LEMON_lpx(func) (lpx_##func)
40 #define LEMON_GLP(def) (LPX_##def)
41 #define LEMON_LPX(def) (LPX_##def)
48 #if !(GLP_MAJOR_VERSION > 4 || \
49 (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15))
50 LEMON_lpx(set_class)(lp,LEMON_GLP(MIP));
54 void MipGlpk::_colType(int i, MipGlpk::ColTypes col_type){
57 LEMON_glp(set_col_kind)(lp,i,LEMON_GLP(IV));
60 LEMON_glp(set_col_kind)(lp,i,LEMON_GLP(CV));
67 MipGlpk::ColTypes MipGlpk::_colType(int i) const {
68 switch (LEMON_glp(get_col_kind)(lp,i)){
70 return INT;//Or binary
79 LpGlpk::SolveExitStatus MipGlpk::_solve() {
80 int result = LEMON_lpx(simplex)(lp);
82 // hack: mip does not contain integer variable
83 #if GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION == 16
85 if (LEMON_glp(get_num_int(lp)) == 0) {
86 tmp = LEMON_lpx(add_cols)(lp, 1);
87 LEMON_glp(set_col_bnds)(lp, tmp, LEMON_GLP(FX), 0.0, 0.0);
88 LEMON_glp(set_col_kind)(lp, tmp, LEMON_GLP(IV));
92 if (LEMON_lpx(get_status)(lp)==LEMON_LPX(OPT)) {
93 //Maybe we could try the routine lpx_intopt(lp), a revised
94 //version of lpx_integer
96 result = LEMON_lpx(integer)(lp);
107 #if GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION == 16
111 LEMON_lpx(del_cols)(lp, 1, tmpa);
114 return solved ? SOLVED : UNSOLVED;
118 LpGlpk::SolutionStatus MipGlpk::_getMipStatus() const {
120 if (LEMON_lpx(get_status)(lp)==LEMON_LPX(OPT)){
121 //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is
122 //infeasible, akkor ez is, de ez lehet maskepp is infeasible.
123 int stat= LEMON_lpx(mip_status)(lp);
126 case LEMON_LPX(I_UNDEF)://Undefined (no solve has been run yet)
128 case LEMON_LPX(I_NOFEAS)://There is no feasible integral solution
130 // case LEMON_LPX(UNBND)://Unbounded
132 case LEMON_LPX(I_FEAS)://Feasible
134 case LEMON_LPX(I_OPT)://Feasible
137 return UNDEFINED; //to avoid gcc warning
142 return UNDEFINED; //Maybe we could refine this: what does the LP
143 //relaxation look like
147 MipGlpk::Value MipGlpk::_getPrimal(int i) const {
148 return LEMON_glp(mip_col_val)(lp,i);
151 MipGlpk::Value MipGlpk::_getPrimalValue() const {
152 return LEMON_glp(mip_obj_val)(lp);
154 } //END OF NAMESPACE LEMON