help about an equation

Problems with modeling
Post Reply
beginner
User
User
Posts: 6
Joined: 4 years ago

help about an equation

Post 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
Attachments
ScreenShot_20190519175130.png
Fred
Posts: 372
Joined: 7 years ago

Re: help about an equation

Post 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
beginner
User
User
Posts: 6
Joined: 4 years ago

Re: help about an equation

Post 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;
Fred
Posts: 372
Joined: 7 years ago

Re: help about an equation

Post 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
beginner
User
User
Posts: 6
Joined: 4 years ago

Re: help about an equation

Post by beginner »

thanks a lot it was what i need for solve it. have a good day :)
beginner
User
User
Posts: 6
Joined: 4 years ago

Re: help about an equation

Post 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
Fred
Posts: 372
Joined: 7 years ago

Re: help about an equation

Post 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).
beginner
User
User
Posts: 6
Joined: 4 years ago

Re: help about an equation

Post by beginner »

thanks a lot again and again
Post Reply