Need assistance with types of variables

Problems with syntax of GAMS
Post Reply
nipj
User
User
Posts: 1
Joined: 5 years ago

Need assistance with types of variables

Post by nipj »

Dear sir or madam,

I'm trying to learn by myself some basic procedures in GAMS and I would like to ask for some help regarding the following issue: I'm trying to run an integer LP using the code below, but I have difficulties when trying to declare my variable x1 as an "integer variable" and x2 as an "positive variable", I literally have no idea what would be te correct way to declare the variables.

Please help me to replace the "<I do no know what to write here>" lines with the correct code.

Code: Select all

$ontext
Min      55*x1+x2
st       13*x1+0.09*x2 =g= 250
         33*x1-0.4*x2 =l= 0
         55*x1 =l= 750
         x1,x2 =g= 0
         x1 = positive integer (Z+)
$offtext

sets
a  /a1*a2/
b  /b1*b3/;

parameters
c(a)  /a1=55,a2=1/
d(b)  /b1=-250,b2=0,b3=750/   ;

table t(b,a) 
         a1      a2
b1       -13     -0.09
b2       33      -0.4
b3       55      0          ;

variables
z;

positive variables
<I do no know what to write here>

integer variable
<I do no know what to write here>

equations
obj 
r ;
obj.. z=e=sum(a,c(a)*x(a)) ;
r(b).. sum(a,t(b,a)*x(a)) =l= d(b);

model model1 /all/;
solve model1 using mip minizing z;
display z.l;
It is easy when I have to use only one type of variables, for example:
When I have to use only continuous variables, I write:

Code: Select all

positive variables
x(a);
When I have to use only discrete variables, I write:

Code: Select all

integer variable
x(a);
My problem is that I do not what to write in the cases where I have to use a mixture of both continuous and discrete variables.

Code: Select all

positive variables
<I do no know what to write here>

integer variable
<I do no know what to write here>
PD: I know an easier way to do this is using the following code:

Code: Select all

$ontext
Min      55*x1+x2
st       13*x1+0.09*x2 =g= 250
         33*x1-0.4*x2 =l= 0
         55*x1 =l= 750
         x1,x2 =g= 0
         x1 = positive integer (Z+)
$offtext

variables
z

positive variables
x2;

integer variables
x1;

equations
obj,r1,r2,r3;
obj.. z =e= 55*x1+x2 ;
r1.. 13*x1+0.09*x2 =g= 250 ;
r2.. 33*x1-0.4*x2 =l= 0 ;
r3.. 55*x1 =l= 750 ;

model model1 /all/;
option optcr=0.000001;
solve model1 using mip minimizing z;
display z.l;
But I really want to make the first one work.

Thanks & Regards
Last edited by nipj 5 years ago, edited 2 times in total.
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Need assistance with types of variables

Post by Renger »

Hi
You might set the lower bound for x1 in your second example to 0:

Code: Select all

X1.LO = 0;
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Post Reply