How can I restrict a variable that can only take value in a list?
Ongoinglist1=[1,2,3,4];
i want a variable that can only take value in that list
-
It is not possible to give an arbitrary list that indicates the allowed values of a variable.
If your variable is only allowed to take a value 1,2,3, or 4, you could define an integer variable with lower bound 1 and upper bound 4.0 -
Dear Marika, dear Morris,
as a workaround, one can try to use indicator variables and constraints to model the desired behaviour (have a look here for an example). This will most likely not scale well though.
Best regards
Jonasz0 -
Thank for Jonasz's help.
I have a idea to achieve it. Using indicator variables and limiting x like (0.9999<=x<=1.0001)&(1.9999<=x<=2.0001)...
There's a similar problem that bothers me. I post it below.
x only can equal 1 or 2 or 3 or 4
y only can equal 2 or 3 or 4 or 5,y is related to x.
for example, x==1, y==2 or x==2, y==3 or ...
And I usually code in matlab, it is hard to express the above by martix.
0
Please sign in to leave a comment.
Comments
3 comments