Added the function isFinite(), and replaced the calls to finite() with it.
This was necessary because finite() is not a standard function. Neither can
we use its standard counterpart isfinite(), because it was introduced only
in C99, and therefore it is not supplied by all C++ implementations.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2007
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>
24 #if GLP_MAJOR_VERSION > 4 || (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15)
25 #define LEMON_glp(func) (glp_##func)
26 #define LEMON_lpx(func) (lpx_##func)
28 #define LEMON_GLP(def) (GLP_##def)
29 #define LEMON_LPX(def) (LPX_##def)
33 #define LEMON_glp(func) (lpx_##func)
34 #define LEMON_lpx(func) (lpx_##func)
36 #define LEMON_GLP(def) (LPX_##def)
37 #define LEMON_LPX(def) (LPX_##def)
44 #if !(GLP_MAJOR_VERSION > 4 || (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15))
45 LEMON_lpx(set_class)(lp,LEMON_GLP(MIP));
49 void MipGlpk::_colType(int i, MipGlpk::ColTypes col_type){
52 LEMON_glp(set_col_kind)(lp,i,LEMON_GLP(IV));
55 LEMON_glp(set_col_kind)(lp,i,LEMON_GLP(CV));
62 MipGlpk::ColTypes MipGlpk::_colType(int i) const {
63 switch (LEMON_glp(get_col_kind)(lp,i)){
65 return INT;//Or binary
74 LpGlpk::SolveExitStatus MipGlpk::_solve() {
75 int result = LEMON_lpx(simplex)(lp);
77 // hack: mip does not contain integer variable
78 #if GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION == 16
80 if (LEMON_glp(get_num_int(lp)) == 0) {
81 tmp = LEMON_lpx(add_cols)(lp, 1);
82 LEMON_glp(set_col_bnds)(lp, tmp, LEMON_GLP(FX), 0.0, 0.0);
83 LEMON_glp(set_col_kind)(lp, tmp, LEMON_GLP(IV));
87 if (LEMON_lpx(get_status)(lp)==LEMON_LPX(OPT)) {
88 //Maybe we could try the routine lpx_intopt(lp), a revised
89 //version of lpx_integer
91 result = LEMON_lpx(integer)(lp);
102 #if GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION == 16
106 LEMON_lpx(del_cols)(lp, 1, tmpa);
109 return solved ? SOLVED : UNSOLVED;
113 LpGlpk::SolutionStatus MipGlpk::_getMipStatus() const {
115 if (LEMON_lpx(get_status)(lp)==LEMON_LPX(OPT)){
116 //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is
117 //infeasible, akkor ez is, de ez lehet maskepp is infeasible.
118 int stat= LEMON_lpx(mip_status)(lp);
121 case LEMON_LPX(I_UNDEF)://Undefined (no solve has been run yet)
123 case LEMON_LPX(I_NOFEAS)://There is no feasible integral solution
125 // case LEMON_LPX(UNBND)://Unbounded
127 case LEMON_LPX(I_FEAS)://Feasible
129 case LEMON_LPX(I_OPT)://Feasible
132 return UNDEFINED; //to avoid gcc warning
137 return UNDEFINED; //Maybe we could refine this: what does the LP
138 //relaxation look like
142 MipGlpk::Value MipGlpk::_getPrimal(int i) const {
143 return LEMON_glp(mip_col_val)(lp,i);
146 MipGlpk::Value MipGlpk::_getPrimalValue() const {
147 return LEMON_glp(mip_obj_val)(lp);
149 } //END OF NAMESPACE LEMON