具有连续中断的调度算法

发布于 2024-09-08 06:53:53 字数 473 浏览 6 评论 0原文

我在这里迷路了。这就是问题所在,我认为它是 NP 难的。一个中心的员工数量是有限的,其条件如下:

  1. 每天 3 个班次,每班 2 人
  2. 每个员工连续工作 5 天,然后休息 2 天,每天只有一个班次

所以问题是:如果中心每天保持活动并保持可行的时间表,我们需要多少工人?

更新:

感谢所有精彩的答案。我最接近的结果(使用随机暴力算法)如下:

X       3       0
1       0       3
2       3       1
2       1       3
0       1       2
0       2       1
3       0       2

我将问题简化为 2 人批次(0-3 代表 4 批次),希望获得可行的解决方案。 X 指的是尚未分配的班次(这不是最初的目标,但看起来可能没有替代方案)。

I'm lost here. Here's the problem and I think it's NP-hard. A center is staffed with a finite number of workers with the following conditions:

  1. There are 3 shifts per day with 2 people in each shift
  2. Each employee works for 5 days straight and then 2 days off with only one shift per day

So the problem is: how many workers do we need if the center remains active every day and a feasible schedule?

Update:

Thanks for all the great answers. The closest I've come to (with a randomized brute-force algorithm) is the following:

X       3       0
1       0       3
2       3       1
2       1       3
0       1       2
0       2       1
3       0       2

I've simplified the problem into batches of 2 people (0-3 represent 4 batches) in the hopes of getting a feasible solution. X refers to a shift which has not been assigned (which was not the initial goal but it looks like there may not be an alternative).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

云淡风轻 2024-09-15 06:53:53

不能完全遵守问题中所表达的约束。
这是因为这些数字没有相加(或者更确切地说“相除”)。

因此,问题应该改写为

  • 每天正好需要 3 个轮班
  • ,每个轮班
  • 最多有 2 个工人工作 连续 5 天的
  • 工人休息至少连续 2 天

随着最小和最大限定条件的引入,所需的最少工人数量为 9(同样假设没有任何人员参与) -时间工人)。
请注意,虽然 9 似乎是绝对最小值,但考虑到每周需要承担 42 个轮班 (3 * 2 * 7),而工人每周最多可以承担 5 个轮班(5 个工作日 2 个休息日 = 一周) ,考虑到连续工作和/或休息日的要求,不能保证 9 就足够了。

我就是这样想的...
8 名工人是不够的,下面的 9 名工人的阵容就是这种时间表的一个例子。
为了让事情变得简单,我将除了工人 #1 和 #9 之外的所有工人分配到一个最佳的时间表,即工作 5 天和休息 2 天; #1 和 #9 工作较少。当然,许多其他安排也可以工作(也许这就是OP在暗示NP完全问题时所感觉到的)。此外,时间表是这样的,每个人每周的时间表都是完全相同的,但这也可以改变(也许引入一些公平性,让所有工人每隔一段时间就有一个轻松的一周,但是顺便说一句,这可能会导致一些遵守最多 5 个工作日的要求有困难)。
示例时间表显示连续两周,以帮助查看连续的工作或休息日,但如上所述,每个周的所有周都是相同的。

                              Max Conseq Ws   Min Conseq Rs
Worker #1   RRWWWRW RRWWWRW         3              2
Worker #2   WWWWWRR WWWWWRR         5              2
Worker #3   WWWRRWW WWWRRWW         5              2
Worker #4   WWWRRWW WWWRRWW         5              2
Worker #5   WRRWWWW WRRWWWW         5              2
Worker #6   WRRWWWW WRRWWWW         5              2
Worker #7   RWWWWWR RWWWWWR         5              2
Worker #8   RWWWWWR RWWWWWR         5              2
Worker #9   WWRRRRW WWRRRRW         3              3

Nb of Ws    6666666 6666666

底部的计数显示每天正好有 6 个工人(考虑到需要覆盖 3 个班次,每个班次有 2 名工人),右侧的最大和最小列显示遵守最大连续工作和最小连续休息要求。

The constraints cannot be respected exactly as expressed in the question.
That's because the numbers don't add up (or rather "divide up").

Consequently, the problem should be reworded to require

  • exactly 3 shifts per day
  • exactly 2 workers per shift
  • workers work a maximum of 5 consecutive days
  • workers rest a minimum of 2 consecutive days

With the introduction of the minimum and maximum qualifiers, the minimum number of workers required is 9 (again assuming no part-time worker).
Note that although 9 appears to be a absolute minimum, given the need to cover 42 shifts per week (3 * 2 * 7) with workers who can cover a maximum of 5 shifts per week (5 work days 2 rest days = a week), there is no assurance that 9 would be sufficient given the consecutive work and/or rest day requirements.

