Function OptScalarToConstraint(opt, constraint, scalarValues, constraintVector)

When you define a Structured Optimization problem using DefineOptimization(), any given constraint in the problem may have intrinsic indexes. A constraint with an intrinsic index becomes an array of scalar constraints. Internally, each constraint in the structured model must be flattened into a vector, and the vector for each constraint must be concatenated to obtain the scalar representation of the problem, which can the be passed to a solver engine. Analytica take care of this mapping from structured constraints to internal vector and back again for you. However, should a reason arise where you need to map from the scalar constraint vector back to an individual structured constraint, OptScalarToConstraint performs that mapping. It extracts the portion of the «scalarValues» corresponding to the indicated «constraint», then unflattens that subvector to obtain a result with the intrinsic indexes of «constraint».

To use, «opt» must be the result of a call to DefineOptimization, «constraint» must identify a constraint in the optimization, «scalarValues» is an array indexed by «constraintVector», which must have exactly the same number of elements as there are scalar constraints in the problem. The «constraintVector» index parameter is optional when «scalarValues» is 1-D.


The function call OptShadow(opt), with a single parameter, returns the shadow price for all scalar constraints. The shadow prices for one particular constraint, Ct2, can be obtained as:

var spv := OptShadow(opt) do OptScalarToConstraint(opt, Ct1, spv, spv.ConstraintVector)

This result is identical to what you get from a call to OptShadow(opt, Ct1) with the second parameter specified.


One example where it has been used has been as followed. A large LP model was formulated in Analytica using Structured Optimization. The scalar representation of the problem was exported using OptWrite, and an external optimization package (Gusek) was used to compute the solution (rather than one of the built-in Engines). The external solves wrote the shadow prices to a file, which was then loaded in and parsed, yielding a vector of the scalar shadow prices. These were then mapped back into the dimensionality of the original constraints and used within the model.


This function was introduced in Analytica 4.3.

See Also


You are not allowed to post comments.