【发布时间】:2013-11-15 18:52:50
【问题描述】:
我想生成一组相当大 (~10,000-50,000) 的完整图 G=(V,E),其中 sharp 三角不等式成立 - 所以对于每个 v,u,w from V: 重量(vu) + 重量(uw) > 重量(vw);权重是正整数。
编辑 顶点是 N 维欧几里得空间中的点,并且边 uv 的每个权重必须大于或等于 u 和 v之间的欧几里得距离>(因此,如果距离是例如 2.753,则允许的最小权重为 3,但可能是 4、5、...)。
到目前为止,我想出了两种幼稚的方法。 这两种方法都是基于N维欧几里得空间中的随机生成点。
一些符号:
- vu 或 vertex1-vertex2 表示一条边
- E(v,u) -- v 和 u 之间的欧式距离
- 对于双精度数/实数 r,ceil(r) 是整数 n,使得 n - 1
- (vu,c) -- 边 vu 的权重为 c
方法一——本地
vertices = {v,u} -- v, u generated randomly
edges = {vu}
weights = {(vu,ceil(E(v,u))}
i = 0
while(i < total_number_of_vertices)
candidate = generate_new_point()
ok = true
foreach (vertex in vertices):
integer_distance = ceil(E(candidate,vertex))
if adding (candidate-vertex, integer_distance) to weights
violates the triangle inequality:
ok = false \\ this candidate is wrong
break \\ breaking for-each; start with new candidate
end_if
end_for_each
if(ok)
i++
add candidate to vertices,
for_each vertex in vertices:
add vertex-candidate to edges
add (vertex-candidate, ceil(E(candidate,vertex))) to weights
end_for_each
end_if
end_while
方法二——全局
vertices = generate_points(total_number_of_vertices)
edges = complete Graph induced by vertices
weights = {}
for_each edge uv:
add (uv, ceil(E(u,v))) to weights
end_for_each
all_good = false
while (!all_good):
all_good = true
for_each edge in edges:
\\ this one has to be check in all triangles that edge belongs to
if edge violates triangle inequality:
\\ by appropriate I mean directly involved
update appropriate weights to satisfy triangle inequality
all_good = false \\ 'updating one edge may disturb other'
end_if
end_for_each
end_while
我非常怀疑这些方法是否足够有效,所以任何帮助——改进它们或提出完全不同的方法——将不胜感激。
如果以上任何内容不够清楚,我会提供更多信息。
如果结果是这样,保持权重为正数integers 太难了,我可以考虑将它们作为正数doubles,但在这种情况下,浮点精度可能是一个需要处理的问题 [因为我真的需要 sharp 三角不等式]
【问题讨论】:
-
为什么不给所有的边赋予相同的权重?
-
对不起,我应该更准确地说(编辑问题)。
-
等一下,你想要一个从顶点到N维欧几里得空间中的点的映射存在吗?您只是提到这个空间作为生成这些权重的一种方式。据我所知,在问题描述中不需要它。所以我认为你的编辑有点不确定。
-
对你的约束有点困惑“对于来自 V 的每个 v,u,w: weight(vu) + weight(uw) > weight(vw)”...如果我们简单地调用 weight(xy ) == distance(x, y),那么你能画出一个不表现出所需属性的非退化三角形吗?我不确定这样的三角形是否存在,除了权重(vu)+权重(uw)==权重(vw)的退化情况(即一个顶点在另外两个定义的线上)。
-
@twalberg 问题是一般距离是
real / double,我想拥有integer的重量。