生成重叠范围的子数组
我的名字是蒂莫西·萨松。我正在用 C# 开发一些调度软件,但遇到了一些麻烦。该程序的最后一部分旨在获取大量每周事件(存储为一周中的一天以及开始和结束时间),并将它们分类到包含彼此重叠的事件的子列表中(这样就没有人可能参加了子列表中的两项活动)。
目前,它通过在列表中查找“最长”事件 ((endTime-startTime)*numDays) 并将其及其重叠的每个课程添加到子列表中来实现此目的。然后,它会找到所有“冲突”(不重叠的事件)并解决它们,同时删除尽可能少的课程。我有这么多,但是由于我必须处理的范围数量,我最终得到了相当多的子列表。有没有更好的方法来分割列表,这样我最终会得到更少的子列表?
我考虑过一种蛮力方法,简单地尝试每种可能性并选择最好的,但范围的数量足够高(平均为 100-500),这样做可能会相当慢。任何建议或指示将不胜感激。
感谢您抽出宝贵时间,
蒂莫西·萨松
my name is Timothy Sassone. I am working on developing some scheduling software of a sort in C#, but have run into some trouble. This last part of the program is intended to take a large list of weekly events (stored as day(s) of the week and a start and end time), and sort them into sub-lists containing events that overlap with one-another (such that no one could possibly have attended two of the events in the sublist).
At the moment, it does this by finding the "longest" event in the list ((endTime-startTime)*numDays), and adding it and every course it overlaps with to a sub-list. It then finds all the "conflicts" (events which do not overlap) and resolves them while removing the fewest number of courses possible. This much I have, but with the number of ranges I have to deal with, I end up with a rather high number of sub-lists. Is there any better way to split the list, such that I end up with fewer sub-lists?
I have considered a brute-force method, simply trying every possibility and going with the best, but the number of ranges is high enough (anywhere from 100-500 on average) that doing so could be rather slow. Any suggestions or pointers would be most appreciated.
Thank you for your time,
Timothy Sassone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.NET 时间段库 http://www.codeproject .com/KB/datetime/TimePeriod.aspx 包含用于搜索重叠时间段的 TimePeriodIntersector。
通过对时间线上的所有时刻进行计数/排序,使用线性快速算法计算重叠。
TimePeriodIntersector 的用法如下所示:
The Time Period Library for .NET http://www.codeproject.com/KB/datetime/TimePeriod.aspx includes the TimePeriodIntersector to search for overlapping time periods.
The overlaps are calculated with a linear and fast algorithm by counting/sorting all moments on the time line.
And the usage of TimePeriodIntersector looks like: