我在此引用的Kung算法简介https://engineering.purdue.edu/~sudhoff/ee630/Lecture09.pdf
我非常感谢一些帮助,使我的代码使用更少的内存(它总是在"解决"函数中失败),并且可能更好/更正确地运行。 Kung的算法本质上是完全递归的,但我确信有比现在更好的方法。这就是我所拥有的!
using PyPlot
function read_graph_data(fname)
f=open(fname)
arr=readdlm(f, ',', Float64, header=true)
close(f)
return arr
end
function solve(data)
if size(data, 1) == 1
return Set(data)
else
T= solve(data[1:convert(Int64, floor(size(data,1)/2))])
B= solve(data[convert(Int64, ceil(size(data,1)/2)): size(data,1)])
for (b in B)
for (t in T)
if (b.>t == all_true)
setdiff!(T, b)
continue
end
if b.>t == all_false
continue
end
end
push!(T, b)
end
return T
end
end
num_obj = 2
all_true = (trues(num_obj))
all_false = transpose(falses(num_obj))
data = first(read_graph_data("Lake-Problem-Reference-Set.csv"))
data[:, 1] *= -1
data = data[:, 1:num_obj]
solve(data)