COIN-OR::LEMON - Graph Library

Changeset 2328:b4931ae52069 in lemon-0.x for lemon


Ignore:
Timestamp:
12/07/06 17:10:54 (13 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)

Location:
lemon
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • lemon/lp_base.h

    r2324 r2328  
    707707
    708708    virtual void _setColLowerBound(int i, Value value) = 0;
     709    virtual Value _getColLowerBound(int i) = 0;
    709710    virtual void _setColUpperBound(int i, Value value) = 0;
     711    virtual Value _getColUpperBound(int i) = 0;
    710712//     virtual void _setRowLowerBound(int i, Value value) = 0;
    711713//     virtual void _setRowUpperBound(int i, Value value) = 0;
    712714    virtual void _setRowBounds(int i, Value lower, Value upper) = 0;
     715    virtual void _getRowBounds(int i, Value &lower, Value &upper)=0;
     716
    713717    virtual void _setObjCoeff(int i, Value obj_coef) = 0;
    714718    virtual Value _getObjCoeff(int i) = 0;
     
    10251029      _setColLowerBound(_lpId(c),value);
    10261030    }
     1031
     1032    /// Get the lower bound of a column (i.e a variable)
     1033
     1034    /// This function returns the lower bound for column (variable) \t c
     1035    /// (this might be -\ref INF as well). 
     1036    ///\return The lower bound for coloumn \t c
     1037    Value colLowerBound(Col c) {
     1038      return _getColLowerBound(_lpId(c));
     1039    }
    10271040   
    10281041    ///\brief Set the lower bound of  several columns
     
    10721085    };
    10731086
    1074     ///\brief Set the lower bound of  several columns
     1087    /// Get the upper bound of a column (i.e a variable)
     1088
     1089    /// This function returns the upper bound for column (variable) \t c
     1090    /// (this might be \ref INF as well). 
     1091    ///\return The upper bound for coloumn \t c
     1092    Value colUpperBound(Col c) {
     1093      return _getColUpperBound(_lpId(c));
     1094    }
     1095
     1096    ///\brief Set the upper bound of  several columns
    10751097    ///(i.e a variables) at once
    10761098    ///
     
    11771199    /// Set the lower and the upper bounds of a row (i.e a constraint)
    11781200
    1179     /// The lower and the upper bounds of
     1201    /// The lower and the upper bound of
    11801202    /// a constraint (row) have to be given by an
    11811203    /// extended number of type Value, i.e. a finite number of type
    1182     /// Value, -\ref INF or \ref INF.
     1204    /// Value, -\ref INF or \ref INF. There is no separate function for the
     1205    /// lower and the upper bound because that would have been hard to implement
     1206    /// for CPLEX.
    11831207    void rowBounds(Row c, Value lower, Value upper) {
    11841208      _setRowBounds(_lpId(c),lower, upper);
    1185       // _setRowUpperBound(_lpId(c),upper);
    1186     }
    1187    
     1209    }
     1210   
     1211    /// Get the lower and the upper bounds of a row (i.e a constraint)
     1212
     1213    /// The lower and the upper bound of
     1214    /// a constraint (row) are 
     1215    /// extended numbers of type Value, i.e.  finite numbers of type
     1216    /// Value, -\ref INF or \ref INF.
     1217    /// \todo There is no separate function for the
     1218    /// lower and the upper bound because we had problems with the
     1219    /// implementation of the setting functions for CPLEX: 
     1220    /// check out whether this can be done for these functions.
     1221    void getRowBounds(Row c, Value &lower, Value &upper) {
     1222      _getRowBounds(_lpId(c),lower, upper);
     1223    }
     1224
    11881225    ///Set an element of the objective function
    11891226    void objCoeff(Col c, Value v) {_setObjCoeff(_lpId(c),v); };
  • lemon/lp_cplex.cc

    r2312 r2328  
    4444
    4545  LpSolverBase &LpCplex::_copyLp() {
     46    ///\bug FixID data is not copied!
    4647    //The first approach opens a new environment
    4748    LpCplex* newlp=new LpCplex();
  • 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 
  • lemon/lp_glpk.h

    r2324 r2328  
    6464
    6565    virtual void _setColLowerBound(int i, Value value);
     66    virtual Value _getColLowerBound(int i);
    6667    virtual void _setColUpperBound(int i, Value value);
     68    virtual Value _getColUpperBound(int i);
     69
    6770//     virtual void _setRowLowerBound(int i, Value value);
    6871//     virtual void _setRowUpperBound(int i, Value value);
    6972    virtual void _setRowBounds(int i, Value lower, Value upper);
     73    virtual void _getRowBounds(int i, Value &lb, Value &ub);
    7074    virtual void _setObjCoeff(int i, Value obj_coef);
    7175    virtual Value _getObjCoeff(int i);
  • lemon/lp_skeleton.cc

    r2326 r2328  
    7979  }
    8080 
     81  LpSkeleton::Value LpSkeleton::_getColLowerBound(int)
     82  {
     83    return 0;
     84  }
     85 
    8186  void LpSkeleton::_setColUpperBound(int, Value)
    8287  {
     88  }
     89
     90  LpSkeleton::Value LpSkeleton::_getColUpperBound(int)
     91  {
     92    return 0;
    8393  }
    8494 
     
    92102
    93103  void LpSkeleton::_setRowBounds(int, Value, Value)
     104  {
     105  }
     106
     107  void LpSkeleton::_getRowBounds(int, Value&, Value&)
    94108  {
    95109  }
  • lemon/lp_skeleton.h

    r2324 r2328  
    6565    /// \e
    6666
     67    /// The lower bound of a variable (column) is an
     68    /// extended number of type Value, i.e. a finite number of type
     69    /// Value or -\ref INF.
     70    virtual Value _getColLowerBound(int i);
     71
    6772    /// The upper bound of a variable (column) have to be given by an
    6873    /// extended number of type Value, i.e. a finite number of type
     
    7075    virtual void _setColUpperBound(int i, Value value);
    7176    /// \e
     77
     78    /// The upper bound of a variable (column) is an
     79    /// extended number of type Value, i.e. a finite number of type
     80    /// Value or \ref INF.
     81    virtual Value _getColUpperBound(int i);
    7282
    7383//     /// The lower bound of a linear expression (row) have to be given by an
     
    8797    /// Value or +/-\ref INF.
    8898    virtual void _setRowBounds(int i, Value lb, Value ub);
     99    /// \e
     100
     101
     102    /// The lower and the upper bound of
     103    /// a constraint (row) are 
     104    /// extended numbers of type Value, i.e.  finite numbers of type
     105    /// Value, -\ref INF or \ref INF.
     106    virtual void _getRowBounds(int i, Value &lb, Value &ub);
    89107    /// \e
    90108
Note: See TracChangeset for help on using the changeset viewer.