4. Class attributes

In the optimization formulation above, there are elements that occur only once, i.e., the cost function and the optimization interval. These elements are intrinsic properties of the respective optimization formulations, and should be specified, once, by the user. In this respect the cost function and optimization interval differ from, for example, constraints, since the user may specify zero, one or more of the latter.

In order to encode these elements, class attributes are introduced. A class attribute is an intrinsic element of a specialized class, and may be modified in a class declaration without the need to explicitly extend from a built-in class. In the Optimica extension, four class attributes are introduced for the specialized class optimization. These are objective, which defines the cost function, startTime, which defines the start of the optimization interval, finalTime, which defines the end of the optimization interval, and static, which indicates whether the class defines a static or dynamic optimization problem. The proposed syntax for class attributes is shown in the following optimization class:

optimization DIMinTime (
 DoubleIntegrator di(u(free=true,
 input Real u = di.u;
end DIMinTime;

The default value of the class attribute static is false, and accordingly, it does not have to be set in this case. In essence, the keyword extends and the reference to the built-in class have been eliminated, and the modification construct is instead given directly after the name of the class itself. The class attributes may be accessed and modified in the same way as if they were inherited.