@Override public ObjectNode getPropertiesAsJsonNode() { final ObjectNode node = getIRVertexPropertiesAsJsonNode(); node.put("remainingIteration", maxNumberOfIterations); node.set("DAG", getDAG().asJsonNode()); node.set("dagIncomingEdges", crossingEdgesToJSON(dagIncomingEdges)); node.set("dagOutgoingEdges", crossingEdgesToJSON(dagOutgoingEdges)); final ObjectNode edgeMappings = node.putObject("edgeWithLoopToEdgeWithInternalVertex"); edgeWithLoopToEdgeWithInternalVertex.entrySet() .forEach(entry -> edgeMappings.put(entry.getKey().getId(), entry.getValue().getId())); return node; }
@Override public ObjectNode getPropertiesAsJsonNode() { final ObjectNode node = getIRVertexPropertiesAsJsonNode(); node.put("remainingIteration", maxNumberOfIterations); node.set("DAG", getDAG().asJsonNode()); node.set("dagIncomingEdges", crossingEdgesToJSON(dagIncomingEdges)); node.set("dagOutgoingEdges", crossingEdgesToJSON(dagOutgoingEdges)); final ObjectNode edgeMappings = node.putObject("edgeWithLoopToEdgeWithInternalVertex"); edgeWithLoopToEdgeWithInternalVertex.entrySet() .forEach(entry -> edgeMappings.put(entry.getKey().getId(), entry.getValue().getId())); return node; }
/** * Copy Constructor for LoopVertex. * * @param that the source object for copying */ public LoopVertex(final LoopVertex that) { super(that); this.compositeTransformFullName = new String(that.compositeTransformFullName); // Copy all elements to the clone final DAG<IRVertex, IREdge> dagToCopy = that.getDAG(); dagToCopy.topologicalDo(v -> { this.getBuilder().addVertex(v, dagToCopy); dagToCopy.getIncomingEdgesOf(v).forEach(this.getBuilder()::connectVertices); }); that.dagIncomingEdges.forEach(((v, es) -> es.forEach(this::addDagIncomingEdge))); that.iterativeIncomingEdges.forEach((v, es) -> es.forEach(this::addIterativeIncomingEdge)); that.nonIterativeIncomingEdges.forEach((v, es) -> es.forEach(this::addNonIterativeIncomingEdge)); that.dagOutgoingEdges.forEach(((v, es) -> es.forEach(this::addDagOutgoingEdge))); that.edgeWithLoopToEdgeWithInternalVertex.forEach((eLoop, eInternal) -> this.mapEdgeWithLoop(eLoop, eInternal)); this.maxNumberOfIterations = that.maxNumberOfIterations; this.terminationCondition = that.terminationCondition; }
/** * Copy Constructor for LoopVertex. * * @param that the source object for copying */ public LoopVertex(final LoopVertex that) { super(that); this.compositeTransformFullName = new String(that.compositeTransformFullName); // Copy all elements to the clone final DAG<IRVertex, IREdge> dagToCopy = that.getDAG(); dagToCopy.topologicalDo(v -> { this.getBuilder().addVertex(v, dagToCopy); dagToCopy.getIncomingEdgesOf(v).forEach(this.getBuilder()::connectVertices); }); that.dagIncomingEdges.forEach(((v, es) -> es.forEach(this::addDagIncomingEdge))); that.iterativeIncomingEdges.forEach((v, es) -> es.forEach(this::addIterativeIncomingEdge)); that.nonIterativeIncomingEdges.forEach((v, es) -> es.forEach(this::addNonIterativeIncomingEdge)); that.dagOutgoingEdges.forEach(((v, es) -> es.forEach(this::addDagOutgoingEdge))); that.edgeWithLoopToEdgeWithInternalVertex.forEach((eLoop, eInternal) -> this.mapEdgeWithLoop(eLoop, eInternal)); this.maxNumberOfIterations = that.maxNumberOfIterations; this.terminationCondition = that.terminationCondition; }
/** * Merge the list of loopVertices into a single LoopVertex. * @param loopVertices list of LoopVertices to merge. * @return the merged single LoopVertex. */ private LoopVertex mergeLoopVertices(final Set<LoopVertex> loopVertices) { final String newName = String.join("+", loopVertices.stream().map(LoopVertex::getName).collect(Collectors.toList())); final LoopVertex mergedLoopVertex = new LoopVertex(newName); loopVertices.forEach(loopVertex -> { final DAG<IRVertex, IREdge> dagToCopy = loopVertex.getDAG(); dagToCopy.topologicalDo(v -> { mergedLoopVertex.getBuilder().addVertex(v); dagToCopy.getIncomingEdgesOf(v).forEach(mergedLoopVertex.getBuilder()::connectVertices); }); loopVertex.getDagIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addDagIncomingEdge)); loopVertex.getIterativeIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addIterativeIncomingEdge)); loopVertex.getNonIterativeIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addNonIterativeIncomingEdge)); loopVertex.getDagOutgoingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addDagOutgoingEdge)); }); return mergedLoopVertex; }
/** * Merge the list of loopVertices into a single LoopVertex. * @param loopVertices list of LoopVertices to merge. * @return the merged single LoopVertex. */ private LoopVertex mergeLoopVertices(final Set<LoopVertex> loopVertices) { final String newName = String.join("+", loopVertices.stream().map(LoopVertex::getName).collect(Collectors.toList())); final LoopVertex mergedLoopVertex = new LoopVertex(newName); loopVertices.forEach(loopVertex -> { final DAG<IRVertex, IREdge> dagToCopy = loopVertex.getDAG(); dagToCopy.topologicalDo(v -> { mergedLoopVertex.getBuilder().addVertex(v); dagToCopy.getIncomingEdgesOf(v).forEach(mergedLoopVertex.getBuilder()::connectVertices); }); loopVertex.getDagIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addDagIncomingEdge)); loopVertex.getIterativeIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addIterativeIncomingEdge)); loopVertex.getNonIterativeIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addNonIterativeIncomingEdge)); loopVertex.getDagOutgoingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addDagOutgoingEdge)); }); return mergedLoopVertex; } }
final List<Map.Entry<IRVertex, Set<IREdge>>> candidates = loopVertex.getNonIterativeIncomingEdges().entrySet() .stream().filter(entry -> loopVertex.getDAG().getIncomingEdgesOf(entry.getKey()).size() == 0 // no internal inEdges loopVertex.getDAG().getOutgoingEdgesOf(candidate.getKey()).forEach(loopVertex::addDagIncomingEdge); loopVertex.getDAG().getOutgoingEdgesOf(candidate.getKey()).forEach(loopVertex::addNonIterativeIncomingEdge);
final List<Map.Entry<IRVertex, Set<IREdge>>> candidates = loopVertex.getNonIterativeIncomingEdges().entrySet() .stream().filter(entry -> loopVertex.getDAG().getIncomingEdgesOf(entry.getKey()).size() == 0 // no internal inEdges loopVertex.getDAG().getOutgoingEdgesOf(candidate.getKey()).forEach(loopVertex::addDagIncomingEdge); loopVertex.getDAG().getOutgoingEdgesOf(candidate.getKey()).forEach(loopVertex::addNonIterativeIncomingEdge);
loopVerticesOfSameLoop.putIfAbsent(rootLoopVertex, rootLoopVertex); equivalentVerticesOfLoops.putIfAbsent(rootLoopVertex, new HashMap<>()); for (IRVertex vertex : rootLoopVertex.getDAG().getTopologicalSort()) { equivalentVerticesOfLoops.get(rootLoopVertex).putIfAbsent(vertex, vertex); finalRootLoopVertex.getDAG().getTopologicalSort().iterator(); final Iterator<IRVertex> verticesOfCurrentLoopVertex = loopVertex.getDAG().getTopologicalSort().iterator(); final HashMap<IRVertex, IRVertex> equivalentVertices = equivalentVerticesOfLoops.get(finalRootLoopVertex); while (verticesOfRootLoopVertex.hasNext() && verticesOfCurrentLoopVertex.hasNext()) {
loopVerticesOfSameLoop.putIfAbsent(rootLoopVertex, rootLoopVertex); equivalentVerticesOfLoops.putIfAbsent(rootLoopVertex, new HashMap<>()); for (IRVertex vertex : rootLoopVertex.getDAG().getTopologicalSort()) { equivalentVerticesOfLoops.get(rootLoopVertex).putIfAbsent(vertex, vertex); finalRootLoopVertex.getDAG().getTopologicalSort().iterator(); final Iterator<IRVertex> verticesOfCurrentLoopVertex = loopVertex.getDAG().getTopologicalSort().iterator(); final HashMap<IRVertex, IRVertex> equivalentVertices = equivalentVerticesOfLoops.get(finalRootLoopVertex); while (verticesOfRootLoopVertex.hasNext() && verticesOfCurrentLoopVertex.hasNext()) {
final DAG<IRVertex, IREdge> dagToAdd = getDAG();
final DAG<IRVertex, IREdge> dagToAdd = getDAG();