Page 1 of 1

help about an equation

Posted: Sun May 19, 2019 4:57 pm
by beginner
how can i write equation at the pic?
gams dosent allow this "d(i,s).. 2*x(i,s,2)+x(i,s+1,1)+ x(i,s+1,2) =l= 2;"
Image

Re: help about an equation

Posted: Mon May 20, 2019 12:55 pm
by Fred
Hi,

Looks as if you want to refer to a particular set element explicitly in the third index position of x. In that case, set elements (aka labels) must be quoted.
Helping you would become a lot easier if you share your code such that users can reproduce the exact issue. Just saying GAMS doesn't allow some equation syntax may lack important context.

Fred

Re: help about an equation

Posted: Mon May 20, 2019 6:08 pm
by beginner
thanks a lot. i am just a beginner about GAMS. so i will be very thanksfull about any help
here is the my model
set
i hemsire numarası /1*20/
j gün numarası /1*30/
s /1*29/
k vardiya numarası /1*2/
w hafta sonu /1,2,8,9,15,16,22,23,29,30/
v hafta içi /3,4,5,6,7,10,11,12,13,14,17,18,19,20,21,24,25,26,27,28/
;

variables
x
z amaç fonk;

binary variables
x
;

equations
cost
a(j,k) her gündüz-gece vardiyasında en az 4 hemşire bulunsun
b(i,k) her hemşire ayda en az 4 hafta içi gündüz-gece vardiyasında çalışsın
c(i,k) her hemşire ayda en az 2 hafta sonu gündüz-gece vardiyasında çalışsın
d(i,s)
;

cost .. z =e= sum((i,j,k), x(i, j, k)) ;
a(j,k) .. sum((i), x(i,j,k)) =g= 4;
b(i,k).. sum((v), x(i,v,k)) =g= 4;
c(i,k).. sum((w), x(i,w,k)) =g= 2;
d(i,s).. 2*x(i,s,2)+x(i,s+1,1)+ x(i,s+1,2) =l= 2;

model ornek1/all/;

solve ornek1 using MIP minizing z;
display x.l, z.l;

Re: help about an equation

Posted: Mon May 20, 2019 8:59 pm
by Fred
Hi,

As indicated in my previous post and by the first error message

Code: Select all

*** Error 145 in ...\new1.gms
    Set identifier or quoted element expected
set elements must be quoted. After changing equation d to

Code: Select all

d(i,s).. 2*x(i,s,'2')+x(i,s+1,'1')+ x(i,s+1,'2') =l= 2;
the model solves.

I hope this helps!

Fred

Re: help about an equation

Posted: Mon May 20, 2019 10:10 pm
by beginner
thanks a lot it was what i need for solve it. have a good day :)

Re: help about an equation

Posted: Tue May 21, 2019 2:26 pm
by beginner
i am so sorry but can i ask one more question
how can i assign x(1,3,2) to 1?
guess x('1','3','2')=1; dosent match what i want

Re: help about an equation

Posted: Tue May 21, 2019 2:45 pm
by Fred
Hi,

A variable has several attributes: https://www.gams.com/latest/docs/UG_Var ... Attributes

You need to specify which one you would like to use, e.g.

Code: Select all

x.l('1','3','2')=1;
to set the variable's level to 1 or

Code: Select all

x.fx('1','3','2')=1;
to fix the variable at 1 (upper and lower bound set to 1).

Re: help about an equation

Posted: Tue May 21, 2019 4:56 pm
by beginner
thanks a lot again and again