Page 1 of 1

How to ranging variables

Posted: Tue Mar 26, 2019 4:46 pm
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

Re: How to ranging variables

Posted: Wed Mar 27, 2019 11:31 am
by saghafiiii
Hi

I'm afraid you did not explain your problem well.
would you mind making it more clear?

Re: How to ranging variables

Posted: Wed Mar 27, 2019 5:05 pm
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

Re: How to ranging variables

Posted: Thu Mar 28, 2019 8:37 am
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.

Re: How to ranging variables

Posted: Thu Mar 28, 2019 2:07 pm
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

Re: How to ranging variables

Posted: Mon Apr 08, 2019 4:32 pm
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

Re: How to ranging variables

Posted: Mon Sep 05, 2022 1:55 pm
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;

Re: How to ranging variables

Posted: Tue Sep 06, 2022 10:43 am
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