scipplan 0.1.0a2__py2.py3-none-any.whl → 0.1.1a0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scipplan/__init__.py +1 -1
- scipplan/parse_model.py +68 -24
- scipplan/plan_model.py +11 -6
- {scipplan-0.1.0a2.dist-info → scipplan-0.1.1a0.dist-info}/METADATA +7 -3
- {scipplan-0.1.0a2.dist-info → scipplan-0.1.1a0.dist-info}/RECORD +9 -9
- {scipplan-0.1.0a2.dist-info → scipplan-0.1.1a0.dist-info}/LICENSE +0 -0
- {scipplan-0.1.0a2.dist-info → scipplan-0.1.1a0.dist-info}/WHEEL +0 -0
- {scipplan-0.1.0a2.dist-info → scipplan-0.1.1a0.dist-info}/entry_points.txt +0 -0
- {scipplan-0.1.0a2.dist-info → scipplan-0.1.1a0.dist-info}/top_level.txt +0 -0
scipplan/__init__.py
CHANGED
scipplan/parse_model.py
CHANGED
@@ -10,13 +10,68 @@ from math import exp, log, sqrt, sin, cos, isclose
|
|
10
10
|
|
11
11
|
from pyscipopt.scip import Model, SumExpr
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
|
14
|
+
def linearise(expr: ast.Compare, aux_var: Variable) -> tuple[ast.Compare, ast.Compare]:
|
15
|
+
"""linearise
|
16
|
+
This function linearises an inequality using an auxilary variable
|
17
|
+
|
18
|
+
The linearisation process is as follows.
|
19
|
+
If the expression is of the form of E1 <= E2, then we linearise by using the following expressions.
|
20
|
+
z=0 ==> E1 <= E2 and z=1 ==> E1 > E2 (equivalent to E1 >= E2 + feastol). This is then equivalent to,
|
21
|
+
E2 + feastol - M + z*M <= E1 <= E2 + zM.
|
22
|
+
|
23
|
+
Similarly, for E1 < E2 we have z=0 ==> E1 < E2 which is equivalent to E1 <= E2 - feastol + z*M
|
24
|
+
and z=1 ==> E1 >= E2.
|
25
|
+
Thus for E1 < E2 we have,
|
26
|
+
E2 + z*M - M <= E1 <= E2 + z*M - feastol.
|
27
|
+
|
28
|
+
If, however, the inequality is of the form of E1 >= E2 then we evaluate the expression, E2 <= E1.
|
29
|
+
Similarly, if the expression is E1 > E2 then we evaluate the expression E2 < E1.
|
30
|
+
|
31
|
+
:param expr: An inequality expression which is linearised.
|
32
|
+
:type expr: ast.Compare
|
33
|
+
:param aux_var: An auxiliary variable used when linearising the inequality to determine if the expression is true or false.
|
34
|
+
:type aux_var: Variable
|
35
|
+
:raises ValueError: If expr is not a valid inequality (i.e. doesn't use <, <=, > and >=)
|
36
|
+
:return: both the linearised inequalities
|
37
|
+
:rtype: tuple[ast.Compare, ast.Compare]
|
38
|
+
"""
|
39
|
+
if not isinstance(expr.ops[0], (ast.Lt, ast.LtE, ast.Gt, ast.GtE)):
|
40
|
+
raise ValueError("Only <, <=, > or >= are allowed")
|
41
|
+
if isinstance(expr.ops[0], ast.GtE):
|
42
|
+
expr.left, expr.comparators[0] = expr.comparators[0], expr.left
|
43
|
+
expr.ops[0] = ast.LtE()
|
44
|
+
if isinstance(expr.ops[0], ast.Gt):
|
45
|
+
expr.left, expr.comparators[0] = expr.comparators[0], expr.left
|
46
|
+
expr.ops[0] = ast.Lt()
|
47
|
+
|
48
|
+
if isinstance(expr.ops[0], ast.LtE):
|
49
|
+
lhs = ast.BinOp(
|
50
|
+
left=expr.comparators[0],
|
51
|
+
op=ast.Add(),
|
52
|
+
right=ast.parse(f"feastol - bigM + {aux_var.name} * bigM").body[0].value
|
53
|
+
)
|
54
|
+
rhs = ast.BinOp(
|
55
|
+
left=expr.comparators[0],
|
56
|
+
op=ast.Add(),
|
57
|
+
right=ast.parse(f"{aux_var.name} * bigM").body[0].value
|
58
|
+
)
|
59
|
+
if isinstance(expr.ops[0], ast.Lt):
|
60
|
+
lhs = ast.BinOp(
|
61
|
+
left=expr.comparators[0],
|
62
|
+
op=ast.Add(),
|
63
|
+
right=ast.parse(f"{aux_var.name} * bigM - bigM").body[0].value
|
64
|
+
)
|
65
|
+
rhs = ast.BinOp(
|
66
|
+
left=expr.comparators[0],
|
67
|
+
op=ast.Add(),
|
68
|
+
right=ast.parse(f"{aux_var.name} * bigM - feastol").body[0].value
|
69
|
+
)
|
70
|
+
expr1 = ast.Compare(lhs, [ast.LtE()], [expr.left])
|
71
|
+
expr2 = ast.Compare(expr.left, [ast.LtE()], [rhs])
|
72
|
+
return expr1, expr2
|
73
|
+
|
74
|
+
|
20
75
|
|
21
76
|
@dataclass
|
22
77
|
class Expressions:
|
@@ -37,8 +92,8 @@ class Expressions:
|
|
37
92
|
|
38
93
|
class ParserType(Enum):
|
39
94
|
"""ParserType
|
40
|
-
|
41
|
-
|
95
|
+
enum type CALCULATOR: Used to calculate using feastol
|
96
|
+
enum type PARSER: Used to parse an expression and create the correct minlp constraints
|
42
97
|
"""
|
43
98
|
CALCULATOR = "calculator"
|
44
99
|
PARSER = "parser"
|
@@ -152,22 +207,11 @@ class ParseModel:
|
|
152
207
|
aux_vars.append(aux_var)
|
153
208
|
self.variables[aux_var.name] = aux_var.model_var
|
154
209
|
|
155
|
-
|
156
|
-
left=expr.left,
|
157
|
-
op=(ast.Add() if isinstance(expr.ops[0], (ast.Gt, ast.GtE)) else ast.Sub()),
|
158
|
-
right=ast.parse(f"bigM * {aux_var.name}").body[0].value
|
159
|
-
)
|
160
|
-
self.expressions.add_expressions(self.evaluate(expr))
|
210
|
+
expr1, expr2 = linearise(expr, aux_var)
|
161
211
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
left=expr.comparators[0],
|
166
|
-
op=(ast.Add() if isinstance(expr.ops[0], (ast.Gt, ast.GtE)) else ast.Sub()),
|
167
|
-
right=ast.parse(f"feastol - bigM").body[0].value
|
168
|
-
)
|
169
|
-
|
170
|
-
self.expressions.add_expressions(self.evaluate(expr))
|
212
|
+
self.expressions.add_expressions(self.evaluate(expr1))
|
213
|
+
self.expressions.add_expressions(self.evaluate(expr2))
|
214
|
+
|
171
215
|
else:
|
172
216
|
raise Exception("or expressions may only be made up of inequalities")
|
173
217
|
lhs = SumExpr()
|
scipplan/plan_model.py
CHANGED
@@ -95,12 +95,17 @@ class PlanModel:
|
|
95
95
|
|
96
96
|
self.var_names.add(name)
|
97
97
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
98
|
+
if vtype.startswith("global"):
|
99
|
+
var = Variable.create_var(self.model, name, vtype, "global", self.constants)
|
100
|
+
for t in range(self.config.horizon + 1):
|
101
|
+
variables[(name, t)] = var
|
102
|
+
else:
|
103
|
+
for t in range(self.config.horizon):
|
104
|
+
variables[(name, t)] = Variable.create_var(self.model, name, vtype, t, self.constants)
|
105
|
+
var_type = variables[(name, t)].var_type
|
106
|
+
if var_type is VarType.STATE:
|
107
|
+
variables[(name, self.config.horizon)] = Variable.create_var(self.model, name, vtype, self.config.horizon, self.constants)
|
108
|
+
|
104
109
|
return variables
|
105
110
|
|
106
111
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: scipplan
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.1a0
|
4
4
|
Summary: Metric Hybrid Factored Planning in Nonlinear Domains with Constraint Generation in Python.
|
5
5
|
Author: Ari Gestetner, Buser Say
|
6
6
|
Author-email: ari.gestetner@monash.edu, buser.say@monash.edu
|
@@ -121,13 +121,17 @@ state_continuous: Location_x
|
|
121
121
|
state_continuous: Location_y
|
122
122
|
state_continuous: Speed_x
|
123
123
|
state_continuous: Speed_y
|
124
|
+
global_boolean: aux_1
|
124
125
|
```
|
125
|
-
where the variable and value type of the variable is set in the format "{variable type}_{value type}" and the variable itself has to be in a Python compatible format (e.g. variables can't use -
|
126
|
+
where the variable and value type of the variable is set in the format "{variable type}_{value type}" and the variable itself has to be in a Python compatible format (e.g. variables can't use - symbol like `some-var` but can use _ like `some_var` as well as the dash sign ' cannot be used). The use of next state variables which is often written using the dash symbol will be explained further in the Transitions section.
|
126
127
|
Additionally a variable for Dt has to be defined and has to be the same as the dt_var in the config object so if you would like to use a different variable name for Dt (e.g. dt) please also ensure you add it to the config via the `--dt-var` tag or the `dt_var` parameter.
|
128
|
+
The variable type `global` is used when you would like a non state variable to be equal over every time step over the horizon (e.g. if $v_t$ is a variable at time $t$ and $H$ is the horizon, then $v_1 = v_2 = \dots = v_{H+1}$).
|
129
|
+
|
127
130
|
The available variable types are
|
128
131
|
- state
|
129
132
|
- action
|
130
133
|
- auxiliary
|
134
|
+
- global
|
131
135
|
|
132
136
|
The available value types are
|
133
137
|
- continuos
|
@@ -144,7 +148,7 @@ Location_y == 0.0
|
|
144
148
|
Speed_x == 0.0
|
145
149
|
Speed_y == 0.0
|
146
150
|
```
|
147
|
-
notice
|
151
|
+
notice the use of the constant value defined earlier in the constants file.
|
148
152
|
### Goals
|
149
153
|
The goals file should encode the final state values such that t=H+1, for example
|
150
154
|
```txt
|
@@ -1,8 +1,8 @@
|
|
1
|
-
scipplan/__init__.py,sha256=
|
1
|
+
scipplan/__init__.py,sha256=uKbPGbRV0K1aJ2e2_4MzHKuJxn36vtQ7yx5CqTL5Jsk,193
|
2
2
|
scipplan/config.py,sha256=0D6UcLjrv4PTjYRiPoIYXAsRu4nwcaOIWnsI4lAdK6Y,5221
|
3
3
|
scipplan/helpers.py,sha256=YwEr0NeDvb29_Ot686km3ZMJ-vHu-L8zjuexmlKDjpY,974
|
4
|
-
scipplan/parse_model.py,sha256
|
5
|
-
scipplan/plan_model.py,sha256=
|
4
|
+
scipplan/parse_model.py,sha256=CI_38xmaiVr8DuOi3UdNrVqWHTdW6qm_5luwLZxIk9I,11136
|
5
|
+
scipplan/plan_model.py,sha256=Zr2NdoSTXkgqpnPVoNvGMjSyNDEJ2ql6_OYIQJGO_E0,11423
|
6
6
|
scipplan/scipplan.py,sha256=z6cuRug4amCg6LU7S4RYHcV6uT3vWLHYGRh9OXFkKoU,8225
|
7
7
|
scipplan/variables.py,sha256=3sxY3zQuxsa5z2fTFjv4zOSb9GarzojZ4W4kIx9FX68,2561
|
8
8
|
scipplan/zero_crossing.py,sha256=kGyJsWZLLXqLW1p3LPDlPC34rTkFF8daDzqgbEcaXus,1043
|
@@ -30,9 +30,9 @@ scipplan/translation/temporal_constraints_navigation_3.txt,sha256=Ki4nAX9-QtBbY9
|
|
30
30
|
scipplan/translation/transitions_navigation_1.txt,sha256=kfnr3_A9mCfflLsL4aq7OeR_BHSNST6eYuAg4ZxaPoU,411
|
31
31
|
scipplan/translation/transitions_navigation_2.txt,sha256=kfnr3_A9mCfflLsL4aq7OeR_BHSNST6eYuAg4ZxaPoU,411
|
32
32
|
scipplan/translation/transitions_navigation_3.txt,sha256=aIPP3FOjXZ3G6sTqicEIZ0JKJxdxHCRRZIdc5bUPFBM,395
|
33
|
-
scipplan-0.1.
|
34
|
-
scipplan-0.1.
|
35
|
-
scipplan-0.1.
|
36
|
-
scipplan-0.1.
|
37
|
-
scipplan-0.1.
|
38
|
-
scipplan-0.1.
|
33
|
+
scipplan-0.1.1a0.dist-info/LICENSE,sha256=tfR4peJA8KJtYEn1NzNV-LWQVRAserdq7OJgYghreR0,1057
|
34
|
+
scipplan-0.1.1a0.dist-info/METADATA,sha256=QSfZ3QemoqT9M0GeUeBV4s5zdi5N5TozOt4iKQmqO8M,11498
|
35
|
+
scipplan-0.1.1a0.dist-info/WHEEL,sha256=-G_t0oGuE7UD0DrSpVZnq1hHMBV9DD2XkS5v7XpmTnk,110
|
36
|
+
scipplan-0.1.1a0.dist-info/entry_points.txt,sha256=3qiNbbp6qIwivyPmmikyp7ByCfmsa9rGFNJPcN9Is8I,52
|
37
|
+
scipplan-0.1.1a0.dist-info/top_level.txt,sha256=xO2FLRn7YQ-C25E8lagIEbik5T5FTr-Ta5bdiZezEPY,9
|
38
|
+
scipplan-0.1.1a0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|