7

Let's say that I have a circular timeline (a 24hr period) with n number of points during these 24hr. I want to cover all points with intervals of a given fixed length k (<24h) and I want to use as few intervals as possible. Is there a good algorithm for determining the start points of the optimal intervals?

If we don't allow intervals to "wrap around" then it becomes easy (we can simply greedily schedule the first interval to start at the first point, cover as many points as possible and pick the next point for the next interval etc.).

A naive quadratic solution would be to try every point as a start point for the "first" interval and do as above but I have a feeling we can do something smarter?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
faximan
  • 324
  • 2
  • 15
  • A possibly-trivial issue: Are intervals allowed to overlap? If 24/k is not an integer and intervals cannot overlap and all intervals are of the same length k, there might be no solution. – James Waldby - jwpat7 Jun 24 '13 at 19:14
  • Oh yeah sure, they can overlap if they need to. – faximan Jun 24 '13 at 19:18
  • My gut feeling is that the greedy approach of starting the first interval at one of the endpoints of the longest empty gap between points should be optimal, but I'm having difficulty thinking of a proof. Anyone have any insights that will help prove/disprove? – beaker Jun 25 '13 at 16:14

3 Answers3

1

Note about your suggested naive quadratic solution: You'll need to consider each point as either an interval start or an interval end.


I'm not sure that this is the optimal solution, but it is better than the naive quadratic:

Let's name the points {P1, ..., Pn}.

Since any point must be covered by at least one interval, find all intervals that may cover point P1 (Assume that an interval either starts at Pi, or ends at Pi). For each of these intervals, continue greedily, as you would on a linear timeline.

To optimize it further, instead of starting with P1, we'll need to find the best start-point - that would be the point that may be covered by the minimal number of intervals. I don't know if we can do this in linear time, but a good heuristic may be to start with the point that the sum of its distances from its two neighbors is maximal.

Edit: An O(nlogn) way for finding the best starting point:

We can build a list of possible 2n segments (for any point Pi an interval may either starts at Pi or ends at Pi). Next, insert these intervals into a segment tree.

Don't use a regular segment tree, but instead of storing the intervals in the canonical subsets, simply store the number of them (See the notes section in Wikipedia's article).

Tree construction would take O(nlogn) time. Now, for each point Pi, count the number of segments (intervals) it falls into. This would take O(logn) for each point, or O(nlogn) total.

Select the point with the minimal number of intervals. For each of the intervals continue with the greedy approach, as described above.

Lior Kogan
  • 19,919
  • 6
  • 53
  • 85
1

The easy answer is ... constraint programming:

  1. you are given a set P of points (say as minutes from midnight) and k the interval length
  2. you want the minimal number of intervals (a set S which denote the beginning of the interval) of length k such that

    a. for all p elem P, there exist s in S st p >= s && p <= s+k, in words all given points are 'covered' (if you want it circular just use mod on s+k)

    b. for all S there exist no S' st the number of elements in S' is less than the number of elements in S. in words the result set has minimal cardinality.

Feed it to gecode...and you are done.

There are various possible representations for the intervals, the tradeoffs are nicely explained in K Apt's book 'Principles of Constraint Programming'.

user1666959
  • 1,805
  • 12
  • 11
0

Maybe you can use a space filling curve and a hierarchical cluster with quadkeys. There is a french website ordering the days along a space filling curve: http://lapin-bleu.net/riviera/?p=78. But what is the probem with the quadratic algorithm?

Micromega
  • 12,486
  • 7
  • 35
  • 72
  • Actually, I just felt like it should be easier to find the best starting point. The proposed solutions might work but I feel that they are too complicated for me since I probably won't have to deal with that many points. Might just do the quadratic one. – faximan Jun 24 '13 at 20:47
  • Space filling curve isn't useless but difficult. At east it reduce the complexity a dimension. – Micromega Jun 24 '13 at 21:23