The Staff Scheduling Problem,Loops Constraints,

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 件のコメント

Nikhilesh
Nikhilesh 2023 年 3 月 3 日
Interesting problem indeed. I am not sure tough how we can making use of this forum for this question.
Steven Lord
Steven Lord 2023 年 3 月 3 日
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 2023 年 3 月 5 日
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)

サインインしてコメントする。

 採用された回答

Torsten
Torsten 2023 年 3 月 5 日
編集済み: Torsten 2023 年 3 月 5 日

0 投票

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 件のコメント

jin yong
jin yong 2023 年 3 月 6 日
編集済み: jin yong 2023 年 3 月 6 日
Thanks very much! I'm not to enlarge the problem size . Just want to realize the constraints:
for i=1:7
schedule(i)=sum(duty(I(i+7):-1:I(i+7-4)))>=required(i);
end
but there are some problems for i=1,2,3,4.
(1, 1)
0 >= 20
(2, 1)
0 >= 16
(3, 1)
0 >= 13
(4, 1)
0 >= 16
(5, 1)
duty(1) + duty(2) + duty(3) + duty(4) + duty(5) >= 19
(6, 1)
duty(2) + duty(3) + duty(4) + duty(5) + duty(6) >= 14
(7, 1)
duty(3) + duty(4) + duty(5) + duty(6) + duty(7) >= 12
And I don not understand what you said "7 clearly arranged constraints in a complicated loop" means.
Torsten
Torsten 2023 年 3 月 6 日
編集済み: Torsten 2023 年 3 月 6 日
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 2023 年 3 月 6 日
Thank you very much for your help!My understanding of short concise commands still needs to be learned from you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

リリース

R2022b

質問済み:

2023 年 3 月 3 日

コメント済み:

2023 年 3 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by