Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs598mp-fall2021-proj
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
chsieh16
cs598mp-fall2021-proj
Commits
68c86728
Commit
68c86728
authored
2 years ago
by
chsieh16
Browse files
Options
Downloads
Patches
Plain Diff
Rename dump function
parent
ba4170fd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
firstpass_teacher.py
+2
-2
2 additions, 2 deletions
firstpass_teacher.py
gem_stanley_teacher.py
+5
-13
5 additions, 13 deletions
gem_stanley_teacher.py
teacher_base.py
+12
-7
12 additions, 7 deletions
teacher_base.py
with
19 additions
and
22 deletions
firstpass_teacher.py
+
2
−
2
View file @
68c86728
...
...
@@ -60,9 +60,9 @@ def test_firstpass_teacher():
teacher
=
FirstpassTeacher
()
teacher
.
set_old_state_bound
(
lb
=
[
6.0
,
5.0
],
ub
=
[
11.0
,
10.0
])
result
=
teacher
.
check
(
CAND0
)
teacher
.
dump_
model
()
teacher
.
dump_
system_encoding
()
result
=
teacher
.
check
(
CAND1
)
teacher
.
dump_
model
(
"
firstpass2
"
)
teacher
.
dump_
system_encoding
(
"
firstpass2
"
)
print
(
result
)
if
result
==
z3
.
sat
:
print
(
teacher
.
model
())
...
...
This diff is collapsed.
Click to expand it.
gem_stanley_teacher.py
+
5
−
13
View file @
68c86728
...
...
@@ -225,17 +225,9 @@ class GEMStanleySymPyTeacher(SymPyTeacherBase):
old_x
,
old_y
,
old_yaw
=
self
.
_old_state
new_x
,
new_y
,
new_yaw
=
self
.
_new_state
if
self
.
_norm_ord
==
1
:
old_err
=
sympy
.
Abs
(
old_y
)
+
sympy
.
Abs
(
old_yaw
)
new_err
=
sympy
.
Abs
(
new_y
)
+
sympy
.
Abs
(
new_yaw
)
elif
self
.
_norm_ord
==
2
:
old_err
=
sympy
.
sqrt
(
old_y
**
2
+
old_yaw
**
2
)
new_err
=
sympy
.
sqrt
(
new_y
**
2
+
new_yaw
**
2
)
else
:
assert
self
.
_norm_ord
==
"
inf
"
old_err
=
sympy
.
Max
(
sympy
.
Abs
(
old_y
),
sympy
.
Abs
(
old_yaw
))
new_err
=
sympy
.
Max
(
sympy
.
Abs
(
new_y
),
sympy
.
Abs
(
new_yaw
))
norm_ord
=
sympy
.
oo
if
self
.
_norm_ord
==
"
inf
"
else
self
.
_norm_ord
old_err
=
sympy
.
Matrix
([
old_y
,
old_yaw
]).
norm
(
ord
=
norm_ord
)
new_err
=
sympy
.
Matrix
([
new_y
,
new_yaw
]).
norm
(
ord
=
norm_ord
)
self
.
_not_inv_cons
.
extend
([
old_err
<=
new_err
])
...
...
@@ -269,7 +261,7 @@ def test_gem_stanley_sympy_teacher():
lb
=
(
-
sympy
.
oo
,
sympy
.
Rational
(
"
0.5
"
),
0.0
),
ub
=
(
sympy
.
oo
,
sympy
.
Rational
(
"
1.2
"
),
sympy
.
pi
/
12
)
)
teacher
.
dump_system_
formula
()
teacher
.
dump_system_
encoding
()
def
test_gem_stanley_gurobi_teacher
():
...
...
@@ -278,7 +270,7 @@ def test_gem_stanley_gurobi_teacher():
lb
=
(
-
np
.
inf
,
0.5
,
0.0625
),
ub
=
(
np
.
inf
,
1.0
,
0.25
)
)
teacher
.
dump_
model
()
teacher
.
dump_
system_encoding
()
print
(
teacher
.
check
(
None
))
print
(
teacher
.
model
())
...
...
This diff is collapsed.
Click to expand it.
teacher_base.py
+
12
−
7
View file @
68c86728
...
...
@@ -25,6 +25,10 @@ class TeacherBase(abc.ABC):
def
reason_unknown
(
self
)
->
str
:
raise
NotImplementedError
@abc.abstractmethod
def
dump_system_encoding
(
self
,
basename
:
str
=
""
)
->
None
:
raise
NotImplementedError
class
DRealTeacherBase
(
TeacherBase
):
@staticmethod
...
...
@@ -125,7 +129,7 @@ class DRealTeacherBase(TeacherBase):
else
:
return
z3
.
unsat
def
dump_
model
(
self
,
basename
:
str
=
""
)
->
None
:
def
dump_
system_encoding
(
self
,
basename
:
str
=
""
)
->
None
:
print
([
dreal
.
And
(
lb_i
<=
var_i
,
var_i
<=
ub_i
)
for
var_i
,
(
lb_i
,
ub_i
)
in
self
.
_var_bounds
.
items
()
...
...
@@ -241,6 +245,7 @@ class GurobiTeacherBase(TeacherBase):
self
.
_old_state
.
ub
=
ub
def
check
(
self
,
candidate
:
sympy
.
logic
.
boolalg
.
Boolean
)
->
z3
.
CheckSatResult
:
raise
NotImplementedError
(
"
TODO convert from sympy
"
)
self
.
_set_candidate
(
candidate
)
self
.
_gp_model
.
optimize
()
if
self
.
_gp_model
.
status
==
gp
.
GRB
.
INF_OR_UNBD
:
...
...
@@ -254,7 +259,7 @@ class GurobiTeacherBase(TeacherBase):
else
:
return
z3
.
unknown
def
dump_
model
(
self
,
basename
:
str
=
""
)
->
None
:
def
dump_
system_encoding
(
self
,
basename
:
str
=
""
)
->
None
:
"""
Dump optimization problem in LP format
"""
if
not
basename
:
basename
=
self
.
_gp_model
.
ModelName
...
...
@@ -283,13 +288,13 @@ class SymPyTeacherBase(TeacherBase):
self
.
_norm_ord
=
norm_ord
# Old state variables
self
.
_old_state
=
sympy
.
symbols
(
names
=
[
f
"
x
[
{
i
}
]
"
for
i
in
range
(
state_dim
)],
real
=
True
)
self
.
_old_state
=
sympy
.
symbols
(
names
=
[
f
"
x
_
{
i
}
"
for
i
in
range
(
state_dim
)],
real
=
True
)
# New state variables
self
.
_new_state
=
sympy
.
symbols
(
names
=
[
f
"
x
'
[
{
i
}
]
"
for
i
in
range
(
state_dim
)],
real
=
True
)
self
.
_new_state
=
sympy
.
symbols
(
names
=
[
f
"
x
'
_
{
i
}
"
for
i
in
range
(
state_dim
)],
real
=
True
)
# Perception variables
self
.
_percept
=
sympy
.
symbols
(
names
=
[
f
"
z
[
{
i
}
]
"
for
i
in
range
(
perc_dim
)],
real
=
True
)
self
.
_percept
=
sympy
.
symbols
(
names
=
[
f
"
z
_
{
i
}
"
for
i
in
range
(
perc_dim
)],
real
=
True
)
# Control variables
self
.
_control
=
sympy
.
symbols
(
names
=
[
f
"
u
[
{
i
}
]
"
for
i
in
range
(
ctrl_dim
)],
real
=
True
)
self
.
_control
=
sympy
.
symbols
(
names
=
[
f
"
u
_
{
i
}
"
for
i
in
range
(
ctrl_dim
)],
real
=
True
)
self
.
_var_bounds
=
{
var
:
(
-
sympy
.
oo
,
sympy
.
oo
)
...
...
@@ -333,7 +338,7 @@ class SymPyTeacherBase(TeacherBase):
def
check
(
self
,
candidate
:
sympy
.
logic
.
boolalg
.
Boolean
)
->
z3
.
CheckSatResult
:
raise
NotImplementedError
def
dump_system_
formula
(
self
,
basename
:
str
=
""
)
->
None
:
def
dump_system_
encoding
(
self
,
basename
:
str
=
""
)
->
None
:
query
=
sympy
.
And
(
*
(
sympy
.
And
(
lb_i
<=
var_i
,
var_i
<=
ub_i
)
for
var_i
,
(
lb_i
,
ub_i
)
in
self
.
_var_bounds
.
items
()),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment