COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/mip_glpk.cc @ 2366:bfbdded3763a

Last change on this file since 2366:bfbdded3763a was 2366:bfbdded3763a, checked in by Balazs Dezso, 13 years ago

Using const in lp interface
colByName functionality

File size: 2.6 KB
Line 
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
20///\brief Implementation of the LEMON-GLPK mip solver interface.
21
22#include <lemon/mip_glpk.h>
23
24namespace lemon {
25 
26  MipGlpk::MipGlpk() {
27    lpx_set_class(lp,LPX_MIP);
28  }
29
30  void MipGlpk::_colType(int i, MipGlpk::ColTypes col_type){
31    switch (col_type){
32      case INT:
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;
38    default:;
39        //FIXME problem
40    }
41  }
42 
43  MipGlpk::ColTypes MipGlpk::_colType(int i) const {
44    switch (lpx_get_col_kind(lp,i)){
45    case LPX_IV:
46      return INT;//Or binary
47    case LPX_CV:
48      return REAL;
49    default:
50      return REAL;//Error!
51    }
52   
53  }
54 
55  LpGlpk::SolveExitStatus MipGlpk::_solve() {
56    int result = lpx_simplex(lp);
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){
63      case LPX_E_OK:
64        return SOLVED;
65      default:
66        return UNSOLVED;
67      }
68     
69    }
70    return UNSOLVED;
71  }
72
73
74  LpGlpk::SolutionStatus MipGlpk::_getMipStatus() const {
75
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:
93      return UNDEFINED; //to avoid gcc warning
94      //FIXME error
95      }
96    }
97    else
98      return UNDEFINED; //Maybe we could refine this: what does the LP
99                        //relaxation look like
100     
101  } 
102
103  MipGlpk::Value MipGlpk::_getPrimal(int i) const {
104    return lpx_mip_col_val(lp,i);
105  }
106 
107  MipGlpk::Value MipGlpk::_getPrimalValue() const {
108    return lpx_mip_obj_val(lp);
109  }
110} //END OF NAMESPACE LEMON
Note: See TracBrowser for help on using the repository browser.