四旅制调度算法

algorithm for a schedule for the four-brigade system

我需要为四旅系统中的三班制编制轮班时间表。 每个班次持续八小时。 第一班从早上 6 点开始。 第二班从下午 2 点开始。 第三班从晚上 10 点开始。 每个周期有4天48小时的休息时间。

下面的 table 显示了 20019 年 1 月的时间表。

"W"表示休息一天

我会编写一个函数来获取参数日期和轮班次数以及returns哪个旅轮班。

例如:

getBrigadeNumber('2019-01-27',1); // should return 'III' for schedule above 

我完全不知道它是怎么写的。

我会写在VBA,但我也知道php,

如有任何建议,我将不胜感激。

您可以在 VBA 的情况下使用 MATCH() 工作表函数完成此操作:

假设您的月份 January 在第 1 行。您可以使用 MATCH() 函数找到您的 1 月 27 日所在的列:

=MATCH(1;AB:AB;0)

代表:

在第 'AB' 列的四行(2 到 5)内使用精确匹配查找值 1。
列 'AB' 可以找到为 =OFFSET(A1;0;27).

乍一看这个问题似乎很困难 - 三班制算法,但是当你意识到班次是一些模式并且这些模式不会及时改变时,问题开始看起来很简单。

"Keeps first month in an array and when I will be need a specific day. I can count it for loops"的想法会解决问题。我想补充的是没有必要使用循环。班次模式每 16 天重复一次 - 1 月 11 日和 1 月 27 日的值相同。

对于特定的一天 d,您可以考虑以下伪代码来计算每个旅的班次:

D = The distance between a particular day d and January 1st in days.
A = Schedule for January 2019. A zero indexed array with 4 rows and 31 columns.

S1=A[1][D mod 16] will be the calculated shift number for brigade 1 at day d.
S2=A[2][D mod 16] will be the calculated shift number for brigade 2 at day d.
            ...
S4=A[4][D mod 16] will be the calculated shift number for brigade 4 at day d.

知道 S1、S2、S3 和 S4 足以 getBrigadeNumber 到 return 正确的值。