Changeset 1273:2b2ffa625775 in lemon0.x for src/work/athos/lp/lp_base.h
 Timestamp:
 03/30/05 12:38:22 (16 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1703
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/work/athos/lp/lp_base.h
r1272 r1273 21 21 #include<map> 22 22 #include<limits> 23 #include<math.h> 23 24 24 25 #include<lemon/utility.h> … … 73 74 return cross[n]; 74 75 } 76 ///\todo Create an own exception type. 75 77 else throw LogicError(); //floatingIds must form a continuous range; 76 78 } … … 127 129 /// 128 130 ///Its value remains valid and correct even after the addition or erase of 129 ///new column (unless the referred column itself was also deleted, 130 ///of course). 131 ///other columns. 131 132 /// 132 133 ///\todo Document what can one do with a Col (INVALID, comparing, … … 151 152 /// 152 153 ///Its value remains valid and correct even after the addition or erase of 153 /// new rows (unless the referred row itself was also deleted, of course).154 ///other rows. 154 155 /// 155 156 ///\todo Document what can one do with a Row (INVALID, comparing, … … 172 173 ///Linear expression 173 174 // typedef SparseLinExpr<Col> Expr; 174 class Expr : public std::map<Col, Col::ExprValue>175 class Expr : public std::map<Col,Value> 175 176 { 176 177 public: 177 typedef Col Var;178 typedef Col::ExprValue Coeff;178 typedef LpSolverBase::Col Key; 179 typedef LpSolverBase::Value Value; 179 180 180 181 protected: 181 typedef std::map<Col, Col::ExprValue> Base;182 typedef std::map<Col,Value> Base; 182 183 183 Coeffconst_comp;184 Value const_comp; 184 185 public: 185 186 typedef True IsLinExpression; … … 187 188 Expr() : Base(), const_comp(0) { } 188 189 ///\e 189 Expr(const Var&v) : const_comp(0) {190 Expr(const Key &v) : const_comp(0) { 190 191 Base::insert(std::make_pair(v, 1)); 191 192 } 192 193 ///\e 193 Expr(const Coeff&v) : const_comp(v) {}194 ///\e 195 void set(const Var &v,const Coeff&c) {194 Expr(const Value &v) : const_comp(v) {} 195 ///\e 196 void set(const Key &v,const Value &c) { 196 197 Base::insert(std::make_pair(v, c)); 197 198 } 198 199 ///\e 199 Coeff&constComp() { return const_comp; }200 ///\e 201 const Coeff&constComp() const { return const_comp; }200 Value &constComp() { return const_comp; } 201 ///\e 202 const Value &constComp() const { return const_comp; } 202 203 203 204 ///Removes the components with zero coefficient. … … 210 211 } 211 212 } 212 213 214 ///Sets all coefficients and the constant component to 0. 215 void clear() { 216 Base::clear(); 217 const_comp=0; 218 } 219 213 220 ///\e 214 221 Expr &operator+=(const Expr &e) { … … 227 234 } 228 235 ///\e 229 Expr &operator*=(const Coeff&c) {236 Expr &operator*=(const Value &c) { 230 237 for (Base::iterator j=Base::begin(); j!=Base::end(); ++j) 231 238 j>second*=c; … … 234 241 } 235 242 ///\e 236 Expr &operator/=(const Coeff&c) {243 Expr &operator/=(const Value &c) { 237 244 for (Base::iterator j=Base::begin(); j!=Base::end(); ++j) 238 245 j>second/=c; … … 248 255 public: 249 256 typedef LpSolverBase::Expr Expr; 250 typedef Expr:: Var Var;251 typedef Expr:: Coeff Coeff;257 typedef Expr::Key Key; 258 typedef Expr::Value Value; 252 259 253 static const CoeffINF;254 static const CoeffNaN;255 // static const CoeffINF=0;256 // static const CoeffNaN=1;260 static const Value INF; 261 static const Value NaN; 262 // static const Value INF=0; 263 // static const Value NaN=1; 257 264 258 Expr expr; 259 Coeff lb,ub; 260 261 Constr() : expr(), lb(NaN), ub(NaN) {} 262 Constr(Coeff _lb,const Expr &e,Coeff _ub) : 263 expr(e), lb(_lb), ub(_ub) {} 264 Constr(const Expr &e,Coeff _ub) : 265 expr(e), lb(NaN), ub(_ub) {} 266 Constr(Coeff _lb,const Expr &e) : 267 expr(e), lb(_lb), ub(NaN) {} 265 protected: 266 Expr _expr; 267 Value _lb,_ub; 268 public: 269 ///\e 270 Constr() : _expr(), _lb(NaN), _ub(NaN) {} 271 ///\e 272 Constr(Value lb,const Expr &e,Value ub) : 273 _expr(e), _lb(lb), _ub(ub) {} 274 ///\e 275 Constr(const Expr &e,Value ub) : 276 _expr(e), _lb(NaN), _ub(ub) {} 277 ///\e 278 Constr(Value lb,const Expr &e) : 279 _expr(e), _lb(lb), _ub(NaN) {} 280 ///\e 268 281 Constr(const Expr &e) : 269 expr(e), lb(NaN), ub(NaN) {} 282 _expr(e), _lb(NaN), _ub(NaN) {} 283 ///\e 284 void clear() 285 { 286 _expr.clear(); 287 _lb=_ub=NaN; 288 } 289 ///\e 290 Expr &expr() { return _expr; } 291 ///\e 292 const Expr &expr() const { return _expr; } 293 ///\e 294 Value &lowerBound() { return _lb; } 295 ///\e 296 const Value &lowerBound() const { return _lb; } 297 ///\e 298 Value &upperBound() { return _ub; } 299 ///\e 300 const Value &upperBound() const { return _ub; } 270 301 }; 271 302 … … 355 386 ///(i.e a new variables) 356 387 /// 357 ///This magic function takes container as its argument388 ///This magic function takes a container as its argument 358 389 ///and fills its elements 359 390 ///with new columns (i.e. variables) 360 ///\param t can be either any standard STL iterable container with 361 ///\ref Col \c values_type or \c mapped_type 362 ///like <tt>std::vector<LpSolverBase::Col></tt>, 363 /// <tt>std::list<LpSolverBase::Col></tt> or 364 /// <tt>std::map<AnyType,LpSolverBase::Col></tt> or 365 ///it can be an iterable lemon map like 366 /// <tt>ListGraph::NodeMap<LpSolverBase::Col></tt>. 391 ///\param t can be 392 /// a standard STL compatible iterable container with 393 ///\ref Col as its \c values_type 394 ///like 395 ///\code 396 ///std::vector<LpSolverBase::Col> 397 ///std::list<LpSolverBase::Col> 398 ///\endcode 399 /// a standard STL compatible iterable container with 400 ///\ref Col as its \c mapped_type 401 ///like 402 ///\code 403 ///std::map<AnyType,LpSolverBase::Col> 404 ///\endcode 405 /// an iterable lemon \ref concept::WriteMap "write map" like 406 ///\code 407 ///ListGraph::NodeMap<LpSolverBase::Col> 408 ///ListGraph::EdgeMap<LpSolverBase::Col> 409 ///\endcode 367 410 ///\return The number of the created column. 368 411 ///\bug Iterable nodemap hasn't been implemented yet. … … 441 484 ///\param c is a linear expression (see \ref Constr) 442 485 void setRow(Row r, const Constr &c) { 443 Value lb= c.lb==NaN?INF:lb; 444 Value ub= c.ub==NaN?INF:lb; 445 setRow(r,lb,c.expr,ub); 486 setRow(r, 487 isnan(c.lowerBound())?INF:c.lowerBound(), 488 c.expr(), 489 isnan(c.upperBound())?INF:c.upperBound()); 446 490 } 447 491 … … 564 608 /// 565 609 inline LpSolverBase::Expr operator*(const LpSolverBase::Expr &a, 566 const LpSolverBase:: Expr::Coeff&b)610 const LpSolverBase::Value &b) 567 611 { 568 612 LpSolverBase::Expr tmp(a); … … 575 619 ///\relates LpSolverBase::Expr 576 620 /// 577 inline LpSolverBase::Expr operator*(const LpSolverBase:: Expr::Coeff&a,621 inline LpSolverBase::Expr operator*(const LpSolverBase::Value &a, 578 622 const LpSolverBase::Expr &b) 579 623 { … … 587 631 /// 588 632 inline LpSolverBase::Expr operator/(const LpSolverBase::Expr &a, 589 const LpSolverBase:: Expr::Coeff&b)633 const LpSolverBase::Value &b) 590 634 { 591 635 LpSolverBase::Expr tmp(a); … … 608 652 ///\relates LpSolverBase::Constr 609 653 /// 610 inline LpSolverBase::Constr operator<=(const LpSolverBase:: Expr::Coeff&e,654 inline LpSolverBase::Constr operator<=(const LpSolverBase::Value &e, 611 655 const LpSolverBase::Expr &f) 612 656 { … … 619 663 /// 620 664 inline LpSolverBase::Constr operator<=(const LpSolverBase::Expr &e, 621 const LpSolverBase:: Expr::Coeff&f)665 const LpSolverBase::Value &f) 622 666 { 623 667 return LpSolverBase::Constr(e,f); … … 639 683 ///\relates LpSolverBase::Constr 640 684 /// 641 inline LpSolverBase::Constr operator>=(const LpSolverBase:: Expr::Coeff&e,685 inline LpSolverBase::Constr operator>=(const LpSolverBase::Value &e, 642 686 const LpSolverBase::Expr &f) 643 687 { … … 651 695 /// 652 696 inline LpSolverBase::Constr operator>=(const LpSolverBase::Expr &e, 653 const LpSolverBase:: Expr::Coeff&f)697 const LpSolverBase::Value &f) 654 698 { 655 699 return LpSolverBase::Constr(f,e); … … 670 714 ///\relates LpSolverBase::Constr 671 715 /// 672 inline LpSolverBase::Constr operator<=(const LpSolverBase:: Constr::Coeff&n,716 inline LpSolverBase::Constr operator<=(const LpSolverBase::Value &n, 673 717 const LpSolverBase::Constr&c) 674 718 { 675 719 LpSolverBase::Constr tmp(c); 676 if(tmp.lb!=tmp.NaN) throw LogicError(); 677 else tmp.lb=n; 720 ///\todo Create an own exception type. 721 if(!isnan(tmp.lowerBound())) throw LogicError(); 722 else tmp.lowerBound()=n; 678 723 return tmp; 679 724 } … … 683 728 /// 684 729 inline LpSolverBase::Constr operator<=(const LpSolverBase::Constr& c, 685 const LpSolverBase:: Constr::Coeff&n)730 const LpSolverBase::Value &n) 686 731 { 687 732 LpSolverBase::Constr tmp(c); 688 if(tmp.ub!=tmp.NaN) throw LogicError(); 689 else tmp.ub=n; 690 return tmp; 691 } 692 693 ///\e 694 695 ///\relates LpSolverBase::Constr 696 /// 697 inline LpSolverBase::Constr operator>=(const LpSolverBase::Constr::Coeff &n, 733 ///\todo Create an own exception type. 734 if(!isnan(tmp.upperBound())) throw LogicError(); 735 else tmp.upperBound()=n; 736 return tmp; 737 } 738 739 ///\e 740 741 ///\relates LpSolverBase::Constr 742 /// 743 inline LpSolverBase::Constr operator>=(const LpSolverBase::Value &n, 698 744 const LpSolverBase::Constr&c) 699 745 { 700 746 LpSolverBase::Constr tmp(c); 701 if(tmp.ub!=tmp.NaN) throw LogicError(); 702 else tmp.ub=n; 747 ///\todo Create an own exception type. 748 if(!isnan(tmp.upperBound())) throw LogicError(); 749 else tmp.upperBound()=n; 703 750 return tmp; 704 751 } … … 708 755 /// 709 756 inline LpSolverBase::Constr operator>=(const LpSolverBase::Constr& c, 710 const LpSolverBase:: Constr::Coeff&n)757 const LpSolverBase::Value &n) 711 758 { 712 759 LpSolverBase::Constr tmp(c); 713 if(tmp.lb!=tmp.NaN) throw LogicError(); 714 else tmp.lb=n; 760 ///\todo Create an own exception type. 761 if(!isnan(tmp.lowerBound())) throw LogicError(); 762 else tmp.lowerBound()=n; 715 763 return tmp; 716 764 }
Note: See TracChangeset
for help on using the changeset viewer.