Posted By: Maddus Mattus | Sep 17th @ 12:49 AM
page 2 of 2
Comments: 43 | Views: 690
TommyCarlier
TommyCarlier
I want my scalps!

Air is not free as in speech, but it is free as in air (= gratis). You don't have to pay for air (yet).

exoteric
exoteric
I : Next<I>

Actually you pay by slowly dying. Talk about a steep price.

One might say you're dying to use it.

 

Big Smile

TommyCarlier
TommyCarlier
I want my scalps!

But not using it will make you die faster. A lot faster.

exoteric
exoteric
I : Next<I>

Not if you're in cryosleep Big Smile

Point taken tho Wink

TommyCarlier
TommyCarlier
I want my scalps!

That would be free if I could get to your house for free. Sad

Thanks for the offer, though. A Dutch guy giving away something for free is quite rare. Wink

figuerres
figuerres
???

Hey I just looked for what the "R-tree" is and from a very fast look it seems to be about spaces.

but what you were asking about was overlap in timespans.

 

perhaps a T-Tree might be in order ?  where the nodes are a date-time and span fwd

and child nodes would then be any date-time +span that occurs "inside" the parent span.

 

leaving R-trees for x,y spaces - slightly different beast.

 

just a thought.

figuerres
figuerres
???

Uhm...  I was using "T-tree" as a name for a new kind of tree form, if there is a "T" already I was not aware of it.

 

if it is based on time then it may be what i was thinking of ....

 

all of the *-Tree algo's  are generally the same at a "generic" or high level view.

take a set of x and organize it such that search time is low .... generlay using a recusive way of decribing and building the tree.

there are textbook examples for things like you pick a number and i can get the number in n or less guesses.

where the number of guesses relates to the total size of the set / range of numbers.

 

the nodes have leaves that hold data.

chunks of the tree are nodes and leaves that have a "subset" of the data.

 

like if you had numbers from 0 to 100 then if 50 was your mid point then you might have

                  50

                    |

                   / \

           0-49    51-100

 

and then the 0 to 49 repeates the same thing untill at the bottom you have just leaves with no lower nodes.

and the same for 51-100

 

note that this is also the way some types of fractals are generated, see IFS or Iterative Function Systems

like the Snowflake or triangle fractals.

and fern leaf

and tree ...

 

 

 

 

staceyw
staceyw
Before C# there was darkness...

"It needs to be sorted by FinishTime not starttime"

 

How so?  Sorting by end date you can miss an overlap.  Unless you scan the whole list which would defeat the purpose of a sort.

 

 // Sort by end date - Does not allow quit eairly.
1/1/09 - 1/3/09
               1/3/09 - 1/4/09 ** does not overlap
      1/2/09             -         1/5/09 ** overlaps 1, but would miss this.

free as in number of pixels in the universe if you would photograph *everything*, how is that? Tongue Out

AdamSpeight2008
AdamSpeight2008
The Bandito Coder

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]

 

 

 

 

staceyw
staceyw
Before C# there was darkness...

"Sorted By Start Time

A  00:00->11:59

B  09:00->10:00

D  11:00->23:00

C  13:00->17:00

..

 Both sorting orders still misses the fact that

 A is overlapped by B & D"

 

Huh?  Sorted by start time does *not miss this.  9:00 is less than 11:59 so B returns true.   11:00 is less then 11:59 so D return true.  Testing C returns false as expected.  B and D overlap A.  Maybe not clear on your point.

 

base = A;

t(i+1).Start < base.End

AdamSpeight2008
AdamSpeight2008
The Bandito Coder

 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

 

Implement the above algorithm in code them

staceyw
staceyw
Before C# there was darkness...

All I said was sorting by start date works, and sorting by end date does not.  Given event X, find all other events that overlap works below.  Note: in this implementation, back-to-back meetings do not overlap, so I use "<" instead of "<=".

 

private static void TestOverlap()
{
    List<Event> list = new List<Event>();
    list.Add(new Event() { Start = "00:00".ToDate(), End = "11:59".ToDate(), Description = "A" });
    list.Add(new Event() { Start = "11:00".ToDate(), End = "23:00".ToDate(), Description = "D" });
    list.Add(new Event() { Start = "13:00".ToDate(), End = "17:00".ToDate(), Description = "C" });
    list.Add(new Event() { Start = "09:00".ToDate(), End = "10:00".ToDate(), Description = "B" });
    list.Add(new Event() { Start = "00:00".ToDate(), End="11:59:30".ToDate(), Description = "E"});
    Event source = list[0]; // Find events that overlap this event.

 

    // Sort collection by start date using default comparer on Event class.
    list.Sort();
    Console.WriteLine("Events sorted:");
    list.WriteEnumerable();


    // Get the new index of source in the sorted list.
    int index = list.BinarySearch(source);


    // Take overlapped events.
    var q = from ev in list.Skip(index + 1).TakeWhile(e => e.Start < source.End)
            select ev;
    Console.WriteLine("\nEvents that overlap event: {0}", list[0]);
    q.WriteEnumerable();
}

xgamer
xgamer
Two Sides to Everything

Recently when I was searching for some similiar efficient data structure came across the following ... may be you can have a look at it .. (listed in order of relevance)

In my opinion interval map should be also one of the ways you can look at it. http://www.emilstefanov.net/Projects/RangeSearchTree.aspx

http://www.itu.dk/research/c5/

http://powercollections.codeplex.com/

page 2 of 2
Comments: 43 | Views: 690
Microsoft Communities