COIN-OR::LEMON - Graph Library

Changeset 2328:b4931ae52069 in lemon-0.x for lemon/lp_glpk.cc


Ignore:
Timestamp:
12/07/06 17:10:54 (17 years ago)
Author:
athos
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3104
Message:

Query functions have been implemented for GLPK (CPLEX breaks at the moment, I guess): These functions include:
retrieving one element of the coeff. matrix
retrieving one element of the obj function
lower bd for a variable
upper bound for a variable
lower and upper bounds for a row (these can not be handled separately at the moment)
direction of the optimization (is_max() function)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/lp_glpk.cc

    r2326 r2328  
    214214  }
    215215
    216   LpGlpk::Value LpGlpk::_getCoeff(int, int)
    217   {
    218     ///\todo This is not yet implemented!!!
     216  LpGlpk::Value LpGlpk::_getCoeff(int row, int col)
     217  {
     218
     219    int length=lpx_get_mat_row(lp, row, 0, 0);
     220   
     221    std::vector<int> indices(length + 2);
     222    std::vector<Value> values(length + 2);
     223   
     224    lpx_get_mat_row(lp, row, &indices[0], &values[0]);
     225   
     226    //The following code does not suppose that the elements of the
     227    //array indices are sorted
     228    for (int i = 1; i <= length; ++i) {
     229      if (indices[i]==col){
     230        return values[i];
     231      }
     232    }
    219233    return 0;
     234
    220235  }
    221236
     
    263278
    264279  }
     280
     281  LpGlpk::Value LpGlpk::_getColLowerBound(int i)
     282  {
     283    int b=lpx_get_col_type(lp, i);
     284      switch (b) {
     285      case LPX_LO:
     286      case LPX_DB:
     287      case LPX_FX:
     288        return lpx_get_col_lb(lp, i);   
     289      default: ;
     290        return -INF;
     291      }
     292  }
    265293 
    266294  void LpGlpk::_setColUpperBound(int i, Value up)
     
    306334      }
    307335    }
     336  }
     337
     338  LpGlpk::Value LpGlpk::_getColUpperBound(int i)
     339  {
     340    int b=lpx_get_col_type(lp, i);
     341      switch (b) {
     342      case LPX_UP:
     343      case LPX_DB:
     344      case LPX_FX:
     345        return lpx_get_col_ub(lp, i);   
     346      default: ;
     347        return INF;
     348      }
    308349  }
    309350 
     
    424465    }
    425466
     467  }
     468
     469  void LpGlpk::_getRowBounds(int i, Value &lb, Value &ub)
     470  {
     471
     472    int b=lpx_get_row_type(lp, i);
     473    switch (b) {
     474    case LPX_FR:
     475    case LPX_UP:
     476      lb = -INF;
     477        break;
     478    default:
     479      lb=lpx_get_row_lb(lp, i);
     480    }
     481
     482    switch (b) {
     483    case LPX_FR:
     484    case LPX_LO:
     485      ub = INF;
     486        break;
     487    default:
     488      ub=lpx_get_row_ub(lp, i);
     489    }
     490   
    426491  }
    427492 
Note: See TracChangeset for help on using the changeset viewer.