Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
db-guided-mrmp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
rmoan2
db-guided-mrmp
Commits
e9780817
Commit
e9780817
authored
5 months ago
by
rachelmoan
Browse files
Options
Downloads
Patches
Plain Diff
Separate out optimizer to be used by multiple problems
parent
cb934865
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
guided_mrmp/conflict_resolvers/traj_opt_resolver.py
+3
-31
3 additions, 31 deletions
guided_mrmp/conflict_resolvers/traj_opt_resolver.py
guided_mrmp/controllers/mpc.py
+4
-31
4 additions, 31 deletions
guided_mrmp/controllers/mpc.py
guided_mrmp/optimizer.py
+37
-0
37 additions, 0 deletions
guided_mrmp/optimizer.py
with
44 additions
and
62 deletions
guided_mrmp/conflict_resolvers/traj_opt_resolver.py
+
3
−
31
View file @
e9780817
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
matplotlib.patches
import
Circle
,
Rectangle
from
guided_mrmp.optimizer
import
Optimizer
from
casadi
import
*
class
TrajOptResolver
():
...
...
@@ -148,37 +149,8 @@ class TrajOptResolver():
return
{
'
opti
'
:
opti
,
'
X
'
:
X
,
'
T
'
:
T
}
def
solve_optimization_problem
(
self
,
problem
,
initial_guesses
=
None
,
solver_options
=
None
):
opti
=
problem
[
'
opti
'
]
if
initial_guesses
:
for
param
,
value
in
initial_guesses
.
items
():
print
(
f
"
param =
{
param
}
"
)
print
(
f
"
value =
{
value
}
"
)
opti
.
set_initial
(
problem
[
param
],
value
)
# Set numerical backend, with options if provided
if
solver_options
:
opti
.
solver
(
'
ipopt
'
,
solver_options
)
else
:
opti
.
solver
(
'
ipopt
'
)
try
:
sol
=
opti
.
solve
()
# actual solve
status
=
'
succeeded
'
except
:
sol
=
None
status
=
'
failed
'
results
=
{
'
status
'
:
status
,
'
solution
'
:
sol
,
}
if
sol
:
for
var_name
,
var
in
problem
.
items
():
if
var_name
!=
'
opti
'
:
results
[
var_name
]
=
sol
.
value
(
var
)
opt
=
Optimizer
(
problem
)
results
=
opt
.
solve_optimization_problem
(
initial_guesses
,
solver_options
)
return
results
def
solve
(
self
,
N
,
x_range
,
y_range
,
initial_guesses
):
...
...
This diff is collapsed.
Click to expand it.
guided_mrmp/controllers/mpc.py
+
4
−
31
View file @
e9780817
import
numpy
as
np
import
casadi
as
ca
from
guided_mrmp.optimizer
import
Optimizer
np
.
seterr
(
divide
=
"
ignore
"
,
invalid
=
"
ignore
"
)
...
...
@@ -95,37 +96,8 @@ class MPC:
}
def
solve_optimization_problem
(
self
,
problem
,
initial_guesses
=
None
,
solver_options
=
None
):
opti
=
problem
[
'
opti
'
]
if
initial_guesses
:
for
param
,
value
in
initial_guesses
.
items
():
# print(f"param = {param}")
# print(f"value = {value}")
opti
.
set_initial
(
problem
[
param
],
value
)
# Set numerical backend, with options if provided
if
solver_options
:
opti
.
solver
(
'
ipopt
'
,
solver_options
)
else
:
opti
.
solver
(
'
ipopt
'
)
try
:
sol
=
opti
.
solve
()
# actual solve
status
=
'
succeeded
'
except
:
sol
=
None
status
=
'
failed
'
results
=
{
'
status
'
:
status
,
'
solution
'
:
sol
,
}
if
sol
:
for
var_name
,
var
in
problem
.
items
():
if
var_name
!=
'
opti
'
:
results
[
var_name
]
=
sol
.
value
(
var
)
opt
=
Optimizer
(
problem
)
results
=
opt
.
solve_optimization_problem
(
initial_guesses
,
solver_options
)
return
results
def
step
(
self
,
initial_state
,
target
,
prev_cmd
,
initial_guesses
=
None
):
...
...
@@ -147,6 +119,7 @@ class MPC:
solver_options
=
{
'
ipopt.print_level
'
:
self
.
print_level
,
'
print_time
'
:
self
.
print_time
,
'
ipopt.tol
'
:
self
.
acceptable_tol
,
'
ipopt.acceptable_tol
'
:
self
.
acceptable_tol
,
'
ipopt.acceptable_iter
'
:
self
.
acceptable_iter
}
...
...
This diff is collapsed.
Click to expand it.
guided_mrmp/optimizer.py
0 → 100644
+
37
−
0
View file @
e9780817
class
Optimizer
:
def
__init__
(
self
,
problem
):
self
.
problem
=
problem
def
solve_optimization_problem
(
self
,
initial_guesses
=
None
,
solver_options
=
None
):
opti
=
self
.
problem
[
'
opti
'
]
if
initial_guesses
:
for
param
,
value
in
initial_guesses
.
items
():
print
(
f
"
param =
{
param
}
"
)
print
(
f
"
value =
{
value
}
"
)
opti
.
set_initial
(
self
.
problem
[
param
],
value
)
# Set numerical backend, with options if provided
if
solver_options
:
opti
.
solver
(
'
ipopt
'
,
solver_options
)
else
:
opti
.
solver
(
'
ipopt
'
)
try
:
sol
=
opti
.
solve
()
# actual solve
status
=
'
succeeded
'
except
:
sol
=
None
status
=
'
failed
'
results
=
{
'
status
'
:
status
,
'
solution
'
:
sol
,
}
if
sol
:
for
var_name
,
var
in
self
.
problem
.
items
():
if
var_name
!=
'
opti
'
:
results
[
var_name
]
=
sol
.
value
(
var
)
return
results
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