ComparisonPart
Requires the Optimizer edition'.'
New to Analytica 5.0
Contents
ComparisonPart( c, item, n )
A Constraint node specifies a inequality or equality relationships that are used by solver engines when solving an optimization. These display as evaluated comparisons in the result table of a constraint node. For example, in a constraint defined as
 x < y
The result view shows 10 < 20
, rather than just 1 (for true), which can be helpful when debugging or when trying to understand the impact of proposed solutions. These values are called comparison terms. The ComparisonPart function gives you access to the separate components of these, such as the value on the lefthand side or righthand side, or the type of comparison.
ComparisonPart can be useful in the Cell Format Expression attribute of a constraint node to color code constraint violations.
Parameters
c
The «c» parameter takes a comparison value. This will typically need to be the identifier of a constraint node, although you can use Subscript or Slice operations, as well as any other Analytica expression logic, to extract a particular comparison. The result of a constraint node is really the only place you'll gain access to a comparison term, since these comparison terms are normally only maintained for the final results of a constraint node, It would not work to evaluate ComparisonPart( x<y, 'Slack')
because the result of evaluating an inequality is simply a Boolean value.
If you pass anything other than a comparison term to «c», the result is Null.
item
The information requested, with the possible values of «item» being:

'LHS'
: The lefthand side value. 
'RHS'
: The righthand side value. 
'Sense'
: The type of comparison, which will be one of'<'
,'>'
or'='
. 
'Slack'
: For a constraint that is strictly satisfied, this is the amount that one side could change before the constraint is strictly violated as is a positive number. For a constraint that is strictly violated (even by a miniscule amount), this is a negative number, where the magnitude reveals by how far the constraint is violated. 
'Violated'
: A Boolean equal to 1 if the constraint is satisfied, or within Sys_ConstraintTolerance of being satisfied. This is equivalent theComparisonPart(c,'Slack')>=Sys_ConstraintTolerance
. 
'N'
: The number of cascadedcomparison stages. For example,0.0 < 0.5 < 1.0
has two stages.
n
Optional. For a cascaded comparison, use «n» to specify which stage you want information for. When requesting 'Slack'
or 'Violated'
, the return value applies to that stage only when «n» is specified, or to the constraint as a whole when «n» is omitted.
Examples
Constraint Ct1 := w < x < y < z
This evaluates to: 10 < 20.0000001 < 20 < 50
Then:
ComparisonPart(Ct1, 'N') → 3
ComparisonPart( Ct1, 'LHS' ) → 10
ComparisonPart( Ct1, 'LHS',1 ) → 10
ComparisonPart( Ct1, 'RHS' ) → 20.0000001
ComparisonPart( Ct1, 'RHS' ,1) → 20.0000001
ComparisonPart( Ct1, 'Sense' ) → '<'
ComparisonPart( Ct1, 'LHS',2 ) → 20.0000001
ComparisonPart( Ct1, 'LHS',4 ) → 50
ComparisonPart( Ct1, 'Slack' ) → 0.0000001
ComparisonPart( Ct1, 'Violated' ) → 0
{ When Sys_ComparisonTolerance = 1e6 }ComparisonPart( Ct1, 'Slack',3 ) → 30
To color code violated constraints in the result table of a constraint node, you can set the Cell Format Expression attribute to
or
You could depict the amount of slack or violation as
Enable comment autorefresher