@Override public void tupleInserted(V source, V target) { alg.notifyTcObservers(alg.sccs.getPartition(source), alg.sccs.getPartition(target), Direction.INSERT); }
public Set<Tuple<V>> getTcRelation() { Set<Tuple<V>> resultSet = new HashSet<Tuple<V>>(); for (V sourceRoot : sccs.getPartitionHeads()) { Set<V> sources = sccs.getPartition(sourceRoot); if (sources.size() > 1 || GraphHelper.getEdgeCount(sources.iterator().next(), gds) == 1) { for (V source : sources) { for (V target : sources) { resultSet.add(new Tuple<V>(source, target)); } } } Set<V> reachableTargets = counting.getAllReachableTargets(sourceRoot); if (reachableTargets != null) { for (V targetRoot : reachableTargets) { for (V source : sources) { for (V target : sccs.getPartition(targetRoot)) { resultSet.add(new Tuple<V>(source, target)); } } } } } return resultSet; }
associations)) { individualRefCounters.get(var).incrementCounter(ReferenceType.READ_ONLY); unifiedRefCounters.get(variableUnions.getPartition(var)).incrementCounter(ReferenceType.READ_ONLY); final ReferenceType referenceClass = classifyReference(ref); individualRefCounters.get(var).incrementCounter(referenceClass); unifiedRefCounters.get(variableUnions.getPartition(var)).incrementCounter(referenceClass);
@Override public void tupleDeleted(V source, V target) { alg.notifyTcObservers(alg.sccs.getPartition(source), alg.sccs.getPartition(target), Direction.DELETE); }
@Override public Set<V> getAllReachableSources(V target) { V targetRoot = sccs.find(target); Set<V> containedNodes = sccs.getPartition(targetRoot); Set<V> sources = CollectionsFactory.createSet(); if (containedNodes.size() > 1 || GraphHelper.getEdgeCount(target, gds) == 1) { sources.addAll(containedNodes); } Set<V> rootSet = counting.getAllReachableSources(targetRoot); if (rootSet != null) { for (V _root : rootSet) { sources.addAll(sccs.getPartition(_root)); } } return sources; }
@Override public Set<V> getAllReachableTargets(V source) { V sourceRoot = sccs.find(source); Set<V> containedNodes = sccs.getPartition(sourceRoot); Set<V> targets = CollectionsFactory.createSet(); if (containedNodes.size() > 1 || GraphHelper.getEdgeCount(source, gds) == 1) { targets.addAll(containedNodes); } Set<V> rootSet = counting.getAllReachableTargets(sourceRoot); if (rootSet != null) { for (V _root : rootSet) { targets.addAll(sccs.getPartition(_root)); } } return targets; }
/** * Return the SCCs which are reachable from the SCC represented by the root node. Note that an SCC can be present * multiple times in the returned list (multiple edges between the two SCCs). * * @param root * @return the list of reachable target SCCs */ private List<V> getTargetSCCsOfSCC(V root) { List<V> targetSCCs = new ArrayList<V>(); for (V containedNode : this.sccs.getPartition(root)) { IMemoryView<V> targetNodes = this.gds.getTargetNodes(containedNode); for (V target : targetNodes.distinctValues()) { targetSCCs.add(this.sccs.find(target)); } } return targetSCCs; }
/** * Return the SCCs from which the SCC represented by the root node is reachable. Note that an SCC can be present * multiple times in the returned list (multiple edges between the two SCCs). * * @param root * @return the list of reachable target SCCs */ private List<V> getSourceSCCsOfSCC(V root) { List<V> sourceSCCs = new ArrayList<V>(); for (V containedNode : this.sccs.getPartition(root)) { IMemoryView<V> sourceNodes = this.gds.getSourceNodes(containedNode); for (V source : sourceNodes.distinctValues()) { sourceSCCs.add(this.sccs.find(source)); } } return sourceSCCs; }
/** * Returns true if the SCC represented by the given root node has incoming edges in the reduced graph, * false otherwise (if this SCC is a source in the reduced graph). * * @param root the root node of an SCC * @return true if it has incoming edges, false otherwise * @since 1.6 */ public boolean hasIncomingEdges(final V root) { for (final V containedNode : this.sccs.getPartition(root)) { final IMemoryView<V> sourceNodes = this.gds.getSourceNodes(containedNode); for (final V source : sourceNodes.distinctValues()) { final V otherRoot = this.sccs.find(source); if (!Objects.equals(root, otherRoot)) { return true; } } } return false; }
/** * Returns true if the SCC represented by the given root node has outgoing edges in the reduced graph, * false otherwise (if this SCC is a sink in the reduced graph). * * @param root the root node of an SCC * @return true if it has outgoing edges, false otherwise * @since 1.6 */ public boolean hasOutgoingEdges(V root) { for (final V containedNode : this.sccs.getPartition(root)) { final IMemoryView<V> targetNodes = this.gds.getTargetNodes(containedNode); for (final V target : targetNodes.distinctValues()) { final V otherRoot = this.sccs.find(target); if (!Objects.equals(root, otherRoot)) { return true; } } } return false; }
public List<V> getReachabilityPath(V source, V target) { if (!isReachable(source, target)) { return null; } else { Set<V> sccsInSubGraph = CollectionHelper.intersectionMutable(counting.getAllReachableTargets(source), counting.getAllReachableSources(target)); sccsInSubGraph.add(sccs.find(source)); sccsInSubGraph.add(sccs.find(target)); Set<V> nodesInSubGraph = CollectionsFactory.createSet(); for (V sccRoot : sccsInSubGraph) { nodesInSubGraph.addAll(sccs.getPartition(sccRoot)); } return GraphHelper.constructPath(source, target, nodesInSubGraph, gds); } }
private void checkParameterUsageCounter(ParameterRef var, Map<Variable, VariableReferenceCount> individualCounters, Map<Set<Variable>, VariableReferenceCount> unifiedRefCounters, UnionFind<Variable> variableUnions, PatternBody body) { Variable parameter = var.getReferredParam(); VariableReferenceCount individualCounter = individualCounters.get(var); VariableReferenceCount unifiedCounter = unifiedRefCounters.get(variableUnions.getPartition(var)); if (individualCounter.getReferenceCount() == 0) { error(String.format("Parameter '%s' is never referenced in body '%s'.", parameter.getName(), getPatternBodyName(body)), parameter, PatternLanguagePackage.Literals.VARIABLE__NAME, IssueCodes.SYMBOLIC_VARIABLE_NEVER_REFERENCED); } else if (unifiedCounter.getReferenceCount(ReferenceType.POSITIVE) == 0) { error(String.format("Parameter '%s' has no enumerable reference in body '%s'.", var.getName(), getPatternBodyName(body)), parameter, PatternLanguagePackage.Literals.VARIABLE__NAME, IssueCodes.SYMBOLIC_VARIABLE_NO_POSITIVE_REFERENCE); } }
public boolean checkTcRelation(DRedTcRelation<V> tc) { for (V s : tc.getTupleStarts()) { for (V t : tc.getTupleEnds(s)) { if (!isReachable(s, t)) return false; } } for (V root : counting.getTcRelation().getTupleStarts()) { for (V end : counting.getTcRelation().getTupleEnds(root)) { for (V s : sccs.getPartition(root)) { for (V t : sccs.getPartition(end)) { if (!tc.containsTuple(s, t)) return false; } } } } return true; }
(sourceSCC.equals(targetSCC) && sccs.getPartition(sourceSCC).size() == 1 && GraphHelper .getEdgeCount(sccs.getPartition(sourceSCC).iterator().next(), gds) == 0) || notifyTcObservers(sccs.getPartition(sourceSCC), sccs.getPartition(targetSCC), Direction.INSERT); Set<V> containedNodes = sccs.getPartition(newRoot); if (observers.size() > 0 && sccs.getPartition(sourceRoot).size() == 1 && GraphHelper.getEdgeCount(source, target, gds) == 1) { notifyTcObservers(source, source, Direction.INSERT);
} else { Graph<V> g = GraphHelper.getSubGraph(sccs.getPartition(sourceRoot), gds); (sourceSCC.equals(targetSCC) && sccs.getPartition(sourceSCC).size() == 1 && GraphHelper .getEdgeCount(sccs.getPartition(sourceSCC).iterator().next(), gds) == 0) || notifyTcObservers(sccs.getPartition(sourceSCC), sccs.getPartition(targetSCC), Direction.DELETE); if (observers.size() > 0 && sccs.getPartition(sourceRoot).size() == 1 && GraphHelper.getEdgeCount(source, target, gds) == 0) { notifyTcObservers(source, source, Direction.DELETE);
private void checkLocalVariableUsageCounter(Variable var, Map<Variable, VariableReferenceCount> individualCounters, Map<Set<Variable>, VariableReferenceCount> unifiedRefCounters, UnionFind<Variable> variableUnions) { VariableReferenceCount individualCounter = individualCounters.get(var); VariableReferenceCount unifiedCounter = unifiedRefCounters.get(variableUnions.getPartition(var)); if (individualCounter.getReferenceCount(ReferenceType.POSITIVE) == 1 && individualCounter.getReferenceCount() == 1 && !PatternLanguageHelper.isNamedSingleUse(var)