From 29977d0cd17447eb82a28d7ab9f7f9d8319d0fa1 Mon Sep 17 00:00:00 2001 From: dfridovi Date: Wed, 27 Nov 2024 16:55:59 -0600 Subject: [PATCH 1/4] adjusting \epsilon upward when linesearch fails --- src/solver.jl | 2 +- test/runtests.jl | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/solver.jl b/src/solver.jl index adfd9d2..4808f97 100644 --- a/src/solver.jl +++ b/src/solver.jl @@ -66,7 +66,7 @@ function solve( iters += 1 end - ϵ *= 1 - exp(-iters) + ϵ *= (status == :solved) ? 1 - exp(-iters) : 1 + exp(-iters) end (; status, x, y, s, kkt_error, ϵ) diff --git a/test/runtests.jl b/test/runtests.jl index 087e52e..cbc9bb1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -16,7 +16,7 @@ using FiniteDiff: FiniteDiff M = [2 1; 1 2] A = [1 0; 0 1] b = [1; 1] - θ = zeros(2) + θ = rand(2) G(x, y; θ) = M * x - A' * y - θ H(x, y; θ) = A * x - b @@ -28,12 +28,12 @@ using FiniteDiff: FiniteDiff end function check_solution(sol) - @test all(abs.(G(sol.x, sol.y; θ)) .≤ 1e-3) + @test all(abs.(G(sol.x, sol.y; θ)) .≤ 2e-3) @test all(H(sol.x, sol.y; θ) .≥ 0) @test all(sol.y .≥ 0) - @test sum(sol.y .* H(sol.x, sol.y; θ)) ≤ 1e-3 - @test all(sol.s .≤ 1e-3) - @test sol.kkt_error ≤ 1e-3 + @test sum(sol.y .* H(sol.x, sol.y; θ)) ≤ 2e-3 + @test all(sol.s .≤ 2e-3) + @test sol.kkt_error ≤ 2e-3 @test sol.status == :solved end From a477dfb7b2c077b890d33a0a9d53f7dbda71677e Mon Sep 17 00:00:00 2001 From: dfridovi Date: Wed, 27 Nov 2024 17:32:40 -0600 Subject: [PATCH 2/4] adding max outer iters to ensure fails gracefully --- src/solver.jl | 19 +++++++++++++------ test/runtests.jl | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/solver.jl b/src/solver.jl index 4808f97..0aa82bf 100644 --- a/src/solver.jl +++ b/src/solver.jl @@ -22,7 +22,8 @@ function solve( x₀ = zeros(mcp.unconstrained_dimension), y₀ = ones(mcp.constrained_dimension), tol = 1e-4, - max_inner_iters = 20 + max_inner_iters = 20, + max_outer_iters = 20 ) x = x₀ y = y₀ @@ -31,11 +32,12 @@ function solve( ϵ = 1.0 kkt_error = Inf status = :solved - while kkt_error > tol && ϵ > tol - iters = 1 + outer_iters = 1 + while kkt_error > tol && ϵ > tol && outer_iters < max_outer_iters + inner_iters = 1 status = :solved - while kkt_error > ϵ && iters < max_inner_iters + while kkt_error > ϵ && inner_iters < max_inner_iters # Compute the Newton step. # TODO! Can add some adaptive regularization. F = mcp.F(x, y, s; θ, ϵ) @@ -63,10 +65,15 @@ function solve( y += α_y * δy kkt_error = maximum(abs.(F)) - iters += 1 + inner_iters += 1 end - ϵ *= (status == :solved) ? 1 - exp(-iters) : 1 + exp(-iters) + ϵ *= (status == :solved) ? 1 - exp(-inner_iters) : 1 + exp(-inner_iters) + outer_iters += 1 + end + + if outer_iters == max_outer_iters + status = :failed end (; status, x, y, s, kkt_error, ϵ) diff --git a/test/runtests.jl b/test/runtests.jl index cbc9bb1..22edcca 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -14,6 +14,7 @@ using FiniteDiff: FiniteDiff 0 ≤ y ⟂ H(x, y) = Ax - b ≥ 0. """ M = [2 1; 1 2] + # M = [0 1; -1 0] A = [1 0; 0 1] b = [1; 1] θ = rand(2) From 00293d10db35831ca6de5f5a72a7b9cd9fe2d24e Mon Sep 17 00:00:00 2001 From: dfridovi Date: Wed, 27 Nov 2024 17:36:17 -0600 Subject: [PATCH 3/4] bumping max outer iters --- src/solver.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver.jl b/src/solver.jl index 0aa82bf..6ac82c3 100644 --- a/src/solver.jl +++ b/src/solver.jl @@ -23,7 +23,7 @@ function solve( y₀ = ones(mcp.constrained_dimension), tol = 1e-4, max_inner_iters = 20, - max_outer_iters = 20 + max_outer_iters = 50 ) x = x₀ y = y₀ From f8cd217809cc93d1f6bd00a5af8cc917288bd488 Mon Sep 17 00:00:00 2001 From: dfridovi Date: Sat, 30 Nov 2024 18:40:03 -0600 Subject: [PATCH 4/4] removing unneeded deps in examples --- examples/Project.toml | 8 +------- test/runtests.jl | 1 - 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/examples/Project.toml b/examples/Project.toml index 764659d..7cc6b41 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -1,19 +1,13 @@ [deps] BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" -ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" -FastDifferentiation = "eb9bf01b-bf85-4b60-bf87-ee5de06c00be" -FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41" -ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a" LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" MixedComplementarityProblems = "6c9e26cb-9263-41b8-a6c6-f4ca104ccdcd" ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca" -Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" TrajectoryGamesBase = "ac1ac542-73eb-4349-ae1b-660ab3609574" TrajectoryGamesExamples = "ff3fa34c-8d8f-519c-b5bc-31760c52507a" -Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [sources] -MixedComplementarityProblems = {path = ".."} \ No newline at end of file +MixedComplementarityProblems = {path = ".."} diff --git a/test/runtests.jl b/test/runtests.jl index 22edcca..cbc9bb1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -14,7 +14,6 @@ using FiniteDiff: FiniteDiff 0 ≤ y ⟂ H(x, y) = Ax - b ≥ 0. """ M = [2 1; 1 2] - # M = [0 1; -1 0] A = [1 0; 0 1] b = [1; 1] θ = rand(2)