235 public: |
235 public: |
236 /// \e |
236 /// \e |
237 enum Bound { FREE, LOWER, UPPER, DOUBLE, FIXED }; |
237 enum Bound { FREE, LOWER, UPPER, DOUBLE, FIXED }; |
238 protected: |
238 protected: |
239 /// \e |
239 /// \e |
|
240 /// The lower bound of a variable (column) have to be given by an |
|
241 /// extended number of type _Value, i.e. a finite number of type |
|
242 /// _Value or -INF. |
|
243 virtual void _setColLowerBound(int i, _Value value) = 0; |
|
244 /// \e |
|
245 /// The upper bound of a variable (column) have to be given by an |
|
246 /// extended number of type _Value, i.e. a finite number of type |
|
247 /// _Value or INF. |
|
248 virtual void _setColUpperBound(int i, _Value value) = 0; |
|
249 /// \e |
|
250 /// The lower bound of a variable (column) is an |
|
251 /// extended number of type _Value, i.e. a finite number of type |
|
252 /// _Value or -INF. |
|
253 virtual _Value _getColLowerBound(int i) = 0; |
|
254 /// \e |
|
255 /// The upper bound of a variable (column) is an |
|
256 /// extended number of type _Value, i.e. a finite number of type |
|
257 /// _Value or INF. |
|
258 virtual _Value _getColUpperBound(int i) = 0; |
|
259 /// \e |
240 virtual void _setColBounds(int i, Bound bound, |
260 virtual void _setColBounds(int i, Bound bound, |
241 _Value lo, _Value up) = 0; |
261 _Value lo, _Value up) = 0; |
242 /// \e |
262 /// \e |
243 virtual void _setRowBounds(int i, Bound bound, |
263 virtual void _setRowBounds(int i, Bound bound, |
244 _Value lo, _Value up) = 0; |
264 _Value lo, _Value up) = 0; |
255 //HIGH LEVEL INTERFACE, MATRIX MANIPULATING FUNTIONS |
275 //HIGH LEVEL INTERFACE, MATRIX MANIPULATING FUNTIONS |
256 |
276 |
257 public: |
277 public: |
258 /// \e |
278 /// \e |
259 RowIt addRow() { |
279 RowIt addRow() { |
260 int i=_addRow(); |
280 int i=_addRow(); |
261 RowIt row_it; |
281 RowIt row_it; |
262 row_iter_map.first(row_it, INVALID_CLASS); |
282 row_iter_map.first(row_it, INVALID_CLASS); |
263 if (row_iter_map.valid(row_it)) { //van hasznalhato hely |
283 if (row_iter_map.valid(row_it)) { //van hasznalhato hely |
264 row_iter_map.set(row_it, INVALID_CLASS, VALID_CLASS); |
284 row_iter_map.set(row_it, INVALID_CLASS, VALID_CLASS); |
265 row_iter_map[row_it]=i; |
285 row_iter_map[row_it]=i; |
326 row_iter_map.valid(it); row_iter_map.next(it)) { |
346 row_iter_map.valid(it); row_iter_map.next(it)) { |
327 if (row_iter_map[it]>rows[1]) --row_iter_map[it]; |
347 if (row_iter_map[it]>rows[1]) --row_iter_map[it]; |
328 } |
348 } |
329 } |
349 } |
330 /// \e |
350 /// \e |
|
351 void setColLowerBound(ColIt col_it, _Value lo) { |
|
352 _setColLowerBound(col_iter_map[col_it], lo); |
|
353 } |
|
354 /// \e |
|
355 void setColUpperBound(ColIt col_it, _Value up) { |
|
356 _setColUpperBound(col_iter_map[col_it], up); |
|
357 } |
|
358 /// \e |
|
359 _Value getColLowerBound(ColIt col_it) { |
|
360 return _getColLowerBound(col_iter_map[col_it]); |
|
361 } |
|
362 /// \e |
|
363 _Value getColUpperBound(ColIt col_it) { |
|
364 return _getColUpperBound(col_iter_map[col_it]); |
|
365 } |
|
366 /// \e |
331 void setColBounds(const ColIt& col_it, Bound bound, |
367 void setColBounds(const ColIt& col_it, Bound bound, |
332 _Value lo, _Value up) { |
368 _Value lo, _Value up) { |
333 _setColBounds(col_iter_map[col_it], bound, lo, up); |
369 _setColBounds(col_iter_map[col_it], bound, lo, up); |
334 } |
370 } |
335 /// \e |
371 /// \e |
470 //LOW LEVEL INTERFACE, MATRIX MANIPULATING FUNCTIONS |
506 //LOW LEVEL INTERFACE, MATRIX MANIPULATING FUNCTIONS |
471 |
507 |
472 protected: |
508 protected: |
473 /// \e |
509 /// \e |
474 int _addCol() { |
510 int _addCol() { |
475 return lpx_add_cols(lp, 1); |
511 int i=lpx_add_cols(lp, 1); |
|
512 _setColLowerBound(i, -INF); |
|
513 _setColUpperBound(i, INF); |
|
514 return i; |
476 } |
515 } |
477 /// \e |
516 /// \e |
478 int _addRow() { |
517 int _addRow() { |
479 return lpx_add_rows(lp, 1); |
518 int i=lpx_add_rows(lp, 1); |
|
519 return i; |
480 } |
520 } |
481 /// \e |
521 /// \e |
482 virtual void _setRowCoeffs(int i, |
522 virtual void _setRowCoeffs(int i, |
483 const std::vector<std::pair<int, double> >& coeffs) { |
523 const std::vector<std::pair<int, double> >& coeffs) { |
484 int mem_length=1+colNum(); |
524 int mem_length=1+colNum(); |
524 virtual void _eraseRow(int i) { |
564 virtual void _eraseRow(int i) { |
525 int rows[2]; |
565 int rows[2]; |
526 rows[1]=i; |
566 rows[1]=i; |
527 lpx_del_rows(lp, 1, rows); |
567 lpx_del_rows(lp, 1, rows); |
528 } |
568 } |
|
569 virtual void _setColLowerBound(int i, double lo) { |
|
570 if (lo==INF) { |
|
571 //FIXME error |
|
572 } |
|
573 int b=lpx_get_col_type(lp, i); |
|
574 double up=lpx_get_col_ub(lp, i); |
|
575 if (lo==-INF) { |
|
576 switch (b) { |
|
577 case LPX_FR: |
|
578 case LPX_LO: |
|
579 lpx_set_col_bnds(lp, i, LPX_FR, lo, up); |
|
580 break; |
|
581 case LPX_UP: |
|
582 break; |
|
583 case LPX_DB: |
|
584 case LPX_FX: |
|
585 lpx_set_col_bnds(lp, i, LPX_UP, lo, up); |
|
586 break; |
|
587 default: ; |
|
588 //FIXME error |
|
589 } |
|
590 } else { |
|
591 switch (b) { |
|
592 case LPX_FR: |
|
593 case LPX_LO: |
|
594 lpx_set_col_bnds(lp, i, LPX_LO, lo, up); |
|
595 break; |
|
596 case LPX_UP: |
|
597 case LPX_DB: |
|
598 case LPX_FX: |
|
599 if (lo==up) |
|
600 lpx_set_col_bnds(lp, i, LPX_FX, lo, up); |
|
601 else |
|
602 lpx_set_col_bnds(lp, i, LPX_DB, lo, up); |
|
603 break; |
|
604 default: ; |
|
605 //FIXME error |
|
606 } |
|
607 } |
|
608 } |
|
609 virtual void _setColUpperBound(int i, double up) { |
|
610 if (up==-INF) { |
|
611 //FIXME error |
|
612 } |
|
613 int b=lpx_get_col_type(lp, i); |
|
614 double lo=lpx_get_col_lb(lp, i); |
|
615 if (up==INF) { |
|
616 switch (b) { |
|
617 case LPX_FR: |
|
618 case LPX_LO: |
|
619 break; |
|
620 case LPX_UP: |
|
621 lpx_set_col_bnds(lp, i, LPX_FR, lo, up); |
|
622 break; |
|
623 case LPX_DB: |
|
624 case LPX_FX: |
|
625 lpx_set_col_bnds(lp, i, LPX_LO, lo, up); |
|
626 break; |
|
627 default: ; |
|
628 //FIXME error |
|
629 } |
|
630 } else { |
|
631 switch (b) { |
|
632 case LPX_FR: |
|
633 lpx_set_col_bnds(lp, i, LPX_UP, lo, up); |
|
634 case LPX_LO: |
|
635 if (lo==up) |
|
636 lpx_set_col_bnds(lp, i, LPX_FX, lo, up); |
|
637 else |
|
638 lpx_set_col_bnds(lp, i, LPX_DB, lo, up); |
|
639 break; |
|
640 case LPX_UP: |
|
641 lpx_set_col_bnds(lp, i, LPX_UP, lo, up); |
|
642 break; |
|
643 case LPX_DB: |
|
644 case LPX_FX: |
|
645 if (lo==up) |
|
646 lpx_set_col_bnds(lp, i, LPX_FX, lo, up); |
|
647 else |
|
648 lpx_set_col_bnds(lp, i, LPX_DB, lo, up); |
|
649 break; |
|
650 default: ; |
|
651 //FIXME error |
|
652 } |
|
653 } |
|
654 } |
|
655 virtual double _getColLowerBound(int i) { |
|
656 int b=lpx_get_col_type(lp, i); |
|
657 switch (b) { |
|
658 case LPX_FR: |
|
659 return -INF; |
|
660 case LPX_LO: |
|
661 return lpx_get_col_lb(lp, i); |
|
662 case LPX_UP: |
|
663 return -INF; |
|
664 case LPX_DB: |
|
665 case LPX_FX: |
|
666 return lpx_get_col_lb(lp, i); |
|
667 default: ; |
|
668 //FIXME error |
|
669 return 0.0; |
|
670 } |
|
671 } |
|
672 virtual double _getColUpperBound(int i) { |
|
673 int b=lpx_get_col_type(lp, i); |
|
674 switch (b) { |
|
675 case LPX_FR: |
|
676 case LPX_LO: |
|
677 return INF; |
|
678 case LPX_UP: |
|
679 case LPX_DB: |
|
680 case LPX_FX: |
|
681 return lpx_get_col_ub(lp, i); |
|
682 default: ; |
|
683 //FIXME error |
|
684 return 0.0; |
|
685 } |
|
686 } |
529 virtual void _setColBounds(int i, Bound bound, |
687 virtual void _setColBounds(int i, Bound bound, |
530 double lo, double up) { |
688 double lo, double up) { |
531 switch (bound) { |
689 switch (bound) { |
532 case FREE: |
690 case FREE: |
533 lpx_set_col_bnds(lp, i, LPX_FR, lo, up); |
691 lpx_set_col_bnds(lp, i, LPX_FR, lo, up); |