Artifact from the data used resulted in the correct solution when ordered by finish time.
The problem exists with Tommy Carlier's Method
[code]
What about this:
- A = all appointments, sorted by StartTime
- For each appointment A(i):
- if A(i).EndTime >= A(i+1).StartTime then A(i) and A(i+1) overlap
[/code]
A 00:00->11:59
B 09:00->10:00
C 13:00->17:00
D 11:00->23:00
Sorted By Start Time
A 00:00->11:59
B 09:00->10:00
D 11:00->23:00
C 13:00->17:00
Sorted By Finish Time
B 09:00->10:00
A 00:00->11:59
C 13:00->17:00
D 11:00->23:00
Both sorting orders still misses the fact that
A is overlapped by B & D
The method I would use is a variation of my original post.
[code]
Dim overlaps = From a As Appo In appos _
From b As Appo In appos _
Where appos.IndexOf(a) <> appos.IndexOf(b) AndAlso Appo.Overlaps(a, b) _
Select New ova With {.A1 = a, .A2 = b}
[/code]
Where overlaps is defined as
[code]
Shared Function Overlaps(ByVal A As Appo, ByVal B As Appo) As Boolean
Return Not ((A.StartTime > B.FinishTime) OrElse (A.FinishTime < B.StartTime) )
End Function
[/code]