带权重限制的图搜索

发布于 2024-11-30 09:16:11 字数 455 浏览 4 评论 0原文

我有一个无向加权图,其中任意类型的对象作为节点。两个节点 A 和 B 之间的边的权重是这两个节点在区间 (0, 1] 中的相似度。相似度为 0 导致节点之间没有连接,因此可以对图进行划分。

给定一个目标权重w 和起始节点 S,这是一种查找权重大于 w 的所有节点的算法。子节点(从 S 中看到)应该具有路径上所有权重的乘积,即:

S --(0.9)-- N1 --(0.9)-- N2 --(0.6) -- N3

从 S 开始,节点将具有 w 和起始节点 S。以下相似值:

N1: 0.9 
N2: 0.9 * 0.9 = 0.81
N3: 0.9 * 0.9 * 0.6 = 0.486

所以给定 S目标权重为 0.5,搜索应返回 N1 和 N3。从 N2 开始的搜索将返回 S、N1 和 N3。

他们有适合我的需求的算法吗?

I have a undirected, weighted graph with objects of an arbitrary type as nodes. The weight of an edge between two nodes A and B is the similarity of these two nodes in the interval (0, 1]. A similarity of 0 leads to no connection between to nodes, so the graph may be partitioned.

Given a target weight w and a start-node S, which is an algorithm to find all nodes that have a weight > w. Subnodes (seen from S) should have the product of all weights on the path. I.e:

S --(0.9)-- N1 --(0.9)-- N2 --(0.6) -- N3

Starting with S the nodes will have the following similarity values:

N1: 0.9 
N2: 0.9 * 0.9 = 0.81
N3: 0.9 * 0.9 * 0.6 = 0.486

So given S and the target weight 0.5 the search should return N1 and N3. Wheres a search starting from N2 would return S, N1 and N3.

Are their any algorithms that fit my needs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷离° 2024-12-07 09:16:11

请注意以下几点:

  1. log(p1 * p2) = log(p1) + log(p2)
  2. 如果 p1 p2 ,然后 log(p1) log(p2) 因此:-log(p1) > -log(p2)

主张【基于上面提到的1,2】:找到从s到t最相似的路线,实际上就是找到从s到t的最小路径,其中权重为-log原始的。

我建议使用以下算法,基于 Dijkstra 算法 和上述声明。

1. define for each edge e: w'(e) = -log(w(e)) //well defined because w(e) > 0
2. run Dijkstra's algorithm on the graph with the modified weights.
3. return all vertices v that their weight is dijkstra(v) < -log(needed)

note the following:

  1. log(p1 * p2) = log(p1) + log(p2)
  2. if p1 < p2 then log(p1) < log(p2) and thus: -log(p1) > -log(p2)

Claim [based on the 1,2 mentioned above]: finding the most similar route from s to t, is actually finding the minimum path from s to t, where weights are -log of original.

I suggest the following algorithm, based on Dijkstra's algorithm and the above claim.

1. define for each edge e: w'(e) = -log(w(e)) //well defined because w(e) > 0
2. run Dijkstra's algorithm on the graph with the modified weights.
3. return all vertices v that their weight is dijkstra(v) < -log(needed)
压抑⊿情绪 2024-12-07 09:16:11

您可以尝试使用贝尔曼-福特算法,因为它可以很好地处理边的求和和乘法,以及最小值和最大值(您可以通过执行反转操作来计算最长路径 - 使用最大值)。

另外,如果对所有路径取对数,问题就会从乘法简化为求和。之后,您可以反转权重的符号(将问题从寻找最小值转变为寻找最大值),并在该图上使用贝尔曼-福特算法。由于所有权重最初都在 0 和 1 之间,因此在这两个转换之后,您应该也能够使用 Dijkstra。

然后在计算路径后,只需恢复转换并检查哪些“距离”适合您。

You could try using the Bellman-Ford algorithm, since it's working fine with both summation and multiplication of edges, as well as with minimums and maximums (you calculate the longest paths -- use the maximum -- by doing the inverted operation).

Also, if you take a logarithm of all your paths, the problem then reduces from multiplication to summation. After that, you could reverse the signs of the weights (to turn the problem from finding a minimum to finding the maximum) and use the Bellman-Ford algorithm on that graph. Since all your weights are initially between 0 and 1, after both of these transformations you should probably be able to use Dijkstra as well.

Then after calculating the paths, just revert the transformations back and check which "distances" suit you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文