具有两个不同边权重的图形

时间:2021-10-06 19:03:03

I'm trying to find a path between two points. Each edge in my graph has two separate weights. I already know the shortest path, if you only take the first weight into account, between the two points. What I need to do is to maximize The second weight whilst making sure the first does not exceed a constraint. The constraint is that the total of the first weight should not exceed it's total on the shortest path by more than X%. How do I go about doing that? The final solution needn't be an exact solution, as it is intended to be a heuristic.

我想找到两点之间的路径。我图中的每条边都有两个不同的权重。我已经知道最短的路径,如果你只考虑第一个重量,在两点之间。我需要做的是最大化第二重量,同时确保第一重量不超过约束。约束条件是第一个重量的总和不应超过它在最短路径上的总数超过X%。我该怎么做呢?最终的解决方案不一定是一个精确的解决方案,因为它旨在成为一种启发式方法。

The graph is directed with edges going from node 1 to 2 and from node 2 to 1 in some cases (but not all).

在某些情况下(但不是全部),图表的边缘从节点1到2以及从节点2到1。

Please note that

请注意

BFS would simply take too much time. My problem is that I need to go down a path that doesn't exceed the limit for the total of the first weight along it but the total for the second weight along it needs to be maximized. The graph is huge with hundreds of thousands of edges.

BFS只需要花费太多时间。我的问题是我需要沿着一条不超过沿着它的第一个重量总和的限制的路径,但沿着它的第二个重量的总和需要最大化。图表非常庞大,有数十万个边缘。

1 个解决方案

#1


I'd simply do a breadth first search:

我只是做一个广度优先搜索:

Beginning from your starting node collect all possible next nodes and keep track of first and second weight, as long as the first weight meets the constraint.

从您的起始节点开始收集所有可能的下一个节点并跟踪第一和第二权重,只要第一个权重满足约束。

Build a list of all possible paths from these nodes and iterate.

从这些节点构建所有可能路径的列表并进行迭代。

If a node doesn't produce any more path candidates, because all edges have a first weight that is to high, compare it to the current best path and replace it with the new one, if the new one is better.

如果一个节点没有产生任何更多的路径候选,因为所有边都具有高的第一权重,将其与当前最佳路径进行比较并将其替换为新路径(如果新的路径更好)。

#1


I'd simply do a breadth first search:

我只是做一个广度优先搜索:

Beginning from your starting node collect all possible next nodes and keep track of first and second weight, as long as the first weight meets the constraint.

从您的起始节点开始收集所有可能的下一个节点并跟踪第一和第二权重,只要第一个权重满足约束。

Build a list of all possible paths from these nodes and iterate.

从这些节点构建所有可能路径的列表并进行迭代。

If a node doesn't produce any more path candidates, because all edges have a first weight that is to high, compare it to the current best path and replace it with the new one, if the new one is better.

如果一个节点没有产生任何更多的路径候选,因为所有边都具有高的第一权重,将其与当前最佳路径进行比较并将其替换为新路径(如果新的路径更好)。