Difference between revisions of "DefineOptimization"
Line 3: | Line 3: | ||
= DefineOptimization( decisions'', maximize/minimize, constraints, type, ... ) = | = DefineOptimization( decisions'', maximize/minimize, constraints, type, ... ) = | ||
− | + | Defines an optimization problem, in which Analytica Optimizer should find a set of values for the indicated decisions variables that satisfies all the indicated constraints and, if an objective is also specified, maximizes or minimizes the objective. The function is used for defining Linear Programs (LPs), Quadratic Programs (QPs), Quadratically Constrained Programs (QCPs), and Non-Linear Programs (NLPs). | |
− | [[DefineOptimization]] | + | [[DefineOptimization]] has a long list of optional parameters, but typically the core parameters («decisions», «minimize» or «maximize», and «constraints») suffice to define the optimization problem definition, with attributes within your model filling in the necessary details about each decision and constraint. You should generally use a named-parameter syntax when calling [[DefineOptimization]], by spelling out the name of each parameter followed by a colon, and then followed by argument(s) for that parameter. |
− | + | A problem definition always specifies one or more decision variables (i.e., there must be at least one thing to solve for or optimize). These are typically decision nodes in your model (the green rectangle nodes), although [[Var..Do|local variables]] may also be used as decision variables. Each decision variable may be scalar or array-valued. For example, when solving for an optimal portfolio allocation, the allocation decision would typically be dimensioned by an ''investment'' index. | |
− | Analytica | + | Many problems include an objective, which is an expression passed to either the «minimize» or «maximize» parameter, such that the expression depends directly or indirectly on the decision variables. To simply solve a system of equations and inequalities to find a feasible solution, the objective is omitted. When specified, the objective is a standard Analytica expression, typically one that computes a scalar result when the decision variables are set to a candidate solution. |
+ | |||
+ | Many problems also specify constraints that must be satisfied by any solution. A problem with no constraints is referred to as an ''unconstrained optimization problem'' and must have an objective function. You may specify any number of constraints, each being an equality or inequality expression. Each constraint may be array-valued, which in effect specifies a collection of constraints that must be satisfied. | ||
+ | |||
+ | The «type» parameter is optional, but may be explicitly specified as 'LP', 'QP', 'QCP', 'CQCP', 'NCQCP', 'NLP', or 'NSP'. (Linear, Quadratic, Quadratically constrained, Convex Quadratically Constrained, Non-convex Quadratically Constrained, Non-Linear, or Non-Smooth). When this is omitted, Analytica will automatically analyze the model to determine the problem type, and will select the solver engine that is appropriate for that type of problem. When you explicitly specify «type», an error will be reported if the problem is found to be outside of that problem class. To utilize a linear or quadratic solver, your model must contain only linear (or quadratic) relationships. | ||
+ | |||
+ | Note that all types of problems, linear, quadratic, non-linear alike, are formulated in the same way, using the structure of an Analytica model, and all formulated using [[DefineOptimization]]. The [[DefineOptimization]] function supercedes the older [[LpDefine]], [[QpDefine]] and [[NlpDefine]] functions that were used in Analytica 4.0 through Analytica 4.2, although these older functions are still available to be used in the cases where they are more convenient. | ||
+ | |||
+ | = Examples = | ||
+ | |||
+ | Suppose your model has two decision node variables, ''X'' and ''Y''. The following specifies a linear program: | ||
+ | |||
+ | [[DefineOptimization]]( | ||
+ | Decisions: X,Y, | ||
+ | Maximize: 3*X + 2*Y, | ||
+ | Constraints: 5*X + 2*Y <= 900, | ||
+ | 8*X + 10*Y <= 2800 ) | ||
+ | |||
+ | Local variables may also be used for the decision variables: | ||
+ | |||
+ | [[Var]] X := 0; | ||
+ | [[Var]] Y := 0; | ||
+ | [[DefineOptimization]]( | ||
+ | Decisions:X,Y, | ||
+ | Maximize: X + 4*Y, | ||
+ | Constraints: | ||
+ | 4*X >= Y-2 | ||
+ | 2*X <= Y+1 ) | ||
+ | |||
+ | = Variable/Node Classes = | ||
+ | |||
+ | In most cases, constraints and objectives are encoded within Analytica variables as part of a larger model. When so doing, the variable (or node) class becomes relevant, where the following distinguished variable classes are used for the respective components of the optimization problem: | ||
+ | |||
+ | [[image::Variable node classes.png]] |
Revision as of 21:35, 7 September 2010
New to Analytica 4.3
DefineOptimization( decisions, maximize/minimize, constraints, type, ... )
Defines an optimization problem, in which Analytica Optimizer should find a set of values for the indicated decisions variables that satisfies all the indicated constraints and, if an objective is also specified, maximizes or minimizes the objective. The function is used for defining Linear Programs (LPs), Quadratic Programs (QPs), Quadratically Constrained Programs (QCPs), and Non-Linear Programs (NLPs).
DefineOptimization has a long list of optional parameters, but typically the core parameters («decisions», «minimize» or «maximize», and «constraints») suffice to define the optimization problem definition, with attributes within your model filling in the necessary details about each decision and constraint. You should generally use a named-parameter syntax when calling DefineOptimization, by spelling out the name of each parameter followed by a colon, and then followed by argument(s) for that parameter.
A problem definition always specifies one or more decision variables (i.e., there must be at least one thing to solve for or optimize). These are typically decision nodes in your model (the green rectangle nodes), although local variables may also be used as decision variables. Each decision variable may be scalar or array-valued. For example, when solving for an optimal portfolio allocation, the allocation decision would typically be dimensioned by an investment index.
Many problems include an objective, which is an expression passed to either the «minimize» or «maximize» parameter, such that the expression depends directly or indirectly on the decision variables. To simply solve a system of equations and inequalities to find a feasible solution, the objective is omitted. When specified, the objective is a standard Analytica expression, typically one that computes a scalar result when the decision variables are set to a candidate solution.
Many problems also specify constraints that must be satisfied by any solution. A problem with no constraints is referred to as an unconstrained optimization problem and must have an objective function. You may specify any number of constraints, each being an equality or inequality expression. Each constraint may be array-valued, which in effect specifies a collection of constraints that must be satisfied.
The «type» parameter is optional, but may be explicitly specified as 'LP', 'QP', 'QCP', 'CQCP', 'NCQCP', 'NLP', or 'NSP'. (Linear, Quadratic, Quadratically constrained, Convex Quadratically Constrained, Non-convex Quadratically Constrained, Non-Linear, or Non-Smooth). When this is omitted, Analytica will automatically analyze the model to determine the problem type, and will select the solver engine that is appropriate for that type of problem. When you explicitly specify «type», an error will be reported if the problem is found to be outside of that problem class. To utilize a linear or quadratic solver, your model must contain only linear (or quadratic) relationships.
Note that all types of problems, linear, quadratic, non-linear alike, are formulated in the same way, using the structure of an Analytica model, and all formulated using DefineOptimization. The DefineOptimization function supercedes the older LpDefine, QpDefine and NlpDefine functions that were used in Analytica 4.0 through Analytica 4.2, although these older functions are still available to be used in the cases where they are more convenient.
Examples
Suppose your model has two decision node variables, X and Y. The following specifies a linear program:
DefineOptimization( Decisions: X,Y, Maximize: 3*X + 2*Y, Constraints: 5*X + 2*Y <= 900, 8*X + 10*Y <= 2800 )
Local variables may also be used for the decision variables:
Var X := 0; Var Y := 0; DefineOptimization( Decisions:X,Y, Maximize: X + 4*Y, Constraints: 4*X >= Y-2 2*X <= Y+1 )
Variable/Node Classes
In most cases, constraints and objectives are encoded within Analytica variables as part of a larger model. When so doing, the variable (or node) class becomes relevant, where the following distinguished variable classes are used for the respective components of the optimization problem:
[[image::Variable node classes.png]]
Enable comment auto-refresher