Index labels auto updates

(Redirected from Index-label dot syntax)

New to Analytica 7.0

When you rename an identifier Analytica automatically updates expressions using that identifier. And when you change labels in an Index, it automatically updates edit tables using that index (what we call Table Splicing). But prior to release 7.0, there was one annoying exception. When you change a label in an index, it wouldn't update expressions using that label. For example. suppose

Index Power_type := ['solar', 'wind', 'gas', 'nuclear']

If you edited Power_type to change 'solar' to 'PV' , it would break this expression:

Capacity[Power_type = 'solar']

But now, it automatically updates it to:

Capacity[Power_type = 'PV']

It sees that 'solar' is an element of Index Power_type and when you change it to 'PV' it so update the expression automatically. It can similarly detect and update equality and inequality comparisons and other expressions mentioning the Index and label, including

Choice, Multichoice, PositionInIndex,  SubIndex, and @[ Power_type = 'solar']). 

Index-dot-label syntax

However, there are some expressions where Analytica can't fix it because it can't figure out that the label is associated with the index. For example:

 Index Renewable_power_types := ['solar', 'wind'];
 Capacity[Power_type =Renewable_power_types ]

You can make sure that the index values are associated with their index using the <index>.<label> syntax, for example:

 Index Renewable_power_types := [Power_type .'solar', Power_type .'wind'];

In this case, any change to elements of Power_type will update the corresponding text values wherever they occur associated with the Index. This dot expression also checks that the label is a valid value of the Index and gives a warning if not.

This syntax provides two advantages:

  1. It tells Analytica that the text literal is the value in the index. If you later change the label in the index. Analytica will automatically rewrite this expression, replacing it with the new value. Hence, it makes the model robust to changes in index labels.
  2. During evaluation, it checks that "label" is indeed an element of the index. If not, it issues an evaluation-time warning. If you ignore the warning, the value is "label".

Domain attribute to check text values

You can also make use of the Domain attribute to also help Analytica spot cases where text literals should be associated with an index value. For example, suppose in another variable you have an edit table like:

Variable Power_plant_type ::= Table( Power_plant )
 ( 'gas', 'hydro', 'gas', 'solar' ....)

Each cell of the table contains a text entry. By itself there is no intrinsic association of these cell values to the index values of Power_type. The overlap may just be coincidence; hence, if you change a label in the Power_type index, Analytica won't rewrite these table cells. If they were indeed meant to refer to the labels of Power_type, that change could introduce a logical error into your model. You may also be faced with a time-consuming task of updating all the cells of the table.

In an example like this, you can use the Domain attribute to establish the association so that Analytica knows that the text values in this table are supposed to be the same text used in Power_type's index labels. You should set the domain type to be "Copy from index", and select Power_type as the index. With that configuration, if you now rename a label in Power_type, it will automatically rewrite the corresponding cells of the table.

See also

Comments


You are not allowed to post comments.