diff --git a/src/solver.jl b/src/solver.jl index 17ed99e..29d2f3a 100644 --- a/src/solver.jl +++ b/src/solver.jl @@ -5,6 +5,15 @@ abstract type AbstractSolver end abstract type AbstractOptimizationSolver <: AbstractSolver end +""" + reset!(solver::AbstractOptimizationSolver, model::AbstractNLPModel) + +Use in the context of restarting or reusing the `solver` structure. +Reset the internal fields of `solver` for the `model` before calling `solve!` on the same structure. +`model` must have the same number of variables, bounds and constraints as that used to instantiate `solver`. +""" +function NLPModels.reset!(::AbstractOptimizationSolver, ::AbstractNLPModel) end + """ solve!(solver, model; kwargs...) solve!(solver, model, stats; kwargs...) diff --git a/test/runtests.jl b/test/runtests.jl index c87c05e..96ffa36 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -12,3 +12,4 @@ include("dummy_solver.jl") include("test_logging.jl") include("test_stats.jl") include("test_callback.jl") +include("test_restart.jl") diff --git a/test/test_restart.jl b/test/test_restart.jl new file mode 100644 index 0000000..6f8a5fd --- /dev/null +++ b/test/test_restart.jl @@ -0,0 +1,17 @@ +@testset "test restart" begin + nlp = ADNLPModel(x -> dot(x, x) / 2, ones(2), x -> [sum(x .^ 3) - 1], [0.0], [0.0]) + solver = DummySolver(nlp) + stats = GenericExecutionStats(nlp) + solve!(solver, nlp, stats, verbose = false) + @test stats.status == :first_order + # Try with a new intial guess + nlp.meta.x0 .= 0.2 + reset!(solver, nlp) + solve!(solver, nlp, stats, verbose = false) + @test stats.status == :first_order + # Try with a new problem of the same size + nlp = ADNLPModel(x -> dot(x, x) / 2, ones(2), x -> [sum(x .^ 3)], [0.0], [0.0]) + reset!(solver, nlp) + solve!(solver, nlp, stats, verbose = false) + @test stats.status == :first_order +end