Skip to content

Commit d23a951

Browse files
committed
add Stopping + import
1 parent e0364a0 commit d23a951

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
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
julia = "1"

src/VariationalInequalitySolver.jl

Lines changed: 4 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

src/solvers/projectionVI.jl

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,37 @@ export ProjectionVI
33
function ProjectionVI(
44
model::AbstractVIModel,
55
x0::AbstractVector;
6-
prec :: Float64 = 1e-6,
76
rho0 :: Float64 = 0.5,
8-
itmax :: Int64 = 10000,
7+
kwargs...
98
)
10-
xk = copy(x0)
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
1122
xkp = similar(xk)
1223
rho = rho0
13-
i=0
14-
OK = false
1524
Fx = similar(xk)
16-
residual!(model, xk, Fx)
17-
Fx .*= rho
18-
Fx .+= xk # xk + rho * F(xk)
25+
abresidual!(stp.pb, xk, rho, Fx)
1926

20-
#main loop
27+
OK = update_and_start!(stp)
2128
while !OK
22-
residual!(model, xk, Fx)
23-
Fx .*= rho
24-
Fx .+= xk # xk + rho * F(xk)
25-
proj!(model, Fx, xkp) # possible failure here
29+
abresidual!(stp.pb, xk, rho, Fx)
30+
project!(stp.pb, Fx, xkp) # possible failure here
2631

27-
i=i+1
28-
OK=(i>=itmax) || (norm(xk-xkp,Inf)<prec*rho )
29-
xk = copy(xkp)
30-
end #end of main loop
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
3137

3238
return xk
33-
end
39+
end

0 commit comments

Comments
 (0)