182 // class ColIt : public Col { |
191 // class ColIt : public Col { |
183 // ColIt(const Col& col) : Col(col) { } |
192 // ColIt(const Col& col) : Col(col) { } |
184 // }; |
193 // }; |
185 |
194 |
186 public: |
195 public: |
|
196 ///. |
187 LPX* lp; |
197 LPX* lp; |
|
198 ///. |
188 typedef IterablePartition<int>::ClassIt RowIt; |
199 typedef IterablePartition<int>::ClassIt RowIt; |
|
200 ///. |
189 IterablePartition<int> row_iter_map; |
201 IterablePartition<int> row_iter_map; |
|
202 ///. |
190 typedef IterablePartition<int>::ClassIt ColIt; |
203 typedef IterablePartition<int>::ClassIt ColIt; |
|
204 ///. |
191 IterablePartition<int> col_iter_map; |
205 IterablePartition<int> col_iter_map; |
192 //std::vector<int> row_id_to_lp_row_id; |
206 //std::vector<int> row_id_to_lp_row_id; |
193 //std::vector<int> col_id_to_lp_col_id; |
207 //std::vector<int> col_id_to_lp_col_id; |
|
208 ///. |
194 const int VALID_ID; |
209 const int VALID_ID; |
|
210 ///. |
195 const int INVALID_ID; |
211 const int INVALID_ID; |
196 |
212 |
197 public: |
213 public: |
|
214 ///. |
198 LPSolverWrapper() : lp(lpx_create_prob()), |
215 LPSolverWrapper() : lp(lpx_create_prob()), |
199 row_iter_map(2), |
216 row_iter_map(2), |
200 col_iter_map(2), |
217 col_iter_map(2), |
201 //row_id_to_lp_row_id(), col_id_to_lp_col_id(), |
218 //row_id_to_lp_row_id(), col_id_to_lp_col_id(), |
202 VALID_ID(0), INVALID_ID(1) { |
219 VALID_ID(0), INVALID_ID(1) { |
203 lpx_set_int_parm(lp, LPX_K_DUAL, 1); |
220 lpx_set_int_parm(lp, LPX_K_DUAL, 1); |
204 } |
221 } |
|
222 ///. |
205 ~LPSolverWrapper() { |
223 ~LPSolverWrapper() { |
206 lpx_delete_prob(lp); |
224 lpx_delete_prob(lp); |
207 } |
225 } |
|
226 ///. |
208 void setMinimize() { |
227 void setMinimize() { |
209 lpx_set_obj_dir(lp, LPX_MIN); |
228 lpx_set_obj_dir(lp, LPX_MIN); |
210 } |
229 } |
|
230 ///. |
211 void setMaximize() { |
231 void setMaximize() { |
212 lpx_set_obj_dir(lp, LPX_MAX); |
232 lpx_set_obj_dir(lp, LPX_MAX); |
213 } |
233 } |
|
234 ///. |
214 ColIt addCol() { |
235 ColIt addCol() { |
215 int i=lpx_add_cols(lp, 1); |
236 int i=lpx_add_cols(lp, 1); |
216 ColIt col_it; |
237 ColIt col_it; |
217 col_iter_map.first(col_it, INVALID_ID); |
238 col_iter_map.first(col_it, INVALID_ID); |
218 if (col_iter_map.valid(col_it)) { //van hasznalhato hely |
239 if (col_iter_map.valid(col_it)) { //van hasznalhato hely |
257 lpx_set_mat_col(lp, col_iter_map[col_it], length, indices, doubles); |
280 lpx_set_mat_col(lp, col_iter_map[col_it], length, indices, doubles); |
258 delete [] indices; |
281 delete [] indices; |
259 delete [] doubles; |
282 delete [] doubles; |
260 } |
283 } |
261 //pair<ColIt, double>-bol kell megadni egy std range-et |
284 //pair<ColIt, double>-bol kell megadni egy std range-et |
|
285 ///. |
262 template <typename Begin, typename End> |
286 template <typename Begin, typename End> |
263 void setRowCoeffs(const RowIt& row_it, |
287 void setRowCoeffs(const RowIt& row_it, |
264 Begin begin, End end) { |
288 Begin begin, End end) { |
265 int mem_length=1+lpx_get_num_cols(lp); |
289 int mem_length=1+lpx_get_num_cols(lp); |
266 int* indices = new int[mem_length]; |
290 int* indices = new int[mem_length]; |
297 for (row_iter_map.first(it, VALID_ID); |
323 for (row_iter_map.first(it, VALID_ID); |
298 row_iter_map.valid(it); row_iter_map.next(it)) { |
324 row_iter_map.valid(it); row_iter_map.next(it)) { |
299 if (row_iter_map[it]>rows[1]) --row_iter_map[it]; |
325 if (row_iter_map[it]>rows[1]) --row_iter_map[it]; |
300 } |
326 } |
301 } |
327 } |
|
328 ///. |
302 void setColBounds(const ColIt& col_it, int bound_type, |
329 void setColBounds(const ColIt& col_it, int bound_type, |
303 double lo, double up) { |
330 double lo, double up) { |
304 lpx_set_col_bnds(lp, col_iter_map[col_it], bound_type, lo, up); |
331 lpx_set_col_bnds(lp, col_iter_map[col_it], bound_type, lo, up); |
305 } |
332 } |
|
333 ///. |
306 void setObjCoef(const ColIt& col_it, double obj_coef) { |
334 void setObjCoef(const ColIt& col_it, double obj_coef) { |
307 lpx_set_obj_coef(lp, col_iter_map[col_it], obj_coef); |
335 lpx_set_obj_coef(lp, col_iter_map[col_it], obj_coef); |
308 } |
336 } |
|
337 ///. |
309 void setRowBounds(const RowIt& row_it, int bound_type, |
338 void setRowBounds(const RowIt& row_it, int bound_type, |
310 double lo, double up) { |
339 double lo, double up) { |
311 lpx_set_row_bnds(lp, row_iter_map[row_it], bound_type, lo, up); |
340 lpx_set_row_bnds(lp, row_iter_map[row_it], bound_type, lo, up); |
312 } |
341 } |
313 // void setObjCoef(const RowIt& row_it, double obj_coef) { |
342 // void setObjCoef(const RowIt& row_it, double obj_coef) { |
314 // lpx_set_obj_coef(lp, row_iter_map[row_it], obj_coef); |
343 // lpx_set_obj_coef(lp, row_iter_map[row_it], obj_coef); |
315 // } |
344 // } |
|
345 ///. |
316 void solveSimplex() { lpx_simplex(lp); } |
346 void solveSimplex() { lpx_simplex(lp); } |
|
347 ///. |
317 void solvePrimalSimplex() { lpx_simplex(lp); } |
348 void solvePrimalSimplex() { lpx_simplex(lp); } |
|
349 ///. |
318 void solveDualSimplex() { lpx_simplex(lp); } |
350 void solveDualSimplex() { lpx_simplex(lp); } |
|
351 ///. |
319 double getPrimal(const ColIt& col_it) { |
352 double getPrimal(const ColIt& col_it) { |
320 return lpx_get_col_prim(lp, col_iter_map[col_it]); |
353 return lpx_get_col_prim(lp, col_iter_map[col_it]); |
321 } |
354 } |
|
355 ///. |
322 double getObjVal() { return lpx_get_obj_val(lp); } |
356 double getObjVal() { return lpx_get_obj_val(lp); } |
|
357 ///. |
323 int rowNum() const { return lpx_get_num_rows(lp); } |
358 int rowNum() const { return lpx_get_num_rows(lp); } |
|
359 ///. |
324 int colNum() const { return lpx_get_num_cols(lp); } |
360 int colNum() const { return lpx_get_num_cols(lp); } |
|
361 ///. |
325 int warmUp() { return lpx_warm_up(lp); } |
362 int warmUp() { return lpx_warm_up(lp); } |
|
363 ///. |
326 void printWarmUpStatus(int i) { |
364 void printWarmUpStatus(int i) { |
327 switch (i) { |
365 switch (i) { |
328 case LPX_E_OK: cout << "LPX_E_OK" << endl; break; |
366 case LPX_E_OK: cout << "LPX_E_OK" << endl; break; |
329 case LPX_E_EMPTY: cout << "LPX_E_EMPTY" << endl; break; |
367 case LPX_E_EMPTY: cout << "LPX_E_EMPTY" << endl; break; |
330 case LPX_E_BADB: cout << "LPX_E_BADB" << endl; break; |
368 case LPX_E_BADB: cout << "LPX_E_BADB" << endl; break; |
331 case LPX_E_SING: cout << "LPX_E_SING" << endl; break; |
369 case LPX_E_SING: cout << "LPX_E_SING" << endl; break; |
332 } |
370 } |
333 } |
371 } |
|
372 ///. |
334 int getPrimalStatus() { return lpx_get_prim_stat(lp); } |
373 int getPrimalStatus() { return lpx_get_prim_stat(lp); } |
|
374 ///. |
335 void printPrimalStatus(int i) { |
375 void printPrimalStatus(int i) { |
336 switch (i) { |
376 switch (i) { |
337 case LPX_P_UNDEF: cout << "LPX_P_UNDEF" << endl; break; |
377 case LPX_P_UNDEF: cout << "LPX_P_UNDEF" << endl; break; |
338 case LPX_P_FEAS: cout << "LPX_P_FEAS" << endl; break; |
378 case LPX_P_FEAS: cout << "LPX_P_FEAS" << endl; break; |
339 case LPX_P_INFEAS: cout << "LPX_P_INFEAS" << endl; break; |
379 case LPX_P_INFEAS: cout << "LPX_P_INFEAS" << endl; break; |
340 case LPX_P_NOFEAS: cout << "LPX_P_NOFEAS" << endl; break; |
380 case LPX_P_NOFEAS: cout << "LPX_P_NOFEAS" << endl; break; |
341 } |
381 } |
342 } |
382 } |
|
383 ///. |
343 int getDualStatus() { return lpx_get_dual_stat(lp); } |
384 int getDualStatus() { return lpx_get_dual_stat(lp); } |
|
385 ///. |
344 void printDualStatus(int i) { |
386 void printDualStatus(int i) { |
345 switch (i) { |
387 switch (i) { |
346 case LPX_D_UNDEF: cout << "LPX_D_UNDEF" << endl; break; |
388 case LPX_D_UNDEF: cout << "LPX_D_UNDEF" << endl; break; |
347 case LPX_D_FEAS: cout << "LPX_D_FEAS" << endl; break; |
389 case LPX_D_FEAS: cout << "LPX_D_FEAS" << endl; break; |
348 case LPX_D_INFEAS: cout << "LPX_D_INFEAS" << endl; break; |
390 case LPX_D_INFEAS: cout << "LPX_D_INFEAS" << endl; break; |
364 } |
407 } |
365 /// Returns the status of the variable assigned to column \c col_it. |
408 /// Returns the status of the variable assigned to column \c col_it. |
366 int getColStat(const ColIt& col_it) { |
409 int getColStat(const ColIt& col_it) { |
367 return lpx_get_col_stat(lp, col_iter_map[col_it]); |
410 return lpx_get_col_stat(lp, col_iter_map[col_it]); |
368 } |
411 } |
|
412 ///. |
369 void printColStatus(int i) { |
413 void printColStatus(int i) { |
370 switch (i) { |
414 switch (i) { |
371 case LPX_BS: cout << "LPX_BS" << endl; break; |
415 case LPX_BS: cout << "LPX_BS" << endl; break; |
372 case LPX_NL: cout << "LPX_NL" << endl; break; |
416 case LPX_NL: cout << "LPX_NL" << endl; break; |
373 case LPX_NU: cout << "LPX_NU" << endl; break; |
417 case LPX_NU: cout << "LPX_NU" << endl; break; |
374 case LPX_NF: cout << "LPX_NF" << endl; break; |
418 case LPX_NF: cout << "LPX_NF" << endl; break; |
375 case LPX_NS: cout << "LPX_NS" << endl; break; |
419 case LPX_NS: cout << "LPX_NS" << endl; break; |
376 } |
420 } |
377 } |
421 } |
378 }; |
422 }; |
|
423 |
|
424 /// @} |
379 |
425 |
380 } //namespace hugo |
426 } //namespace hugo |
381 |
427 |
382 #endif //HUGO_LP_SOLVER_WRAPPER_H |
428 #endif //HUGO_LP_SOLVER_WRAPPER_H |