Location: LEMON/LEMON-official/lemon/mip_glpk.cc - annotation
Load file history
Port LP and MIP solvers from SVN -r3509 (#44)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 r481:7afc121e0689 | /* -*- 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
* purpose.
*
*/
///\file
///\brief Implementation of the LEMON-GLPK mip solver interface.
#include <lemon/mip_glpk.h>
extern "C" {
#include <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)
#else
#define LEMON_glp(func) (lpx_##func)
#define LEMON_lpx(func) (lpx_##func)
#define LEMON_GLP(def) (LPX_##def)
#define LEMON_LPX(def) (LPX_##def)
#endif
namespace lemon {
MipGlpk::MipGlpk() {
#if !(GLP_MAJOR_VERSION > 4 || \
(GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15))
LEMON_lpx(set_class)(lp,LEMON_GLP(MIP));
#endif
}
void MipGlpk::_colType(int i, MipGlpk::ColTypes col_type){
switch (col_type){
case INT:
LEMON_glp(set_col_kind)(lp,i,LEMON_GLP(IV));
break;
case REAL:
LEMON_glp(set_col_kind)(lp,i,LEMON_GLP(CV));
break;
default:;
//FIXME problem
}
}
MipGlpk::ColTypes MipGlpk::_colType(int i) const {
switch (LEMON_glp(get_col_kind)(lp,i)){
case LEMON_GLP(IV):
return INT;//Or binary
case LEMON_GLP(CV):
return REAL;
default:
return REAL;//Error!
}
}
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
int tmp = -1;
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));
}
#endif
if (LEMON_lpx(get_status)(lp)==LEMON_LPX(OPT)) {
//Maybe we could try the routine lpx_intopt(lp), a revised
//version of lpx_integer
result = LEMON_lpx(integer)(lp);
switch (result){
case LEMON_LPX(E_OK):
solved = true;
break;
default:
solved = false;
}
} else {
solved = false;
}
#if GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION == 16
if (tmp != -1) {
int tmpa[2];
tmpa[1] = tmp;
LEMON_lpx(del_cols)(lp, 1, tmpa);
}
#endif
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);
switch (stat) {
case LEMON_LPX(I_UNDEF)://Undefined (no solve has been run yet)
return UNDEFINED;
case LEMON_LPX(I_NOFEAS)://There is no feasible integral solution
return INFEASIBLE;
// case LEMON_LPX(UNBND)://Unbounded
// return INFINITE;
case LEMON_LPX(I_FEAS)://Feasible
return FEASIBLE;
case LEMON_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) 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
|