Select 2D points respecting criteria

Hello,
I have som trouble to write some script part. I do have the optimization tool box, but I'm not sure how to apply properly them. I was considering to use GA, but any optimization would do.
I want to select a number (N) of 2D points from a larger pool of number. But under the constrains of Minimum distance between points X.
ex : I have 100 points (pool), and I want to select 10 (N) of these points with a minium distance of 10 (X)
Edited exemple using 'basic swapt' :
Pool=rand(100,2)*100;
N=10; % Number of points to be selected
X=10; % Mimumum distance
[~,te]=datasample(Pool,N,'Replace',false);
Base=Pool(te,:);
rest=Pool; rest(te,:)=[];
while sum(pdist(Base)<X)>1 % repeat until solution found
tested=sum(pdist(Base)<X); % Objective function
if tested>1
temp=Base;
[~,t1]=datasample(rest,1); % Randomly select one from 'available'
[~,t2]=datasample(Base,1); % Randomly select one from 'selected'
temp(t2,:)=[];
temp=[temp;rest(t1,:)];
if sum(pdist(temp)<X)<tested % if swapt improve results, then keep it
Base=temp;
rest(t1,:)=[];rest=[rest;Base(t2,:)];
end
end
end
scatter(Pool(:,1),Pool(:,2))
hold on
scatter(Base(:,1),Base(:,2),'*r')
The result would be 'Base' at the end. But I would prefer to use a matlab buitl-in function.
Any suggestions how to implement that ?
Thanks,

Answers (0)

Asked:

on 9 Jun 2019

Edited:

on 10 Jun 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!