Optimizer Quick Start
Introduction to Structured Optimization
The Analytica Optimizer releases from v,4.3 onward include a set of features, collectively called Structured Optimization, designed to simplify the optimization modeling process. In Structured Optimization format, Linear Programming (LP), Quadratic Programming (QP) and Nonlinear Programming (NLP) optimizations can all be modeled in similar ways. All types of optimization are specified using the «DefineOptimization()» function.
The «DefineOptimization()» function automatically analyzes your model to determine the type of optimization and selects the appropriate optimization engine, although you can still override this process if desired.
Another significant change associated with Structured Optimization is the introduction of the «Constraint» object type. «Constraint» objects give users the ability to specify constraints, or arrays of constraints, in common expression format using equality or inequality operators. This intuitive interface allows users to easily integrate different types of constraints and to organize constraint arrays efficiently.
This section includes simple NLP examples to demonstrate the roles of Decision variables, Constraint objects, Objective variables, and Decision attributes in the Structured Optimization framework. The same basic structure applies to LP and QP optimizations as well.
Notation
Throughout this guide, we use a shorthand notation for displaying the definitions of Analytica objects. An object’s class (e.g., Variable, Decision, Constraint, etc) and identifier is followed by :=, and then the definition is shown, e.g.:
The Optimum Can Example
The Optimum Can example determines the dimensions of a cylindrical object having a minimum surface area for a given volume. Admittedly, this is not a very interesting optimization problem. In fact, the solution can be derived on paper using basic differential calculus. (Spoiler alert! The optimum can has height equal to twice the radius.) But the simplicity of the example allows us to focus on the workflow and object relationships using the new Structured Optimization framework in Analytica.
Decisions
In this example we will decide on the Radius and Height of a cylindrical vessel. We represent each of these as a Decision variable in the influence diagram. The values we define for these nodes will be used as initial guesses for optimization types that require an initial guess (NLP or non-convex QP). Otherwise the definitions of these inputs are not important. We use 1cm as an initial guess for both the radius and height.
Decision Radius := 1
Decision Height := 1
Constants
Constants have no special interpretation in optimization definitions. They can be used as usual for values that stay constant in the model. In this example, we will use a Constant for the required volume which does not vary in the model.
Constant Required_Volume := 1000
Variables
General variables are used for intermediate values as well as for the central DefineOptimization() function described below. We also use a variable to define Volume of the cylinder.
Variable Volume := pi*Radius^2*Height
Constraints
Constraints contain equalities or inequalities that restrict the range of optimized results. In this example, we use a constraint object to enforce the minimum volume requirement on our can.
Constraint Volume_Constraint := (Volume >= Required_Volume)
Objectives
Most optimizations have an objective value to maximize or minimize. (Some problems are only concerned with feasible solutions that meet constraints.) In this example we are minimizing the surface area of our can. We define surface area using an Objective variable. The can has round disks at the top and base with surface area (πR2) and a tubular side with surface area (2πRH).
Objective Surface_area := 2 * (pi * Radius^2) + (2 * pi * Radius * Height)
The DefineOptimization() function
The DefineOptimization() function is the key component of all Structured Optimization models. It brings all other components together, specifying the optimization to be performed. This function is typically placed in a Variable object in the center of our influence diagram. Although this function includes many optional parameters, we will only use the core parameters in this example:
Decision:
Identifier for the decision node (or a list of identifiers separated by commas if there are multiple decisions). Specify All to include all decision nodes in the model or All in module to include all desired decisions within a designated module.
Constraint:
Identifier for the constraint node (or a list of identifiers separated by commas if there are multiple constraints). Specify All to include all constraint nodes in the model or All in module to include all desired constraints within a designated module. You can also specify inequality or equality expressions directly, or omit the parameter entirely in an unconstrained optimization problem.
Maximize/Minimize:
Use the words “Maximize” or “Minimize” depending on the type of problem. Follow this with an expression or with the identifier for the relevant objective node.
We define our Define Optimization node as:
Variable Opt := DefineOptimization(Decisions: Radius, Height, Constraints: Volume_Constraint, Minimize: Surface_area)
Viewing the Optimization Object
The DefineOptimization() function evaluates to a special object that contains detailed information about the optimization. The object appears as a blue hyperlink that shows the type of optimization problem you have constructed. In this case we see it is «NLP». You can double-click the optimization object to open a new window revealing internal details from the optimization engine. Clicking reference objects allows you to drill down to finer levels of detail. This information is also available by using the OptInfo() function (See “OptInfo(Opt, "Item", Decision, Constraint, asRef)” on page 79 for more details).
In this case, we have allowed Analytica to automatically determine the type of problem. Alternatively, you can specify the problem type along with the desired engine and other settings by adding optional parameters to DefineOptimization(). See the “Optimizer Function Reference” chapter on page 70 for more details about the Type and Engine parameters of DefineOptimization().
Obtaining the Solution
Now that we have specified an optimization, how do you compute and view the result? You may be tempted to re-evaluate the Radius and Height decision variables to see if their values have changed. But this is not how optimization works in Analytica. Input values always retain their original definitions. (In this case we simply used 1 as a dummy value for Radius and Height.) To obtain the solution, you need to create an output node defined with the OptSolution() function. This function usually uses two parameters:
OptSolution(Opt, Decision)
• Opt: Identifier for the node containing DefineOptimization()
• Decision: Identifier for the counterpart Decision input node
Decision Opt_Radius := OptSolution(Opt, Radius)
Decision Opt_Height := OptSolution(Opt, Height)
The Decision parameter is optional. If it is omitted, the solution will include all decisions along a local index named .DecisionVector.
Obtaining the Optimized Objective Value
To conveniently evaluate the optimized objective value (the surface area of the solution can) you can use the OptObjective() function. The only parameter is the identifier for the Define Optimization node.
Objective Opt_Surface := OptObjective(Opt)
Viewing Optimization Status
To check the status of an optimization, use the OptStatusText() function. Enter the identifier for the node containing DefineOptimization().
Variable Status := OptStatusText(Opt)
This will reveal a text string describing the status of the optimization result. Status messages differ according to problem characteristics and the engine being used. In general these messages indicate whether or not a feasible solution has been found and if so, whether or not the optimizer was able to converge to a bounded solution. In this example status is: “Optimal solution has been found.”
Copying Optimized Results to Definitions
In some cases, you may wish to copy the optimized decision values into the definition of the original decisions. With this, the result for variables downstream of the decisions will reflect their optimal values as well.
You can configure your model to copy optimized results into the original decisions by adding two buttons to your model. The first button solves for the optimal solution and copy the optimal values. The second button restores the original (non-optimized) definition. Functions provided in the Structured Optimization Tool.ana library take care of the details.
To configure these buttons:
1. With the diagram in focus, select Add Library... from the File menu. 2. Select Structured Optimization Tools.ana and press Open. Select Embed, OK. 3. Drag a button from the tool bar, title it “Set to Optimal”:
4. Click Expr to edit the button’s Script attribute. Enter: Use_opt_decisions( opt ).
5. Drag a second button to the diagram, name it “Restore Defintions” and set its Script attribute to: Restore_Decision_Defs( opt ).
Now we’re ready to try them out.
6. Press to enter browse mode. Press the Set to Optimal button. 7. Open the object window for Radius:

Enable comment auto-refresher