algorithm - 帕累托边界(集):算法的顺序
问题描述
我必须进行一项挑战,该挑战涉及制定算法来计算帕累托(集合)边界。声明基本上是:
给定正方形 [0,1] x [0,1] 中的 n 个点的集合 S,用算法确定 S 中包含的由 S 的非支配点组成的子集 P。
也有人说,很容易详细说明实现此目的的n*n点比较算法。好吧,我通过到处研究提出了一个算法。挑战仍然是实现n*log(n)阶的算法。我如何获得这些算法的顺序?
提前致谢!
#data
set.seed(103)
x = runif(200)
y = runif(200)
#algorithm
pareto = 1:length(x)
for(i in 1:length(x)){
cond1 = y[i]!=min(y[which(x==x[i])])
cond2 = x[i]!=min(x[which(y==y[i])])
for(k in 1:length(x)){
if((x[i]>x[k] & y[i]>y[k]) | (x[i]==x[k] & cond1) | (y[i]==y[k] & cond2)){
pareto[i] = NA
break
}
}
}
xPareto = x[pareto[!is.na(pareto)]]
yPareto = y[pareto[!is.na(pareto)]]
#graphic:
plot(x, y)
points(xPareto, yPareto, col=2, pch=16)
dat = data.frame(x=xPareto, y=yPareto)
dat = dat[order(dat$x),]
for(i in 1:(nrow(dat)-1)){
segments(dat$x[i], dat$y[i], dat$x[i+1], dat$y[i+1], col=2, lty=2)
}
解决方案
这个问题的有效贪心解决方案背后的直觉在于一个点i
由点j
iffx[i] > x[j]
和 y[i] > y[j]
支配,这意味着当点按任一坐标排序时j
必须在之前。i
因此,如果我们以 x 坐标的递增顺序遍历这些点,那么j
支配点的点(如果有的话)i
必须在点被遍历之前i
被遍历。换句话说,在这个排序中,支配点不可能j
出现在支配点之后。i
因此,使用这种遍历顺序,支配问题(即检查一个点是否被其他点支配)归结为检查我们是否已经看到一个具有较低 y 坐标的点,因为遍历顺序已经强制执行 x 坐标条件. 这可以通过检查每个点的 y 坐标到我们目前看到的最低(最小)y 坐标来轻松完成——如果最小 y 坐标小于当前点i
的 y 坐标,那么j
具有最小 y 坐标占主导地位i
,x[j] < x[i]
因为j
之前看到过i
。
按 x 坐标排序需要O(n log n)
时间,检查每个点(同时保持部分最小 y 坐标)需要O(n)
时间,使整个算法需要O(n log n)
时间。
o = order(x)
minY = Inf
pareto = 1:n
for(j in 1:n){
i = o[j]
if (y[i] <= minY) {
# Part of pareto boundary
minY = y[i]
} else {
# Dominated by some point in pareto boundary
pareto[i] = NA
}
}
推荐阅读
- excel - Excel:如何在 excel 中转义逗号以在另一个函数(具有多个参数)内传递一个函数(具有多个参数)
- classification - 表分类
- python - 使用 Tensorflow 进行深度学习:一次学习一个元素的个性化训练循环
- mysql - codeigniter3,根据时间数据查找总命中数
- javascript - 有没有办法让相机在一个框架中正确使用threejs?
- java - 如何从队列(ArrayBlockingQueue)中获取多个项目?
- c# - 使用 google chrome 浏览器扩展打开带有参数的 .net 应用程序
- gem5 - 在 garnet (gem5) 中进行模拟时,在 stats.txt 文件中获取平均数据包延迟,flit 延迟范围为数千
- java - 如何从 RestController 调用 WebController 并在 Java 中的 String 响应中获取渲染模板
- angular - 使用传入的参数作为过滤器中的属性,角度