[2144] | 1 | /* -*- C++ -*- |
---|
| 2 | * |
---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 2003-2006 |
---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 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. |
---|
| 12 | * |
---|
| 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 |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | ///\file |
---|
[2218] | 20 | ///\brief Implementation of the LEMON-GLPK mip solver interface. |
---|
[2144] | 21 | |
---|
| 22 | #include <lemon/mip_glpk.h> |
---|
| 23 | |
---|
| 24 | namespace lemon { |
---|
| 25 | |
---|
| 26 | MipGlpk::MipGlpk() { |
---|
| 27 | lpx_set_class(lp,LPX_MIP); |
---|
| 28 | } |
---|
[2148] | 29 | |
---|
[2149] | 30 | void MipGlpk::_colType(int i, MipGlpk::ColTypes col_type){ |
---|
[2148] | 31 | switch (col_type){ |
---|
[2267] | 32 | case INT: |
---|
[2148] | 33 | lpx_set_col_kind(lp,i,LPX_IV); |
---|
| 34 | break; |
---|
| 35 | case REAL: |
---|
| 36 | lpx_set_col_kind(lp,i,LPX_CV); |
---|
| 37 | break; |
---|
[2149] | 38 | default:; |
---|
[2148] | 39 | //FIXME problem |
---|
[2144] | 40 | } |
---|
| 41 | } |
---|
| 42 | |
---|
[2149] | 43 | MipGlpk::ColTypes MipGlpk::_colType(int i){ |
---|
[2148] | 44 | switch (lpx_get_col_kind(lp,i)){ |
---|
| 45 | case LPX_IV: |
---|
[2267] | 46 | return INT;//Or binary |
---|
[2148] | 47 | case LPX_CV: |
---|
| 48 | return REAL; |
---|
| 49 | default: |
---|
| 50 | return REAL;//Error! |
---|
[2144] | 51 | } |
---|
[2148] | 52 | |
---|
[2144] | 53 | } |
---|
| 54 | |
---|
| 55 | LpGlpk::SolveExitStatus MipGlpk::_solve(){ |
---|
| 56 | int result = lpx_simplex(lp); |
---|
[2213] | 57 | // |
---|
| 58 | if (lpx_get_status(lp)==LPX_OPT){ |
---|
| 59 | //Maybe we could try the routine lpx_intopt(lp), a revised |
---|
| 60 | //version of lpx_integer |
---|
| 61 | result = lpx_integer(lp); |
---|
| 62 | switch (result){ |
---|
[2144] | 63 | case LPX_E_OK: |
---|
[2213] | 64 | return SOLVED; |
---|
[2144] | 65 | default: |
---|
[2213] | 66 | return UNSOLVED; |
---|
| 67 | } |
---|
| 68 | |
---|
[2144] | 69 | } |
---|
[2213] | 70 | return UNSOLVED; |
---|
[2144] | 71 | } |
---|
[2185] | 72 | |
---|
| 73 | |
---|
| 74 | LpGlpk::SolutionStatus MipGlpk::_getMipStatus(){ |
---|
| 75 | |
---|
[2213] | 76 | if (lpx_get_status(lp)==LPX_OPT){ |
---|
| 77 | //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is |
---|
| 78 | //infeasible, akkor ez is, de ez lehet maskepp is infeasible. |
---|
| 79 | int stat= lpx_mip_status(lp); |
---|
| 80 | |
---|
| 81 | switch (stat) { |
---|
| 82 | case LPX_I_UNDEF://Undefined (no solve has been run yet) |
---|
| 83 | return UNDEFINED; |
---|
| 84 | case LPX_I_NOFEAS://There is no feasible integral solution |
---|
| 85 | return INFEASIBLE; |
---|
| 86 | // case LPX_UNBND://Unbounded |
---|
| 87 | // return INFINITE; |
---|
| 88 | case LPX_I_FEAS://Feasible |
---|
| 89 | return FEASIBLE; |
---|
| 90 | case LPX_I_OPT://Feasible |
---|
| 91 | return OPTIMAL; |
---|
| 92 | default: |
---|
[2185] | 93 | return UNDEFINED; //to avoid gcc warning |
---|
| 94 | //FIXME error |
---|
[2213] | 95 | } |
---|
[2185] | 96 | } |
---|
[2213] | 97 | else |
---|
| 98 | return UNDEFINED; //Maybe we could refine this: what does the LP |
---|
| 99 | //relaxation look like |
---|
| 100 | |
---|
[2185] | 101 | } |
---|
| 102 | |
---|
[2144] | 103 | MipGlpk::Value MipGlpk::_getPrimal(int i){ |
---|
| 104 | return lpx_mip_col_val(lp,i); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | MipGlpk::Value MipGlpk::_getPrimalValue(){ |
---|
| 108 | return lpx_mip_obj_val(lp); |
---|
| 109 | } |
---|
[2218] | 110 | } //END OF NAMESPACE LEMON |
---|