# HG changeset patch
# User tapolcai@opti.tmit.bme.hu
# Date 1232384495 -3600
# Node ID a7b59195961a46c22b4caf361fd36cde482c0e6a
# Parent c46afb3f67a660bc039746a688210033927b1f5a
faster lb _addRow function
diff --git a/lemon/lp_base.h b/lemon/lp_base.h
a
|
b
|
namespace lemon { |
597 | 597 | const Value &upperBound() const { return _ub; } |
598 | 598 | ///Is the constraint lower bounded? |
599 | 599 | bool lowerBounded() const { |
600 | | return _lb != -INF && !isnan(_lb); |
| 600 | return _lb != -INF && !std::isnan(_lb); |
601 | 601 | } |
602 | 602 | ///Is the constraint upper bounded? |
603 | 603 | bool upperBounded() const { |
604 | | return _ub != INF && !isnan(_ub); |
| 604 | return _ub != INF && !std::isnan(_ub); |
605 | 605 | } |
606 | 606 | |
607 | 607 | }; |
… |
… |
namespace lemon { |
941 | 941 | virtual void _setRowName(int row, const std::string& name) = 0; |
942 | 942 | virtual int _rowByName(const std::string& name) const = 0; |
943 | 943 | |
| 944 | virtual int _addRow(ExprIterator b, ExprIterator e){ |
| 945 | int i=_addRow();_setRowCoeffs(i, b, e); return i; |
| 946 | }; |
944 | 947 | virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e) = 0; |
945 | 948 | virtual void _getRowCoeffs(int i, InsertIterator b) const = 0; |
946 | 949 | |
… |
… |
namespace lemon { |
1067 | 1070 | ///a better one. |
1068 | 1071 | void col(Col c, const DualExpr &e) { |
1069 | 1072 | e.simplify(); |
1070 | | _setColCoeffs(cols(id(c)), ExprIterator(e.comps.begin(), rows), |
1071 | | ExprIterator(e.comps.end(), rows)); |
| 1073 | _setColCoeffs(cols(id(c)), ExprIterator(e.comps.begin(), cols), |
| 1074 | ExprIterator(e.comps.end(), cols)); |
1072 | 1075 | } |
1073 | 1076 | |
1074 | 1077 | ///Get a column (i.e a dual constraint) of the LP |
… |
… |
namespace lemon { |
1197 | 1200 | ///\param u is the upper bound (\ref INF means no bound) |
1198 | 1201 | ///\return The created row. |
1199 | 1202 | Row addRow(Value l,const Expr &e, Value u) { |
1200 | | Row r=addRow(); |
1201 | | row(r,l,e,u); |
| 1203 | Row r; |
| 1204 | e.simplify(); |
| 1205 | int id=_addRow(ExprIterator(e.comps.begin(), cols), |
| 1206 | ExprIterator(e.comps.end(), cols)); |
| 1207 | _setRowLowerBound(id,l - *e); |
| 1208 | _setRowUpperBound(id,u - *e); |
| 1209 | r._id=id; |
1202 | 1210 | return r; |
1203 | 1211 | } |
1204 | 1212 | |
… |
… |
namespace lemon { |
1207 | 1215 | ///\param c is a linear expression (see \ref Constr) |
1208 | 1216 | ///\return The created row. |
1209 | 1217 | Row addRow(const Constr &c) { |
1210 | | Row r=addRow(); |
1211 | | row(r,c); |
| 1218 | Row r=addRow(c.lowerBounded()?c.lowerBound():-INF, |
| 1219 | c.expr(), c.upperBounded()?c.upperBound():INF); |
1212 | 1220 | return r; |
1213 | 1221 | } |
1214 | 1222 | ///Erase a column (i.e a variable) from the LP |
… |
… |
namespace lemon { |
1666 | 1674 | inline LpBase::Constr operator<=(const LpBase::Value &n, |
1667 | 1675 | const LpBase::Constr &c) { |
1668 | 1676 | LpBase::Constr tmp(c); |
1669 | | LEMON_ASSERT(isnan(tmp.lowerBound()), "Wrong LP constraint"); |
| 1677 | LEMON_ASSERT(std::isnan(tmp.lowerBound()), "Wrong LP constraint"); |
1670 | 1678 | tmp.lowerBound()=n; |
1671 | 1679 | return tmp; |
1672 | 1680 | } |
… |
… |
namespace lemon { |
1678 | 1686 | const LpBase::Value &n) |
1679 | 1687 | { |
1680 | 1688 | LpBase::Constr tmp(c); |
1681 | | LEMON_ASSERT(isnan(tmp.upperBound()), "Wrong LP constraint"); |
| 1689 | LEMON_ASSERT(std::isnan(tmp.upperBound()), "Wrong LP constraint"); |
1682 | 1690 | tmp.upperBound()=n; |
1683 | 1691 | return tmp; |
1684 | 1692 | } |
… |
… |
namespace lemon { |
1690 | 1698 | inline LpBase::Constr operator>=(const LpBase::Value &n, |
1691 | 1699 | const LpBase::Constr &c) { |
1692 | 1700 | LpBase::Constr tmp(c); |
1693 | | LEMON_ASSERT(isnan(tmp.upperBound()), "Wrong LP constraint"); |
| 1701 | LEMON_ASSERT(std::isnan(tmp.upperBound()), "Wrong LP constraint"); |
1694 | 1702 | tmp.upperBound()=n; |
1695 | 1703 | return tmp; |
1696 | 1704 | } |
… |
… |
namespace lemon { |
1702 | 1710 | const LpBase::Value &n) |
1703 | 1711 | { |
1704 | 1712 | LpBase::Constr tmp(c); |
1705 | | LEMON_ASSERT(isnan(tmp.lowerBound()), "Wrong LP constraint"); |
| 1713 | LEMON_ASSERT(std::isnan(tmp.lowerBound()), "Wrong LP constraint"); |
1706 | 1714 | tmp.lowerBound()=n; |
1707 | 1715 | return tmp; |
1708 | 1716 | } |
diff --git a/lemon/lp_skeleton.cc b/lemon/lp_skeleton.cc
a
|
b
|
namespace lemon { |
43 | 43 | void SkeletonSolverBase::_setRowName(int, const std::string &) {} |
44 | 44 | int SkeletonSolverBase::_rowByName(const std::string&) const { return -1; } |
45 | 45 | |
| 46 | int SkeletonSolverBase::_addRow(ExprIterator, ExprIterator) { return -1; } |
46 | 47 | void SkeletonSolverBase::_setRowCoeffs(int, ExprIterator, ExprIterator) {} |
47 | 48 | void SkeletonSolverBase::_getRowCoeffs(int, InsertIterator) const {} |
48 | 49 | |
diff --git a/lemon/lp_skeleton.h b/lemon/lp_skeleton.h
a
|
b
|
namespace lemon { |
57 | 57 | /// \e |
58 | 58 | virtual int _rowByName(const std::string& name) const; |
59 | 59 | |
| 60 | /// \e |
| 61 | virtual int _addRow(ExprIterator b, ExprIterator e); |
60 | 62 | /// \e |
61 | 63 | virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
62 | 64 | /// \e |