Changeset 2441:d8d6ab871608 in lemon0.x for lemon/mip_glpk.cc
 Timestamp:
 05/07/07 20:19:55 (12 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@3278
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

lemon/mip_glpk.cc
r2391 r2441 22 22 #include <lemon/mip_glpk.h> 23 23 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) 27 28 #define LEMON_GLP(def) (GLP_##def) 29 #define LEMON_LPX(def) (LPX_##def) 30 31 #else 32 33 #define LEMON_glp(func) (lpx_##func) 34 #define LEMON_lpx(func) (lpx_##func) 35 36 #define LEMON_GLP(def) (LPX_##def) 37 #define LEMON_LPX(def) (LPX_##def) 38 39 #endif 40 24 41 namespace lemon { 25 42 26 43 MipGlpk::MipGlpk() { 27 lpx_set_class(lp,LPX_MIP); 44 #if !(GLP_MAJOR_VERSION > 4  (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15)) 45 LEMON_lpx(set_class)(lp,LEMON_GLP(MIP)); 46 #endif 28 47 } 29 48 … … 31 50 switch (col_type){ 32 51 case INT: 33 lpx_set_col_kind(lp,i,LPX_IV);52 LEMON_glp(set_col_kind)(lp,i,LEMON_GLP(IV)); 34 53 break; 35 54 case REAL: 36 lpx_set_col_kind(lp,i,LPX_CV);55 LEMON_glp(set_col_kind)(lp,i,LEMON_GLP(CV)); 37 56 break; 38 57 default:; … … 42 61 43 62 MipGlpk::ColTypes MipGlpk::_colType(int i) const { 44 switch ( lpx_get_col_kind(lp,i)){45 case L PX_IV:63 switch (LEMON_glp(get_col_kind)(lp,i)){ 64 case LEMON_GLP(IV): 46 65 return INT;//Or binary 47 case L PX_CV:66 case LEMON_GLP(CV): 48 67 return REAL; 49 68 default: … … 54 73 55 74 LpGlpk::SolveExitStatus MipGlpk::_solve() { 56 int result = lpx_simplex(lp); 57 // 58 if (lpx_get_status(lp)==LPX_OPT){ 75 int result = LEMON_lpx(simplex)(lp); 76 77 // hack: mip does not contain integer variable 78 #if GLP_MAJOR_VERSION > 4  (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15) 79 int tmp = 1; 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)); 84 } 85 #endif 86 87 if (LEMON_lpx(get_status)(lp)==LEMON_LPX(OPT)) { 59 88 //Maybe we could try the routine lpx_intopt(lp), a revised 60 89 //version of lpx_integer 61 result = lpx_integer(lp); 90 91 result = LEMON_lpx(integer)(lp); 62 92 switch (result){ 63 case L PX_E_OK:64 return SOLVED;93 case LEMON_LPX(E_OK): 94 solved = true; 65 95 default: 66 return UNSOLVED; 67 } 68 96 solved = false; 97 } 98 } else { 99 solved = false; 69 100 } 70 return UNSOLVED; 101 #if GLP_MAJOR_VERSION > 4  (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15) 102 if (tmp != 1) { 103 int tmpa[2]; 104 tmpa[1] = tmp; 105 LEMON_lpx(del_cols)(lp, 1, tmpa); 106 } 107 #endif 108 return solved ? SOLVED : UNSOLVED; 71 109 } 72 110 … … 74 112 LpGlpk::SolutionStatus MipGlpk::_getMipStatus() const { 75 113 76 if ( lpx_get_status(lp)==LPX_OPT){114 if (LEMON_lpx(get_status)(lp)==LEMON_LPX(OPT)){ 77 115 //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is 78 116 //infeasible, akkor ez is, de ez lehet maskepp is infeasible. 79 int stat= lpx_mip_status(lp);117 int stat= LEMON_lpx(mip_status)(lp); 80 118 81 119 switch (stat) { 82 case L PX_I_UNDEF://Undefined (no solve has been run yet)120 case LEMON_LPX(I_UNDEF)://Undefined (no solve has been run yet) 83 121 return UNDEFINED; 84 case L PX_I_NOFEAS://There is no feasible integral solution122 case LEMON_LPX(I_NOFEAS)://There is no feasible integral solution 85 123 return INFEASIBLE; 86 // case L PX_UNBND://Unbounded124 // case LEMON_LPX(UNBND)://Unbounded 87 125 // return INFINITE; 88 case L PX_I_FEAS://Feasible126 case LEMON_LPX(I_FEAS)://Feasible 89 127 return FEASIBLE; 90 case L PX_I_OPT://Feasible128 case LEMON_LPX(I_OPT)://Feasible 91 129 return OPTIMAL; 92 130 default: 93 131 return UNDEFINED; //to avoid gcc warning 94 132 //FIXME error 95 133 } … … 102 140 103 141 MipGlpk::Value MipGlpk::_getPrimal(int i) const { 104 return lpx_mip_col_val(lp,i);142 return LEMON_glp(mip_col_val)(lp,i); 105 143 } 106 144 107 145 MipGlpk::Value MipGlpk::_getPrimalValue() const { 108 return lpx_mip_obj_val(lp);146 return LEMON_glp(mip_obj_val)(lp); 109 147 } 110 148 } //END OF NAMESPACE LEMON
Note: See TracChangeset
for help on using the changeset viewer.