Problems with modeling
beginner
User
Posts: 6
Joined: 4 months ago

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;"
Attachments

Fred
Posts: 158
Joined: 3 years ago

### Re: help about an equation

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

beginner
User
Posts: 6
Joined: 4 months ago

### Re: help about an equation

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;

Fred
Posts: 158
Joined: 3 years ago

### Re: help about an equation

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

beginner
User
Posts: 6
Joined: 4 months ago

### Re: help about an equation

thanks a lot it was what i need for solve it. have a good day

beginner
User
Posts: 6
Joined: 4 months ago

### Re: help about an equation

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

Fred
Posts: 158
Joined: 3 years ago

### Re: help about an equation

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).

beginner
User
Posts: 6
Joined: 4 months ago

### Re: help about an equation

thanks a lot again and again