lemon/mip_glpk.cc
author alpar
Wed, 19 Jul 2006 15:13:24 +0000
changeset 2156 478ba329ffb7
parent 2148 ab368e0ab662
child 2185 e2bf51eab7f7
permissions -rw-r--r--
spellcheck
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@2148
    32
athos@2149
    33
  void MipGlpk::_colType(int i, MipGlpk::ColTypes col_type){
athos@2148
    34
    switch (col_type){
athos@2148
    35
      case INTEGER:
athos@2148
    36
	lpx_set_col_kind(lp,i,LPX_IV);
athos@2148
    37
	break;
athos@2148
    38
      case REAL:
athos@2148
    39
	lpx_set_col_kind(lp,i,LPX_CV);
athos@2148
    40
	break;
athos@2149
    41
    default:;
athos@2148
    42
        //FIXME problem
athos@2144
    43
    }
athos@2144
    44
  }
athos@2144
    45
  
athos@2149
    46
  MipGlpk::ColTypes MipGlpk::_colType(int i){
athos@2148
    47
    switch (lpx_get_col_kind(lp,i)){
athos@2148
    48
    case LPX_IV:
athos@2148
    49
      return INTEGER;//Or binary
athos@2148
    50
    case LPX_CV:
athos@2148
    51
      return REAL;
athos@2148
    52
    default:
athos@2148
    53
      return REAL;//Error!
athos@2144
    54
    }
athos@2148
    55
    
athos@2144
    56
  }
athos@2144
    57
  
athos@2144
    58
  LpGlpk::SolveExitStatus MipGlpk::_solve(){
athos@2144
    59
    int result = lpx_simplex(lp);
athos@2144
    60
    result = lpx_integer(lp);
athos@2144
    61
    switch (result){
athos@2144
    62
      case LPX_E_OBJLL:
athos@2144
    63
      case LPX_E_OBJUL:
athos@2144
    64
      case LPX_E_ITLIM:
athos@2144
    65
      case LPX_E_TMLIM:
athos@2144
    66
      case LPX_E_OK:
athos@2144
    67
        return SOLVED;
athos@2144
    68
      default:
athos@2144
    69
        return UNSOLVED;
athos@2144
    70
    }
athos@2144
    71
  }
athos@2144
    72
  
athos@2144
    73
  MipGlpk::Value MipGlpk::_getPrimal(int i){
athos@2144
    74
    return lpx_mip_col_val(lp,i);
athos@2144
    75
  }
athos@2144
    76
  
athos@2144
    77
  MipGlpk::Value MipGlpk::_getPrimalValue(){
athos@2144
    78
    return lpx_mip_obj_val(lp);
athos@2144
    79
  }
athos@2144
    80
} //END OG NAMESPACE LEMON
athos@2144
    81
athos@2144
    82
#endif