jlblancoc / nanoflann

nanoflann: a C++11 header-only library for Nearest Neighbor (NN) search with KD-trees
Other
2.22k stars 488 forks source link

Customized masks support on KD tree? #206

Closed majianjia closed 1 year ago

majianjia commented 1 year ago

I am trying to solve the Travel Salesmen Problem on some 2d points using a greedy algorithm. Where I have to mark which point has been visited. In this scenario, those points have been visited should be excluded when searing for the next nearest point.

I found nanoflann lacks of this kind of interface that for calling customized masks function. Am I right or I doing it wrong? Thanks

jlblancoc commented 1 year ago

It's correct, that feature is not built it, since it's too specific and are too may ways to implement it.

One possible way to do it is with your custom metric/dataset adaptor class, which should have access to the list of already visited indices, then when asked for the coordinates of an already-visited point, just return some crazy large number, to ensure it will not be picked as the closest one...

My two cents :-)

majianjia commented 1 year ago

Thanks for your reply. Not sure your 2 cents actually work but cost nothing to try :-)