OptSolution
New to Analytica 4.3. For earlier versions, use LpSolution
OptSolution(prog,decision)
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 variable. «Decision» may be the identifier of a global decision variable that was passed to the «decisions» parameter of DefineOptimization, or a local variable that is current in lexical scope having the same identifier as a local variable passed to the «decisions» parameter of DefineOptimization. You 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 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.
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 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.
Examples
Find the minimum of the GammaFn(x) for x>0:
Var x := 1; Var prog := DefineOptimization( decisions:x, minimize: GammaFn(x), domain:Continuous(lb:0)); OptSolution(prog,x)
See Also
- LpSolution -- for Analytica 4.2 and earlier
- DefineOptimization OptStatusText, OptStatusNum
- OptStatusText, OptStatusNum
- OptObjective
Enable comment auto-refresher