diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/SelectableDataTransfers.java b/AlgebraicDataflowArchitectureModel/src/algorithms/SelectableDataTransfers.java index cc1594b..c59e4f2 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/SelectableDataTransfers.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/SelectableDataTransfers.java @@ -9,12 +9,14 @@ public class SelectableDataTransfers { static public ResourceDependencyGraph init(ResourceDependencyGraph graph) { List nodes = new ArrayList<>(graph.getNodes()); + // set push only attributes for (Node n: graph.getNodes()) { if (nodes.contains(n) && ((StoreAttribute) ((ResourceNode) n).getAttribute()).isNeeded()) { nodes.remove(n); trackEdges(n, nodes); } } + // set push/pull attributes to the remaining edges for (Edge e : graph.getEdges()) { if (((ResourceDependency) e).getAttribute() == null) { PushPullAttribute ppat = new PushPullAttribute(); @@ -28,6 +30,7 @@ } static private void trackEdges(Node n, List nodes) { + // recursively set push only attributes to input side edges for (Edge e : ((ResourceNode) n).getInEdges()) { PushPullAttribute ppat = new PushPullAttribute(); ppat.addOption(PushPullValue.PUSH); diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java index 19a23a3..9473eb6 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java @@ -6,6 +6,9 @@ import java.io.FileReader; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import com.mxgraph.layout.mxCircleLayout; import com.mxgraph.layout.mxCompactTreeLayout; @@ -23,6 +26,7 @@ import models.Node; import models.dataFlowModel.DataFlowModel; import models.dataFlowModel.DataflowChannelGenerator; +import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.ResourceDependency; import models.dataFlowModel.ResourceDependencyGraph; import models.dataFlowModel.ResourceNode; @@ -124,27 +128,24 @@ geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); geo2.setRelative(true); - HashMap channelsIn = new HashMap<>(); - HashMap channelsOut = new HashMap<>(); - HashMap resources = new HashMap<>(); + Map channelsIn = new HashMap<>(); + Map channelsOut = new HashMap<>(); + Map resources = new HashMap<>(); + Map> resourceToChannels = new HashMap<>(); + Map> channelToResources = new HashMap<>(); for (Edge e : resourceDependencyGraph.getEdges()) { if (e instanceof ResourceDependency) { ResourceDependency dependency = (ResourceDependency) e; DataflowChannelGenerator channelGen = dependency.getChannelGenerator(); if (channelsIn.get(channelGen) == null || channelsOut.get(channelGen) == null) { - Object channel = graph.insertVertex(parent, null, channelGen.getChannelName(), 150, 20, 30, 30); // insert - // a - // channel - // as - // a - // vertex + Object channel = graph.insertVertex(parent, null, channelGen.getChannelName(), 150, 20, 30, 30); // insert�@a�@channel�@as�@a�@vertex mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); port_in.setVertex(true); - graph.addCell(port_in, channel); + graph.addCell(port_in, channel); // insert the input port of a channel mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); port_out.setVertex(true); - graph.addCell(port_out, channel); + graph.addCell(port_out, channel); // insert the output port of a channel channelsIn.put(channelGen, port_in); channelsOut.put(channelGen, port_out); } @@ -165,10 +166,29 @@ if (e instanceof ResourceDependency) { ResourceDependency dependency = (ResourceDependency) e; DataflowChannelGenerator channelGen = dependency.getChannelGenerator(); - graph.insertEdge(parent, null, dependency.getAttribute(), resources.get(dependency.getSource()), - channelsIn.get(channelGen)); - graph.insertEdge(parent, null, null, channelsOut.get(channelGen), - resources.get(dependency.getDestination())); + ResourceNode srcResource = (ResourceNode) dependency.getSource(); + ResourceNode dstResource = (ResourceNode) dependency.getDestination(); + Map resToChannelEdges = resourceToChannels.get(srcResource); + if (resToChannelEdges == null) { + resToChannelEdges = new HashMap<>(); + resourceToChannels.put(srcResource, resToChannelEdges); + } + if (resToChannelEdges.get(channelGen) == null) { + mxCell edge = (mxCell) graph.insertEdge(parent, null, dependency.getAttribute(), resources.get(srcResource), channelsIn.get(channelGen)); + resToChannelEdges.put(channelGen, edge); + } else { + mxCell edge = resToChannelEdges.get(channelGen); + ((PushPullAttribute) edge.getValue()).intersectOptions(((PushPullAttribute) dependency.getAttribute()).getOptions()); + } + Set resSet = channelToResources.get(channelGen); + if (resSet == null) { + resSet = new HashSet<>(); + channelToResources.put(channelGen, resSet); + } + if (!resSet.contains(dstResource)) { + graph.insertEdge(parent, null, null, channelsOut.get(channelGen), resources.get(dstResource)); + resSet.add(dstResource); + } } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/PushPullAttribute.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/PushPullAttribute.java index 4e7243f..598894a 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/PushPullAttribute.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/PushPullAttribute.java @@ -33,6 +33,10 @@ options.remove(option); } + public void intersectOptions(List options) { + this.options.retainAll(options); + } + public String[] getOptionStrings() { String[] optionString = new String[options.size()]; for (int i = 0; i < options.size(); i++) {