This is how I figure...
8 workers isn't enough, and the following 9 workers line-up, is an example of such a schedule.
To make things easy, I assigned all workers except for worker #1 and #9, to an optimal schedule of exactly a 5 days-on and 2 days-off schedule; #1 and #9 work less. Of course many other arrangements would work (maybe this is what the OP sensed when he hinted at an NP-complete problem). Also, the schedule is such that each week's schedule is exactly the same for everyone, but that could also be changed (maybe introducing some fairness, by having all workers have a lighter week every once in a while, but this BTW can lead to some difficulties of respecting the requirement of 5 maximum work days).
The sample schedule shows two consecutive weeks to help see the consecutive work or rest days, but as said, all weeks are the same for every one.

                              Max Conseq Ws   Min Conseq Rs
Worker #1   RRWWWRW RRWWWRW         3              2
Worker #2   WWWWWRR WWWWWRR         5              2
Worker #3   WWWRRWW WWWRRWW         5              2
Worker #4   WWWRRWW WWWRRWW         5              2
Worker #5   WRRWWWW WRRWWWW         5              2
Worker #6   WRRWWWW WRRWWWW         5              2
Worker #7   RWWWWWR RWWWWWR         5              2
Worker #8   RWWWWWR RWWWWWR         5              2
Worker #9   WWRRRRW WWRRRRW         3              3

Nb of Ws    6666666 6666666

The tally at the bottom shows exactly 6 workers per day (respecting the need to cover 3 shifts with 2 workers each), the max and min columns on the right show that the maximum consecutive work and minimum consecutive rest requirements are respected.

风流物 2024-09-15 06:53:53

每天 3 个班次 * 每班 2 人 *(每周 7 天/每人 5 个工作日)= 8.4 人(如果不能选择兼职,则为 9 人)。

3 shifts per day * 2 people per shift * (7 days per week / 5 working days per person) = 8.4 people (9 if part time is not an option).

你曾走过我的故事 2024-09-15 06:53:53

3 个班次 x 7 天 = 21

这不能被 5 或 2 整除 - 因此您的约束将不允许完全填满空位。

3 shifts x 7 days = 21

this does not divide evenly by 5 nor 2 - so your constraints will not allow a complete filling of the slots.

神爱温柔 2024-09-15 06:53:53

好吧——尽管你已经有了答案,但还是让我尝试一下。

让我们考虑一下一般问题:7 天 x 3 个班次 = 21 个不同的班次需要填补
有 7 种可能的员工时间表,以 (1) 和 (1) 上的天数表示。休息日 (0)

MTWTFSS
0011111
1001111
1100111
1110011
1111001
1111100
0111110

我们希望最大限度地减少与所需工时数相匹配的计划员工数量。

我有一个每个班次每种类型的员工数量矩阵,该数字是一个整数变量。我的优化模型是:

Min(员工数量)

服从于:(安排的员工数量*员工计划)=每个班次所需的员工

安排的员工数量的总和是整数

您可以更改=将第一个约束标记为 >=。然后您将获得一个可行的解决方案,并需要额外的人员。您可以使用基本的 SOLVER 插件在 Excel 中解决此问题。

假设我每天需要四名员工轮班,但我愿意容忍额外的员工。

使用上述时间表的解决方案是:

按时间表类型划分的员工人数: 0,2,0,2,0,2,0

时间表类型 0011111,1001111,1100111,1110011,1111001,1111100,0111110

(换句话说,时间表为 2) 1001111,2 个时间表为 1111001,另外 2 个时间表为 1111100)

这会导致一天(星期一)有两名额外员工,其他日子有 4 名员工。

当然,这不是唯一的解决方案。至少有 6 个其他解决方案需要两名额外的工作人员。约束规划将是一种更好、更快的方法,因为通常会有许多可行的时间表。

OK - even though you have an answer, let me take a shot.

Let's take the general problem: 7 days x 3 shifts = 21 different shifts to fill
There are 7 possible employee schedules expressed as days on (1) & days off (0)

MTWTFSS
0011111
1001111
1100111
1110011
1111001
1111100
0111110

We want to minimize the number of scheduled employees that matches the number of required hours.

I have a matrix of number of employees of each type per shift and that number is an integer variable. My optimization model is:

Min (number of employees)

Subject to: sum of (# of emp sched * employee schedule) = staff required for each shift

and

number of employees scheduled is integer

You can change the = sign in the first constraint to a >=. Then you'll get a feasible solution with extra staff. You can solve this in Excel with the basic SOLVER addin.

Let's say I need four employees for each day on a shift but I'm willing to tolerate extra staff.

A solution using the schedules above is:

Number of staff by schedule type: 0,2,0,2,0,2,0

Schedule types 0011111,1001111,1100111,1110011,1111001,1111100,0111110

(In other words 2 with schedules 1001111, 2 with schedules 1111001, and 2 more with schedules 1111100)

This results in one day (Monday) with two extra staff and 4 employees on all the other days.

Of course, this isn't a unique solution. There are at least 6 other solutions with two extra staff members. Constraint programming would be a better and much faster approach since there will often be many feasible schedules.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文