Error Messages/42425
Error message
You have specified Self as the first parameter to Choice, i.e., the parameter named «I». In this case since Self is Variable 'Selected_city', Choice expects 'Selected_city' to have a discrete domain with explicit values. But the domain of Variable 'Selected_city' is not discrete with explicit values.
Cause
The Domain attribute for your choice variable is not properly defined. It needs to be set to either Explicit values, Copy from index, or an Expression that evaluates to be an unindexed list. When set to Explicit values, the possible options for the Choice pulldown will be listed in the domain attribute. When using Copy from index, the possible options are copied from another existing index in your model (in this case, you can also simply set the first parameter of Choice to be the name of your index, rather than using Choice(Self,...)
).
Remedy
Open the Object Window for your choice variable and examine its Domain attribute. Select Explicit values from the domain type pulldown and enter the possible values.
Array-valued domain
A domain may evaluate to an array, which would not be applicable to a Choice, and hence cause this error. One case where this can be confusing is where you've set your domain to be an Explicit List with type set to Any, and entered identifiers in each cell. Although it looks like a list in the domain attribute, the actual domain is the result when that list is evaluated. Hence, if the variables listed are scalars, you are fine. But if a variable that is listed is array-valued, you end up with an array-valued domain.
Array-valued domains can result from a number of mistakes, and these can be confusing. One trick for helping to debug this is to look at the domain in Expression view. Then copy-paste that expression into the definition of another variable and evaluate it. As one example, suppose the domain expression is Discrete(I, type: 'all')
, where I
is defined as [0, 1, 2]. When you evaluate this Domain expression, you see:
This is an array, hence, you have an array-valued domain. Each cell here is a different set of allowed values. This array-valued domain says that the only legitimate value in the I = 0 slice of the result is 0. The only legit value in the I = 1 slice is 1. This domain is fine for correctness validation, although with only one legal value, probably not what you intended! But as an array-valued domain, it is not sensible for a Choice(Self,...)
.
Enable comment auto-refresher