Model Variables with Limited Values¶
This article was originally posted to the AIMMS Tech Blog.
In this article we’ll learn how to model a variable that can only take a limited set of values, for example:
You can use binary variables to ensure exactly one of the values is selected. But let’s find out how to get the chosen option as a variable value again.
If you have the situation as given above, to have exactly one of the values selected, you can introduce the following three binary variables:
To ensure only one value gets selected, we add the following constraint:
To get the option that was chosen as a variable value again, we can use an easy modeling trick: sum the products of the binary variables with their corresponding values.
You can do so by introducing the following equality constraint (or use everything right of the equals sign in the definition attribute of variable \(x\)):
Because exactly one of the variables will take the value of
1, the sum will result in the variable \(x\) taking the value of the chosen option. All the other terms in the sum will have value
0, as the corresponding binary variables will have the value
Last Updated: July, 2020