How to ranging variables

Problems with modeling
Post Reply
Yehuda
User
User
Posts: 10
Joined: 6 years ago

How to ranging variables

Post by Yehuda »

Hi all,

I'm having trouble with variables that the model chooses to give them very small values but not zero, values that are not reasonable for these variables. My question is how can I give the model a range for these variables such that: on the one hand they can be zero and on the other hand they can not be for example smaller than 0.1? Something like: x=0 or x>0.1.
Currently, these variables are defined as positive variables.

Thanks,

Yehuda
saghafiiii
User
User
Posts: 6
Joined: 5 years ago

Re: How to ranging variables

Post by saghafiiii »

Hi

I'm afraid you did not explain your problem well.
would you mind making it more clear?
Yehuda
User
User
Posts: 10
Joined: 6 years ago

Re: How to ranging variables

Post by Yehuda »

Thank for your response.
I'll try to make it clear.

Since small values for one of the variables in my model are causing an infeasible solution, I'm looking for a way to solve this problem.
However, a simple restriction like X>1 is inapplicable because I want to give this variable the option to be zero. Therefore, I'm trying to give this variable a specific range like:
X=0 or X>1 but I don't know how to do so.
In other words, what I'm trying to do is to create a specific range in which one of my variables can be changed. This range is not continuous. The first part is zero (only one value), and the second part is all the values above 1.

I hope my problem is clear now.
Thank you again for the willingness to help, I really appreciate it!

Yehuda
saghafiiii
User
User
Posts: 6
Joined: 5 years ago

Re: How to ranging variables

Post by saghafiiii »

Hi again.
Now I know what is your problem.

I'm afraid you can not use ".lo" or ".up" for doing this but I think there is an alternative solution:

foe example suppose you have an equation on X in your problem.
X + Y * Z >= 6 ;

firstly you define :

Code: Select all

positive variable X , Y , Z;
Equations
eq1
;

eq1$(X = 0 or X > 1  ) .. 	X + Y * Z =e= 6;

I believe it works, try it.
Yehuda
User
User
Posts: 10
Joined: 6 years ago

Re: How to ranging variables

Post by Yehuda »

Thank you again.

So I tried your suggestion but it causes another problem. Now the model is declaring an endogenous problem and it prohibits the use of $ operation.

I thought that the ranging issue will be easy to defined, but it's apparently not.

Anyway, thanks a lot!

Yehuda
Fred
Posts: 372
Joined: 7 years ago

Re: How to ranging variables

Post by Fred »

Yehuda,

You might want top have a look at semi-continous variables: https://www.gams.com/latest/docs/UG_Var ... iableTypes

Best,
Fred
ibrahim
User
User
Posts: 1
Joined: 1 year ago

Re: How to ranging variables

Post by ibrahim »

I wrote double inequalities like the following, but getting error msg. How can I write it?

Plz help

ratio (s).. 0.2=l=(sum (d, x(d,s)))/(sum(d,(x(d,s)+y(d,s))))=l=0.3;
range(s).. 300=l=sum (d, x(d,s)+y(d,s))=l=500;
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: How to ranging variables

Post by bussieck »

GAMS does not have ranging constraints. So you need to write two constraints:

Code: Select all

ratioLO (s).. 0.2=l=(sum (d, x(d,s)))/(sum(d,(x(d,s)+y(d,s))));
ratioUP (s)..           (sum (d, x(d,s)))/(sum(d,(x(d,s)+y(d,s)))) =l=0.3;
You can also declare a free variable r(s), have a defining equation and set bounds of r:

Code: Select all

variable r(s)
defratio (s).. r(s) =e= (sum (d, x(d,s)))/(sum(d,(x(d,s)+y(d,s))));
r.lo(s) = 0.2; r.up(s) = 0.3;
-Michael
Post Reply