Java Code Examples for edu.uci.ics.jung.graph.Graph#addEdge()
The following examples show how to use
edu.uci.ics.jung.graph.Graph#addEdge() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FGViewUpdater.java From ghidra with Apache License 2.0 | 6 votes |
private void validateAndAddEdge(FGController controller, FunctionGraph functionGraph, GroupedFunctionGraphVertex groupedVertex, FGEdge edge) { Graph<FGVertex, FGEdge> graph = functionGraph; FGVertex startVertex = updateEdgeVertexForUngrouping(functionGraph, groupedVertex, edge.getStart()); FGVertex destinationVertex = updateEdgeVertexForUngrouping(functionGraph, groupedVertex, edge.getEnd()); if (edge.getStart() != startVertex || edge.getEnd() != destinationVertex) { // one or both of the original endpoints must have been grouped edge = edge.cloneEdge(startVertex, destinationVertex); } graph.addEdge(edge, startVertex, destinationVertex); }
Example 2
Source File: SelectByScopedFlowPlugin.java From ghidra with Apache License 2.0 | 6 votes |
private void addEdgesForStartVertex(Graph<CodeBlockVertex, CodeBlockEdge> graph, Map<CodeBlock, CodeBlockVertex> blockToVertexMap, CodeBlockVertex start, TaskMonitor monitor) throws CancelledException { CodeBlock codeBlock = start.getCodeBlock(); CodeBlockReferenceIterator destinations = codeBlock.getDestinations(monitor); for (; destinations.hasNext();) { monitor.checkCanceled(); CodeBlockReference reference = destinations.next(); CodeBlock destinationBlock = reference.getDestinationBlock(); CodeBlockVertex end = blockToVertexMap.get(destinationBlock); if (end == null) { continue; // no vertex means the code block is not in our function } graph.addEdge(new CodeBlockEdge(start, end), start, end); } }
Example 3
Source File: DependencyGraph.java From baleen with Apache License 2.0 | 6 votes |
private void addAnnotatorDependencies( Graph<AnalysisEngine, Integer> graph, AnalysisEngine ae1, AnalysisEngine ae2) { // If there's already a dependency, then just return as we don't want multiple edges if (graph.findEdge(ae1, ae2) != null) return; // If the inputs of ae1 match the outputs of ae2, then ae1 is dependent on ae2 // We don't need to check both ways as this will be caught by the loop, although // we could be more efficient here. AnalysisEngineAction a1 = getAction(ae1); AnalysisEngineAction a2 = getAction(ae2); if (overlaps(a1.getInputs(), a2.getOutputs())) { graph.addEdge(++edgeId, ae2, ae1, EdgeType.DIRECTED); return; } }
Example 4
Source File: DependencyGraphTest.java From baleen with Apache License 2.0 | 6 votes |
@Test public void testRemoveLoops() { Graph<String, String> graph = new SparseMultigraph<>(); graph.addVertex("v1"); graph.addVertex("v2"); graph.addVertex("v3"); graph.addEdge("e1", "v1", "v2", EdgeType.DIRECTED); graph.addEdge("e2", "v2", "v1", EdgeType.DIRECTED); graph.addEdge("e3", "v1", "v3", EdgeType.DIRECTED); DependencyGraph.removeLoops(graph); assertEquals(3, graph.getVertexCount()); assertEquals(2, graph.getEdgeCount()); assertTrue(graph.getEdges().contains("e1")); assertTrue(graph.getEdges().contains("e3")); }
Example 5
Source File: DependencyGraphTest.java From baleen with Apache License 2.0 | 6 votes |
@Test public void testRemoveLayer() { Graph<String, String> graph = new SparseMultigraph<>(); graph.addVertex("v1"); graph.addVertex("v2"); graph.addVertex("v3"); graph.addEdge("e1", "v1", "v2", EdgeType.DIRECTED); graph.addEdge("e2", "v2", "v1", EdgeType.DIRECTED); graph.addEdge("e3", "v3", "v2", EdgeType.DIRECTED); DependencyGraph.removeLayer(graph); assertEquals(2, graph.getVertexCount()); assertEquals(2, graph.getEdgeCount()); assertTrue(graph.getVertices().contains("v1")); assertTrue(graph.getVertices().contains("v2")); assertTrue(graph.getEdges().contains("e1")); assertTrue(graph.getEdges().contains("e2")); }
Example 6
Source File: PageRankTest.java From AGDISTIS with GNU Affero General Public License v3.0 | 6 votes |
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void soEqual() throws IOException { Graph g = new DirectedSparseMultigraph<Node, String>(); Node n1 = new Node("N1", 0, 0,"pagerank"); Node n2 = new Node("N2", 0, 0,"pagerank"); Node n3 = new Node("N3", 0, 0,"pagerank"); Node n4 = new Node("N4", 0, 0,"pagerank"); g.addEdge("e1", n1, n2); g.addEdge("e2", n2, n3); g.addEdge("e3", n3, n4); g.addEdge("e4", n4, n1); PageRank pr = new PageRank(); pr.runPr(g, 100, 0.001); assertTrue(n1.getPageRank() == 0.25); assertTrue(n2.getPageRank() == n3.getPageRank()); assertTrue(n3.getPageRank() == n4.getPageRank()); assertTrue(n4.getPageRank() == n1.getPageRank()); // System.out.println("EQUAL1: " + n1); }
Example 7
Source File: AqlViewer.java From CQL with GNU Affero General Public License v3.0 | 5 votes |
private static <N, E> JComponent viewGraph(DMG<N, E> g) { Graph<N, E> sgv = new DirectedSparseMultigraph<>(); for (N n : g.nodes) { sgv.addVertex(n); } for (E e : g.edges.keySet()) { sgv.addEdge(e, g.edges.get(e).first, g.edges.get(e).second); } if (sgv.getVertexCount() == 0) { return new JPanel(); } Layout<N, E> layout = new FRLayout<>(sgv); layout.setSize(new Dimension(600, 400)); VisualizationViewer<N, E> vv = new VisualizationViewer<>(layout); Function<N, Paint> vertexPaint = x -> Color.black; DefaultModalGraphMouse<N, E> gm = new DefaultModalGraphMouse<>(); gm.setMode(Mode.TRANSFORMING); vv.setGraphMouse(gm); gm.setMode(Mode.PICKING); vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); Function<E, String> et = Object::toString; Function<N, String> vt = Object::toString; vv.getRenderContext().setEdgeLabelTransformer(et); vv.getRenderContext().setVertexLabelTransformer(vt); GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv); JPanel ret = new JPanel(new GridLayout(1, 1)); ret.add(zzz); ret.setBorder(BorderFactory.createEtchedBorder()); vv.getRenderContext().setLabelOffset(16); vv.setBackground(Color.white); return ret; }
Example 8
Source File: ClusterModelGraphCreator.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
private void createGraph(Graph<String, String> graph, String parentName, HierarchicalClusterNode node) { String childName = vertexFactory.create(); vertexMap.put(childName, node); graph.addEdge(edgeFactory.create(), parentName, childName); for (HierarchicalClusterNode subNode : node.getSubNodes()) { createGraph(graph, childName, subNode); } }
Example 9
Source File: PageRankTest.java From AGDISTIS with GNU Affero General Public License v3.0 | 5 votes |
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void oneGetsMost() throws IOException { Graph g = new DirectedSparseMultigraph<Node, String>(); Node m = new Node("Master", 0, 0,"pagerank"); Node s1 = new Node("Slave1", 0, 0,"pagerank"); Node s2 = new Node("Slave2", 0, 0,"pagerank"); Node s3 = new Node("Slave3", 0, 0,"pagerank"); Node s4 = new Node("Slave4", 0, 0,"pagerank"); g.addEdge("e1", s1, m); g.addEdge("e2", s2, m); g.addEdge("e3", s3, m); g.addEdge("e4", s4, m); g.addEdge("self", m, m); // node to self: this edge prevents // randomWalker PageRank pr = new PageRank(); pr.runPr(g, 100, 0.001); // System.out.println(m + " ( = 1/5 * 0.15 + 0.85)"); // System.out.println(s1 + " ( = 1/5 * 0.15)"); // System.out.println(s2 + " (usw.)"); // System.out.println(s3); // System.out.println(s4); }
Example 10
Source File: JungBuilder.java From depan with Apache License 2.0 | 4 votes |
private void addForwardEdge( Graph<GraphNode, GraphEdge> graph, GraphEdge edge) { graph.addEdge(edge, edge.getHead(), edge.getTail()); }
Example 11
Source File: JungBuilder.java From depan with Apache License 2.0 | 4 votes |
private void addReverseEdge( Graph<GraphNode, GraphEdge> graph, GraphEdge edge) { graph.addEdge(edge, edge.getTail(), edge.getHead()); }
Example 12
Source File: HitsTest.java From AGDISTIS with GNU Affero General Public License v3.0 | 4 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testSimpleHITS() throws InterruptedException, IOException { Graph g = new DirectedSparseMultigraph<Node, String>(); Node a = new Node("dbpedia:Barack_Obama,_Sr.", 0, 0, "hits"); Node b = new Node("dbpedia:Barack_Obama", 0, 0,"hits"); Node c = new Node("dbpedia:Washington,_D.C.", 0, 0,"hits"); Node d = new Node("dbpedia:Washington,_D.C._(novel)", 0, 0,"hits"); Node e1 = new Node("dbpedia:Ann_Dunham", 0, 1,"hits"); Node e2 = new Node("dbpedia:University_of_Hawaii", 0, 1,"hits"); Node e3 = new Node("dbpedia:Hawaii", 0, 1,"hits"); Node e4 = new Node("dbpedia:White_House", 0, 1,"hits"); Node e5 = new Node("dbpedia:Federal_district", 0, 1,"hits"); Node e6 = new Node("dbpedia:Elizabeth_II", 0, 1,"hits"); Node e7 = new Node("dbpedia:London", 0, 1,"hits"); Node e8 = new Node("dbpedia:New_York", 0, 1,"hits"); Node e9 = new Node("dbpedia:United_Kingdom", 0, 1,"hits"); Node e10 = new Node("dbpedia:Gore_Vidal", 0, 1,"hits"); g.addEdge("dbpedia:Barack_Obama,_Sr.", a, b); g.addEdge("dbpedia:Barack_Obama,_Sr.1", a, e1); g.addEdge("dbpedia:Barack_Obama,_Sr.2", a, e2); g.addEdge("dbpedia:Barack_Obama,_Sr.3", e1, a); g.addEdge("dbpedia:Barack_Obama,_Sr.4", e2, a); g.addEdge("dbpedia:Barack_Obama", b, e3); g.addEdge("dbpedia:Barack_Obama1", b, e4); g.addEdge("dbpedia:Barack_Obama2", e3, b); g.addEdge("dbpedia:Washington,_D.C.", c, e5); g.addEdge("dbpedia:Washington,_D.C.1", e5, c); g.addEdge("dbpedia:Washington,_D.C._(novel)", d, e10); g.addEdge("dbpedia:Washington,_D.C._(novel)1", e10, d); g.addEdge("dbpedia:Washington,_D.C._(novel)2", d, e9); g.addEdge("dbpedia:United_Kingdom", e9, e6); g.addEdge("dbpedia:United_Kingdom2", e9, e7); g.addEdge("dbpedia:United_Kingdom3", e7, e9); g.addEdge("dbpedia:Gore_Vidal", e10, e8); g.addEdge("dbpedia:White_House", e4, c); g.addEdge("dbpedia:White_House1", e4, b); g.addEdge("dbpedia:Ann_Dunham", e1, e2); g.addEdge("dbpedia:University_of_Hawaii", e2, e3); HITS algo = new HITS(); int k = 20; algo.runHits(g, k); }