-2

I'm working on timetable for school purposes. I receive time-ordered list of events and my goal is to draw them on timeline. The problem is that some event overlaps another (as shown on the picture below). What I want to do is to "pack" this events into the smallest space possible. This is single day with overlapping events.

First picture shows what I managed to do so far. As seen on picture, rectangles do not intersect each other and fill free space nicely. BUT I didn't manage to come up with reasonable algorithm for ordering.Second picture shows how events should be ordered.

This are two conditions, which make this problem different from classic packing problem:

  1. Events has given x-coordinates (defined by beginning and end).
  2. Events has fixed width, height is arbitrary.

1 Answers1

0

This Problem reminds me a little bit of file system fragmentation problem. Easy solutions would be to implement one of the famous algorithm e.g. first-fit or best-fit.

But I guess you want the best solution. That's why I'd suggest implementing a backtracking algorithm. Be aware that I can cause long runtimes but I think this doesn't really matter in your context.

magoeke
  • 111
  • 6