-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLPSConstraint.py
77 lines (68 loc) · 2 KB
/
LPSConstraint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from enum import Enum
class InequalityType(Enum):
EQ = 1
GE = 2
GT = 3
LE = 4
LT = 5
class LPSConstraint(object):
""" <summary>
If x = Term, op = Inequality, represents x `op` 0
</summary>
"""
def __init__(self):
""" <summary>
If x = Term, op = Inequality, represents x `op` 0
</summary>
"""
pass
# default = false. Have we added this constraint to the solver? No. Yikes.
class LPSConstraints(IEnumerable):
""" <summary>
A simple (list-implemented) set of constraints and inequalities that
encode an LP instance. The list-based implementation exists because
we only iterate/insert. If we need more, make sure to optimize this!
</summary>
"""
def __init__(self):
""" <summary>
A simple (list-implemented) set of constraints and inequalities that
encode an LP instance. The list-based implementation exists because
we only iterate/insert. If we need more, make sure to optimize this!
</summary>
"""
# To support O(1) extension
self._constraints_ = [None] *
# To support O(1) union
self._unioned_ = [None] *
self._constraintCount_ = 0
def And(self, s):
self._unioned_.append(s)
self._constraintCount_ += s.constraintCount_
def And(self, term, inequality):
self._constraints_.append(LPSConstraint(Inequality = inequality, Term = term))
self._constraintCount_ += 1
# (left `binop` right), equivalently: (left - right `binop` 0)
# NB: Allocates, does not overwrite the left or right term.
def And(self, left, inequality, right):
t = LPSTerm.Const(0.0)
t.append(left)
t.AddMul(right, -1.0)
self.And(t, inequality)
def get_Count(self):
return self._constraintCount_
Count = property(fget=get_Count)
def GetEnumerator(self):
raise NotImplementedError("not sure")
for e in self._constraints_:
yield o
for o in self._unioned_:
for e in e._constraints_:
yield o
def ToList(self):
raise NotImplementedError("not sure")
ret = self._constraints_[:]
for e in self._unioned_:
for o in e._constraints_:
ret.append(o)
return ret