检测重叠重复时间段的算法 [英] Algorithm to detect overlapping recurent time periods

查看:1123
本文介绍了检测重叠重复时间段的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



一个比这个问题更复杂的版本检测重复期间的算法



我的案例:
A活动是从星期二,星期四和星期六之间的上午8点到下午1点,两个日期之间。



B活动从上午11点到下午2点,所有星期二和星期四在两个日期之间(事件A的不同)



这里,我把两个事件之间的比较分成两个。



我花了一小时尝试写一个算法来检测两个事件之间是否有至少一个分界。



顺便说一下,事件结束的日期(倾向)可能是不确定的。



有没有现有的算法来管理这个?



< img src =https://i.stack.imgur.com/CT7nv.pngalt =在此输入图像说明>

解决方案

找出哪一个首先结束。如果A和B都是无限制的,将来会选择一些随机的日期。



我将假设你的活动每周重复一次(每周都有相同的次数)。如果这不是真的,以最大的重复基础(月/年/任何)取代周。



在第一步选择日期之前的最后一周。生成本周发生的所有事件(确保执行所有检查,因为其中一个事件可能在此期间开始重复)对于每个事件,您应该具有开始和结束的具体时间戳,现在检查这些是否重叠如果至少有一些你们碰碰撞,如果不是,那么你很好。


I'm trying to detect event's colision depending of the days recurrency and the timetable.

A version more complex than this issue Algorithm to detect overlapping periods.

My case : The A event is from 8am to 1pm all the tuesday, thurday and saturday, between two dates.

The B event is from 11am to 2pm all the tuesday and thurday, between two dates(differents of event A)

Here, I putted in red the colisions between the two events.

I spent hour trying to write an algorithm to detect if there at least one colision between the two event.

By the way the date of end of an event (tend) can be undeterminate.

Is there an existing algorithm to manage this?

解决方案

Figure out which one ends first. If both A and B are unlimited just pick some random date in the future.

I'm going to assume that your events repeat on a weekly basis (every week there's the same recurring times). If that's not true replace week with the largest repeting basis (month/year/whatever).

Take the last week before the date you picked in the first step. Generate all the events that happen that week (make sure you do all the checks, since one of the events might start repeating in this period. For each event you should have a concrete timestamp for start and end. Now check if these overlap. If at least some of them do then you have a collision. If not then you're good.

这篇关于检测重叠重复时间段的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