Skip to content

Commit 1d53a36

Browse files
authored
Merge pull request #1 from JuliaOptimizationVariationalAnalysis/projection-solver
Add basic projection method
2 parents 6f4c6b2 + d23a951 commit 1d53a36

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ FastClosures = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
1111
NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6"
12+
Stopping = "c4fe5a9e-e7fb-5c3d-89d5-7f405ab2214f"
1213

1314
[compat]
1415
CaNNOLeS = "0.5"

src/VariationalInequalitySolver.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module VariationalInequalitySolver
22

3-
using FastClosures, LinearAlgebra, Logging, NLPModels
3+
using FastClosures, LinearAlgebra, Logging, NLPModels, Stopping
4+
5+
import NLPModels: residual!, jac_structure_residual!, jac_coord_residual!, jprod_residual!, jtprod_residual!, jac_op_residual!, hess_structure_residual!, hess_coord_residual!, hprod_residual!, hess_op_residual!
6+
47

58
abstract type AbstractVIModel{T, S} end
69

@@ -52,6 +55,7 @@ function project!(model::NLSVIModel, d::AbstractVector{T}, Px::AbstractVector{T}
5255
return Px
5356
end
5457

58+
include("solvers/projectionVI.jl")
5559
#=
5660
include("projector/ProjNLP.jl")
5761
include("solvers/penalizedVI.jl")

src/solvers/projectionVI.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
export ProjectionVI
2+
3+
function ProjectionVI(
4+
model::AbstractVIModel,
5+
x0::AbstractVector;
6+
rho0 :: Float64 = 0.5,
7+
kwargs...
8+
)
9+
stp = GenericStopping(model, x0; kwargs...)
10+
return ProjectionVI(stp, rho0 = rho0)
11+
end
12+
13+
function abresidual!(model, xk, rho, Fx) # xk + rho * F(xk)
14+
residual!(model, xk, Fx)
15+
Fx .*= rho
16+
Fx .+= xk
17+
return Fx
18+
end
19+
20+
function ProjectionVI(stp::AbstractStopping; rho0 :: Float64 = 0.5)
21+
xk = stp.current_state.x
22+
xkp = similar(xk)
23+
rho = rho0
24+
Fx = similar(xk)
25+
abresidual!(stp.pb, xk, rho, Fx)
26+
27+
OK = update_and_start!(stp)
28+
while !OK
29+
abresidual!(stp.pb, xk, rho, Fx)
30+
project!(stp.pb, Fx, xkp) # possible failure here
31+
32+
if norm(xk - xkp, Inf) < stp.meta.atol * rho
33+
stp.meta.optimal = true
34+
end
35+
OK = OK || update_and_stop!(stp, x = xk)
36+
end
37+
38+
return xk
39+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ Random.seed!(1234)
99
vi = NLSVIModel(nls)
1010
xr = rand(2)
1111
@test project(vi, xr) == xr
12+
sol = ProjectionVI(vi, xr)
1213
end

0 commit comments

Comments
 (0)