After solving an optimal control problem in Gekko (IMODE = 6) is there any way to access or reconstruct the adjoint state p ? Since the documentation does not provide any resource for this, I hopping that there is an way to retrieve some information that may led to reconstruction of the adjoint state.
A bonus question, is there any optimal control solver (with python API) that returns the adjoint state?
There is the
m.options.SENSITIVITY = 1option ingekkoto producesensitivity.txtin the run directorym.path. However, this only works if there are zero DOF for simulation or an optimization problem that has zero DOF when the MV status is off.The other alternative is to add the adjoint equations to the problems. Here is an example dynamic optimization problem.
Adding the adjoint equation gives the value of
lam, as the sensitivity of the objective function to changes inx. The transversality condition for this problem is thatlam(T)=0(final time constraint) and the initial condition is calculated. This is achieved withfixed_initial=Falsewhen declaringlamand settingm.fix_final(lam,0)to fix the final value at zero.