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 -->
 
   
 
   
''[[New to Analytica 4.3]].  For earlier versions, use [[LpSolution]]''
 
  
= OptSolution(prog'',decision'') =
+
== OptSolution(opt'', decision'') ==
 +
Returns the solution to an optimization problem «opt» specified by [[DefineOptimization]].
  
Solves and returns the solution to an optimization problem specified by [[DefineOptimization]].  Use «decision» to specify which decision variable you want the solution for, and the result has the same indexes as that decision variableYou may omit «decision», in which case the result is a vector in indexed by a local index named '''''.Vars''''' containing all the scalar decision variables, which consists of a flattened version of all decision variables concatenated together.
+
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.  
  
If the problem has already been solved as a result of calling a related function, such as [[OptStatusText]], the solution is obtained immediately.  If it hasn't been solved yet ([[DefineOptimization]] defines and analyzes the structure of the problem, but doesn't solve it), then it launches the search for the solution.
+
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]].  
  
The value returned is only valid when the solver believes that an optimal, or likely optimal solution has been found. A warning results if no feasible solution is found and you have [[Preferences|Show Result Warnings]] turned on. You should always check [[OptStatusText]] or [[OptStatusNum]] to validate that a feasible and optimal solution has been found.  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.
+
[[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. 
  
= See Also =
+
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>
  
* [[LpSolution]] -- for Analytica 4.2 and earlier
+
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]], [[OptStatusNum]]
+
:<code>Variable D1_solution := VAR d1 := 0; OptSolution(OptimizeIt, d1)</code>
* [[OptStatusText]], [[OptStatusNum]]
+
 
 +
== 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.

See Also

Comments


You are not allowed to post comments.