You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- ode_solver: Takes in a symbol representing the solver. Acceptable solvers may be found at https://docs.sciml.ai/DiffEqDevDocs/stable/internals/tableaus/. Note that the symbol may be different than the typical name of the solver, e.g. :Tsitouras5 rather than Tsit5.
199
+
200
+
Returns a JuMPControlSolution, which contains both the model and the ODE solution.
197
201
"""
198
202
function DiffEqBase.solve(prob::JuMPControlProblem, jump_solver, ode_solver::Symbol)
199
203
model = prob.model
200
204
tableau_getter =Symbol(:construct, ode_solver)
201
205
@eval tableau =$tableau_getter()
202
206
ts =supports(model[:t])
207
+
208
+
# Unregister current solver constraints
209
+
for con inall_constraints(model)
210
+
ifoccursin("solve", JuMP.name(con))
211
+
unregister(model, Symbol(JuMP.name(con)))
212
+
delete(model, con)
213
+
end
214
+
end
215
+
for var inall_variables(model)
216
+
@show JuMP.name(var)
217
+
ifoccursin("K", JuMP.name(var))
218
+
unregister(model, Symbol(JuMP.name(var)))
219
+
delete(model, var)
220
+
end
221
+
end
203
222
add_solve_constraints!(prob, tableau)
204
223
205
224
set_optimizer(model, jump_solver)
206
225
optimize!(model)
207
226
208
-
ifis_solved_and_feasible(model)
209
-
sol = DiffEqBase.build_solution(prob, ode_solver, ts, value.(U))
210
-
JuMPControlSolution(model, sol)
211
-
else
212
-
sol = DiffEqBase.build_solution(prob, ode_solver, ts, value.(U))
227
+
tstatus =termination_status(model)
228
+
pstatus =primal_status(model)
229
+
!has_values(model) &&error("Model not solvable; please report this to github.com/SciML/ModelingToolkit.jl.")
230
+
231
+
U_vals =value.(model[:U])
232
+
U_vals = [[U_vals[i][j] for i in1:length(U_vals)] for j in1:length(ts)]
233
+
sol = DiffEqBase.build_solution(prob, ode_solver, ts, U_vals)
0 commit comments