给定一个非直接的图G,我想用最少的简单路径覆盖所有边。
例如,对于这样的图表,
B E
| |
A--C--D--F--G
A--C--D--F--G, B--C--D--F--E
是最佳解决方案,而A--C--D--F--G , B--C , E--F
则不是。{{1}}。
任何算法?
答案 0 :(得分:2)
这为您提供了两个选项:
对于选项一,您可以尝试一种贪婪的解决方案:
while (graph is not covered):
pick arbitrary 2 connected not covered vertices v1,v2
if there are none matching:
choose an arbitrary not covered vertex
add an arbitrary path starting from this vertex
else:
choose the longest simple path from v1 to v2 [can be found with BFS/DFS]
add this path
对于选项二,一个天真的回溯解决方案将是
1. find P={all possible paths}
2. create S=2^P //the power set of P
3. chose s in S such that for each s' in S: |s| <= |s'| and both s,s' cover all vertices.
请注意,此解决方案为O(2^(n!))
,因此虽然它是最佳的,但却不切实际。