Changeset 1110:ba28dfbea5f2 in lemon-0.x
- Timestamp:
- 01/31/05 18:00:12 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1509
- Location:
- src/work/marci/lp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/marci/lp/lp_solver_wrapper_3.h
r1104 r1110 238 238 protected: 239 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 260 virtual void _setColBounds(int i, Bound bound, 241 261 _Value lo, _Value up) = 0; … … 258 278 /// \e 259 279 RowIt addRow() { 260 int i=_addRow(); 280 int i=_addRow(); 261 281 RowIt row_it; 262 282 row_iter_map.first(row_it, INVALID_CLASS); … … 329 349 } 330 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 367 void setColBounds(const ColIt& col_it, Bound bound, 332 368 _Value lo, _Value up) { … … 473 509 /// \e 474 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 516 /// \e 478 517 int _addRow() { 479 return lpx_add_rows(lp, 1); 518 int i=lpx_add_rows(lp, 1); 519 return i; 480 520 } 481 521 /// \e … … 527 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 687 virtual void _setColBounds(int i, Bound bound, 530 688 double lo, double up) { -
src/work/marci/lp/max_flow_expression.cc
r1104 r1110 50 50 typedef Graph::EdgeMap<ColIt> EdgeIndexMap; 51 51 EdgeIndexMap edge_index_map(g); 52 PrimalMap<Edge, EdgeIndexMap> lp_flow(lp, edge_index_map);52 PrimalMap<Edge, EdgeIndexMap> flow(lp, edge_index_map); 53 53 54 54 // capacity function … … 56 56 ColIt col_it=lp.addCol(); 57 57 edge_index_map.set(e, col_it); 58 if (cap[e]==0) 59 lp.setColBounds(col_it, LPSolver::FIXED, 0, cap[e]); 60 else 61 lp.setColBounds(col_it, LPSolver::DOUBLE, 0, cap[e]); 58 // interesting property in GLPK: 59 // if you change the order of the following two lines, the 60 // two runs of GLPK are extremely different 61 lp.setColUpperBound(col_it, cap[e]); 62 lp.setColLowerBound(col_it, 0); 62 63 } 63 64 … … 80 81 } 81 82 lp.solveSimplex(); 82 //std::cout << lp.colNum() << std::endl; 83 //std::cout << lp.rowNum() << std::endl; 84 //std::cout << "flow value: "<< lp.getObjVal() << std::endl; 85 for (Graph::EdgeIt e(g); e!=INVALID; ++e) 86 flow.set(e, lp_flow[e]); 83 cout << "elapsed time: " << ts << endl; 87 84 }
Note: See TracChangeset
for help on using the changeset viewer.