src/work/athos/lp/lp_glpk.cc
author athos
Fri, 25 Mar 2005 15:32:05 +0000
changeset 1262 61f989e3e525
child 1263 a490938ad0aa
permissions -rw-r--r--
This was a bug, I guess
     1 /* -*- C++ -*-
     2  * src/lemon/lp_glpk.cc - Part of LEMON, a generic C++ optimization library
     3  *
     4  * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     5  * (Egervary Combinatorial Optimization Research Group, EGRES).
     6  *
     7  * Permission to use, modify and distribute this software is granted
     8  * provided that this copyright notice appears in all copies. For
     9  * precise terms see the accompanying LICENSE file.
    10  *
    11  * This software is provided "AS IS" with no warranty of any kind,
    12  * express or implied, and with no claim as to its suitability for any
    13  * purpose.
    14  *
    15  */
    16 
    17 #ifndef LEMON_LP_GLPK_CC
    18 #define LEMON_LP_GLPK_CC
    19 
    20 ///\file
    21 ///\brief Implementation of the LEMON-GLPK lp solver interface.
    22 
    23 #include "lp_glpk.h"
    24 
    25 namespace lemon {
    26 
    27     /// \e
    28     int LpGlpk::_addCol() { 
    29 	int i=lpx_add_cols(lp, 1);
    30 	_setColLowerBound(i, -INF);
    31 	_setColUpperBound(i, INF);
    32 	return i;
    33     }
    34 
    35     /// \e
    36     int LpGlpk::_addRow() { 
    37 	int i=lpx_add_rows(lp, 1);
    38 	return i;
    39     }
    40 
    41   
    42     void LpGlpk::_setRowCoeffs(int i, 
    43 			       int length,
    44 			       int   * indices, 
    45 			       Value   * values )
    46     {
    47 	lpx_set_mat_row(lp, i, length, indices, values);
    48     }
    49   
    50     void LpGlpk::_setColCoeffs(int i, 
    51 			       int length,
    52 			       int   * indices, 
    53 			       Value   * values)
    54     {
    55 	lpx_set_mat_col(lp, i, length, indices, values);
    56     }
    57   
    58     void LpGlpk::_setColLowerBound(int i, Value lo)
    59     {
    60       if (lo==INF) {
    61 	//FIXME error
    62       }
    63       int b=lpx_get_col_type(lp, i);
    64       double up=lpx_get_col_ub(lp, i);	
    65       if (lo==-INF) {
    66 	switch (b) {
    67 	case LPX_FR:
    68 	case LPX_LO:
    69 	  lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
    70 	  break;
    71 	case LPX_UP:
    72 	  break;
    73 	case LPX_DB:
    74 	case LPX_FX:
    75 	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
    76 	  break;
    77 	default: ;
    78 	  //FIXME error
    79 	}
    80       } else {
    81 	switch (b) {
    82 	case LPX_FR:
    83 	case LPX_LO:
    84 	  lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
    85 	  break;
    86 	case LPX_UP:	  
    87 	case LPX_DB:
    88 	case LPX_FX:
    89 	  if (lo==up) 
    90 	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
    91 	  else 
    92 	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
    93 	  break;
    94 	default: ;
    95 	  //FIXME error
    96 	}
    97       }
    98 
    99     }
   100   
   101     void LpGlpk::_setColUpperBound(int i, Value up)
   102     {
   103       if (up==-INF) {
   104 	//FIXME error
   105       }
   106       int b=lpx_get_col_type(lp, i);
   107       double lo=lpx_get_col_lb(lp, i);
   108       if (up==INF) {
   109 	switch (b) {
   110 	case LPX_FR:
   111 	case LPX_LO:
   112 	  break;
   113 	case LPX_UP:
   114 	  lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
   115 	  break;
   116 	case LPX_DB:
   117 	case LPX_FX:
   118 	  lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
   119 	  break;
   120 	default: ;
   121 	  //FIXME error
   122 	}
   123       } else {
   124 	switch (b) {
   125 	case LPX_FR:
   126 	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
   127 	  break;
   128 	case LPX_UP:
   129 	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
   130 	  break;
   131 	case LPX_LO:
   132 	case LPX_DB:
   133 	case LPX_FX:
   134 	  if (lo==up) 
   135 	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
   136 	  else 
   137 	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
   138 	  break;
   139 	default: ;
   140 	  //FIXME error
   141 	}
   142       }
   143     }
   144   
   145     void LpGlpk::_setRowLowerBound(int i, Value lo)
   146     {
   147       if (lo==INF) {
   148 	//FIXME error
   149       }
   150       int b=lpx_get_row_type(lp, i);
   151       double up=lpx_get_row_ub(lp, i);	
   152       if (lo==-INF) {
   153 	switch (b) {
   154 	case LPX_FR:
   155 	case LPX_LO:
   156 	  lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
   157 	  break;
   158 	case LPX_UP:
   159 	  break;
   160 	case LPX_DB:
   161 	case LPX_FX:
   162 	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
   163 	  break;
   164 	default: ;
   165 	  //FIXME error
   166 	}
   167       } else {
   168 	switch (b) {
   169 	case LPX_FR:
   170 	case LPX_LO:
   171 	  lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
   172 	  break;
   173 	case LPX_UP:	  
   174 	case LPX_DB:
   175 	case LPX_FX:
   176 	  if (lo==up) 
   177 	    lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
   178 	  else 
   179 	    lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
   180 	  break;
   181 	default: ;
   182 	  //FIXME error
   183 	}
   184       }
   185     }
   186   
   187     void LpGlpk::_setRowUpperBound(int i, Value up)
   188     {
   189       if (up==-INF) {
   190 	//FIXME error
   191       }
   192       int b=lpx_get_row_type(lp, i);
   193       double lo=lpx_get_row_lb(lp, i);
   194       if (up==INF) {
   195 	switch (b) {
   196 	case LPX_FR:
   197 	case LPX_LO:
   198 	  break;
   199 	case LPX_UP:
   200 	  lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
   201 	  break;
   202 	case LPX_DB:
   203 	case LPX_FX:
   204 	  lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
   205 	  break;
   206 	default: ;
   207 	  //FIXME error
   208 	}
   209       } else {
   210 	switch (b) {
   211 	case LPX_FR:
   212 	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
   213 	  break;
   214 	case LPX_UP:
   215 	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
   216 	  break;
   217 	case LPX_LO:
   218 	case LPX_DB:
   219 	case LPX_FX:
   220 	  if (lo==up) 
   221 	    lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
   222 	  else 
   223 	    lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
   224 	  break;
   225 	default: ;
   226 	  //FIXME error
   227 	}
   228       }
   229     }
   230   
   231     void LpGlpk::_setObjCoeff(int i, Value obj_coef)
   232     {
   233       lpx_set_obj_coef(lp, i, obj_coef);
   234     }
   235 
   236 } //END OF NAMESPACE LEMON
   237 
   238 #endif //LEMON_LP_GLPK_CC