Set Up Your Own Problem¶
moba_muscod
uses complex numerical algorithms to solve Optimal Control Problems.
If everything is well designed, the algorithms work very efficient and you get
solutions quite fast. But when you start with a new problem there are many pitfalls
that can lead to slow performance or errors.
We recommend to stick to the following guide when setting up new problems. Always start with the most simplest model and problem formulation and add complexity step by step.
Load Model¶
Your model is exported as FMU and can be loaded by moba_muscod
:
import moba_muscod as momu
ocp = momu.OptimalControlProblem()
ocp.loadFMU('MyModel.fmu')
Your model might contain many parameters. By default they are all included as optimization variables. For our first steps we don’t want to have any parameter free for optimization:
ocp.selectParameters([])
Bounds and scaling values¶
We need to set start and scaling values as well as lower and upper bounds for all remaining optimization variables. That means for inputs and differential states. For large models this task is time consuming. That’s why we use a quick-start method to estimate bounds and scaling values from a simulation:
ocp.setTimeHorizon(nmsi=10, hstart=100.0)
ocp.estimateSettings()
Initial values for differential states and default values for inputs
are taken from the FMU. If you want to use other input values you can optionally
set them as argument to estimateSettings()
Cost function¶
For now we are only interested in getting the model running within moba_muscod
.
We don’t want to solve any optimization problem yet.
The cost function can be constant:
ocp.setCostFunction(mval='0.0')
Forward integration¶
Now, we want to do one forward integration and see if the model can be simulated
with moba_muscod
’s DAE solver. We set the maximum number of iterations to 0
and solve the problem:
ocp.config.itmax=0
ocp.solve()
If this runs without any error and in reasonable time, you are ready to set up the real optimization problem by adding meaningful bounds, cost functions and constraints.
If not, you need to fix the problems by iterating on your model. Try to start with small models and add complexity step by step.