COIN-OR::LEMON - Graph Library

Changeset 1321:bc3a4c498eb2 in lemon-0.x for src/lemon/lp_glpk.cc


Ignore:
Timestamp:
04/08/05 08:33:11 (19 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1760
Message:

No output messages by default

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/lp_glpk.cc

    r1314 r1321  
    2525namespace lemon {
    2626
    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                                const int   * indices,
    45                                const Value   * values )
    46     {
    47       lpx_set_mat_row(lp, i, length,
    48                       const_cast<int * >(indices) ,
    49                       const_cast<Value * >(values));
    50     }
    51  
    52     void LpGlpk::_setColCoeffs(int i,
    53                                int length,
    54                                const int   * indices,
    55                                const Value   * values)
    56     {
    57       lpx_set_mat_col(lp, i, length,
    58                       const_cast<int * >(indices),
    59                       const_cast<Value * >(values));
    60     }
    61  
    62     void LpGlpk::_setColLowerBound(int i, Value lo)
    63     {
    64       if (lo==INF) {
    65         //FIXME error
    66       }
    67       int b=lpx_get_col_type(lp, i);
    68       double up=lpx_get_col_ub(lp, i); 
    69       if (lo==-INF) {
    70         switch (b) {
    71         case LPX_FR:
    72         case LPX_LO:
    73           lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
    74           break;
    75         case LPX_UP:
    76           break;
    77         case LPX_DB:
    78         case LPX_FX:
    79           lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
    80           break;
    81         default: ;
    82           //FIXME error
    83         }
    84       } else {
    85         switch (b) {
    86         case LPX_FR:
    87         case LPX_LO:
    88           lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
    89           break;
    90         case LPX_UP:     
    91         case LPX_DB:
    92         case LPX_FX:
    93           if (lo==up)
    94             lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
    95           else
    96             lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
    97           break;
    98         default: ;
    99           //FIXME error
    100         }
    101       }
    102 
    103     }
    104  
    105     void LpGlpk::_setColUpperBound(int i, Value up)
    106     {
    107       if (up==-INF) {
    108         //FIXME error
    109       }
    110       int b=lpx_get_col_type(lp, i);
    111       double lo=lpx_get_col_lb(lp, i);
    112       if (up==INF) {
    113         switch (b) {
    114         case LPX_FR:
    115         case LPX_LO:
    116           break;
    117         case LPX_UP:
    118           lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
    119           break;
    120         case LPX_DB:
    121         case LPX_FX:
    122           lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
    123           break;
    124         default: ;
    125           //FIXME error
    126         }
    127       } else {
    128         switch (b) {
    129         case LPX_FR:
    130           lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
    131           break;
    132         case LPX_UP:
    133           lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
    134           break;
    135         case LPX_LO:
    136         case LPX_DB:
    137         case LPX_FX:
    138           if (lo==up)
    139             lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
    140           else
    141             lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
    142           break;
    143         default: ;
    144           //FIXME error
    145         }
    146       }
    147     }
    148  
    149     void LpGlpk::_setRowLowerBound(int i, Value lo)
    150     {
    151       if (lo==INF) {
    152         //FIXME error
    153       }
    154       int b=lpx_get_row_type(lp, i);
    155       double up=lpx_get_row_ub(lp, i); 
    156       if (lo==-INF) {
    157         switch (b) {
    158         case LPX_FR:
    159         case LPX_LO:
    160           lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
    161           break;
    162         case LPX_UP:
    163           break;
    164         case LPX_DB:
    165         case LPX_FX:
    166           lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
    167           break;
    168         default: ;
    169           //FIXME error
    170         }
    171       } else {
    172         switch (b) {
    173         case LPX_FR:
    174         case LPX_LO:
    175           lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
    176           break;
    177         case LPX_UP:     
    178         case LPX_DB:
    179         case LPX_FX:
    180           if (lo==up)
    181             lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
    182           else
    183             lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
    184           break;
    185         default: ;
    186           //FIXME error
    187         }
    188       }
    189     }
    190  
    191   void LpGlpk::_setRowUpperBound(int i, Value up)
     27  LpGlpk::LpGlpk() : Parent(),
     28                     lp(lpx_create_prob()) {
     29    ///\todo constrol function for this:
     30    lpx_set_int_parm(lp, LPX_K_DUAL, 1);
     31    messageLevel(0);
     32  }
     33 
     34  LpGlpk::~LpGlpk() {
     35    lpx_delete_prob(lp);
     36  }
     37 
     38  int LpGlpk::_addCol() {
     39    int i=lpx_add_cols(lp, 1);
     40    _setColLowerBound(i, -INF);
     41    _setColUpperBound(i, INF);
     42    return i;
     43  }
     44
     45  int LpGlpk::_addRow() {
     46    int i=lpx_add_rows(lp, 1);
     47    return i;
     48  }
     49
     50 
     51  void LpGlpk::_setRowCoeffs(int i,
     52                             int length,
     53                             const int   * indices,
     54                             const Value   * values )
     55  {
     56    lpx_set_mat_row(lp, i, length,
     57                    const_cast<int * >(indices) ,
     58                    const_cast<Value * >(values));
     59  }
     60 
     61  void LpGlpk::_setColCoeffs(int i,
     62                             int length,
     63                             const int   * indices,
     64                             const Value   * values)
     65  {
     66    lpx_set_mat_col(lp, i, length,
     67                    const_cast<int * >(indices),
     68                    const_cast<Value * >(values));
     69  }
     70 
     71  void LpGlpk::_setColLowerBound(int i, Value lo)
     72  {
     73    if (lo==INF) {
     74      //FIXME error
     75    }
     76    int b=lpx_get_col_type(lp, i);
     77    double up=lpx_get_col_ub(lp, i);   
     78    if (lo==-INF) {
     79      switch (b) {
     80      case LPX_FR:
     81      case LPX_LO:
     82        lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
     83        break;
     84      case LPX_UP:
     85        break;
     86      case LPX_DB:
     87      case LPX_FX:
     88        lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
     89        break;
     90      default: ;
     91        //FIXME error
     92      }
     93    } else {
     94      switch (b) {
     95      case LPX_FR:
     96      case LPX_LO:
     97        lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
     98        break;
     99      case LPX_UP:       
     100      case LPX_DB:
     101      case LPX_FX:
     102        if (lo==up)
     103          lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
     104        else
     105          lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
     106        break;
     107      default: ;
     108        //FIXME error
     109      }
     110    }
     111
     112  }
     113 
     114  void LpGlpk::_setColUpperBound(int i, Value up)
    192115  {
    193116    if (up==-INF) {
    194117      //FIXME error
    195118    }
     119    int b=lpx_get_col_type(lp, i);
     120    double lo=lpx_get_col_lb(lp, i);
     121    if (up==INF) {
     122      switch (b) {
     123      case LPX_FR:
     124      case LPX_LO:
     125        break;
     126      case LPX_UP:
     127        lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
     128        break;
     129      case LPX_DB:
     130      case LPX_FX:
     131        lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
     132        break;
     133      default: ;
     134        //FIXME error
     135      }
     136    } else {
     137      switch (b) {
     138      case LPX_FR:
     139        lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
     140        break;
     141      case LPX_UP:
     142        lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
     143        break;
     144      case LPX_LO:
     145      case LPX_DB:
     146      case LPX_FX:
     147        if (lo==up)
     148          lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
     149        else
     150          lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
     151        break;
     152      default: ;
     153        //FIXME error
     154      }
     155    }
     156  }
     157 
     158  void LpGlpk::_setRowLowerBound(int i, Value lo)
     159  {
     160    if (lo==INF) {
     161      //FIXME error
     162    }
    196163    int b=lpx_get_row_type(lp, i);
    197     double lo=lpx_get_row_lb(lp, i);
    198     if (up==INF) {
    199       switch (b) {
    200       case LPX_FR:
    201       case LPX_LO:
    202         break;
    203       case LPX_UP:
     164    double up=lpx_get_row_ub(lp, i);   
     165    if (lo==-INF) {
     166      switch (b) {
     167      case LPX_FR:
     168      case LPX_LO:
    204169        lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
    205170        break;
    206       case LPX_DB:
    207       case LPX_FX:
     171      case LPX_UP:
     172        break;
     173      case LPX_DB:
     174      case LPX_FX:
     175        lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
     176        break;
     177      default: ;
     178        //FIXME error
     179      }
     180    } else {
     181      switch (b) {
     182      case LPX_FR:
     183      case LPX_LO:
    208184        lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
    209185        break;
    210       default: ;
    211         //FIXME error
    212       }
    213     } else {
    214       switch (b) {
    215       case LPX_FR:
    216         lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
    217         break;
    218       case LPX_UP:
    219         lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
    220         break;
    221       case LPX_LO:
     186      case LPX_UP:       
    222187      case LPX_DB:
    223188      case LPX_FX:
     
    233198  }
    234199 
     200  void LpGlpk::_setRowUpperBound(int i, Value up)
     201  {
     202    if (up==-INF) {
     203      //FIXME error
     204    }
     205    int b=lpx_get_row_type(lp, i);
     206    double lo=lpx_get_row_lb(lp, i);
     207    if (up==INF) {
     208      switch (b) {
     209      case LPX_FR:
     210      case LPX_LO:
     211        break;
     212      case LPX_UP:
     213        lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
     214        break;
     215      case LPX_DB:
     216      case LPX_FX:
     217        lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
     218        break;
     219      default: ;
     220        //FIXME error
     221      }
     222    } else {
     223      switch (b) {
     224      case LPX_FR:
     225        lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
     226        break;
     227      case LPX_UP:
     228        lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
     229        break;
     230      case LPX_LO:
     231      case LPX_DB:
     232      case LPX_FX:
     233        if (lo==up)
     234          lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
     235        else
     236          lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
     237        break;
     238      default: ;
     239        //FIXME error
     240      }
     241    }
     242  }
     243 
    235244  void LpGlpk::_setObjCoeff(int i, Value obj_coef)
    236245  {
     
    291300  void LpGlpk::_setMax()
    292301  {
    293       lpx_set_obj_dir(lp, LPX_MAX);
    294    }
     302    lpx_set_obj_dir(lp, LPX_MAX);
     303  }
     304
    295305  void LpGlpk::_setMin()
    296306  {
    297       lpx_set_obj_dir(lp, LPX_MIN);
    298    }
     307    lpx_set_obj_dir(lp, LPX_MIN);
     308  }
     309
     310 
     311  void LpGlpk::messageLevel(int m)
     312  {
     313    lpx_set_int_parm(lp, LPX_K_MSGLEV, m);
     314  }
    299315
    300316 
Note: See TracChangeset for help on using the changeset viewer.