gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Fix LpBase::addRow(Constr) (#334)
0 1 0
default
1 file changed with 2 insertions and 2 deletions:
↑ Collapse diff ↑
Ignore white space 192 line context
... ...
@@ -1136,196 +1136,196 @@
1136 1136
    ///\endcode
1137 1137
    ///- an iterable lemon \ref concepts::WriteMap "write map" like
1138 1138
    ///\code
1139 1139
    ///ListGraph::NodeMap<LpBase::Row>
1140 1140
    ///ListGraph::ArcMap<LpBase::Row>
1141 1141
    ///\endcode
1142 1142
    ///\return The number of rows created.
1143 1143
#ifdef DOXYGEN
1144 1144
    template<class T>
1145 1145
    int addRowSet(T &t) { return 0;}
1146 1146
#else
1147 1147
    template<class T>
1148 1148
    typename enable_if<typename T::value_type::LpRow,int>::type
1149 1149
    addRowSet(T &t, dummy<0> = 0) {
1150 1150
      int s=0;
1151 1151
      for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addRow();s++;}
1152 1152
      return s;
1153 1153
    }
1154 1154
    template<class T>
1155 1155
    typename enable_if<typename T::value_type::second_type::LpRow, int>::type
1156 1156
    addRowSet(T &t, dummy<1> = 1) {
1157 1157
      int s=0;
1158 1158
      for(typename T::iterator i=t.begin();i!=t.end();++i) {
1159 1159
        i->second=addRow();
1160 1160
        s++;
1161 1161
      }
1162 1162
      return s;
1163 1163
    }
1164 1164
    template<class T>
1165 1165
    typename enable_if<typename T::MapIt::Value::LpRow, int>::type
1166 1166
    addRowSet(T &t, dummy<2> = 2) {
1167 1167
      int s=0;
1168 1168
      for(typename T::MapIt i(t); i!=INVALID; ++i)
1169 1169
        {
1170 1170
          i.set(addRow());
1171 1171
          s++;
1172 1172
        }
1173 1173
      return s;
1174 1174
    }
1175 1175
#endif
1176 1176

	
1177 1177
    ///Set a row (i.e a constraint) of the LP
1178 1178

	
1179 1179
    ///\param r is the row to be modified
1180 1180
    ///\param l is lower bound (-\ref INF means no bound)
1181 1181
    ///\param e is a linear expression (see \ref Expr)
1182 1182
    ///\param u is the upper bound (\ref INF means no bound)
1183 1183
    void row(Row r, Value l, const Expr &e, Value u) {
1184 1184
      e.simplify();
1185 1185
      _setRowCoeffs(rows(id(r)), ExprIterator(e.comps.begin(), cols),
1186 1186
                    ExprIterator(e.comps.end(), cols));
1187 1187
      _setRowLowerBound(rows(id(r)),l - *e);
1188 1188
      _setRowUpperBound(rows(id(r)),u - *e);
1189 1189
    }
1190 1190

	
1191 1191
    ///Set a row (i.e a constraint) of the LP
1192 1192

	
1193 1193
    ///\param r is the row to be modified
1194 1194
    ///\param c is a linear expression (see \ref Constr)
1195 1195
    void row(Row r, const Constr &c) {
1196 1196
      row(r, c.lowerBounded()?c.lowerBound():-INF,
1197 1197
          c.expr(), c.upperBounded()?c.upperBound():INF);
1198 1198
    }
1199 1199

	
1200 1200

	
1201 1201
    ///Get a row (i.e a constraint) of the LP
1202 1202

	
1203 1203
    ///\param r is the row to get
1204 1204
    ///\return the expression associated to the row
1205 1205
    Expr row(Row r) const {
1206 1206
      Expr e;
1207 1207
      _getRowCoeffs(rows(id(r)), InsertIterator(e.comps, cols));
1208 1208
      return e;
1209 1209
    }
1210 1210

	
1211 1211
    ///Add a new row (i.e a new constraint) to the LP
1212 1212

	
1213 1213
    ///\param l is the lower bound (-\ref INF means no bound)
1214 1214
    ///\param e is a linear expression (see \ref Expr)
1215 1215
    ///\param u is the upper bound (\ref INF means no bound)
1216 1216
    ///\return The created row.
1217 1217
    Row addRow(Value l,const Expr &e, Value u) {
1218 1218
      Row r;
1219 1219
      e.simplify();
1220 1220
      r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), cols),
1221 1221
                                ExprIterator(e.comps.end(), cols), u - *e));
1222 1222
      return r;
1223 1223
    }
1224 1224

	
1225 1225
    ///Add a new row (i.e a new constraint) to the LP
1226 1226

	
1227 1227
    ///\param c is a linear expression (see \ref Constr)
1228 1228
    ///\return The created row.
