-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from CLeARoboticsLab/benchmark/trajectory-game
benchmark on trajectory games
- Loading branch information
Showing
9 changed files
with
333 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
[deps] | ||
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" | ||
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" | ||
LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
MixedComplementarityProblems = "6c9e26cb-9263-41b8-a6c6-f4ca104ccdcd" | ||
PATHSolver = "f5f7c340-0bb3-5c69-969a-41884d311d1b" | ||
ParametricMCPs = "9b992ff8-05bb-4ea1-b9d2-5ef72d82f7ad" | ||
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca" | ||
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | ||
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" | ||
TrajectoryGamesBase = "ac1ac542-73eb-4349-ae1b-660ab3609574" | ||
TrajectoryGamesExamples = "ff3fa34c-8d8f-519c-b5bc-31760c52507a" | ||
|
||
[sources] | ||
MixedComplementarityProblems = {path = ".."} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
""" Generate a random (convex) quadratic problem of the form | ||
min_x 0.5 xᵀ M x - ϕᵀ x | ||
s.t. Ax - b ≥ 0. | ||
NOTE: the problem may not be feasible! | ||
""" | ||
function generate_test_problem( | ||
::QuadraticProgramBenchmark; | ||
num_primals = 100, | ||
num_inequalities = 100, | ||
) | ||
G(x, y; θ) = | ||
let | ||
(; M, A, ϕ) = unpack_parameters( | ||
QuadraticProgramBenchmark(), | ||
θ; | ||
num_primals, | ||
num_inequalities, | ||
) | ||
M * x - ϕ - A' * y | ||
end | ||
|
||
H(x, y; θ) = | ||
let | ||
(; A, b) = unpack_parameters( | ||
QuadraticProgramBenchmark(), | ||
θ; | ||
num_primals, | ||
num_inequalities, | ||
) | ||
A * x - b | ||
end | ||
|
||
K(z, θ) = | ||
let | ||
x = z[1:num_primals] | ||
y = z[(num_primals + 1):end] | ||
|
||
[G(x, y; θ); H(x, y; θ)] | ||
end | ||
|
||
unconstrained_dimension = num_primals | ||
constrained_dimension = num_inequalities | ||
lower_bounds = [fill(-Inf, num_primals); fill(0, num_inequalities)] | ||
upper_bounds = fill(Inf, num_primals + num_inequalities) | ||
|
||
(; K, lower_bounds, upper_bounds) | ||
end | ||
|
||
"Generate a random parameter vector Θ corresponding to a convex QP." | ||
function generate_random_parameter( | ||
::QuadraticProgramBenchmark; | ||
rng, | ||
num_primals = 100, | ||
num_inequalities = 100, | ||
sparsity_rate = 0.9, | ||
) | ||
bernoulli = Distributions.Bernoulli(1 - sparsity_rate) | ||
|
||
M = let | ||
P = | ||
randn(rng, num_primals, num_primals) .* | ||
rand(rng, bernoulli, num_primals, num_primals) | ||
P' * P | ||
end | ||
|
||
A = | ||
randn(rng, num_inequalities, num_primals) .* | ||
rand(rng, bernoulli, num_inequalities, num_primals) | ||
b = randn(rng, num_inequalities) | ||
ϕ = randn(rng, num_primals) | ||
|
||
[reshape(M, length(M)); reshape(A, length(A)); b; ϕ] | ||
end | ||
|
||
"Unpack a parameter vector θ into the components of a convex QP." | ||
function unpack_parameters(::QuadraticProgramBenchmark, θ; num_primals, num_inequalities) | ||
M = reshape(θ[1:(num_primals^2)], num_primals, num_primals) | ||
A = reshape( | ||
θ[(num_primals^2 + 1):(num_primals^2 + num_inequalities * num_primals)], | ||
num_inequalities, | ||
num_primals, | ||
) | ||
|
||
b = | ||
θ[(num_primals^2 + num_inequalities * num_primals + 1):(num_primals^2 + num_inequalities * (num_primals + 1))] | ||
ϕ = θ[(num_primals^2 + num_inequalities * (num_primals + 1) + 1):end] | ||
|
||
(; M, A, b, ϕ) | ||
end |
Oops, something went wrong.