projects
/
linpy.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
445188d
)
LinExpr() accepts rational numbers
author
Vivien Maisonneuve
<v.maisonneuve@gmail.com>
Tue, 9 Sep 2014 08:59:10 +0000
(10:59 +0200)
committer
Vivien Maisonneuve
<v.maisonneuve@gmail.com>
Tue, 9 Sep 2014 09:08:10 +0000
(11:08 +0200)
linpy/polyhedra.py
patch
|
blob
|
history
diff --git
a/linpy/polyhedra.py
b/linpy/polyhedra.py
index
1ccbe9c
..
ead9b83
100644
(file)
--- a/
linpy/polyhedra.py
+++ b/
linpy/polyhedra.py
@@
-94,15
+94,23
@@
class Polyhedron(Domain):
sc_equalities = []
if equalities is not None:
for equality in equalities:
sc_equalities = []
if equalities is not None:
for equality in equalities:
- if not isinstance(equality, LinExpr):
- raise TypeError('equalities must be linear expressions')
- sc_equalities.append(equality.scaleint())
+ if isinstance(equality, LinExpr):
+ sc_equalities.append(equality.scaleint())
+ elif isinstance(equality, numbers.Rational):
+ sc_equalities.append(Rational(equality).scaleint())
+ else:
+ raise TypeError('equalities must be linear expressions '
+ 'or rational numbers')
sc_inequalities = []
if inequalities is not None:
for inequality in inequalities:
sc_inequalities = []
if inequalities is not None:
for inequality in inequalities:
- if not isinstance(inequality, LinExpr):
- raise TypeError('inequalities must be linear expressions')
- sc_inequalities.append(inequality.scaleint())
+ if isinstance(inequality, LinExpr):
+ sc_inequalities.append(inequality.scaleint())
+ elif isinstance(inequality, numbers.Rational):
+ sc_inequalities.append(Rational(inequality).scaleint())
+ else:
+ raise TypeError('inequalities must be linear expressions '
+ 'or rational numbers')
symbols = cls._xsymbols(sc_equalities + sc_inequalities)
islbset = cls._toislbasicset(sc_equalities, sc_inequalities, symbols)
return cls._fromislbasicset(islbset, symbols)
symbols = cls._xsymbols(sc_equalities + sc_inequalities)
islbset = cls._toislbasicset(sc_equalities, sc_inequalities, symbols)
return cls._fromislbasicset(islbset, symbols)