public ProcessEdge addEdge( Process sourceVertex, Process targetVertex ) { return graph.addEdge( sourceVertex, targetVertex ); }
public boolean addEdge( Process sourceVertex, Process targetVertex, ProcessEdge processEdge ) { return graph.addEdge( sourceVertex, targetVertex, processEdge ); }
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++ ); }
/** * 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)); } }
/** * This method is synchronized and adds an edge and its associated vertices to simple directed graph stored in static memory of this process. * * @param graph synchronized parameter contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}. * @param relation contains parent-child relationship targeted for addition. * @return {@code org.jgrapht.graph.SimpleDirectedGraph} containing the vertices of {@code String}, and edges, as {@link Relationship}s that correspond to relational data. */ private static void addEdge( SimpleDirectedGraph<String, Relationship> graph, Relationship relation ) { LOG.debug( "addEdge" ); synchronized ( graph ) { graph.addVertex( relation.getChild().toUpperCase() ); graph.addVertex( relation.getParent().toUpperCase() ); graph.addEdge( relation.getChild().toUpperCase(), relation.getParent().toUpperCase(), relation ); } }
/** * {@inheritDoc} * * <p> * The complexity of adding a new edge in the graph depends on the number of edges incident to * the "affected region", and should in general be faster than recomputing the whole topological * ordering from scratch. * * @throws IllegalArgumentException if the edge would induce a cycle in the graph */ @Override public E addEdge(V sourceVertex, V targetVertex) { assertVertexExist(sourceVertex); assertVertexExist(targetVertex); E result; try { updateDag(sourceVertex, targetVertex); result = super.addEdge(sourceVertex, targetVertex); } catch (CycleFoundException e) { throw new IllegalArgumentException(EDGE_WOULD_INDUCE_A_CYCLE); } return result; }
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); }
/** * {@inheritDoc} * * <p> * The complexity of adding a new edge in the graph depends on the number of edges incident to * the "affected region", and should in general be faster than recomputing the whole topological * ordering from scratch. * * @throws IllegalArgumentException if the edge would induce a cycle in the graph */ @Override public boolean addEdge(V sourceVertex, V targetVertex, E e) { if (e == null) { throw new NullPointerException(); } else if (containsEdge(e)) { return false; } assertVertexExist(sourceVertex); assertVertexExist(targetVertex); boolean result; try { updateDag(sourceVertex, targetVertex); result = super.addEdge(sourceVertex, targetVertex, e); } catch (CycleFoundException ex) { throw new IllegalArgumentException(EDGE_WOULD_INDUCE_A_CYCLE); } return result; }
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); }
@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); }
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 ); } }
private void insertProcessFactory( ProcessFactory<?, ?, Resource> processFactory ) { for( Resource resource : processFactory.getAllSourceResources() ) resourceGraph.addVertex( resource ); for( Resource resource : processFactory.getAllSinkResources() ) resourceGraph.addVertex( resource ); for( Resource incoming : processFactory.getAllSourceResources() ) { for( Resource outgoing : processFactory.getAllSinkResources() ) resourceGraph.addEdge( incoming, outgoing, new ProcessFactoryHolder( processFactory ) ); } }
@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 ); }
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" ); contracted.addVertex( "a" ); contracted.addVertex( "c" ); contracted.addEdge( "a", "c" ); contracted.addEdge( "1", "c" ); result.addVertex( "b" ); result.addVertex( "c" ); result.addEdge( "a", "b", full.getEdge( "a", "b" ) ); result.addEdge( "b", "c", full.getEdge( "b", "c" ) ); result.addEdge( "1", "0", full.getEdge( "1", "0" ) ); result.addEdge( "0", "c", full.getEdge( "0", "c" ) );
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; }
/** * 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; }
protected void registerObject(ObjectType objectType, boolean registerChildrenLinks) { if (!(objectType instanceof OrgType)) { return; } String oid = objectType.getOid(); LOGGER.info("Registering {} into memory graph", oid); registerVertexIfNeeded(oid); for (ObjectReferenceType ort : objectType.getParentOrgRef()) { registerVertexIfNeeded(ort.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; } } if (registerChildrenLinks) { // let's check for existing children List<String> children = getOrgChildren(oid); LOGGER.info("Registering children of {}: {} into memory graph", oid, children); for (String child : children) { registerVertexIfNeeded(child); orgGraph.addEdge(child, oid); } } LOGGER.info("Registration of {} done.", oid); }
protected void addOrgParent(OrgType org, ObjectReferenceType parentOrgRef, boolean useReplace, OperationResult opResult) throws Exception { List<ItemDelta> modifications = new ArrayList<>(); PrismReferenceValue existingValue = parentOrgRef.asReferenceValue(); ItemDelta itemDelta; if (!useReplace) { itemDelta = prismContext.deltaFactory().reference().createModificationAdd(OrgType.class, OrgType.F_PARENT_ORG_REF, existingValue.clone()); } else { List<PrismReferenceValue> newValues = new ArrayList<>(); for (ObjectReferenceType ort : org.getParentOrgRef()) { newValues.add(ort.asReferenceValue().clone()); } newValues.add(existingValue.clone()); PrismObjectDefinition objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(OrgType.class); itemDelta = prismContext.deltaFactory().reference().createModificationReplace(OrgType.F_PARENT_ORG_REF, objectDefinition, newValues); } modifications.add(itemDelta); repositoryService.modifyObject(OrgType.class, org.getOid(), modifications, opResult); orgGraph.addEdge(org.getOid(), existingValue.getOid()); }
private void addEdge(Edge edge) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException { List<ItemDelta> modifications = new ArrayList<>(); ObjectReferenceType parentOrgRef = new ObjectReferenceType(); parentOrgRef.setType(OrgType.COMPLEX_TYPE); parentOrgRef.setOid(edge.getAncestor()); ItemDelta itemDelta = prismContext.deltaFactory().reference().createModificationAdd(OrgType.class, OrgType.F_PARENT_ORG_REF, parentOrgRef.asReferenceValue()); modifications.add(itemDelta); repositoryService.modifyObject(OrgType.class, edge.getDescendant(), modifications, new OperationResult("dummy")); synchronized(this) { orgGraph.addEdge(edge.getDescendant(), edge.getAncestor()); } }
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"); }