athos@2144
|
1 |
/* -*- C++ -*-
|
athos@2144
|
2 |
*
|
athos@2144
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
athos@2144
|
4 |
*
|
athos@2144
|
5 |
* Copyright (C) 2003-2006
|
athos@2144
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
athos@2144
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
athos@2144
|
8 |
*
|
athos@2144
|
9 |
* Permission to use, modify and distribute this software is granted
|
athos@2144
|
10 |
* provided that this copyright notice appears in all copies. For
|
athos@2144
|
11 |
* precise terms see the accompanying LICENSE file.
|
athos@2144
|
12 |
*
|
athos@2144
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
athos@2144
|
14 |
* express or implied, and with no claim as to its suitability for any
|
athos@2144
|
15 |
* purpose.
|
athos@2144
|
16 |
*
|
athos@2144
|
17 |
*/
|
athos@2144
|
18 |
|
athos@2144
|
19 |
#ifndef LEMON_ILP_GLPK_CC
|
athos@2144
|
20 |
#define LEMON_ILP_GLPK_CC
|
athos@2144
|
21 |
|
athos@2144
|
22 |
///\file
|
athos@2144
|
23 |
///\brief Implementation of the LEMON-GLPK lp solver interface.
|
athos@2144
|
24 |
|
athos@2144
|
25 |
#include <lemon/mip_glpk.h>
|
athos@2144
|
26 |
|
athos@2144
|
27 |
namespace lemon {
|
athos@2144
|
28 |
|
athos@2144
|
29 |
MipGlpk::MipGlpk() {
|
athos@2144
|
30 |
lpx_set_class(lp,LPX_MIP);
|
athos@2144
|
31 |
}
|
athos@2144
|
32 |
|
athos@2144
|
33 |
void MipGlpk::_integer(int i, bool enable){
|
athos@2144
|
34 |
if(enable){
|
athos@2144
|
35 |
lpx_set_col_kind(lp,i,LPX_IV);
|
athos@2144
|
36 |
}else{
|
athos@2144
|
37 |
lpx_set_col_kind(lp,i,LPX_CV);
|
athos@2144
|
38 |
}
|
athos@2144
|
39 |
}
|
athos@2144
|
40 |
|
athos@2144
|
41 |
bool MipGlpk::_integer(int i){
|
athos@2144
|
42 |
if(LPX_IV == lpx_get_col_kind(lp,i)){
|
athos@2144
|
43 |
return true;
|
athos@2144
|
44 |
}
|
athos@2144
|
45 |
return false;
|
athos@2144
|
46 |
}
|
athos@2144
|
47 |
|
athos@2144
|
48 |
LpGlpk::SolveExitStatus MipGlpk::_solve(){
|
athos@2144
|
49 |
int result = lpx_simplex(lp);
|
athos@2144
|
50 |
result = lpx_integer(lp);
|
athos@2144
|
51 |
switch (result){
|
athos@2144
|
52 |
case LPX_E_OBJLL:
|
athos@2144
|
53 |
case LPX_E_OBJUL:
|
athos@2144
|
54 |
case LPX_E_ITLIM:
|
athos@2144
|
55 |
case LPX_E_TMLIM:
|
athos@2144
|
56 |
case LPX_E_OK:
|
athos@2144
|
57 |
return SOLVED;
|
athos@2144
|
58 |
default:
|
athos@2144
|
59 |
return UNSOLVED;
|
athos@2144
|
60 |
}
|
athos@2144
|
61 |
}
|
athos@2144
|
62 |
|
athos@2144
|
63 |
MipGlpk::Value MipGlpk::_getPrimal(int i){
|
athos@2144
|
64 |
return lpx_mip_col_val(lp,i);
|
athos@2144
|
65 |
}
|
athos@2144
|
66 |
|
athos@2144
|
67 |
MipGlpk::Value MipGlpk::_getPrimalValue(){
|
athos@2144
|
68 |
return lpx_mip_obj_val(lp);
|
athos@2144
|
69 |
}
|
athos@2144
|
70 |
} //END OG NAMESPACE LEMON
|
athos@2144
|
71 |
|
athos@2144
|
72 |
#endif
|