在加权无向图中,如何找到从特定节点v开始的最小平均成本周期? [英] In weighted undirected graph, how to find the minimum average cost cycle starting from a specific node v?
问题描述
现在,选择一个节点,比如v,我们希望找到包含v且具有最小平均成本的循环。 (即平均成本意味着沿一个周期的平均边缘权重)。
是否有任何有效的算法?
对不起,我错过了一个点 - 循环不需要包含此图中的所有节点。这使得它与汉密尔顿循环问题有所不同。 这相当于哈密尔顿周期问题,它是NP完全的。除非 P = NP ,否则没有最坏情况多项式算法能够解决此问题。
我们可以将哈密尔顿循环问题简化为这个问题:
$ b $ ul
n循环的平均成本为(n + 2)/ n
- a减少正数 n
的顺序。对于v-顶点图,如果图是哈密尔顿图,则存在(v + 2)/ v
的平均成本周期。因为确定哈密尔顿图是NP完全的,所以这个问题是NP难的。
与这个问题相关的决策问题(是否存在一个简单的循环(如果平均长度的路径存在,那么验证一个周期是一个有足够低的平均成本的有效周期),则需要 O(v)
time(使用相邻矩阵表示法)。
因此,你不能希望最坏-case-polynomial-time算法。但是,根据边缘成本的分布,使用动态规划的分支定界算法或分支定界可以非常有效: + :如果图是一个多图,则需要采取两个最便宜的平行边缘而不是相同边缘两次。这可能是最好的一个单独的步骤。 动态编程检查可能非常便宜(只需对一个顶点集合进行散列),但是如果没有预期的保存(该算法很可能会提前结束),可以省略它 - 删除完成集并忽略队列中的任何重复项(具有相同签名的不同路径)。 只要可以计算下限,此算法对任何路径成本度量都可以正常工作。对于平均边缘成本问题,我可以想到几种启发式: 在任何情况下,如果路径是一个循环,计算并返回它的确切成本。 / b> 一个简单的启发式就是假设您可以访问所有剩余的顶点,其边不会比整个图或2连接组件中最便宜的路径便宜。那么相应的预期成本是 如果边数不多的价格低于最便宜的价格,您可以在图的所有边中准备 您始终必须使用公共边以及起点(如果存在的话)的末端顶点或与每个顶点相邻的一个边( 在哈密尔顿循环缩减的情况下,前两个启发法的性能同样很差。启发式(1 + 3)和(2 + 3)的性能相同。最好的情况是时间线性的。最坏的情况是带动态编程的 请注意,测试一般图中是否存在哈密尔顿循环的最着名算法是 Suppose we have a weighted undirected graph, and the number of edge |E| is about k times of node number |V|, i.e, |E| ~= k * |V|. Now, one node, say v, is choosen, and we want to find the cycle containing v with the minimum average cost. (i.e., average cost means average edge weight along a cycle.) Is there any efficient algorithms? Sorry, I missed one point-the cycle do not need to contain all nodes in this Graph. This makes it different from Hamilton cycle problem. This is equivalent to the Hamiltonian cycle problem, which is NP-complete. There is no worst-case-polynomial algorithm able to solve this unless P = NP. We can reduce the hamiltonian cycle problem to this problem: the average cost of an n-cycle is The decision problem associated with this problem ("Is there a simple cycle of an average edge cost of x passing through a vertex V") is in NP: if a path of that average length exists, then verifying that a cycle is a valid cycle with low enough average cost takes Thus, you cannot hope for a worst-case-polynomial-time algorithm. But, depending on the distribution of edge costs, the branch-and-bound algorithm or branch-and-bound with dynamic programming can be very efficient: +: if the graph is a multigraph, you need to to take two cheapest parallel edges rather than the same edge twice. This is probably best handled in a separate step. Dynamic programming checks can be very cheap (just hash a vertex set with a vertex) but if there are very few expected saves (the algorithm is likely to end early), it can be left out - drop the "done" set and ignore any duplicates (different paths with the same signature) in the queue. This algorithm works just as fine for any path cost metric as long as you can compute a lower bound. For the average-edge-cost problem, I can think of several heuristics: In any case, if the path is a cycle, compute and return its exact cost. One simple heuristic is to assume that you may be able to visit all remaining vertices with edges no cheaper than the cheapest path in the entire graph or 2-connected component. Then the respective expected cost is If there are few edges as cheap as the cheapest one, you can prepare a list of You always have to use either a common edge to the start vertex and the end vertex of the path (if one exists) or one of the edges adjanced to each vertex ( In case of the hamiltonian cycle reduction, both of the first two heuristics will perform equally poorly. The heuristics (1+3) and (2+3) will perform equally. The best-case scenario is linear in time. The worst-case scenario is Note that the best known algorithm to test whether a hamiltonian cycle exists in a general graph is 这篇关于在加权无向图中,如何找到从特定节点v开始的最小平均成本周期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
q
:
c_best
,终止循环。否则,
c_best
,拒绝此路径。否则,
c_best_path
设置为此路径,并且 c_path $ c如果具有相同的被访问顶点集合和相同的最后一个顶点(=签名)的路径尚未存在于完成集合中,那么添加$ c到它的成本
q
。
c_best_path
$ b $ p
(cost +(v-edge_length)* c_min)/ edge_length
。好处是这是快速计算。不利的一面是,如果图形很大,而且边缘很少,几乎和最便宜的一样便宜,那么这种算法可以扩展很多路径,以达到它认为的绿洲。
v
的最低价格清单。然后为了估计一个图的成本,考虑:只有最便宜的边完成的路径,用最便宜的两个边完成的路径,用最便宜的三个边完成的路径... while(exp_cost_decreases& amp ;& length< v)exp_cost =(exp_total_cost + = best_edges.next)/ ++长度
。好处是它可以做出更好的猜测。缺点是需要较长的时间来计算是否有很多边缘会降低估计值。
min_cost_adjanced(V)+ min_cost_adjanced(end)
)。如果找到了共同的边缘,那么循环的处理应该在这里完成。
O(v * k * 2 ^ v)
或 O(v * k * log(k)* (假设优先级队列中的
O(log n)
push,pop-min和decrease-key)
O(1.657 ^ v)
a href =http://en.wikipedia.org/wiki/Hamiltonian_cycle_problem#Algorithms =nofollow>根据维基百科,截至2013年8月)
(n+2)/n
- a decreasing sequence for positive n
. For a v-vertex graph, there is a cycle of the average cost of (v+2)/v
iff the graph is a hamiltonian graph. Since the determination if a hamiltonian graph is NP-complete, this problem is NP-hard.O(v)
time (using an adjancency matrix representation).
q
:
c_best
, terminate the loop. Else,
c_best
, reject this path. Else,c_best_path
to this path and c_path
to its cost.q
.c_best_path
(cost + (v - edge_length) * c_min) / edge_length
. The upside is this is fast to compute. The downside is that if the graph is big and there are few edges nearly as cheap as the cheapest one, then this algorithm could expand a lot of paths to reach the "oasis" it thinks there is.v
lowest costs among all edges in the graph. Then to estimate the cost of a graph, consider: The path completed with only the cheapest edge, the path completed with the cheapest two edges, the path completed with the cheapest three edges... while(exp_cost_decreases && length < v) exp_cost = (exp_total_cost += best_edges.next) / ++length
. The upside is it makes better guesses. The downside is that it takes longer to compute if there are lot of edges that lower the estimate.min_cost_adjanced(V) + min_cost_adjanced(end)
). If a common edge is found, the handling of cycles should possibly be done here.O(v*k*2^v)
with dynamic programming or O(v*k*log(k)*k^v)
without (assuming a priority queue with O(log n)
push, pop-min and decrease-key)O(1.657^v)
(according to wikipedia, as of Aug 2013)