资源调度应用

发布于 2024-08-06 12:48:53 字数 615 浏览 9 评论 0原文

我正在尝试实现一个应用程序来协调调度独占资源的多个用户。调度数据必须在具有单个主节点的网络上保持强一致性。调度的资源可以是从会议室到工作现场的工作人员的任何资源。

我们假设会议室不能同时安排两次会议,并且一名工人不能同时在两个工作地点。应用程序的业务逻辑不得允许用户“超量预订”资源。

我不明白的是如何表示数据,以便如果两个或多个用户同时按计划进行操作,并且存在冲突,其中一个更新将中止。

到目前为止,我见过的唯一解决方案是跟踪每个排他资源的时间段。因此,如果会议室以 5 分钟为间隔使用,并且预定时间为上午 9-9:30,则上午 9-9:30 对应的 5 分钟时段将全部返回 TRUE,而未预定时段将返回 FALSE 或 NULL 。然后,数据库事务将从存储中取出会议室对象,检查所有时隙,如果更新与现有时隙冲突则中止。

然而,它似乎会变得非常大、非常快。也许它可以被垃圾收集?此外,设计的目标之一是支持可变粒度,因此某些对象将按分钟进行调度,而其他对象可能会按天进行调度,而这种数据设计对此支持得不太好。

目前,我正在尝试使用 Python 在 Google App Engine 上实现此功能,但我非常有兴趣看到针对此问题的一些更通用的解决方案。我在谷歌搜索中想到的只是安排重复的任务,或者执行一次性操作以自动构建优化计划的算法。

I'm trying to implement an application that coordinates multiple users who are scheduling exclusive resources. The schedule data must maintain strong consistency over a network with a single master node. The scheduled resources could be anything from a conference room to a worker on a job site.

We assume the conference room cannot be scheduled for two meetings at once and a worker cannot be on two job sites at the same time. The business logic of the application must not allow a user to "overbook" a resource.

What I can't figure out is how to represent the data so that if two or more users operate on the schedule at the same time, and there are conflicts, one of the updates will abort.

The only solution I've seen so far is to track time slots for each exclusionary resource. So if the conference room is used on 5 min intervals, and it was scheduled for 9-9:30am, then the corresponding 5 minute time slots for 9-9:30am would all return TRUE, while the unscheduled slots would return FALSE or NULL. The DB transaction would then pull the conference room object out of the store, check all the time slots, and abort if the update conflicted with existing time slots.

However, this seems like it will get really big, really fast. Perhaps it could be garbage collected? Also, one of the goals of the design is to support variable granularity, so some objects will get scheduled on a minute to minute basis while others could be on a day to day basis, and this data design does not support that very well.

Currently, I am trying to implement this on Google App Engine using Python, but I would be really interested to see some more general solutions to this problem. All I've come up with Googling is scheduling recurring tasks, or algorithms that perform one time operations to automatically build optimized schedules.

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

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

发布评论

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

评论(2

仅此而已 2024-08-13 12:48:53

您需要跟踪每个排除资源的开始和结束时间。问题中的数据存储实际上是简单的部分 - 困难的部分是精心设计查询以查找时间间隔中的冲突。

如果我的逻辑在 21 小时后是正确的,则以下伪代码应检查会议冲突。

# Set up your proposed meeting
proposed.start = <thursday, 1pm>
proposed.end   = <thursday, 2pm>

# Look for meetings that intersect with or straddle proposed meeting
conflicts = <SELECT * FROM meeting WHERE
             meeting.start BETWEEN proposed.start AND proposed.end OR
             meeting.end   BETWEEN proposed.start AND proposed.end OR
             meeting.start <= proposed.start AND meeting.end >= proposed.end>


if conflicts.length > 0:
   # We have a conflict!

You'll want to track just start and end times for each exclusionary resource. The data storage in your problem is actually the easy part - the hard(er) part is crafting queries to look for conflicts in time intervals.

If my logic is correct after being up for 21 hours, the following psuedo-code should check for meeting conflicts.

# Set up your proposed meeting
proposed.start = <thursday, 1pm>
proposed.end   = <thursday, 2pm>

# Look for meetings that intersect with or straddle proposed meeting
conflicts = <SELECT * FROM meeting WHERE
             meeting.start BETWEEN proposed.start AND proposed.end OR
             meeting.end   BETWEEN proposed.start AND proposed.end OR
             meeting.start <= proposed.start AND meeting.end >= proposed.end>


if conflicts.length > 0:
   # We have a conflict!
你丑哭了我 2024-08-13 12:48:53

要自动优化学校或大学的时间表(甚至其他问题),请查看以下 Java 工具:

TimeFinder< /a>、UniTimeDrools Solver

用户交互的问题并不像我认为的那样容易解决,因为可能存在其他约束违规好吧(时间表可能会变得更加复杂)。

首先,我只允许时间表人员访问/更改时间表数据。

其次,我将为每个时间表创建一个独立的解决方案,然后使用上面建议的工具优化该解决方案。然后,解决方案可以存储到数据库中,时间表制定者可以使用它们来进一步优化时间表或与其他解决方案进行比较。

To automatically optimize a timetable of a school or university (or even other problems) take a look at the following Java tools:

TimeFinder, UniTime or Drools Solver

The problem with user interaction is not as easiely solved as you explained I think, because there could be other constraint violations as well (timetabling can get a lot more complicated).

First, I would only allow timetablers accessing/changing the timetable data.

Second, I would create an independent solution for each timetabler and then optimize this solution with the proposed tools above. The solutions then can be stored to the database and the timetabler could use them to further optimize the schedule or to compare to other solutions.

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