How can I find k minimum bounding rectangles to enclose all the given points?

丶灬走出姿态 提交于 2021-01-28 20:27:48

问题


Given a parameter k for the number of boxes and n data points, is there anyway I can find or approximate k axis-aligned bounding rectangles that enclose all the points while keeping the sum of the area of the rectangles minimum?


回答1:


One way is to directly write this as a mathematical optimization problem.

A high-level optimization model can look like as follows:

We first define the decision variables:

r(k,c) = coordinates for k-th box  (e.g. c={x,y,w,h})
         continuous variable with appropriate bounds

x(i,k) = 1 if point i is assigned to box k
         0 otherwise
         binary variable

Then the 2D model can look like:

 minimize sum(k, r(k,w)*r(k,h))          (sum of areas)
 sum(k, x(i,k)) = 1                      (assign point to one box)
 x(i,k) = 1 ==> point i is inside box k  (can be formulated as linear big-M constraints 
                                          or indicator constraints ) 

For testing, I generated 30 points in [0,1]x[0,1] unit box.

Using |k|=5 boxes, we get:

This can be directly generalized to more dimensions (plotting becomes more difficult).

This is essentially a model that combines an assignment problem (for the x variables) and a location problem (for the r variables). It probably only works for relatively small data sets. For this example, I used Gurobi (non-convex MIQP) and this is the proven globally optimal solution. It is noted that even for higher dimensional problems, we can reformulate things into a non-convex MIQCP (i.e. solvable by Gurobi).

For completeness, the data and results for the above model were:

----     52 PARAMETER p  data points

              x           y

i1        0.806       0.173
i2        0.530       0.149
i3        0.648       0.692
i4        0.352       0.020
i5        0.431       0.554
i6        0.641       0.775
i7        0.235       0.781
i8        0.268       0.082
i9        0.973       0.114
i10       0.874       0.667
i11       0.756       0.968
i12       0.199       0.240
i13       0.220       0.261
i14       0.989       0.172
i15       0.066       0.930
i16       0.806       0.832
i17       0.105       0.029
i18       0.229       0.094
i19       0.130       0.903
i20       0.437       0.728
i21       0.248       0.575
i22       0.360       0.516
i23       0.710       0.746
i24       0.704       0.746
i25       0.185       0.936
i26       0.817       0.673
i27       0.463       0.578
i28       0.089       0.657
i29       0.973       0.691
i30       0.894       0.078


----     52 VARIABLE x.L  assignment variables

             k1          k2          k3          k4          k5

i1                                            1.000
i2                                            1.000
i3                                                        1.000
i4                    1.000
i5                                1.000
i6                                                        1.000
i7        1.000
i8                    1.000
i9                                            1.000
i10                                                       1.000
i11                                                       1.000
i12                   1.000
i13                   1.000
i14                                           1.000
i15       1.000
i16                                                       1.000
i17                   1.000
i18                   1.000
i19       1.000
i20                               1.000
i21       1.000
i22                               1.000
i23                                                       1.000
i24                                                       1.000
i25       1.000
i26                                                       1.000
i27                               1.000
i28       1.000
i29                                                       1.000
i30                                           1.000


----     52 VARIABLE r.L  rectangles

             x           y           w           h

k1       0.066       0.575       0.181       0.361
k2       0.105       0.020       0.247       0.241
k3       0.360       0.516       0.103       0.211
k4       0.530       0.078       0.459       0.095
k5       0.641       0.667       0.332       0.301


----     52 VARIABLE z.L                   =        0.290  objective



回答2:


One way of doing it, and I have absolutely no idea if it's any good:

  • Start with N zero-size boxes enclosing N points.
  • Find two points with shortest distance that are in different boxes, and replace two of their boxes with one enclosing box. Now you have one box less.
  • Repeat previous step until you have K boxes.

And now that we have an algorithm that takes as closer to the goal with each iteration we can use A* search to find the best solution, in case the straightforward one isn't the best. Heuristic function is of course the total covered area.



来源:https://stackoverflow.com/questions/60401171/how-can-i-find-k-minimum-bounding-rectangles-to-enclose-all-the-given-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!