Index labels auto updates
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 had 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']
In this example, Analytica 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'];
zssion with the new label.
- When
Power_type . "solar"is evaluated, it double checks that the index contains the label and issues a warning if not, helping you to find mistakes. The result of the evaluation is the text value"solar".
One change that can impact logic in other expressions throughout your model is a name change to an index label. This occurs when you have defined an index to be a List of Text, and then you have used the text values in the definitions (or other expressions) in other variables. For example:
Index Power_type ::= [ 'coal', 'gas', 'hydro', 'nuclear', 'solar', 'wind' ]
Variable Nems2_offset ::= If Power_type = 'solar' Then ...
This partial example illustrates a case where a label from the Power_type index, 'solar', appears in the definition of a different variable. At some point you might change one or more label names in Power_type which would cause the definition in Nems2_offset to become incorrect (and not necessarily in a way that throws an error).
You can 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.
Index-label syntax
In the above examples, Analytica automatically figures out to rewrite certain definitions that use text literals that correspond to an index label. It looks for equality or inequality comparison, use of the text literal in calls to Subscript (X[Power_type='solar']), PositionInIndex (including @[ Power_type = 'solar']), and SubIndex. It notices comparisons to a Choice variable that uses the index to a text literal. It finds literal definitions or cells when the domain is connected to the index.
Although it automatically finds and updates the most common and most obvious cases, it cannot recognize all cases where it can be far less obvious that text literal is associated with an index. This would include the following examples.
zssion with the new label.
- When
Power_type . "solar"is evaluated, it double checks that the index contains the label and issues a warning if not, helping you to find mistakes. The result of the evaluation is the text value"solar".
Enable comment auto-refresher