@Override protected void initializeIterations() { parentCapacityMap.put(source, Integer.MAX_VALUE); parentMap.put(source, source); List<E> edgeList = new ArrayList<E>(mFlowGraph.getEdges()); for (int eIdx=0;eIdx< edgeList.size();eIdx++) { E edge = edgeList.get(eIdx); Number capacity = edgeCapacityTransformer.apply(edge); if (capacity == null) { throw new IllegalArgumentException("Edge capacities must be provided in Function passed to constructor"); } residualCapacityMap.put(edge, capacity); V source = mFlowGraph.getSource(edge); V destination = mFlowGraph.getDest(edge); if(mFlowGraph.isPredecessor(source, destination) == false) { E backEdge = edgeFactory.get(); mFlowGraph.addEdge(backEdge, destination, source, EdgeType.DIRECTED); residualCapacityMap.put(backEdge, 0); } } }
private static int addToGraph(final DirectedGraph<ElementName, Integer> g, int edgeCount, final ElementName p) { final ElementName parent = p.getParent(); if (!g.containsVertex(p) || !g.containsVertex(parent)) { if (!parent.asJavaName().equals("")) { g.addEdge(edgeCount, p, parent); edgeCount++; } else { g.addVertex(p); } } return edgeCount; }
@Override public void addDependency(final ModuleDependency dependency) { if (graph.getVertices().containsAll(Arrays.asList(dependency.source, dependency.dest))) { Optional<ModuleDependency> dependencyOptional = Optional.ofNullable(graph.findEdge(dependency.source, dependency.dest)); final ModuleDependency moduleDependency = dependencyOptional.orElseGet(() -> { graph.addEdge(dependency, dependency.source, dependency.dest); return dependency; }); moduleDependency.incrementCount(); } }
@Override public void printStats() { logger.info( "Graph contains {} nodes.", graph.getVertexCount() ); logger.info( "Graph contains {} relationships.", graph.getEdgeCount() ); }
private AnnisNode findRoot() { for (AnnisNode n: graph.getVertices()) { if (graph.getInEdges(n).isEmpty()) { return n; } } // This state is impossible to reach given graphs that are created by the TigerTreeVisualizer. throw new RuntimeException("Cannot find a root for the graph."); }
private List<Object> getEndpointVertices() { final List<Object> result = new ArrayList<>(); for (final Object vertex : _graph.getVertices()) { final Collection<JobGraphLink> outEdges = _graph.getOutEdges(vertex); if (outEdges == null || outEdges.isEmpty()) { result.add(vertex); } } return result; }
private Invocation locateInvocation(Method caller, Method callee) { MethodStatistics callerMethod = locateMethodStatistics(caller); MethodStatistics calleeMethod = locateMethodStatistics(callee); Invocation invocation = graph.findEdge(callerMethod, calleeMethod); if (invocation == null) { invocation = new Invocation(); graph.addEdge(invocation, callerMethod, calleeMethod); } return invocation; }
@Override protected void visitClassScc(final DirectedGraph<ElementName, Dependency> scc) { final String sccFile = this.getCurrentClassSccName(); final ElementName firstClass = scc.getVertices().iterator().next(); writeIndex("<li><a href=\"" + sccFile + "\">" + firstClass + " and " + (scc.getVertexCount() - 1) + " others</a></li>"); }
for ( final ProjectRelationship<?, ?> rel : rels ) if ( !graph.containsVertex( rel.getDeclaring() ) ) graph.addVertex( rel.getDeclaring() ); addGA( rel.getDeclaring() ); variableSubgraphs.add( target ); else if ( !graph.containsVertex( target ) ) if ( !graph.containsVertex( target ) ) graph.addVertex( target.asProjectVersionRef() ); addGA( target ); new ArrayList<ProjectRelationship<?, ?>>( graph.findEdgeSet( rel.getDeclaring(), target ) ); if ( !edges.contains( rel ) ) graph.addEdge( rel, rel.getDeclaring(), target.asProjectVersionRef() ); graph.removeEdge( rel ); this.cycles.addAll( cycles );
@Override public void addModule(Module vertex) { graph.addVertex(vertex); }
private edu.uci.ics.jung.graph.DirectedGraph<VertexRef, Edge> convert(final Graph g) { if (!isFullyLevelAware(g)) { throw new IllegalStateException("The graph is not LevelAware. Cannot apply Hierarchy Layout. Aborting"); } // We need to sort the elements. For this purpose we use the DirectedOrderedSparseMultigraph final edu.uci.ics.jung.graph.DirectedGraph<VertexRef, Edge> jungGraph = new DirectedOrderedSparseMultigraph<>(); final Collection<Vertex> displayVertices = g.getDisplayVertices(); // Sort by level final List<Vertex> sortedVertices = displayVertices.stream().filter(v -> v instanceof LevelAware).sorted(new Comparator<Vertex>() { @Override public int compare(Vertex o1, Vertex o2) { return Integer.compare(((LevelAware) o1).getLevel(), ((LevelAware) o2).getLevel()); } }).collect(Collectors.toList()); // Build the graph for(VertexRef v : sortedVertices) { jungGraph.addVertex(v); } // The order of edges does not matter for(Edge e : g.getDisplayEdges()) { jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex()); } return jungGraph; }
for( State st: pg.getVertices()){ StateImplementation impl = new StateImplementation(graph, st, guideName); stateMap.put(st, impl); for( TransitionInstance ti: pg.getEdges()){ State src = pg.getSource(ti); State dest = pg.getDest(ti);
mSinkPartitionNodes.addAll(mFlowGraph.getVertices()); Number currentCapacity = parentCapacityMap.get(currentVertex); Collection<E> neighboringEdges = mFlowGraph.getOutEdges(currentVertex); V neighboringVertex = mFlowGraph.getDest(neighboringEdge);
private void computeMinCut() { for (E e : mOriginalGraph.getEdges()) { V source = mOriginalGraph.getSource(e); V destination = mOriginalGraph.getDest(e); if (mSinkPartitionNodes.contains(source) && mSinkPartitionNodes.contains(destination)) { continue; } if (mSourcePartitionNodes.contains(source) && mSourcePartitionNodes.contains(destination)) { continue; } if (mSinkPartitionNodes.contains(source) && mSourcePartitionNodes.contains(destination)) { continue; } mMinCutEdges.add(e); } }
@Override public Set<ProjectVersionRef> getAllProjects( final ViewParams params ) { return new HashSet<ProjectVersionRef>( graph.getVertices() ); }
@Override public void addDisconnectedProject( final ProjectVersionRef ref ) { if ( !graph.containsVertex( ref.asProjectVersionRef() ) ) { graph.addVertex( ref.asProjectVersionRef() ); } }
public int getMethodCount() { return graph.getVertexCount(); }
/** * print the current graph in a graphviz format. */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("digraph {\n"); for (State s : graph.getVertices()) sb.append(s.toString()).append(";\n"); for (TransitionInstance t: graph.getEdges()) sb.append(t.toString()).append(";\n"); sb.append("}\n"); return sb.toString(); }
private DirectedGraph<AnnisNode, Edge> extractGraph(AnnotationGraph ag, AnnisNode n, String terminalNamespace, String terminalName) { DirectedGraph<AnnisNode, Edge> graph = new DirectedSparseGraph<AnnisNode, Edge>(); copyNode(graph, n, terminalNamespace, terminalName); for (Edge e : ag.getEdges()) { if (hasEdgeSubtype(e, getSecEdgeSubType()) && graph. containsVertex(e.getDestination()) && graph.containsVertex(e.getSource())) { graph.addEdge(e, e.getSource(), e.getDestination()); } } return graph; }
private void dfs(V v, Set<V> mark, Set<V> onStack) { if (mark.contains(v)) return; mark.add(v); onStack.add(v); for (E e : graph.getOutEdges(v)) { V w = graph.getDest(e); if (onStack.contains(w)) { cycles.add(e); w = graph.getSource(e); } else { // mark.remove(w); dfs(w, mark, onStack); } } onStack.remove(v); } }