Problems with early conversion of assignments

Problems with syntax of GAMS
Post Reply
bw0717
User
User
Posts: 6
Joined: 1 year ago

Problems with early conversion of assignments

Post by bw0717 »

Set
i 'employees' / zhu, tsai, xu, lu, chen, wang, shortage /
j 'workstation' / zone1, zone2, zone3, zone4, vacation, notassigned /
t 'days'/1*13/
work_zone(j) / zone1, zone2, zone3, zone4/
employees(i) / zhu, tsai, xu, lu, chen, wang/

$onImplicitAssign
Parameter preferences(i, j);
preferences('zhu', 'zone1') = 100; preferences('zhu', 'zone2') = 100; preferences('zhu','notassigned') = 10; preferences('zhu','vacation') = -100;
preferences('tsai', 'zone2') = 100; preferences('tsai', 'zone3') = 100;preferences('tsai','notassigned') = 10; preferences('tsai','vacation') = -100;
preferences('xu', 'zone3') = 100; preferences('xu', 'zone4') = 100; preferences('xu','notassigned') = 10; preferences('xu','vacation') = -100;
preferences('lu', 'zone1') = 100; preferences('lu', 'zone4') = 100;preferences('lu','notassigned') = 10; preferences('lu','vacation') = -100;
preferences('chen', 'zone2') = 100;preferences('chen','notassigned') = 10; preferences('chen','vacation') = -100;
preferences('wang', 'zone1') = 100;preferences('wang', 'zone3') = 100;preferences('wang','notassigned') = 10; preferences('wang','vacation') = -100;
preferences('shortage', j) = -1000

Parameter M;
M = 1000;

Table L(i, j, t);
L(i, j, t) = 0;
L('zhu', 'vacation', '1') = 1;
L('tsai', 'vacation', '1') = 1;
L('tsai', 'vacation', '2') = 1;
L('lu', 'vacation', '3') = 1;
L('zhu', 'vacation', '4') = 1;
L('tsai', 'vacation', '4') = 1;
L('chen', 'vacation', '5') = 1;
L('chen', 'vacation', '6') = 1;
L('chen', 'vacation', '7') = 1;
L('xu', 'vacation', '8') = 1;
L('xu', 'vacation', '9') = 1;
L('zhu', 'vacation', '10') = 1;

Table A(i, j, t);
A(i, j, t) = 0;
A('zhu','zone1',t) = 1; A('zhu','zone2',t) = 1; A('zhu','zone3',t) = 0; A('zhu','zone4',t) = 0; A('zhu','vacation',t) = 1; A('zhu','notassigned',t) = 1;
A('tsai','zone1',t) = 0; A('tsai','zone2',t) = 1; A('tsai','zone3',t) = 1; A('tsai','zone4',t) = 0; A('tsai','vacation',t) = 1; A('tsai','notassigned',t) = 1;
A('xu','zone1',t) = 0; A('xu','zone2',t) = 0; A('xu','zone3',t) = 1; A('xu','zone4',t) = 1; A('xu','vacation',t) = 1; A('xu','notassigned',t) = 1;
A('lu','zone1',t) = 1; A('lu','zone2',t) = 0; A('lu','zone3',t) = 0; A('lu','zone4',t) = 1; A('lu','vacation',t) = 1; A('lu','notassigned',t) = 1;
A('chen','zone1',t) = 0; A('chen','zone2',t) = 1; A('chen','zone3',t) = 0; A('chen','zone4',t) = 0; A('chen','vacation',t) = 1; A('chen','notassigned',t) = 1;
A('wang','zone1',t) = 1; A('wang','zone2',t) = 0; A('wang','zone3',t) = 1; A('wang','zone4',t) = 0; A('wang','vacation',t) = 1; A('wang','notassigned',t) = 1;
A('shortage','zone1',t) = 1; A('shortage','zone2',t) = 1; A('shortage','zone3',t) = 1; A('shortage','zone4',t) = 1; A('shortage','vacation',t) = 1; A('shortage','notassigned',t) = 1;
display L;

Binary Variables
x(i, j, t)
y(i, j, t)
k(i, j, t)
u(i, j ,t)
f(i,j,t)
g(i,j,t)
;

Variable z;

Equations
assign_employee(j, t)
assign_workstation(i, t)
constraint(i, j, t)
constraint2(i, j, t)
constraint3(i, j, t)
table_L(i, j, t)
A_x(i,j,t)
obj_function
shift(i, j, t)
shift2(i, j, t)
shift3(i, j, t)
shift4(i, j, t)
shift_relationship
;

assign_employee(j, t)$work_zone(j).. sum(i, x(i, j, t)) =e= 1;
assign_workstation(i, t)$employees(i).. sum(j, x(i, j, t)) =e= 1;
constraint(i, j, t).. x(i, j, t) + x(i, j, t+1) =g= -M*(1 - y(i, j, t)) + 2;
constraint2(i, j, t).. x(i, j, t) + x(i, j, t+1) + x(i, j, t+2) =g= -M*(1-k(i, j, t)) + 3;
constraint3(i, j, t).. y(i, j, t) + k(i, j, t) + u(i, j, t) =e= 1;
table_L(i, j, t).. x(i, j, t) =g= L(i, j, t);
A_x(i,j,t).. x(i,j,t) =l= A(i,j,t);
obj_function.. z =e= sum((i, j, t), preferences(i, j) * x(i, j, t) + k(i, j, t) * 10**(2) + y(i, j, t) * 10**(-2) + f(i,j,t) * 10**(2));
shift(i, j, t)$(ord(t) <= card(t)-4).. f(i, j, t) =g= (x(i, 'zone1', t) + x(i, 'zone1', t+1) + x(i, 'zone1', t+2)+ x(i, 'zone1', t+3) - 3);
shift2(i, j, t)$(ord(t) <= card(t)-6).. (x(i, 'zone1', t+4) + x(i, 'zone1', t+5)) =l= 2 * (1 - f(i, j, t));
shift3(i, j, t)$(ord(t) <= card(t)-4).. g(i, j, t) =g= (x(i, 'zone1', t) + x(i, 'zone1', t+1) + x(i, 'zone1', t+2)+ x(i, 'zone1', t+3) - 3);
shift4(i, j, t)$(ord(t) <= card(t)-6).. (x(i, 'zone1', t+4) + x(i, 'zone1', t+5)) =l= 2 * g(i, j, t);
shift_relationship(i, j, t).. f(i, j, t)+g(i, j, t) =e= 1

Model test / all /;

solve test using mip Maximizing z;

display x.l, x.m, A;


Why is it that when I set up employee i to be assigned to zone1 for four consecutive days, the assignment switches over the next two days, but in reality, they switch assignments early, after three days of assignment?
t+(t+1)+(t+2)+(t+3) =g= 1
image.png
Post Reply