1229 1229
    Row addRow(const Constr &c) {
1230 1230
      Row r;
1231 1231
      c.expr().simplify();
1232
      r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound():-INF, 
1232
      r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound()-*c.expr():-INF, 
1233 1233
                                ExprIterator(c.expr().comps.begin(), cols),
1234 1234
                                ExprIterator(c.expr().comps.end(), cols),
1235
                                c.upperBounded()?c.upperBound():INF));
1235
                                c.upperBounded()?c.upperBound()-*c.expr():INF));
1236 1236
      return r;
1237 1237
    }
1238 1238
    ///Erase a column (i.e a variable) from the LP
1239 1239

	
1240 1240
    ///\param c is the column to be deleted
1241 1241
    void erase(Col c) {
1242 1242
      _eraseCol(cols(id(c)));
1243 1243
      _eraseColId(cols(id(c)));
1244 1244
    }
1245 1245
    ///Erase a row (i.e a constraint) from the LP
1246 1246

	
1247 1247
    ///\param r is the row to be deleted
1248 1248
    void erase(Row r) {
1249 1249
      _eraseRow(rows(id(r)));
1250 1250
      _eraseRowId(rows(id(r)));
1251 1251
    }
1252 1252

	
1253 1253
    /// Get the name of a column
1254 1254

	
1255 1255
    ///\param c is the coresponding column
1256 1256
    ///\return The name of the colunm
1257 1257
    std::string colName(Col c) const {
1258 1258
      std::string name;
1259 1259
      _getColName(cols(id(c)), name);
1260 1260
      return name;
1261 1261
    }
1262 1262

	
1263 1263
    /// Set the name of a column
1264 1264

	
1265 1265
    ///\param c is the coresponding column
1266 1266
    ///\param name The name to be given
1267 1267
    void colName(Col c, const std::string& name) {
1268 1268
      _setColName(cols(id(c)), name);
1269 1269
    }
1270 1270

	
1271 1271
    /// Get the column by its name
1272 1272

	
1273 1273
    ///\param name The name of the column
1274 1274
    ///\return the proper column or \c INVALID
1275 1275
    Col colByName(const std::string& name) const {
1276 1276
      int k = _colByName(name);
1277 1277
      return k != -1 ? Col(cols[k]) : Col(INVALID);
1278 1278
    }
1279 1279

	
1280 1280
    /// Get the name of a row
1281 1281

	
1282 1282
    ///\param r is the coresponding row
1283 1283
    ///\return The name of the row
1284 1284
    std::string rowName(Row r) const {
1285 1285
      std::string name;
1286 1286
      _getRowName(rows(id(r)), name);
1287 1287
      return name;
1288 1288
    }
1289 1289

	
1290 1290
    /// Set the name of a row
1291 1291

	
1292 1292
    ///\param r is the coresponding row
1293 1293
    ///\param name The name to be given
1294 1294
    void rowName(Row r, const std::string& name) {
1295 1295
      _setRowName(rows(id(r)), name);
1296 1296
    }
1297 1297

	
1298 1298
    /// Get the row by its name
1299 1299

	
1300 1300
    ///\param name The name of the row
1301 1301
    ///\return the proper row or \c INVALID
1302 1302
    Row rowByName(const std::string& name) const {
1303 1303
      int k = _rowByName(name);
1304 1304
      return k != -1 ? Row(rows[k]) : Row(INVALID);
1305 1305
    }
1306 1306

	
1307 1307
    /// Set an element of the coefficient matrix of the LP
1308 1308

	
1309 1309
    ///\param r is the row of the element to be modified
1310 1310
    ///\param c is the column of the element to be modified
1311 1311
    ///\param val is the new value of the coefficient
1312 1312
    void coeff(Row r, Col c, Value val) {
1313 1313
      _setCoeff(rows(id(r)),cols(id(c)), val);
1314 1314
    }
1315 1315

	
1316 1316
    /// Get an element of the coefficient matrix of the LP
1317 1317

	
1318 1318
    ///\param r is the row of the element
1319 1319
    ///\param c is the column of the element
1320 1320
    ///\return the corresponding coefficient
1321 1321
    Value coeff(Row r, Col c) const {
1322 1322
      return _getCoeff(rows(id(r)),cols(id(c)));
1323 1323
    }
1324 1324

	
1325 1325
    /// Set the lower bound of a column (i.e a variable)
1326 1326

	
1327 1327
    /// The lower bound of a variable (column) has to be given by an
1328 1328
    /// extended number of type Value, i.e. a finite number of type
1329 1329
    /// Value or -\ref INF.
1330 1330
    void colLowerBound(Col c, Value value) {
1331 1331
      _setColLowerBound(cols(id(c)),value);
0 comments (0 inline)