How do I restrict the increments of a variable to certain values only?

Frequently asked questions about GAMS

Moderator: aileen

Forum rules
Please ask questions in the other sub-forums
Locked
aileen
User
User
Posts: 136
Joined: 4 years ago

How do I restrict the increments of a variable to certain values only?

Post by aileen »

I've got a model that is working correctly. It includes a positive variable x(metals), which contains the results I'm seeking. I thought it might be interesting to restrict x to increments of a quarter of a unit. For example, x = 1, 1.25, 1.5, 1.75, 2, etc. would be encouraged, while x = 1.35, 1.47, etc., would be discouraged.
aileen
User
User
Posts: 136
Joined: 4 years ago

Re: How do I restrict the increments of a variable to certain values only?

Post by aileen »

Contributed by Arne Drud: You will need an integer variable. An addition of something like this should work:

Code: Select all

Integer variable y;
equation y2xdef;
y2xdef .. x =E= 1 + 0.25*y;
You should note, that if your original model was an LP the new model is a MIP model, and the solution time could be much larger. Also note, the default upper bound on an integer variable is 100 which will translate into an upper bound on x of 1+0.25*100 = 26. If you have larger x-values you can increase the upper bound on y or change the value of the command line parameter intVarUp.
Locked