1

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?

enter image description here

Community
  • 1
  • 1
Christophe Debove
  • 6,088
  • 20
  • 73
  • 124
  • How you represent it? Basic algorithm would be to check every keypoint (collection of points when anything starts or finishes). If any keypoint occurs between specific event {start; end} interval - you have overlap. Create collection of keypoints for each event (where odd index is start and even is end) and then create collection of all events (which you going to iterate in `foreach`). For each keypoint check every event collection (find index of element which is less). If index is even - you have overlap. You have to avoid checking keypoint with keypoint of same event somehow. – Sinatr Jan 07 '16 at 15:02
  • Has this been resolved? – Nkosi Sep 22 '16 at 22:39

1 Answers1

0

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.

Sorin
  • 11,863
  • 22
  • 26