javascript – JS – 基于密度的精细点数

假设我有一个如下数组(每个小数组是[x,y]):
var myPoints = [[25,28],[26,26],[70,40],[50,50],[300,300],[285,350],[1000,1000]];

假设我需要将阵列缩小到4分. (这是一个小例子,我的实际阵列有几千个点)我怎样才能根据密度对阵列进行细化,以便从点距离较近的区域中移除更多的点,从较低密度的区域移除较少的点?

在这种情况下(将上面的数组从8项减少到4项)我希望返回的数组看起来如下所示:

var thinnedPoints = [[25,1000]];

关于如何处理这个问题的想法是生成一个字典,将点映射到它与另一个点的最小距离(例如,靠近另一个点的点将具有较小的最小距离)然后根据递增的最小距离对字典进行排序,然后删除字典中的每个n’tn项.

这种方法的问题是我不知道如何有效地为每个点生成距离最近的其他点值的距离.

有没有一种有效的方法生成这些值,或者是否有另一种方法来处理这种基于密度的细化问题?

谢谢!

解决方法

看起来你想要解决P中心问题或P中值问题.

Approximability Results for the p-Center Problem by Stefan Buettcher,

The p-Center problem,also kNown as the Min-Max Multicenter problem
or the Facility Location problem,is a famous problem from operations
research. Informally,it is the problem of placing fire stations in a
city so that the maximum time to reach any point in the city is
minimized.

从J. Reese开始于Methods for Solving the p-Median Problem: An Annotated Bibliography

The p-median problem is simply stated as: Given a graph or a network
G = (V,E),find Vp ⊆ V such that |Vp| = p,where p may either
be variable or fixed […],and that the sum of the shortest distances
from the vertices in {V\Vp} to their nearest vertex in Vp is
minimized.

这两个问题一般都是NP完全的,所以没有(已知的)方法在多项式时间内解决它们.但是你可以尝试各种启发式方法.

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...