简体   繁体   English

ruby/rails 中的预约调度

[英]Appointment Scheduling in ruby/rails

I am working on a call center software in rails and need to schedule appointments for agents that can handle calls for the customers.我正在开发 Rails 中的呼叫中心软件,需要为可以处理客户呼叫的代理安排约会。 Having said the call center software, need to make sure that I schedule the appointments utilizing the entire agent's schedule as much as possible, leaving scope for least number of holes (where agent has no appointment).说到呼叫中心软件,需要确保我尽可能利用整个座席的时间表安排约会,让 scope 留出最少的漏洞(座席没有预约)。

Given an agent's schedule, for example 9:00AM to 5:30PM for a given day, with a lunch break of 30 minutes between 1:00PM - 1:30PM, I need to schedule appointments of varying length in duration, some 60 minutes and some 90 minutes.给定代理的日程安排,例如某一天的上午 9:00 到下午 5:30,下午 1:00 到下午 1:30 之间有 30 分钟的午休时间,我需要安排不同长度的约会,大约 60 分钟和大约90分钟。

And if some reason, lunch break is leaving some holes in the schedule, I should be able to move lunch break 30minutes +/-, so instead of 1:00PM - 1:30PM it could be moved between 1:30PM - 2:00PM or 12:30PM - 1:00PM.如果由于某种原因,午休时间在日程安排上留下了一些漏洞,我应该能够将午休时间 +/- 移动 30 分钟,因此可以在下午 1:30 到下午 2:00 之间移动而不是下午 1:00 - 下午 1:30或中午 12:30 - 下午 1:00。

I started off creating lunch breaks as a kind of appointment which will provide the flexibility of moving the starts_at and finishes_at attributes.我开始创建午休时间作为一种约会,它将提供移动starts_at 和finishs_at 属性的灵活性。 And the appointments being either 60 minutes or 90 minutes, which are multiple of 30 minutes and lunch also being 30 minutes, I started off splitting agents schedule into slots of 30 minutes each.约会是 60 分钟或 90 分钟,是 30 分钟的倍数,午餐也是 30 分钟,我开始将座席安排分成每个 30 分钟的时段。

So for a given agent on a given day, looking at his schedule I instantiated an array of slots each with a duration of 30 minutes and starts_at and finishes_at attributes be like 9:00AM - 9:30AM, 9:30AM - 10:00AM, etc.因此,对于给定一天的给定代理,查看他的日程安排,我实例化了一个插槽数组,每个插槽的持续时间为 30 分钟,starts_at 和 finish_at 属性类似于上午 9:00 - 上午 9:30,上午 9:30 - 上午 10:00,等等

I need some help on looping through this array of appointment slots and pull either 2 consecutive slots or 3 consecutive slots depending upon 60 or 90 minute duration appointment, keeping in mind that I should be able to move the lunch +/- 30 minutes.我需要一些帮助来遍历这一系列预约时段,并根据 60 或 90 分钟的预约时间拉动 2 个连续的时段或 3 个连续的时段,请记住,我应该能够将午餐移动 +/- 30 分钟。

Any help is much appreciated.任何帮助深表感谢。

Looking at your problem:看看你的问题:

  1. Appointments are either 60 or 90 minutes long.约会时间为 60 或 90 分钟。
  2. Lunch can vary between a 90 minute interval 12:30-2:00午餐间隔 90 分钟 12:30-2:00

And we want to minimize the amount of minutes that have no appointments.我们希望尽量减少没有约会的分钟数。

Now, you have a time interval to fill, which is 9:00AM to 5:30pm.现在,您需要填写一个时间间隔,即上午 9:00 到下午 5:30。 Assuming appointments fall between 9:00-5:30, we can use a greedy algorithm for interval scheduling based on earliest finish time ( source ) with your additional constraint.假设约会在 9:00-5:30 之间,我们可以使用基于最早完成时间 ( source ) 的贪心算法进行间隔调度,并有额外的约束。

Basically the algorithm is as follows (in pseudo)基本上算法如下(伪)

Let R be the set of all appointments
Let R11 be the set of appointments from R before 12:30 that are compatible with 12:30-1:00 and R12 be the set of appointments from R after 1:00 that are compatible with 12:30-1:00
Let R21 be the set of appointments from R before 1:00 that are compatible with 1:00-1:30 and R22 be the set of appointments from R after 1:30 that are compatible with 1:00-1:30
Let R31 be the set of appointments from R before 1:30 that are compatible with 1:30-2:00 and R32 be the set of appointments from R after 2:00 that are compatible with 1:30-2:00

Let R1Comb = findSet(R11) + 12:30-1:00 + findSet(R12)
Let R2Comb = findSet(R21) + 1:00-1:30 + findSet(R22)
Let R3Comb = findSet(R31) + 1:30-2:00 + findSet(R32)

Function findSet(R) 
    Let A be the time interval to fill    
    While R is not empty
        Choose a request r in R that has the smallest finishes_at
        Add r to A
        Remove all appointments in R that are not compatible with r
    EndWhile
    Return A
EndFunction

Return the R that has the smallest amount of holes in R1Comb, R2Comb, R3Comb

This algorithm makes use of a few concepts该算法利用了一些概念

  1. An appointment r1 is not compatible with r2 if they overlap.如果约会 r1 与 r2 重叠,则它们不兼容。
  2. Because of #1, we know that Ri1/Ri2 for i=1,2,3 will not be conflicting with each other.由于#1,我们知道 i=1,2,3 的 Ri1/Ri2 不会相互冲突。 Because if an appointment in Ri2 is not compatible with Ri1, then it is also not compatible with the lunch period, which is a contradiction because we took out all the non compatible appointments.因为如果 Ri2 中的约会与 Ri1 不兼容,那么它也与午餐时段不兼容,这是一个矛盾,因为我们将所有不兼容的约会都取出了。
  3. Once we split the set of appointments, then it's a matter of solving 2 scheduling problems, which can be solved greedily.一旦我们拆分了这组约会,那么就需要解决 2 个调度问题,这可以贪婪地解决。

An this algorithm is still O(n log n) because you are doing the greedy algorithm 6 times (a constant), and each greedy iteration is O(n log n), and the first few lines and the last line are all O(n).这个算法仍然是O(n log n),因为你做了6次贪心算法(一个常数),每次贪心迭代都是O(n log n),前几行和最后一行都是O( n)。

People write theses on scheduling and it's not an easy problem.人们写关于日程安排的论文,这不是一个容易的问题。 I suggest you looking at http://www.asap.cs.nott.ac.uk/watt/resources/university.html to get a better understanding.我建议您查看http://www.asap.cs.nott.ac.uk/watt/resources/university.html以获得更好的理解。

Good luck:)祝你好运:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM