/** * Retrieves array of simple class names of nodes within a particular flow step. * * @param step step in main flow. * @return list step's graph's vertex names. */ protected String[] getNodeFeatures(BaseFlowStep step) { SimpleDirectedGraph graph = step.getGraph(); Object[] vertices = graph.vertexSet().toArray(); String[] returnedFeatures = new String[vertices.length]; for (int i = 0; i < returnedFeatures.length; i++) { returnedFeatures[i] = vertices[i].getClass().getSimpleName(); } return returnedFeatures; }
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; }
@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 ); }
/** * 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; }
public BaseProcessGraph() { graph = new SimpleDirectedGraph( ProcessEdge.class ); }
Set<V> vertexSet = graph.vertexSet(); newEdgeTargets.clear(); for (E v1OutEdge : graph.outgoingEdgesOf(v1)) { V v2 = graph.getEdgeTarget(v1OutEdge); for (E v2OutEdge : graph.outgoingEdgesOf(v2)) { V v3 = graph.getEdgeTarget(v2OutEdge); if (graph.getEdge(v1, v3) != null) { graph.addEdge(v1, v3);
final Map<List<Spot>, Branch> branchMap = new HashMap<>(); for ( final List< Spot > branch : branchGraph.vertexSet() ) final Set< DefaultEdge > incomingEdges = branchGraph.incomingEdgesOf( branch ); final Set< List< Spot >> predecessors = new HashSet<>( incomingEdges.size() ); for ( final DefaultEdge edge : incomingEdges ) final List< Spot > predecessorBranch = branchGraph.getEdgeSource( edge ); predecessors.add( predecessorBranch ); final Set< DefaultEdge > outgoingEdges = branchGraph.outgoingEdgesOf( branch ); final Set< List< Spot >> successors = new HashSet<>( outgoingEdges.size() ); for ( final DefaultEdge edge : outgoingEdges ) final List< Spot > successorBranch = branchGraph.getEdgeTarget( edge ); successors.add( successorBranch );
public void addPredicate( String fromID, String toID, Predicate predicate, Object score ) { if( nodes.containsKey( toID ) ) throw new IllegalArgumentException( "duplicate node name: " + toID ); Node toNode = new Node( toID, predicate, score ); nodes.put( toID, toNode ); graph.addVertex( toNode ); graph.addEdge( nodes.get( fromID ), toNode, count++ ); }
private void rebuildGraph() { OperationResult result = new OperationResult("dummy"); info("Graph before rebuilding: " + orgGraph.vertexSet().size() + " vertices, " + orgGraph.edgeSet().size() + " edges"); orgGraph.removeAllVertices(new HashSet<>(orgGraph.vertexSet())); List<PrismObject> objects = null; try { objects = (List) repositoryService.searchObjects(OrgType.class, null, null, result); } catch (SchemaException e) { throw new AssertionError(e); } for (PrismObject object : objects) { String oid = object.getOid(); orgGraph.addVertex(oid); } for (PrismObject<ObjectType> object : objects) { for (ObjectReferenceType ort : object.asObjectable().getParentOrgRef()) { if (orgGraph.containsVertex(ort.getOid())) { String oid = object.getOid(); try { orgGraph.addEdge(oid, ort.getOid()); } catch (RuntimeException e) { System.err.println("Couldn't add edge " + oid + " -> " + ort.getOid() + " into the graph"); throw e; } } } } info("Graph after rebuilding: "+orgGraph.vertexSet().size()+" vertices, "+orgGraph.edgeSet().size()+" edges"); }
= new SimpleDirectedGraph<>(DefaultEdge.class); objectProperties.addVertex(reducedNode); = new SimpleDirectedGraph<>(DefaultEdge.class); dataProperties.addVertex(reducedNode); SimpleDirectedGraph<Equivalences<ClassExpression>, DefaultEdge> classes = new SimpleDirectedGraph<>(DefaultEdge.class); classes.addVertex(reducedNode);
public ProcessEdge addEdge( Process sourceVertex, Process targetVertex ) { return graph.addEdge( sourceVertex, targetVertex ); }
public void setChildren( ElementGraph parent, List<? extends ElementGraph> children ) { Delegate parentDelegate = new Delegate( parent ); if( !graph.addVertex( parentDelegate ) ) graph.removeAllVertices( Graphs.successorListOf( graph, parentDelegate ) ); for( ElementGraph child : children ) { Delegate childDelegate = new Delegate( child ); graph.addVertex( childDelegate ); graph.addEdge( parentDelegate, childDelegate ); } }
public DefaultDirectedGraph<T,DefaultEdge> getGraph() { if (graph == null) { graph = new DefaultDirectedGraph<>(DefaultEdge.class); for (Equivalences<T> node : dag.vertexSet()) { for (T v : node) graph.addVertex(v); for (T v : node) { graph.addEdge(v, node.getRepresentative()); graph.addEdge(node.getRepresentative(), v); } } for (DefaultEdge edge : dag.edgeSet()) graph.addEdge(dag.getEdgeSource(edge).getRepresentative(), dag.getEdgeTarget(edge).getRepresentative()); } return graph; }
public static <T> EquivalencesDAGImpl<T> reduce(EquivalencesDAGImpl<T> source, SimpleDirectedGraph <Equivalences<T>,DefaultEdge> target) { ImmutableMap.Builder<T, Equivalences<T>> vertexIndexBuilder = new ImmutableMap.Builder<>(); for (Equivalences<T> tSet : target.vertexSet()) { for (T s : source.getVertex(tSet.getRepresentative())) if (tSet.contains(s)) vertexIndexBuilder.put(s, tSet); } ImmutableMap<T, Equivalences<T>> vertexIndex = vertexIndexBuilder.build(); // create induced edges in the target graph for (Equivalences<T> sSet : source) { Equivalences<T> tSet = vertexIndex.get(sSet.getRepresentative()); for (Equivalences<T> sSetSub : source.getDirectSub(sSet)) { Equivalences<T> tSetSub = vertexIndex.get(sSetSub.getRepresentative()); target.addEdge(tSetSub, tSet); } } return new EquivalencesDAGImpl<>(null, target, vertexIndex, source.vertexIndex); }
protected void checkOrgGraph() throws SchemaException { OperationResult result = new OperationResult("temp"); int numberOfOrgsInRepo = repositoryService.countObjects(OrgType.class, null, null, result); info("Checking graph with repo. Orgs in repo: " + numberOfOrgsInRepo + ", orgs in graph: " + orgGraph.vertexSet().size()); assertTrue("# of orgs in repo (" + numberOfOrgsInRepo + ") is different from # of orgs in graph (" + orgGraph.vertexSet().size() + ")", numberOfOrgsInRepo == orgGraph.vertexSet().size()); for (String oid : orgGraph.vertexSet()) { //info("Checking " + oid); OrgType orgType; try { orgType = repositoryService.getObject(OrgType.class, oid, null, result).asObjectable(); } catch (ObjectNotFoundException|SchemaException e) { throw new AssertionError("Couldn't fetch " + oid, e); } assertTrue(orgGraph.vertexSet().contains(orgType.getOid())); Set<String> parentOidsInRepo = new HashSet<>(); for (ObjectReferenceType ort : orgType.getParentOrgRef()) { if (orgGraph.vertexSet().contains(ort.getOid())) { // i.e. the parent does exist parentOidsInRepo.add(ort.getOid()); } } Set<String> parentOidsInGraph = new HashSet<>(); for (DefaultEdge edge : orgGraph.outgoingEdgesOf(oid)) { parentOidsInGraph.add(orgGraph.getEdgeTarget(edge)); } assertEquals("Unexpected parentRefOrg set in " + orgType, parentOidsInGraph, parentOidsInRepo); } info("Graph is OK w.r.t. repo"); }
/** * Store the relationship between a source and a target chord * * @param from source chord * @param to target chord * @param rel the relationship value */ private void setRel (AbstractChordInter from, AbstractChordInter to, Rel rel) { Edge edge = graph.getEdge(from, to); if (edge != null) { edge.rel = rel; } else { graph.addEdge(from, to, new Edge(rel)); } }
@Override public V addVertex() { V v = super.addVertex(); if (v != null) { // add to the topological map ++maxTopoIndex; topoOrderMap.putVertex(maxTopoIndex, v); ++topoModCount; } return v; }
public ResultTree() { graph = new SimpleDirectedGraph<>( new PathFactory() ); ( (PathFactory) graph.getEdgeFactory() ).tree = this; }
/** * */ @Override public Set<Equivalences<T>> getDirectSuper(Equivalences<T> v) { Set<Equivalences<T>> result = new LinkedHashSet<>(); for (DefaultEdge edge : dag.outgoingEdgesOf(v)) { Equivalences<T> source = dag.getEdgeTarget(edge); result.add(source); } return Collections.unmodifiableSet(result); }
public Set<ProcessEdge> outgoingEdgesOf( Process vertex ) { return graph.outgoingEdgesOf( vertex ); }