lemon/mip_glpk.cc
author deba
Fri, 29 Sep 2006 11:26:29 +0000
changeset 2224 f973894da54e
parent 2213 2c094dfa176d
child 2253 1645f6cc9667
permissions -rw-r--r--
Moving the file into correct group
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@2218
    19
#ifndef LEMON_MIP_GLPK_CC
athos@2218
    20
#define LEMON_MIP_GLPK_CC
athos@2144
    21
athos@2144
    22
///\file
athos@2218
    23
///\brief Implementation of the LEMON-GLPK mip 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@2218
    35
      case LEMON_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@2218
    49
      return LEMON_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@2213
    60
    //
athos@2213
    61
    if (lpx_get_status(lp)==LPX_OPT){
athos@2213
    62
      //Maybe we could try the routine lpx_intopt(lp), a revised
athos@2213
    63
      //version of lpx_integer
athos@2213
    64
      result = lpx_integer(lp);
athos@2213
    65
      switch (result){
athos@2144
    66
      case LPX_E_OK:
athos@2213
    67
	return SOLVED;
athos@2144
    68
      default:
athos@2213
    69
	return UNSOLVED;
athos@2213
    70
      }
athos@2213
    71
      
athos@2144
    72
    }
athos@2213
    73
    return UNSOLVED;
athos@2144
    74
  }
athos@2185
    75
athos@2185
    76
athos@2185
    77
  LpGlpk::SolutionStatus MipGlpk::_getMipStatus(){
athos@2185
    78
athos@2213
    79
    if (lpx_get_status(lp)==LPX_OPT){
athos@2213
    80
      //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is
athos@2213
    81
      //infeasible, akkor ez is, de ez lehet maskepp is infeasible.
athos@2213
    82
      int stat=  lpx_mip_status(lp);
athos@2213
    83
      
athos@2213
    84
      switch (stat) {
athos@2213
    85
      case LPX_I_UNDEF://Undefined (no solve has been run yet)
athos@2213
    86
	return UNDEFINED;
athos@2213
    87
      case LPX_I_NOFEAS://There is no feasible integral solution
athos@2213
    88
	return INFEASIBLE;
athos@2213
    89
	//     case LPX_UNBND://Unbounded
athos@2213
    90
	//       return INFINITE;
athos@2213
    91
      case LPX_I_FEAS://Feasible
athos@2213
    92
	return FEASIBLE;
athos@2213
    93
      case LPX_I_OPT://Feasible
athos@2213
    94
	return OPTIMAL;
athos@2213
    95
      default:
athos@2185
    96
      return UNDEFINED; //to avoid gcc warning
athos@2185
    97
      //FIXME error
athos@2213
    98
      }
athos@2185
    99
    }
athos@2213
   100
    else 
athos@2213
   101
      return UNDEFINED; //Maybe we could refine this: what does the LP
athos@2213
   102
			//relaxation look like
athos@2213
   103
      
athos@2185
   104
  }  
athos@2185
   105
athos@2144
   106
  MipGlpk::Value MipGlpk::_getPrimal(int i){
athos@2144
   107
    return lpx_mip_col_val(lp,i);
athos@2144
   108
  }
athos@2144
   109
  
athos@2144
   110
  MipGlpk::Value MipGlpk::_getPrimalValue(){
athos@2144
   111
    return lpx_mip_obj_val(lp);
athos@2144
   112
  }
athos@2218
   113
} //END OF NAMESPACE LEMON
athos@2144
   114
athos@2218
   115
#endif //END OF MIP_GLPK_CC