Quantcast
Channel: Yet Another Math Programming Consultant
Viewing all articles
Browse latest Browse all 809

Maximum number of points with minimum distance

$
0
0

In [1] the following problem is posted:


Consider \(N\) points and a minimum distance \(\mathit{\color{darkblue}{MinDist}}\). Pick as many points as possible from this collection, such that the distances between the selected points is at least \(\mathit{\color{darkblue}{MinDist}}\).

A small data set can look like:

----      9 PARAMETER p  coordinates of points

x y

i1 17.17584.327
i2 55.03830.114
i3 29.22122.405
i4 34.98385.627
i5 6.71150.021
i6 99.81257.873
i7 99.11376.225
i8 13.06963.972
i9 15.95225.008
i10 66.89343.536
i11 35.97035.144
i12 13.14915.010
i13 58.91183.089
i14 23.08266.573
i15 77.58630.366
i16 11.04950.238
i17 16.01787.246
i18 26.51128.581
i19 59.39672.272
i20 62.82546.380
i21 41.33111.770
i22 31.4214.655
i23 33.85518.210
i24 64.57356.075
i25 76.99629.781
i26 66.11175.582
i27 62.74528.386
i28 8.64210.251
i29 64.12554.531
i30 3.15279.236
i31 7.27717.566
i32 52.56375.021
i33 17.8123.414
i34 58.51362.123
i35 38.93635.871
i36 24.30324.642
i37 13.05093.345
i38 37.99478.340
i39 30.00312.548
i40 74.8876.923
i41 20.2020.507
i42 26.96149.985
i43 15.12917.417
i44 33.06431.691
i45 32.20996.398
i46 99.36036.990
i47 37.28977.198
i48 39.66891.310
i49 11.95873.548
i50 5.54257.630


One way to formulate this is using a quadratic model:


MIQCP Model
\[\begin{align}\max&\sum_i \color{darkred}x_i \\ & \mathit{\color{darkblue}{Dist}}_{i,j} \ge \mathit{\color{darkblue}{MinDist}} \cdot \color{darkred}x_i \cdot \color{darkred}x_j && \forall i\lt j \\ & \color{darkred}x_i \in \{0,1\}\end{align}\]


The quadratic constraint implement the implication \[\color{darkred}x_i=\color{darkred}x_j=1 \Longrightarrow \mathit{\color{darkblue}{Dist}}_{i,j} \ge \mathit{\color{darkblue}{MinDist}}\] I.e., the constraint is not binding when either \(\color{darkred}x_i=0\) or \(\color{darkred}x_j=0\). Note that the input is just the distance matrix. We don't need to know the coordinates of the points. This means that this model works for any dimension (2d in this case or 3d in the original question).

We can easily linearize the model:

 
Linear MIP Model
\[\begin{align}\max&\sum_i \color{darkred}x_i \\ & \mathit{\color{darkblue}{Dist}}_{i,j} \ge \mathit{\color{darkblue}{MinDist}} \cdot ( \color{darkred}x_i + \color{darkred}x_j -1) && \forall i\lt j \\ & \color{darkred}x_i \in \{0,1\}\end{align}\]



Here we plot the solution when we want a minimum distance of 50. The maximum number of points we can select under this regime is 5. Note that the solution is, in general, not unique. For this particular dataset, there are 29 different, optimal solutions with 5 selected points.

A more frugal version of the linearized model is suggested by Paul Rubin:

 
Frugal MIP Model
\[\begin{align}\max&\sum_i \color{darkred}x_i \\ &  \color{darkred}x_i + \color{darkred}x_j \le 1 && \forall i\lt j | \mathit{\color{darkblue}{Dist}}_{i,j} \lt \mathit{\color{darkblue}{MinDist}}   \\ & \color{darkred}x_i \in \{0,1\}\end{align}\]


This version has fewer constraints. It says: \(\color{darkred}x_i\) and \(\color{darkred}x_j\) cannot be both in the solution if they are too close.

To measure the performance, I increased the problem size to \(N=150\). We see:


----    107 PARAMETER results  

miqcp mip mip2

n 150.000150.000150.000
rows 11176.00011176.0005329.000
status Optimal Optimal Optimal
obj 6.0006.0006.000
time 1004.3440.0470.031
nodes 108742.000
iterations 1313398.00033.00041.000


Obviously, the linear models are doing much better. These were solved during preprocessing and did not need any branch&bound nodes. 

References



Appendix: GAMS model



$onText

 

 

    Find a maximal subset of points such that the distance between the

    selected points is larger than some given value.

   

 

$offText

 

 

option mip = cplex, miqcp = cplex, threads=0;

 

 

*-----------------------------------------------------------

* data

*-----------------------------------------------------------

 

set

   'all points' /i1*i150/

   '2d coordinates' /x,y/

;

alias(i,j);

 

parameter p(i,c) 'coordinates of points';

p(i,c) = uniform(0,100);

display$(card(p)<=5) p;

 

scalar mindist /50/;

 

*-----------------------------------------------------------

* derived data

*-----------------------------------------------------------

 

set ij(i,j) 'lower triangular part';

ij(i,j) = ord(i) < ord(j);

 

parameter dist(i,j) 'distances';

dist(ij(i,j)) = sqrt(sum(c,sqr(p(i,c)-p(j,c))));

 

*------------------------------------------------

* reporting macros

*------------------------------------------------

 

parameter results(*,*);

 

acronym TimeLimit;

acronym Optimal;

 

* macros for reporting

$macro report(m,label) \

    results('n',label) = card(i); \

    results('rows',label) = m.numequ; \

    results('status',label)$(m.solvestat=1) = Optimal; \

    results('status',label)$(m.solvestat=3) = TimeLimit; \

    results('obj',label) = z.l; \

    results('time',label) = m.resusd; \

    results('nodes',label) = m.nodusd; \

    results('iterations',label) = m.iterusd; \

    display results;

 

*-----------------------------------------------------------

* MIQCP model

*-----------------------------------------------------------

 

binary variable x(i) 'selected points';

variable 'objective variable';

 

equations

   obj      'objective'

   emindist 'minimum distance constraint'

;

 

obj.. z =e= sum(i, x(i));

emindist(ij(i,j))..  dist(i,j) =g= mindist*x(i)*x(j);

 

model m /all/;

solve m maximizing z using miqcp;

report(m,'miqcp')

 

*-----------------------------------------------------------

* linearized MIP model

*-----------------------------------------------------------

 

equations

  emindist2 'linearized minimum distance constraint'

;

 

emindist2(ij(i,j))..  dist(i,j) =g= mindist*(x(i)+x(j)-1);

 

model m2 /obj,emindist2/;

solve m2 maximizing z using mip;

report(m2,'mip')

 

*-----------------------------------------------------------

* frugal MIP model

*-----------------------------------------------------------

 

equations

  emindist3 "if distance<mindist, don't allow both in solution"

;

 

emindist3(ij(i,j))$(dist(ij)<mindist)..

      x(i)+x(j) =l= 1;

 

model m3 /obj,emindist3/;

solve m3 maximizing z using mip;

report(m3,'mip2')

 


Viewing all articles
Browse latest Browse all 809

Trending Articles