Skip to content

Commit 1d0fae7

Browse files
committed
solver
1 parent eacdece commit 1d0fae7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/NLPModelsIpopt.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,27 @@ function SolverCore.reset!(solver::IpoptSolver, nlp::AbstractNLPModel)
107107
return problem
108108
end
109109

110+
"""
111+
solver = reset!(solver::IpoptSolver)
112+
113+
Reset the `solver` state without changing the underlying problem.
114+
This resets the solver's internal state while keeping the same problem structure and callbacks.
115+
"""
116+
function SolverCore.reset!(solver::IpoptSolver)
117+
problem = solver.problem
118+
119+
# Reset solver state to initial values
120+
problem.obj_val = Inf
121+
problem.status = -1 # Use -1 to indicate not solved yet
122+
problem.intermediate = nothing
123+
124+
# Note: We keep the same problem structure, callbacks, and initial guess
125+
# The user can call reset!(solver, nlp) if they want to change the problem
126+
127+
# TODO: reset problem.ipopt_problem
128+
return solver
129+
end
130+
110131
"""
111132
set_callbacks(nlp::AbstractNLPModel)
112133

test/runtests.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,15 @@ end
115115

116116
# Test that FeasibilityFormNLS is callable and returns the same object
117117
@test FeasibilityFormNLS(nls) === nls
118+
119+
# Test SolverCore.reset! method
120+
nlp = ADNLPModel(x -> (x[1] - 1)^2 + (x[2] - 1)^2, [0.0, 0.0])
121+
solver = IpoptSolver(nlp)
122+
123+
# Test that reset! can be called without error
124+
reset!(solver)
125+
126+
# Test that we can solve after reset
127+
result = solve!(solver, nlp, print_level=0)
128+
@test result.status == :first_order
118129
end

0 commit comments

Comments
 (0)