The Staff Scheduling Problem,Loops Constraints,

6 visualizaciones (últimos 30 días)
jin yong
jin yong el 3 de Mzo. de 2023
Comentada: jin yong el 6 de Mzo. de 2023
The Staff Scheduling Problem
Suppose you run the popular Pluto Dogs hot dog stand that is open seven days a week. You hire employees to work a five-day workweek with two consecutive days off. Each employee receives the same weekly salary. Some days of the week are busier than others and, based on past experience, you know how many workers are required on a given day of the week. In particular, your forecast calls for these staffing requirements:
Day Mon Tue Wed Thu Fri Sat Sun
Staff Req'd 20 16 13 16 19 14 12
You need to determine how many employees to start on each day of the week in order to minimize the total number of employees, while still meeting or exceeding staffing requirements each day of the week.
In other words, to compute the number of employees working today, we sum up the number of people starting today plus those starting over the previous four days. The number of employees starting five and six days back don't count because they are on their days off.
ANSWER: we need to hire 22 workers.We start our workers according to the schedule:
Day Mon Tue Wed Thu Fri Sat Sun
Start 8 2 0 6 3 3 0
clear
prob=optimproblem
required=[20,16,13,16,19,14,12]
duty=optimvar('duty',7,'Type','integer')
obj=sum(duty)
prob.Objective=obj
schedule=optimconstr(7)
for i=1:7
schedule(i)=duty(i)+duty(i-1)+duty(i-2)+duty(i-3)+duty(i-4)>=required(i)
end
show(schedule)
prob.Constraints=schedule
[xsol,fval,eflag,output]=solve(prob)
xsol.duty
How can I set the loops to realize thefunction was showed below
% schedule(1)=duty(1)+duty(7)+duty(6)+duty(5)+duty(4)>=required(1)
% schedule(2)=duty(2)+duty(1)+duty(7)+duty(6)+duty(5)>=required(2)
% schedule(3)=duty(3)+duty(2)+duty(1)+duty(7)+duty(6)>=required(3)
% schedule(4)=duty(4)+duty(3)+duty(2)+duty(1)+duty(7)>=required(4)
% schedule(5)=duty(5)+duty(4)+duty(3)+duty(2)+duty(1)>=required(5)
% schedule(6)=duty(6)+duty(5)+duty(4)+duty(3)+duty(2)>=required(6)
% schedule(7)=duty(7)+duty(6)+duty(5)+duty(4)+duty(3)>=required(7)
  3 comentarios
Steven Lord
Steven Lord el 3 de Mzo. de 2023
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
jin yong
jin yong el 5 de Mzo. de 2023
clear
prob=optimproblem
required=[20,16,13,16,19,14,12]
duty=optimvar('duty',7,'Type','integer')
obj=sum(duty)
prob.Objective=obj
schedule=optimconstr(7)
for i=1:7
schedule(i)=duty(i)+duty(i-1)+duty(i-2)+duty(i-3)+duty(i-4)>=required(i)
end
show(schedule)
prob.Constraints=schedule
[xsol,fval,eflag,output]=solve(prob)
xsol.duty
How can I set the loops to realize thefunction was showed below
% schedule(1)=duty(1)+duty(7)+duty(6)+duty(5)+duty(4)>=required(1)
% schedule(2)=duty(2)+duty(1)+duty(7)+duty(6)+duty(5)>=required(2)
% schedule(3)=duty(3)+duty(2)+duty(1)+duty(7)+duty(6)>=required(3)
% schedule(4)=duty(4)+duty(3)+duty(2)+duty(1)+duty(7)>=required(4)
% schedule(5)=duty(5)+duty(4)+duty(3)+duty(2)+duty(1)>=required(5)
% schedule(6)=duty(6)+duty(5)+duty(4)+duty(3)+duty(2)>=required(6)
% schedule(7)=duty(7)+duty(6)+duty(5)+duty(4)+duty(3)>=required(7)

Iniciar sesión para comentar.

Respuesta aceptada

Torsten
Torsten el 5 de Mzo. de 2023
Editada: Torsten el 5 de Mzo. de 2023
Do you want to enlarge the problem size ? If not, why writing 7 clearly arranged constraints in a complicated loop ?
But if you insist:
clear
prob=optimproblem;
required=[20,16,13,16,19,14,12];
duty=optimvar('duty',7,'Type','integer');
obj=sum(duty);
prob.Objective=obj;
schedule=optimconstr(7);
I = repmat(1:7,1,2);
for i=1:7
schedule(i)=duty(I(i+7))+duty(I(i+7-1))+duty(I(i+7-2))+duty(I(i+7-3))+duty(I(i+7-4))>=required(i);
end
%show(schedule)
prob.Constraints=schedule;
[xsol,fval,eflag,output]=solve(prob);
Solving problem using intlinprog. LP: Optimal objective value is 22.000000. Optimal solution found. Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 0 (the default value). The intcon variables are integer within tolerance, options.IntegerTolerance = 1e-05 (the default value).
xsol.duty
ans = 7×1
8 2 0 6 3 3 0
  3 comentarios
Torsten
Torsten el 6 de Mzo. de 2023
Editada: Torsten el 6 de Mzo. de 2023
clear
prob=optimproblem;
required=[20,16,13,16,19,14,12];
duty=optimvar('duty',7,'Type','integer');
obj=sum(duty);
prob.Objective=obj;
schedule=optimconstr(7);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% And you think you will understand what you did here in two weeks ?
% That's the disadvantage of short concise commands: they lack
% readability.
I = repmat(1:7,1,2);
for i=1:7
schedule(i)=sum(duty(I(i+7:-1:i+7-4)))>=required(i);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%show(schedule)
prob.Constraints=schedule;
[xsol,fval,eflag,output]=solve(prob);
Solving problem using intlinprog. LP: Optimal objective value is 22.000000. Optimal solution found. Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 0 (the default value). The intcon variables are integer within tolerance, options.IntegerTolerance = 1e-05 (the default value).
xsol.duty
ans = 7×1
8 2 0 6 3 3 0
jin yong
jin yong el 6 de Mzo. de 2023
Thank you very much for your help!My understanding of short concise commands still needs to be learned from you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by