lemon/mip_glpk.cc
author alpar
Thu, 07 Sep 2006 13:34:14 +0000
changeset 2208 37b5c870a953
parent 2149 b437bdee6fd0
child 2213 2c094dfa176d
permissions -rw-r--r--
Revert an unintentional commit in r2933
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@2185
    72
athos@2185
    73
athos@2185
    74
  LpGlpk::SolutionStatus MipGlpk::_getMipStatus(){
athos@2185
    75
athos@2185
    76
    //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is
athos@2185
    77
    //infeasible, akkor ez is, de ez lehet maskepp is infeasible.
athos@2185
    78
    int stat=  lpx_mip_status(lp);
athos@2185
    79
    switch (stat) {
athos@2185
    80
    case LPX_I_UNDEF://Undefined (no solve has been run yet)
athos@2185
    81
      return UNDEFINED;
athos@2185
    82
   case LPX_I_NOFEAS://There is no feasible integral solution (primal, I guess)
athos@2185
    83
      return INFEASIBLE;
athos@2185
    84
//     case LPX_UNBND://Unbounded
athos@2185
    85
//       return INFINITE;
athos@2185
    86
    case LPX_I_FEAS://Feasible
athos@2185
    87
      return FEASIBLE;
athos@2185
    88
    case LPX_I_OPT://Feasible
athos@2185
    89
      return OPTIMAL;
athos@2185
    90
    default:
athos@2185
    91
      return UNDEFINED; //to avoid gcc warning
athos@2185
    92
      //FIXME error
athos@2185
    93
    }
athos@2185
    94
  }  
athos@2185
    95
athos@2144
    96
  MipGlpk::Value MipGlpk::_getPrimal(int i){
athos@2144
    97
    return lpx_mip_col_val(lp,i);
athos@2144
    98
  }
athos@2144
    99
  
athos@2144
   100
  MipGlpk::Value MipGlpk::_getPrimalValue(){
athos@2144
   101
    return lpx_mip_obj_val(lp);
athos@2144
   102
  }
athos@2144
   103
} //END OG NAMESPACE LEMON
athos@2144
   104
athos@2144
   105
#endif