MATLAB built-in function "wrap around" an index in multiperiod planning models
29 次查看(过去 30 天)
显示 更早的评论
Does MATLAB have a built-in function that functions similarl with @WRAP in LINGO ?
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. So, using athematical notation, what one might consider doing is adding the constraint:
Translating into LINGO notation, we can write this as:
@FOR( DAYS( J):
@SUM( DAYS( I) | I #LE# 5: START( J - I + 1))>= REQUIRED( J));
In words, the LINGO statement says, for each day of the week, the sum of the employees starting overthe five day period beginning four days ago and ending today must be greater-than-or-equal-to the required number of staff for the day. This sounds correct, but there is a slight roblem.
Thursday has an index of 4 in our set DAYS. As written, the staffing constraint for Thursday will be:
START( 4) + START( 3) +START( 2) + START( 1) +START( 0) >= REQUIRED( 4);
The START( 0) term is the root of our problem. START is defined for days 1 through 7. START( 0) does not exist. An index of 0 on START is considered "out of range.”
We would like to have any indices less-than-or-equal-to 0 wrap around to the end of the week.Specifically, 0 would correspond to Sunday (7), -1 to Saturday (6), and so on. LINGO has a functionthat does just this: @WRAP.
The @WRAP function takes two arguments⎯call them INDEX and LIMIT.Formally, J = @WRAP( INDEX, LIMIT) returns J such that J = INDEX - K * LIMIT, where K is an integer such that 1 <= J < LIMIT+1. Informally, @WRAP will subtract or add LIMIT to INDEX until it falls in the range 1 to LIMIT + 0.99999. Therefore, this is just what we need to "wrap around" an index in multiperiod planning models.
@FOR( DAYS( J):
@SUM( DAYS( I) | I #LE# 5:
START( @WRAP( J - I + 1, 7)))>= REQUIRED( J));
The objective value of 22 means 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
0 个评论
采纳的回答
Walter Roberson
2023-3-3
Example wrapping at 7
temp = -10:10;
[temp;
mod(temp-1, 7)+1]
The mod is the important part.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Install Products 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!