@@ -572,18 +572,14 @@ function optim_objective!(mpc::LinMPC, b, q̃, p)
572572 ΔŨ0 = [lastΔŨ[(mpc. model. nu+ 1 ): (mpc. Hc* mpc. model. nu)]; zeros (mpc. model. nu)]
573573 # if soft constraints, append the last slack value ϵ_{k-1}:
574574 ! isinf (mpc. C) && (ΔŨ0 = [ΔŨ0; lastΔŨ[end ]])
575- set_start_value .(ΔŨ, ΔŨ0)
575+ # set_start_value.(ΔŨ, ΔŨ0)
576576 optimize! (optmodel)
577577 status = termination_status (optmodel)
578578 if ! (status == OPTIMAL || status == LOCALLY_SOLVED)
579- @warn " MPC termination status not OPTIMAL or LOCALLY_SOLVER ($status )"
579+ @warn " MPC termination status not OPTIMAL or LOCALLY_SOLVED ($status )"
580580 @debug solution_summary (optmodel)
581581 end
582- if has_values (optmodel)
583- ΔŨ = value .(ΔŨ)
584- else # if error, we take last value :
585- ΔŨ = ΔŨ0
586- end
582+ ΔŨ = isfatal (status) ? ΔŨ0 : value .(ΔŨ) # fatal status : use last value
587583 J = objective_value (optmodel) + p # optimal objective value by adding constant p
588584 return ΔŨ, J
589585end
@@ -973,6 +969,16 @@ function Base.show(io::IO, mpc::PredictiveController)
973969 print (io, " $(mpc. estim. model. nd) measured disturbances d" )
974970end
975971
972+ " Verify that the solver termination status means 'no solution available'."
973+ function isfatal (status:: TerminationStatusCode )
974+ fatalstatuses = [
975+ INFEASIBLE, DUAL_INFEASIBLE, LOCALLY_INFEASIBLE, INFEASIBLE_OR_UNBOUNDED,
976+ SLOW_PROGRESS, NUMERICAL_ERROR, INVALID_MODEL, INVALID_OPTION, INTERRUPTED,
977+ OTHER_ERROR
978+ ]
979+ return any (status .== fatalstatuses)
980+ end
981+
976982
977983" Functor allowing callable `PredictiveController` object as an alias for `moveinput!`."
978984function (mpc:: PredictiveController )(
0 commit comments