lemon/mip_glpk.cc
author deba
Wed, 06 Sep 2006 09:54:46 +0000
changeset 2198 416b0c06b5c8
parent 2149 b437bdee6fd0
child 2213 2c094dfa176d
permissions -rw-r--r--
Using abort() instead of exit(1)

If a program is aborted then the call stack can be analyzed with debugger.
The exit(1) does not provides that.
     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 #ifndef LEMON_ILP_GLPK_CC
    20 #define LEMON_ILP_GLPK_CC
    21 
    22 ///\file
    23 ///\brief Implementation of the LEMON-GLPK lp solver interface.
    24 
    25 #include <lemon/mip_glpk.h>
    26 
    27 namespace lemon {
    28   
    29   MipGlpk::MipGlpk() {
    30     lpx_set_class(lp,LPX_MIP);
    31   }
    32 
    33   void MipGlpk::_colType(int i, MipGlpk::ColTypes col_type){
    34     switch (col_type){
    35       case INTEGER:
    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;
    41     default:;
    42         //FIXME problem
    43     }
    44   }
    45   
    46   MipGlpk::ColTypes MipGlpk::_colType(int i){
    47     switch (lpx_get_col_kind(lp,i)){
    48     case LPX_IV:
    49       return INTEGER;//Or binary
    50     case LPX_CV:
    51       return REAL;
    52     default:
    53       return REAL;//Error!
    54     }
    55     
    56   }
    57   
    58   LpGlpk::SolveExitStatus MipGlpk::_solve(){
    59     int result = lpx_simplex(lp);
    60     result = lpx_integer(lp);
    61     switch (result){
    62       case LPX_E_OBJLL:
    63       case LPX_E_OBJUL:
    64       case LPX_E_ITLIM:
    65       case LPX_E_TMLIM:
    66       case LPX_E_OK:
    67         return SOLVED;
    68       default:
    69         return UNSOLVED;
    70     }
    71   }
    72 
    73 
    74   LpGlpk::SolutionStatus MipGlpk::_getMipStatus(){
    75 
    76     //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is
    77     //infeasible, akkor ez is, de ez lehet maskepp is infeasible.
    78     int stat=  lpx_mip_status(lp);
    79     switch (stat) {
    80     case LPX_I_UNDEF://Undefined (no solve has been run yet)
    81       return UNDEFINED;
    82    case LPX_I_NOFEAS://There is no feasible integral solution (primal, I guess)
    83       return INFEASIBLE;
    84 //     case LPX_UNBND://Unbounded
    85 //       return INFINITE;
    86     case LPX_I_FEAS://Feasible
    87       return FEASIBLE;
    88     case LPX_I_OPT://Feasible
    89       return OPTIMAL;
    90     default:
    91       return UNDEFINED; //to avoid gcc warning
    92       //FIXME error
    93     }
    94   }  
    95 
    96   MipGlpk::Value MipGlpk::_getPrimal(int i){
    97     return lpx_mip_col_val(lp,i);
    98   }
    99   
   100   MipGlpk::Value MipGlpk::_getPrimalValue(){
   101     return lpx_mip_obj_val(lp);
   102   }
   103 } //END OG NAMESPACE LEMON
   104 
   105 #endif