The Staff Scheduling Problem,Loops Constraints,
7 views (last 30 days)
Show older comments
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 Comments
Steven Lord
on 3 Mar 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.
Accepted Answer
Torsten
on 5 Mar 2023
Edited: Torsten
on 5 Mar 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);
xsol.duty
3 Comments
Torsten
on 6 Mar 2023
Edited: Torsten
on 6 Mar 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);
xsol.duty
More Answers (0)
See Also
Categories
Find more on Particle & Nuclear Physics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!