COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/mip_glpk.cc @ 2218:50f1a780a5ff

Last change on this file since 2218:50f1a780a5ff was 2218:50f1a780a5ff, checked in by athos, 13 years ago

Interface to the cplex MIP solver: it is little, a bit sour but it is ours.

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