Find best suitable time from given time interval of different users.
Rows: 5
fid userid FromDateTime ToDateTime flag
62 1 2012-07-18 01:
I created a 1D line-segment intersection algorithm in PHP utilizing a sweep line (Wikipedia). It works because datetimes can be mapped to a number-line: for example using "milliseconds since epoch".
See the implementation here: http://pastebin.com/iLwJQEF0
The algorithm outputs an array of line-segment intersections (which are also line-segments) that also have a list of all the users available for the duration. You can sort the intersections by your definition of "best" (and reverse it for descending): first by the number of available users and then by their durations. (Already implemented!)
It runs in O(n * log n)
, where n
is the number of time-periods.
Notes: