我有一个描述物体之间距离的二维数组:
A B C
A 0 1 2
B 1 0 3
C 2 3 0
例如距离(A,B)= 1,距离(B,C)= 3,距离(A,C)= 2, 距离(x,y)=距离(x,y)。我不知道关于这个距离的更多信息,它不是欧几里德距离或任何公知的距离函数。
如何查找组和分区点数(x,y)?
答案 0 :(得分:1)
我找到了解决方案:
D =[x][y] #two dimencion array with distances between x and y
sorted_distance = sorted_distance(D) # all values apears in D, delete duplicates and sort from max to min value
for distance in sorted_distance:
V = D.keys()
E = []
for x in V:
for y in V:
if x==y: continue
if D[x][y]<=distance:
E.append((x,y))
G = Grapth(V,E)
connected_components = get_connected_components(G)
if len(connected_components)>1: # this value could be increase if result is not rewarding
return connected_components