MadNLP / DynamicNLPModels.jl

NLPModels for dynamic optimization
MIT License
11 stars 1 forks source link

Added functions to reset `s0` within the dense and sparse models #44

Closed dlcole3 closed 2 years ago

dlcole3 commented 2 years ago

After each sample period, the new initial states, s0, need to be reset within the model. This PR adds support for resetting that value within the dynamic data and impacted parts of the dynamic model. The function reset_s0! is now exported so that the user can reset this value. In addition, I added tests for this function within runtests.jl and I reformatted the test/ subdirectory slightly so that all of the functions are in their own file.

In the sparse formulation, reset_s0! resets s0 within the dynamic data, and it resets the variable bounds on s at time 0 (thus fixing the first state to the value of s0.

For the dense formulation, reset_s0! resets s0 in the dynamic data, and it also calculates a new linear and constant term in the objective function. It also changes the impacted constraint bounds for the Jacobian. Because resetting s0 should be a quick and efficient call, I added blocks to the DenseLQDynamicBlocks that store the matrices needed to get the new linear and constant terms and for calculating the new constraint bounds. This also meant reconfiguring the functions _build_H_blocks and _set_G_blocks!. The data within DenseLQDynamicBlocks is designed to just be multiplied by s0 to get the desired final values.