views:

76

answers:

4

In two dimensional space, given a bunch of rectangles, every rectangle covers a number of points and there may be overlap between two arbitrary rectangles, for a specified number K, how can i find the k rectangles such that their union cover the maximum number of points? In this problem, if a point is covered by more than two rectangles it is only counted once and we assume that the positions & size of rectangles and positions of points are fixed as given in the input.

Can someone give me the algorithm used to solve it? Or point out that it can be reduced to some known problem?

A: 

I think You need combinatorial optimization algorithm which can select values/nodes(eg here rectangles) so that given function gives maxima. I don't know it in detail but you can try optimization in MATLAB

Thx, but i want a definite algorithm
outlaw
A: 

I'm assuming you have fixed rectangles (i.e., you can't choose how big your rectangles are, and where they are positioned). If you could choose the size of the rectangles, the problem would be trivial. If you could choose where to position your rectangles, this would also be a different problem (solved by another greedy algorithm).

For more details, you need to tell us how your rectangles and points are specified, and how they are stocked---or whether you need help picking a good data structure given your input format.

Now, a greedy solution to your problem is to proceed as follow. Initially begin with all rectangles "chosen" as covering points. Then, one by one, remove the rectangle covering the least amount of points, until you have only K rectangles in your set. The complexity of this algorithm is polynomial, and its efficiency hinges on how you are going to implement the query "find out which rectangle covers the least points". Using a heap, you could do this in O(1), with a pre-processing phase to build the heap (the complexity of which will depend on how your points are stored).

EDIT : the problem with this solution is that at each step, the answer to "will make it so I have the least amount of points uncovered" is not unique, several rectangles can, at that step, fill the criterion; in the end, it may turn out that one choice would have been better than another, and this could not have been determined at that step...

   /---------\
   |2        |
/-----\   /-------\
|1 | *|   |* |   3|
\-----/   \-------/
   |         |
   \---------/

For example, here, all rectangles are tied: if you remove any one rectangle, you will uncover no points. However it is obvious to see that the best 1-solution is to have rectangle 2 cover the points (note that rectangles 1 and 3 could be arbitrarily wide, so size is not a telling factor).

Jérémie
I'm afraid this greedy method is wrong, because those rectangle covering large number of points may overlap with each other badly, and other rectangles which cover small number of points may have no overlap with each other
outlaw
Fear not! :-), this greedy method is not wrong, but perhaps I should rephrase what I am testing for so it is clearer: "which rectangle, if removed, will make it so I have the least amount of points uncovered."
Jérémie
A: 

If you have n rectangles, k of which you have to choose, then there are (choose n k) different combinations, i.e. (/ (factorial n) (factorial k) (factorial (- n k))). In the general case, I suspect that you have to enumerate these combinations and calculate their coverage. However, you might be able to cut this short a bit by ordering the rectangles by coverage (i.e. number of points covered by themselves), starting with the combination of the biggest rectangles, and stopping when the remaining rectangles cannot surpass your previously best combination.

Svante
Ordering the rectangles by area is not necessarily useful: a very large rectangle could be covering few or no points at all, because it is not in the zone where the points are concentrated; and this zone could be covered by a single very small rectangle. On the other hand, maybe the given fixed set of rectangles makes this a useful criterion.
Jérémie
@Jérémie: that objection is trivially solvable by measuring the area in covered points. I shall edit accordingly.
Svante
+2  A: 

This looks like a geometric version of the Maximum Coverage Problem which is closely related to the Set Cover Problem, and those two are NP-Complete.

From what I could find, it looks like the Geometric version of Set Cover is also NP-Complete and the paper here has a fast approximation algorithm which exploits the fact that it is geometric: http://www.almaden.ibm.com/u/kclarkson/set_cover/p.pdf. The fact the the geometric version of Set Cover is NP-Complete implies that the geometric version of the Maximum Coverage problem is also NP-Complete.

Of course, your special case of the sets being rectangles might still lend itself to exact polynomial time algorithms, but I doubt it. Perhaps the references in the above paper might lead you to a good solution.

Hope that helps!

Moron
+1, of course, well spotted.
Jérémie
Thx, you are right, my problem can be reduced to the Maximum Coverage Problem, so it is NP!Proof is by contradiction:Suppose my problem can be solved in polynomial time O(POLY(N)), then the Maximum Coverage Problem can be solved in time O(K*POLY(N)), this contradicts that MCP is NP.
outlaw
@outlaw: No. You have to reduce Maximum coverage to your problem, not the other way round (in order to prove NP-Completeness). Also, being in NP and being NP-complete mean two very different things. Every NP-Complete problem is in NP, but not necessarily the other way round.
Moron