kriegaex/jgrapht中CyclicTransitiveReduction报错:未找到哈密顿环(HC)
JGraphT CyclicTransitiveReduction 抛出无哈密顿环异常问题
问题场景
测试JGraphT的CyclicTransitiveReduction类时,针对一个强连通有向图调用reduce()方法,抛出运行时异常,提示未找到哈密顿环,但该图实际为强连通图,按照算法逻辑应当存在哈密顿环。同时无法在kriegaex/jgrapht仓库找到提交Issue的入口。
测试代码
Graph<String, DefaultEdge> graph = GraphTypeBuilder .<String, DefaultEdge>directed() .allowingMultipleEdges(false) .allowingSelfLoops(false) .edgeClass(DefaultEdge.class) .buildGraph(); graph.addVertex("a"); graph.addVertex("b"); graph.addVertex("c"); graph.addVertex("d"); graph.addEdge("a", "b"); graph.addEdge("b", "c"); graph.addEdge("c", "a"); graph.addEdge("c", "d"); graph.addEdge("d", "b"); new CyclicTransitiveReduction<>(graph).reduce();
抛出的异常
java.lang.RuntimeException: No Hamiltonian cycle (HC) found. This should never happen and indicates an error in the algorithm, because the graph is strongly connected and a HC must therefore exist.
预期结果
执行CyclicTransitiveReduction.reduce()操作时不应抛出该异常。
内容的提问来源于stack exchange,提问作者sht
相关产品推荐
相关产品推荐

