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
90c9ed52
Commit
90c9ed52
authored
5 months ago
by
rachelmoan
Browse files
Options
Downloads
Patches
Plain Diff
Delete unused code
parent
a2bbca32
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
guided_mrmp/optimizers/optimizer.py
+0
-63
0 additions, 63 deletions
guided_mrmp/optimizers/optimizer.py
guided_mrmp/tests/traj_from_points_test.py
+0
-77
0 additions, 77 deletions
guided_mrmp/tests/traj_from_points_test.py
with
0 additions
and
140 deletions
guided_mrmp/optimizers/optimizer.py
deleted
100644 → 0
+
0
−
63
View file @
a2bbca32
import
cvxpy
as
opt
import
numpy
as
np
class
Optimizer
:
def
__init__
(
self
):
pass
def
solve
(
self
,
cost_function
,
constraints
,
initial_guess
):
"""
Solve the optimization problem.
Parameters:
- cost_function: Function to minimize
- constraints: List of constraints
- initial_guess: Initial guess for the optimizer
Returns:
- optimal_solution: The optimal control input found by the optimizer
"""
raise
NotImplementedError
(
"
This method should be implemented by a specific optimizer.
"
)
class
iLQR
(
Optimizer
):
def
__init__
(
self
,
nx
,
nu
,
control_horizon
):
self
.
nx
=
nx
self
.
nu
=
nu
self
.
control_horizon
=
control_horizon
def
solve
(
self
,
x
,
u
,
cost
,
constraints
,
initial_guess
=
None
):
"""
Solve the optimization problem.
Parameters:
- cost_function: Function to minimize
- constraints: List of constraints
- initial_guess: Optional initial guess for the optimizer
Returns:
- x_opt: Optimal state trajectory
- u_opt: Optimal control trajectory
"""
# Set up variables for the optimization problem
# x = opt.Variable((self.nx, self.control_horizon + 1))
# u = opt.Variable((self.nu, self.control_horizon))
# If initial guess is provided, set the initial values
# if initial_guess:
# x.value = initial_guess['x']
# u.value = initial_guess['u']
prob
=
opt
.
Problem
(
opt
.
Minimize
(
cost
),
constraints
)
# Solve the problem
prob
.
solve
(
solver
=
opt
.
OSQP
,
warm_start
=
True
,
verbose
=
False
)
if
prob
.
status
!=
opt
.
OPTIMAL
:
raise
ValueError
(
"
The optimization problem did not solve successfully.
"
)
# print(f"x val = {x.value}")
# print(f"u val = {u.value}")
return
x
.
value
,
u
.
value
\ No newline at end of file
This diff is collapsed.
Click to expand it.
guided_mrmp/tests/traj_from_points_test.py
deleted
100644 → 0
+
0
−
77
View file @
a2bbca32
import
time
import
numpy
as
np
from
guided_mrmp.utils
import
get_traj_from_points
,
plot_sim
,
Env
,
Roomba
from
guided_mrmp.planners
import
RRTStar
def
test_traj_from_points
():
T
=
1
# Prediction Horizon [s]
DT
=
0.2
# discretization step [s]
target_velocity
=
3.0
# m/s
num_robots
=
20
dynamics
=
Roomba
()
radius
=
10
N
=
20
env
=
Env
([
-
10
,
10
],
[
-
10
,
10
],
[],
[])
# Generate start and goal positions in a circle
angles
=
np
.
linspace
(
0
,
2
*
np
.
pi
,
num_robots
,
endpoint
=
False
)
robot_starts
=
[(
radius
*
np
.
cos
(
angle
),
radius
*
np
.
sin
(
angle
))
for
angle
in
angles
]
robot_goals
=
[(
radius
*
np
.
cos
(
angle
+
np
.
pi
),
radius
*
np
.
sin
(
angle
+
np
.
pi
))
for
angle
in
angles
]
success_count
=
0
total_time
=
0
x_hists
,
y_hists
,
h_hists
,
paths
=
[],
[],
[],
[]
for
i
in
range
(
num_robots
):
start_time
=
time
.
time
()
start
=
robot_starts
[
i
]
goal
=
robot_goals
[
i
]
try
:
rrtstar
=
RRTStar
(
env
,
(
start
[
0
],
start
[
1
]),
(
goal
[
0
],
goal
[
1
]),
0.5
,
0.05
,
500
,
r
=
2.0
)
rrtstarpath
=
rrtstar
.
run
()
rrtstarpath
=
list
(
reversed
(
rrtstarpath
))
xs
=
[]
ys
=
[]
for
node
in
rrtstarpath
:
xs
.
append
(
node
[
0
])
ys
.
append
(
node
[
1
])
dx
=
xs
[
1
]
-
xs
[
0
]
dy
=
ys
[
1
]
-
ys
[
0
]
theta
=
np
.
arctan2
(
dy
,
dx
)
x
,
y
,
h
,
path
=
get_traj_from_points
(
np
.
array
([
start
[
0
],
start
[
1
],
theta
]),
dynamics
,
target_velocity
,
T
,
DT
,
[
xs
,
ys
])
x_hists
.
append
(
x
)
y_hists
.
append
(
y
)
h_hists
.
append
(
h
)
paths
.
append
(
path
)
success_count
+=
1
except
Exception
as
e
:
print
(
f
"
Robot
{
i
}
failed to find a valid trajectory:
{
e
}
"
)
end_time
=
time
.
time
()
total_time
+=
(
end_time
-
start_time
)
print
(
f
"
Robot
{
i
}
took
{
end_time
-
start_time
:
.
2
f
}
seconds to find a trajectory
"
)
print
(
f
"
Success rate:
{
success_count
}
/
{
num_robots
}
"
)
print
(
f
"
Average time per robot:
{
total_time
/
num_robots
:
.
2
f
}
seconds
"
)
plot_sim
(
x_hists
,
y_hists
,
h_hists
,
paths
)
if
__name__
==
"
__main__
"
:
import
os
import
random
seed
=
42
print
(
f
"
***Setting Python Seed
{
seed
}
***
"
)
os
.
environ
[
'
PYTHONHASHSEED
'
]
=
str
(
seed
)
np
.
random
.
seed
(
seed
)
random
.
seed
(
seed
)
test_traj_from_points
()
\ No newline at end of file
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