5. Constraints

Constraints are similar to equations, and in fact, a path equality constraint is equivalent to a Modelica equation. But in addition, inequality constraints, as well as point equality and inequality constraints should be supported. It is therefore natural to have a separation between equations and constraints. In Modelica, initial equations, equations, and algorithms are specified in separate sections, within a class body. A reasonable alternative for specifying constraints is therefore to introduce a new kind of section, constraint. Constraint sections are only allowed inside an optimization class, and may contain equality, inequality as well as point constraints. In the double integrator example, there are several constraints. Apart from the constraints specifying bounds on the control input u and the velocity v, there are also terminal constraints. The latter are conveniently expressed using the mechanism for accessing the value of a variable at a particular time instant; di.x(finalTime)=1 and di.v(finalTime)=0. In addition, bounds may have to be specified for the finalTime class attribute. The resulting optimization formulation may now be written:

optimization DIMinTime (
    objective=finalTime,
    startTime=0,
    finalTime(free=true,initialGuess=1))
 DoubleIntegrator di(u(free=true,
                       initialGuess=0.0));
 input Real u = di.u; 
constraint
 finalTime>=0.5;
 finalTime<=10;
 di.x(finalTime)=1;
 di.v(finalTime)=0;
 di.v<=0.5;
 di.u>=-1; di.u<=1;
end DIMinTime;

The Optimica specification can be translated into executable format and solved by a numerical solver, yielding the result seen in Figure 10.1.

Figure 10.1. Optimization result

Optimization result