public BaseProcessGraph() { graph = new SimpleDirectedGraph( ProcessEdge.class ); }
/** * Create a builder for this kind of graph. * * @param edgeClass class on which to base factory for edges * @param <V> the graph vertex type * @param <E> the graph edge type * @return a builder for this kind of graph */ public static <V, E> GraphBuilder<V, E, ? extends SimpleDirectedGraph<V, E>> createBuilder( Class<? extends E> edgeClass) { return new GraphBuilder<>(new SimpleDirectedGraph<>(edgeClass)); }
/** * Create a builder for this kind of graph. * * @param edgeSupplier the edge supplier of the new graph * @param <V> the graph vertex type * @param <E> the graph edge type * @return a builder for this kind of graph */ public static <V, E> GraphBuilder<V, E, ? extends SimpleDirectedGraph<V, E>> createBuilder( Supplier<E> edgeSupplier) { return new GraphBuilder<>(new SimpleDirectedGraph<>(null, edgeSupplier, false)); }
protected void rebuildResourceGraph() { resourceGraph = new SimpleDirectedGraph<Resource, ProcessFactoryHolder>( ProcessFactoryHolder.class ); for( ProcessFactory processFactory : processFactories ) insertProcessFactory( processFactory ); }
private static Graph<String, DefaultEdge> generateGraph(Map<String, ComponentMetadata> commands) { Graph<String, DefaultEdge> graph = new SimpleDirectedGraph<>(DefaultEdge.class); commands.keySet().stream().forEach( c -> graph.addVertex(c) ); commands.entrySet().stream().forEach(entry -> { String key = entry.getKey(); entry.getValue().getDependencies().stream().forEach(dependency -> { try { graph.addEdge(key, dependency); } catch (IllegalArgumentException e) { //ignore it : if a dependency is declared in metadata but is not present on runtime LOGGER.warn("{} is not declared into the component's dependencies {}", key, dependency); } }); } ); return graph; }
Graph<String, DefaultEdge> generateGraph(Map<String, Bootstrap> commands) { Graph<String, DefaultEdge> graph = new SimpleDirectedGraph<>(DefaultEdge.class); commands.keySet().stream().forEach( c -> graph.addVertex(c) ); commands.entrySet().stream().forEach(entry -> { String key = entry.getKey(); entry.getValue().getMetadata().getDependencies().stream().forEach(dependency -> { try { graph.addEdge(key, dependency); } catch (IllegalArgumentException e) { //ignore it : if a dependency is declared in metadata but is not present on runtime LOGGER.warn("{} is not declared into the component's dependencies {}", key, dependency); } }); } ); return graph; }
Graph<String, DefaultEdge> generateGraph(Map<String, Bootstrap> commands) { Graph<String, DefaultEdge> graph = new SimpleDirectedGraph<>(DefaultEdge.class); commands.keySet().stream().forEach( c -> graph.addVertex(c) ); commands.entrySet().stream().forEach(entry -> { String key = entry.getKey(); entry.getValue().getMetadata().getDependencies().stream().forEach(dependency -> { try { graph.addEdge(key, dependency); } catch (IllegalArgumentException e) { //ignore it : if a dependency is declared in metadata but is not present on runtime LOGGER.warn("{} is not declared into the component's dependencies {}", key, dependency); } }); } ); return graph; }
/** * Construct the Module dependency graph of a module loader where each vertex is the module name * @return a mutable snapshot of the underlying dependency */ public DirectedGraph<ModuleId, DefaultEdge> getModuleNameGraph() { SimpleDirectedGraph<ModuleId, DefaultEdge> graph = new SimpleDirectedGraph<ModuleId, DefaultEdge>(DefaultEdge.class); Map<ModuleId, ModuleIdentifier> moduleIdentifiers = getLatestRevisionIds(); GraphUtils.addAllVertices(graph, moduleIdentifiers.keySet()); for (Entry<ModuleId, ModuleIdentifier> entry : moduleIdentifiers.entrySet()) { ModuleId scriptModuleId = entry.getKey(); ModuleIdentifier revisionID = entry.getValue(); ModuleSpec moduleSpec = moduleSpecs.get(revisionID); Set<ModuleId> dependencyNames = getDependencyScriptModuleIds(moduleSpec); GraphUtils.addOutgoingEdges(graph, scriptModuleId, dependencyNames); } return graph; }
public ResultTree() { graph = new SimpleDirectedGraph<>( new PathFactory() ); ( (PathFactory) graph.getEdgeFactory() ).tree = this; }
@Override public Graph<Graph<V, E>, DefaultEdge> getCondensation() { List<Set<V>> sets = stronglyConnectedSets(); Graph<Graph<V, E>, DefaultEdge> condensation = new SimpleDirectedGraph<>(DefaultEdge.class); Map<V, Graph<V, E>> vertexToComponent = new HashMap<>(); for (Set<V> set : sets) { Graph<V, E> component = new AsSubgraph<>(graph, set, null); condensation.addVertex(component); for (V v : set) { vertexToComponent.put(v, component); } } for (E e : graph.edgeSet()) { V s = graph.getEdgeSource(e); Graph<V, E> sComponent = vertexToComponent.get(s); V t = graph.getEdgeTarget(e); Graph<V, E> tComponent = vertexToComponent.get(t); if (sComponent != tComponent) { // reference equal on purpose condensation.addEdge(sComponent, tComponent); } } return condensation; }
config -> { NavigableMap<String, Interface> allInterfaces = config.getAllInterfaces(); Graph<String, Dependency> graph = new SimpleDirectedGraph<>(Dependency.class); allInterfaces.keySet().forEach(graph::addVertex); allInterfaces
new SimpleDirectedGraph<>( Relationship.class ); List<Relationship> edges = hier.getRelationships(); if ( edges != null && edges.size() > 0 )
private void setup(BuildFlow job) { if (jobsGraph == null) { jobsGraph = new SimpleDirectedGraph<JobInvocation, JobEdge>(JobEdge.class); } if (startJob == null) { startJob = new JobInvocation.Start(this); } this.dsl = job.getDsl(); this.dslFile = job.getDslFile(); this.buildNeedsWorkspace = job.getBuildNeedsWorkspace(); startJob.buildStarted(this); jobsGraph.addVertex(startJob); state.set(new FlowState(SUCCESS, startJob)); }
static public <V> SimpleDirectedGraph<V, Edge<V>> getSimpleDiGraph(BinaryRelation<V, V> source) { final SimpleEdgeFactory<V> factory = new SimpleEdgeFactory<V>(); final SimpleDirectedGraph<V, Edge<V>> g = new SimpleDirectedGraph<V, Edge<V>>(factory); final Set<Pair<V, V>> pairs = source.asPairs(); for (Pair<V, V> pair : pairs) { g.addVertex(pair.getElt1()); g.addVertex(pair.getElt2()); g.addEdge(pair.getElt1(), pair.getElt2()); } return g; }
private void assertGraphs( SimpleDirectedGraph<String, Object> full, SimpleDirectedGraph<String, Object> contracted, SimpleDirectedGraph<String, Object> result ) { // Set<String> vertices = ElementGraphs.findClosureViaBiConnected( full, contracted ); Set<String> vertices = ElementGraphs.findClosureViaFloydWarshall( full, contracted ).getLhs(); // Set<String> vertices = ElementGraphs.findClosureViaKShortest( full, contracted ); DirectedSubgraph<String, Object> subgraph = new DirectedSubgraph<>( full, vertices, null ); // System.out.println( "subgraph = " + subgraph ); SimpleDirectedGraph<String, Object> clone = new SimpleDirectedGraph<>( Object.class ); Graphs.addGraph( clone, subgraph ); assertEquals( result, clone ); }
/** * Constructor for the NamedDAG * @param dag the DAG from which we want to keep only the named descriptions */ public static <T> SimpleDirectedGraph <T,DefaultEdge> getNamedDAG(EquivalencesDAG<T> dag) { SimpleDirectedGraph<T,DefaultEdge> namedDAG = new SimpleDirectedGraph<>(DefaultEdge.class); for (Equivalences<T> v : dag) namedDAG.addVertex(v.getRepresentative()); for (Equivalences<T> s : dag) for (Equivalences<T> t : dag.getDirectSuper(s)) namedDAG.addEdge(s.getRepresentative(), t.getRepresentative()); for (Equivalences<T> v : dag) if (!v.isIndexed()) { // eliminate node for (DefaultEdge incEdge : namedDAG.incomingEdgesOf(v.getRepresentative())) { T source = namedDAG.getEdgeSource(incEdge); for (DefaultEdge outEdge : namedDAG.outgoingEdgesOf(v.getRepresentative())) { T target = namedDAG.getEdgeTarget(outEdge); namedDAG.addEdge(source, target); } } namedDAG.removeVertex(v.getRepresentative()); // removes all adjacent edges as well } return namedDAG; }
@Test public void testFindSubGraph2() { SimpleDirectedGraph<String, Object> full = new SimpleDirectedGraph<>( Object.class ); full.addVertex( "1" ); full.addVertex( "0" ); full.addVertex( "a" ); full.addVertex( "b" ); full.addVertex( "c" ); full.addVertex( "d" ); full.addVertex( "e" ); full.addEdge( "a", "b" ); full.addEdge( "b", "c" ); full.addEdge( "c", "d" ); full.addEdge( "c", "e" ); full.addEdge( "1", "0" ); full.addEdge( "0", "c" ); SimpleDirectedGraph<String, Object> contracted = new SimpleDirectedGraph<>( Object.class ); contracted.addVertex( "a" ); contracted.addVertex( "c" ); contracted.addEdge( "a", "c" ); SimpleDirectedGraph<String, Object> result = new SimpleDirectedGraph<>( Object.class ); result.addVertex( "a" ); result.addVertex( "b" ); result.addVertex( "c" ); result.addEdge( "a", "b", full.getEdge( "a", "b" ) ); result.addEdge( "b", "c", full.getEdge( "b", "c" ) ); assertGraphs( full, contracted, result ); }
@Test public void testFindSubGraph() SimpleDirectedGraph<String, Object> full = new SimpleDirectedGraph<>( Object.class ); full.addEdge( "0", "c" ); SimpleDirectedGraph<String, Object> contracted = new SimpleDirectedGraph<>( Object.class ); contracted.addEdge( "1", "c" ); SimpleDirectedGraph<String, Object> result = new SimpleDirectedGraph<>( Object.class );
@BeforeClass public static void setUpBeforeClass() throws Exception { tree = new SimpleDirectedGraph<>(DefaultEdge.class); root = new int[] { 1}; int[] c1 = new int[] {1}; int[] c11 = new int[] {1}; int[] c111 = new int[] {1}; int[] c112 = new int[] {1}; int[] c12 = new int[] {1}; int[] c2 = new int[] {1}; tree.addVertex(root); tree.addVertex(c1); tree.addVertex(c2); tree.addVertex(c11); tree.addVertex(c12); tree.addVertex(c111); tree.addVertex(c112); tree.addEdge(root, c1); tree.addEdge(root, c2); tree.addEdge(c1, c11); tree.addEdge(c1, c12); tree.addEdge(c11, c111); tree.addEdge(c11, c112); }
@Test public void testFindSubGraph3() SimpleDirectedGraph<String, Object> full = new SimpleDirectedGraph<>( Object.class ); full.addEdge( "0", "c" ); SimpleDirectedGraph<String, Object> contracted = new SimpleDirectedGraph<>( Object.class ); contracted.addEdge( "A", "c" ); SimpleDirectedGraph<String, Object> result = new SimpleDirectedGraph<>( Object.class );