... | ... |
@@ -1573,144 +1573,144 @@ |
1573 | 1573 |
LpBase::Expr tmp(a); |
1574 | 1574 |
tmp+=b; |
1575 | 1575 |
return tmp; |
1576 | 1576 |
} |
1577 | 1577 |
///Substraction |
1578 | 1578 |
|
1579 | 1579 |
///\relates LpBase::Expr |
1580 | 1580 |
/// |
1581 | 1581 |
inline LpBase::Expr operator-(const LpBase::Expr &a, const LpBase::Expr &b) { |
1582 | 1582 |
LpBase::Expr tmp(a); |
1583 | 1583 |
tmp-=b; |
1584 | 1584 |
return tmp; |
1585 | 1585 |
} |
1586 | 1586 |
///Multiply with constant |
1587 | 1587 |
|
1588 | 1588 |
///\relates LpBase::Expr |
1589 | 1589 |
/// |
1590 | 1590 |
inline LpBase::Expr operator*(const LpBase::Expr &a, const LpBase::Value &b) { |
1591 | 1591 |
LpBase::Expr tmp(a); |
1592 | 1592 |
tmp*=b; |
1593 | 1593 |
return tmp; |
1594 | 1594 |
} |
1595 | 1595 |
|
1596 | 1596 |
///Multiply with constant |
1597 | 1597 |
|
1598 | 1598 |
///\relates LpBase::Expr |
1599 | 1599 |
/// |
1600 | 1600 |
inline LpBase::Expr operator*(const LpBase::Value &a, const LpBase::Expr &b) { |
1601 | 1601 |
LpBase::Expr tmp(b); |
1602 | 1602 |
tmp*=a; |
1603 | 1603 |
return tmp; |
1604 | 1604 |
} |
1605 | 1605 |
///Divide with constant |
1606 | 1606 |
|
1607 | 1607 |
///\relates LpBase::Expr |
1608 | 1608 |
/// |
1609 | 1609 |
inline LpBase::Expr operator/(const LpBase::Expr &a, const LpBase::Value &b) { |
1610 | 1610 |
LpBase::Expr tmp(a); |
1611 | 1611 |
tmp/=b; |
1612 | 1612 |
return tmp; |
1613 | 1613 |
} |
1614 | 1614 |
|
1615 | 1615 |
///Create constraint |
1616 | 1616 |
|
1617 | 1617 |
///\relates LpBase::Constr |
1618 | 1618 |
/// |
1619 | 1619 |
inline LpBase::Constr operator<=(const LpBase::Expr &e, |
1620 | 1620 |
const LpBase::Expr &f) { |
1621 |
return LpBase::Constr(0, f - e, LpBase:: |
|
1621 |
return LpBase::Constr(0, f - e, LpBase::NaN); |
|
1622 | 1622 |
} |
1623 | 1623 |
|
1624 | 1624 |
///Create constraint |
1625 | 1625 |
|
1626 | 1626 |
///\relates LpBase::Constr |
1627 | 1627 |
/// |
1628 | 1628 |
inline LpBase::Constr operator<=(const LpBase::Value &e, |
1629 | 1629 |
const LpBase::Expr &f) { |
1630 | 1630 |
return LpBase::Constr(e, f, LpBase::NaN); |
1631 | 1631 |
} |
1632 | 1632 |
|
1633 | 1633 |
///Create constraint |
1634 | 1634 |
|
1635 | 1635 |
///\relates LpBase::Constr |
1636 | 1636 |
/// |
1637 | 1637 |
inline LpBase::Constr operator<=(const LpBase::Expr &e, |
1638 | 1638 |
const LpBase::Value &f) { |
1639 |
return LpBase::Constr( |
|
1639 |
return LpBase::Constr(LpBase::NaN, e, f); |
|
1640 | 1640 |
} |
1641 | 1641 |
|
1642 | 1642 |
///Create constraint |
1643 | 1643 |
|
1644 | 1644 |
///\relates LpBase::Constr |
1645 | 1645 |
/// |
1646 | 1646 |
inline LpBase::Constr operator>=(const LpBase::Expr &e, |
1647 | 1647 |
const LpBase::Expr &f) { |
1648 |
return LpBase::Constr(0, e - f, LpBase:: |
|
1648 |
return LpBase::Constr(0, e - f, LpBase::NaN); |
|
1649 | 1649 |
} |
1650 | 1650 |
|
1651 | 1651 |
|
1652 | 1652 |
///Create constraint |
1653 | 1653 |
|
1654 | 1654 |
///\relates LpBase::Constr |
1655 | 1655 |
/// |
1656 | 1656 |
inline LpBase::Constr operator>=(const LpBase::Value &e, |
1657 | 1657 |
const LpBase::Expr &f) { |
1658 | 1658 |
return LpBase::Constr(LpBase::NaN, f, e); |
1659 | 1659 |
} |
1660 | 1660 |
|
1661 | 1661 |
|
1662 | 1662 |
///Create constraint |
1663 | 1663 |
|
1664 | 1664 |
///\relates LpBase::Constr |
1665 | 1665 |
/// |
1666 | 1666 |
inline LpBase::Constr operator>=(const LpBase::Expr &e, |
1667 | 1667 |
const LpBase::Value &f) { |
1668 |
return LpBase::Constr(f, e, LpBase:: |
|
1668 |
return LpBase::Constr(f, e, LpBase::NaN); |
|
1669 | 1669 |
} |
1670 | 1670 |
|
1671 | 1671 |
///Create constraint |
1672 | 1672 |
|
1673 | 1673 |
///\relates LpBase::Constr |
1674 | 1674 |
/// |
1675 | 1675 |
inline LpBase::Constr operator==(const LpBase::Expr &e, |
1676 | 1676 |
const LpBase::Value &f) { |
1677 | 1677 |
return LpBase::Constr(f, e, f); |
1678 | 1678 |
} |
1679 | 1679 |
|
1680 | 1680 |
///Create constraint |
1681 | 1681 |
|
1682 | 1682 |
///\relates LpBase::Constr |
1683 | 1683 |
/// |
1684 | 1684 |
inline LpBase::Constr operator==(const LpBase::Expr &e, |
1685 | 1685 |
const LpBase::Expr &f) { |
1686 | 1686 |
return LpBase::Constr(0, f - e, 0); |
1687 | 1687 |
} |
1688 | 1688 |
|
1689 | 1689 |
///Create constraint |
1690 | 1690 |
|
1691 | 1691 |
///\relates LpBase::Constr |
1692 | 1692 |
/// |
1693 | 1693 |
inline LpBase::Constr operator<=(const LpBase::Value &n, |
1694 | 1694 |
const LpBase::Constr &c) { |
1695 | 1695 |
LpBase::Constr tmp(c); |
1696 | 1696 |
LEMON_ASSERT(isNaN(tmp.lowerBound()), "Wrong LP constraint"); |
1697 | 1697 |
tmp.lowerBound()=n; |
1698 | 1698 |
return tmp; |
1699 | 1699 |
} |
1700 | 1700 |
///Create constraint |
1701 | 1701 |
|
1702 | 1702 |
///\relates LpBase::Constr |
1703 | 1703 |
/// |
1704 | 1704 |
inline LpBase::Constr operator<=(const LpBase::Constr &c, |
1705 | 1705 |
const LpBase::Value &n) |
1706 | 1706 |
{ |
1707 | 1707 |
LpBase::Constr tmp(c); |
1708 | 1708 |
LEMON_ASSERT(isNaN(tmp.upperBound()), "Wrong LP constraint"); |
1709 | 1709 |
tmp.upperBound()=n; |
1710 | 1710 |
return tmp; |
1711 | 1711 |
} |
1712 | 1712 |
|
1713 | 1713 |
///Create constraint |
1714 | 1714 |
|
1715 | 1715 |
///\relates LpBase::Constr |
1716 | 1716 |
/// |
... | ... |
@@ -121,96 +121,104 @@ |
121 | 121 |
); |
122 | 122 |
|
123 | 123 |
|
124 | 124 |
c = (e <= f ); |
125 | 125 |
c = (e <= 2.2); |
126 | 126 |
c = (e <= 2 ); |
127 | 127 |
c = (e <= p1 ); |
128 | 128 |
c = (2.2<= f ); |
129 | 129 |
c = (2 <= f ); |
130 | 130 |
c = (p1 <= f ); |
131 | 131 |
c = (p1 <= p2 ); |
132 | 132 |
c = (p1 <= 2.2); |
133 | 133 |
c = (p1 <= 2 ); |
134 | 134 |
c = (2.2<= p2 ); |
135 | 135 |
c = (2 <= p2 ); |
136 | 136 |
|
137 | 137 |
c = (e >= f ); |
138 | 138 |
c = (e >= 2.2); |
139 | 139 |
c = (e >= 2 ); |
140 | 140 |
c = (e >= p1 ); |
141 | 141 |
c = (2.2>= f ); |
142 | 142 |
c = (2 >= f ); |
143 | 143 |
c = (p1 >= f ); |
144 | 144 |
c = (p1 >= p2 ); |
145 | 145 |
c = (p1 >= 2.2); |
146 | 146 |
c = (p1 >= 2 ); |
147 | 147 |
c = (2.2>= p2 ); |
148 | 148 |
c = (2 >= p2 ); |
149 | 149 |
|
150 | 150 |
c = (e == f ); |
151 | 151 |
c = (e == 2.2); |
152 | 152 |
c = (e == 2 ); |
153 | 153 |
c = (e == p1 ); |
154 | 154 |
c = (2.2== f ); |
155 | 155 |
c = (2 == f ); |
156 | 156 |
c = (p1 == f ); |
157 | 157 |
//c = (p1 == p2 ); |
158 | 158 |
c = (p1 == 2.2); |
159 | 159 |
c = (p1 == 2 ); |
160 | 160 |
c = (2.2== p2 ); |
161 | 161 |
c = (2 == p2 ); |
162 | 162 |
|
163 | 163 |
c = ((2 <= e) <= 3); |
164 | 164 |
c = ((2 <= p1) <= 3); |
165 | 165 |
|
166 | 166 |
c = ((2 >= e) >= 3); |
167 | 167 |
c = ((2 >= p1) >= 3); |
168 | 168 |
|
169 |
{ //Tests for #430 |
|
170 |
LP::Col v=lp.addCol(); |
|
171 |
LP::Constr c = v >= -3; |
|
172 |
c = c <= 4; |
|
173 |
LP::Constr c2; |
|
174 |
c2 = -3 <= v <= 4; |
|
175 |
} |
|
176 |
|
|
169 | 177 |
e[x[3]]=2; |
170 | 178 |
e[x[3]]=4; |
171 | 179 |
e[x[3]]=1; |
172 | 180 |
*e=12; |
173 | 181 |
|
174 | 182 |
lp.addRow(-LP::INF,e,23); |
175 | 183 |
lp.addRow(-LP::INF,3.0*(x[1]+x[2]/2)-x[3],23); |
176 | 184 |
lp.addRow(-LP::INF,3.0*(x[1]+x[2]*2-5*x[3]+12-x[4]/3)+2*x[4]-4,23); |
177 | 185 |
|
178 | 186 |
lp.addRow(x[1]+x[3]<=x[5]-3); |
179 | 187 |
lp.addRow((-7<=x[1]+x[3]-12)<=3); |
180 | 188 |
lp.addRow(x[1]<=x[5]); |
181 | 189 |
|
182 | 190 |
std::ostringstream buf; |
183 | 191 |
|
184 | 192 |
|
185 | 193 |
e=((p1+p2)+(p1-0.99*p2)); |
186 | 194 |
//e.prettyPrint(std::cout); |
187 | 195 |
//(e<=2).prettyPrint(std::cout); |
188 | 196 |
double tolerance=0.001; |
189 | 197 |
e.simplify(tolerance); |
190 | 198 |
buf << "Coeff. of p2 should be 0.01"; |
191 | 199 |
check(e[p2]>0, buf.str()); |
192 | 200 |
|
193 | 201 |
tolerance=0.02; |
194 | 202 |
e.simplify(tolerance); |
195 | 203 |
buf << "Coeff. of p2 should be 0"; |
196 | 204 |
check(const_cast<const LpSolver::Expr&>(e)[p2]==0, buf.str()); |
197 | 205 |
|
198 | 206 |
//Test for clone/new |
199 | 207 |
LP* lpnew = lp.newSolver(); |
200 | 208 |
LP* lpclone = lp.cloneSolver(); |
201 | 209 |
delete lpnew; |
202 | 210 |
delete lpclone; |
203 | 211 |
|
204 | 212 |
} |
205 | 213 |
|
206 | 214 |
{ |
207 | 215 |
LP::DualExpr e,f,g; |
208 | 216 |
LP::Row p1 = INVALID, p2 = INVALID, p3 = INVALID, |
209 | 217 |
p4 = INVALID, p5 = INVALID; |
210 | 218 |
|
211 | 219 |
e[p1]=2; |
212 | 220 |
e[p1]+=2; |
213 | 221 |
e[p1]-=2; |
214 | 222 |
|
215 | 223 |
e=p1; |
216 | 224 |
e=f; |
0 comments (0 inline)