Difference between revisions of "OptSolution"
(10 intermediate revisions by 4 users not shown) | |||
Line 2: | Line 2: | ||
[[Category:Doc Status D]] <!-- For Lumina use, do not change --> | [[Category:Doc Status D]] <!-- For Lumina use, do not change --> | ||
− | |||
− | = OptSolution( | + | == OptSolution(opt'', decision'') == |
+ | Returns the solution to an optimization problem «opt» specified by [[DefineOptimization]]. | ||
− | + | If you specify as «decision» the name of a global Decision variable used in the Optimization, it returns the solution (optimal value) for that decision. If you omit «decision», it returns the solution to all Decision variables as a vector indexed by a local index '''.Vars''', which contains all the decision values flattened so that each solution is a scalar. | |
− | + | Evaluating a variable that uses [[OptSolution]]() will trigger an attempt to solve the optimization problem, unless it has already been solved by another call to [[OptSolution]], or a related function, such as [[OptStatusText]]. | |
− | + | [[OptSolution]] returns a result when it finds an optimal, or likely optimal solution. If it finds no feasible solution it gives a warning if you have [[Preferences|Show Result Warnings]] turned on. It is entirely possible that there is no solution, or that the solver could not find a feasible solution, in which cases the values returned by [[OptSolution]] are arbitrary. So, you should always check [[OptStatusText]] or [[OptStatusNum]] to check that it has found a feasible and optimal solution. | |
− | = | + | If the Optimization used a local variable, say <code>D1</code>, as a Decision, declared as local in the expression using [[DefineOptimization]], for example |
+ | :<code>Variable OptimizeIt := VAR d1 := 0; DefineOptimization(Decisions: d1; ....)</code> | ||
− | + | you can get its solution by defining a local with the same identifier, <code>D1</code>, preceding [[OptSolution]](), and giving <code>D1</code> as «decision»: | |
− | * [[DefineOptimization]] [[OptStatusText]] | + | :<code>Variable D1_solution := VAR d1 := 0; OptSolution(OptimizeIt, d1)</code> |
− | * [[OptStatusText]] | + | |
+ | == Example == | ||
+ | Find the minimum of the [[GammaFn]](x) for <code>x > 0</code>: | ||
+ | |||
+ | :<code>Var x := 1;</code> | ||
+ | :<code>Var opt := DefineOptimization(decisions: x, minimize: GammaFn(x), domain: Continuous(lb: 0));</code> | ||
+ | :<code>OptSolution(opt, x)</code> | ||
+ | |||
+ | ==History== | ||
+ | This function was introduced in [[Analytica 4.3]], in earlier versions, use [[LpSolution]]. | ||
+ | |||
+ | == See Also == | ||
+ | * [[Using SetContext to efficiently solve NLPs]] | ||
+ | * [[DefineOptimization]] | ||
+ | * [[OptInfo]] | ||
+ | * [[OptStatusText]] | ||
+ | * [[OptStatusNum]] | ||
+ | * [[OptStatusText]] | ||
+ | * [[OptStatusNum]] | ||
* [[OptObjective]] | * [[OptObjective]] |
Latest revision as of 23:56, 3 February 2016
OptSolution(opt, decision)
Returns the solution to an optimization problem «opt» specified by DefineOptimization.
If you specify as «decision» the name of a global Decision variable used in the Optimization, it returns the solution (optimal value) for that decision. If you omit «decision», it returns the solution to all Decision variables as a vector indexed by a local index .Vars, which contains all the decision values flattened so that each solution is a scalar.
Evaluating a variable that uses OptSolution() will trigger an attempt to solve the optimization problem, unless it has already been solved by another call to OptSolution, or a related function, such as OptStatusText.
OptSolution returns a result when it finds an optimal, or likely optimal solution. If it finds no feasible solution it gives a warning if you have Show Result Warnings turned on. It is entirely possible that there is no solution, or that the solver could not find a feasible solution, in which cases the values returned by OptSolution are arbitrary. So, you should always check OptStatusText or OptStatusNum to check that it has found a feasible and optimal solution.
If the Optimization used a local variable, say D1
, as a Decision, declared as local in the expression using DefineOptimization, for example
Variable OptimizeIt := VAR d1 := 0; DefineOptimization(Decisions: d1; ....)
you can get its solution by defining a local with the same identifier, D1
, preceding OptSolution(), and giving D1
as «decision»:
Variable D1_solution := VAR d1 := 0; OptSolution(OptimizeIt, d1)
Example
Find the minimum of the GammaFn(x) for x > 0
:
Var x := 1;
Var opt := DefineOptimization(decisions: x, minimize: GammaFn(x), domain: Continuous(lb: 0));
OptSolution(opt, x)
History
This function was introduced in Analytica 4.3, in earlier versions, use LpSolution.
Enable comment auto-refresher