本文整理汇总了Java中org.aikodi.rejuse.graph.Graph类的典型用法代码示例。如果您正苦于以下问题:Java Graph类的具体用法?Java Graph怎么用?Java Graph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Graph类属于org.aikodi.rejuse.graph包,在下文中一共展示了Graph类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testCompleteCycles
import org.aikodi.rejuse.graph.Graph; //导入依赖的package包/类
@Test
public void testCompleteCycles() {
Graph<Integer> graph = new Graph<>(new UniEdgeFactory<>());
int size = 10;
for(int i = 0; i < size; i++) {
graph.addNode(i);
}
for(int i = 0; i < size; i++) {
for(int j = 0; j < size; j++) {
if(i != j) {
graph.addEdge(i, j);
}
}
}
// List<Path<Integer>> simpleCycles = graph.simpleCycles();
List<List<Integer>> simpleCyclesByNodes = graph.simpleCyclesByNodes();
// List<Path<Integer>> inefficientCycles = graph.inefficientCycles();
// assertEquals(inefficientCycles.size(), simpleCyclesByNodes.size());
}
示例3: 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());
}
示例4: 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");
}
示例5: writeEdges
import org.aikodi.rejuse.graph.Graph; //导入依赖的package包/类
private void writeEdges(Graph<Type> graph, Writer stream, Set<Type> cycleEdges) throws IOException {
for(Edge<Type> n: graph.edges()) {
String color ="";
if(cycleEdges.contains(n.getFirst().object())) {
color = "color=\"red\"";
}
stream.write(name(n.getFirst().object()) + " -> " +name(n.getSecond().object())+ "[ label=\"\" "+color+" ];\n");
};
}
示例6: visualize
import org.aikodi.rejuse.graph.Graph; //导入依赖的package包/类
public void visualize(Writer writer) throws InputException, IOException {
// ListenableDirectedGraph<Element, DefaultEdge> graph = buildDependencyGraph();
// DOTExporter<Element,DefaultEdge> exporter = createExporter();
// exporter.export(writer, graph);
Graph graph = dependencyResult(Handler.printer(System.out), Handler.printer(System.out)).graph();
new DOTWriter().write(graph, writer);
}
示例7: writeNodes
import org.aikodi.rejuse.graph.Graph; //导入依赖的package包/类
private void writeNodes(Graph<Type> graph, Writer stream,Set<Type> types) throws IOException {
for(Node<Type> n: graph.nodes()){
stream.write(name(n.object()) + "[ label=\""+n.object().name() + "\" " + attributes(n.object(), types) +" ];\n");
};
}