本文整理汇总了Java中org.aikodi.rejuse.graph.Graph.simpleCycles方法的典型用法代码示例。如果您正苦于以下问题:Java Graph.simpleCycles方法的具体用法?Java Graph.simpleCycles怎么用?Java Graph.simpleCycles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.aikodi.rejuse.graph.Graph
的用法示例。
在下文中一共展示了Graph.simpleCycles方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNoCycles
import org.aikodi.rejuse.graph.Graph; //导入方法依赖的package包/类
@Test
public void testNoCycles() {
Graph<Integer> graph = new Graph<>(new UniEdgeFactory<>());
for(int i = 0; i < 10; i++) {
graph.addNode(i);
}
for(int i = 0; i < 9; i++) {
graph.addEdge(i, i+1);
}
List<Path<Integer>> simpleCycles = graph.simpleCycles();
assertTrue(simpleCycles.isEmpty());
graph.addEdge(8, 0);
simpleCycles = graph.simpleCycles();
assertEquals(1,simpleCycles.size());
graph.addEdge(5, 2);
simpleCycles = graph.simpleCycles();
assertEquals(2,simpleCycles.size());
}
示例2: testCycles
import org.aikodi.rejuse.graph.Graph; //导入方法依赖的package包/类
@Test
public void testCycles() {
Graph<Integer> graph = new Graph<>(new UniEdgeFactory<>());
int size = 9;
for(int i = 0; i < size; i++) {
graph.addNode(i);
}
for(int i = 0; i < size - 1; i++) {
graph.addEdge(i, i + 1);
}
graph.addEdge(size - 1, 0);
List<Path<Integer>> simpleCycles = graph.simpleCycles();
assertEquals(1, simpleCycles.size());
}
示例3: write
import org.aikodi.rejuse.graph.Graph; //导入方法依赖的package包/类
public void write(Graph<Type> graph, Writer stream) throws IOException {
List<Path<Type>> simpleCycles = graph.simpleCycles();
Set<Type> involvedInCycle = simpleCycles.stream().flatMap(p -> p.nodes().stream().map(x -> x.object())).collect(Collectors.toSet());
// Set<Edge<Type>> cycleEdges = simpleCycles.stream().flatMap(p -> p.getEdges().stream()).collect(Collectors.toSet());
stream.write("digraph G {\n");
writeNodes(graph,stream, involvedInCycle);
writeEdges(graph,stream, involvedInCycle);
stream.write("}\n");
}