Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ include("dummy_solver.jl")
include("test_logging.jl")
include("test_stats.jl")
include("test_callback.jl")
include("test_restart.jl")
17 changes: 17 additions & 0 deletions test/test_restart.jl
Original file line number Diff line number Diff line change
@@ -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