diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/ConcreteResourcePath.java b/AlgebraicDataflowArchitectureModel/src/simulator/ConcreteResourcePath.java new file mode 100644 index 0000000..3f07fb8 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/simulator/ConcreteResourcePath.java @@ -0,0 +1,11 @@ +package simulator; + +import models.dataConstraintModel.ResourcePath; + +public class ConcreteResourcePath extends ResourcePath { + + public ConcreteResourcePath(ResourcePath another) { + super(another); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/Event.java b/AlgebraicDataflowArchitectureModel/src/simulator/Event.java index 84fe389..b5a174b 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/Event.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/Event.java @@ -1,7 +1,7 @@ package simulator; -import java.util.AbstractMap; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -18,6 +18,7 @@ private List channelParameters; private Set inputResources; private Set outputResources; + private Set succEvents = new HashSet<>(); private Map> channelSelectorToInputResource = new HashMap<>(); private Map> channelSelectorToOutputResource = new HashMap<>(); @@ -29,18 +30,17 @@ // Extract channel parameters from the output resource. List channelSelectors = channel.getAllSelectors(); - ResourcePath outputResPath = null; + Set outputResPathSet = null; for (int i = 0; i < channelSelectors.size(); i++) { - Selector sel = channelSelectors.get(i); - if (outputResPath == null) { - for (ResourcePath resPath: channel.getOutputResources()) { - if (resPath.getPathParams().contains(sel.getExpression())) { - outputResPath = resPath; // target output resource. - break; - } - } + if (outputResPathSet == null) { + outputResPathSet = channelSelectorToOutputResource.get(i).keySet(); + } else { + outputResPathSet.retainAll(channelSelectorToOutputResource.get(i).keySet()); } - if (outputResPath != null) { + } + if (outputResPathSet.size() > 0) { + ResourcePath outputResPath = outputResPathSet.iterator().next(); + for (int i = 0; i < channelSelectors.size(); i++) { int paramIdx = channelSelectorToOutputResource.get(i).get(outputResPath); Resource ancestor = outputResource; while (ancestor != null) { @@ -62,28 +62,29 @@ // Extract channel parameters from the input resource. List channelSelectors = channel.getAllSelectors(); - ResourcePath inputResPath = null; + Set inputResPathSet = null; for (int i = 0; i < channelSelectors.size(); i++) { - Selector sel = channelSelectors.get(i); - if (inputResPath == null) { - for (ResourcePath resPath: channel.getInputResources()) { - if (resPath.getPathParams().contains(sel.getExpression())) { - inputResPath = resPath; // target input resource. - break; - } - } + if (inputResPathSet == null) { + inputResPathSet = channelSelectorToInputResource.get(i).keySet(); + } else { + inputResPathSet.retainAll(channelSelectorToInputResource.get(i).keySet()); } - if (inputResPath != null) { - int paramIdx = channelSelectorToInputResource.get(i).get(inputResPath); - Resource ancestor = inputResource; - while (ancestor != null) { - if (ancestor.getResourceHierarchy().getNumParameters() > 0) { - paramIdx++; - if (paramIdx == inputResPath.getPathParams().size()) break; + } + if (inputResPathSet.size() > 0) { + ResourcePath inputResPath = inputResPathSet.iterator().next(); + for (int i = 0; i < channelSelectors.size(); i++) { + if (inputResPath != null) { + int paramIdx = channelSelectorToInputResource.get(i).get(inputResPath); + Resource ancestor = inputResource; + while (ancestor != null) { + if (ancestor.getResourceHierarchy().getNumParameters() > 0) { + paramIdx++; + if (paramIdx == inputResPath.getPathParams().size()) break; + } + ancestor = ancestor.getParent(); } - ancestor = ancestor.getParent(); + channelParameters.add(ancestor.getParameter()); } - channelParameters.add(ancestor.getParameter()); } } } @@ -136,4 +137,16 @@ public Set getOutputResources() { return outputResources; } + + public Set getSuccessors() { + return succEvents; + } + + public void addSuccessor(Event succEvt) { + succEvents.add(succEvt); + } + + public ConcreteResourcePath getConcreteResourcePath(ResourcePath resPath) { + return null; + } } diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java b/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java index 0ad9b60..6e1f4b7 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java @@ -23,6 +23,7 @@ curState = new SystemState(); for (ResourceHierarchy res: model.getResourceHierarchies()) { if (res.getParent() == null) { + // root resource curState.addResource(new Resource(res)); } } @@ -33,10 +34,31 @@ return curState; } - public SystemState transition(Event inputEvent) { - SystemState nextState = new SystemState(curState); + public SystemState transition(final Event inputEvent) { + final SystemState nextState = new SystemState(curState); nextState.addEvent(inputEvent); + IResourceStateAccessor resouceStateAccessor = new IResourceStateAccessor() { + @Override + public Expression getCurrentStateAccessorFor(ChannelMember target, ChannelMember from) { + ConcreteResourcePath resPath = inputEvent.getConcreteResourcePath(target.getResource()); + return curState.getResource(resPath).getState().getValue(); + } + + @Override + public Expression getNextStateAccessorFor(ChannelMember target, ChannelMember from) { + ConcreteResourcePath resPath = inputEvent.getConcreteResourcePath(target.getResource()); + return nextState.getResource(resPath).getState().getValue(); + } + + @Override + public Expression getDirectStateAccessorFor(ResourcePath target, ResourcePath from) { + ConcreteResourcePath resPath = inputEvent.getConcreteResourcePath(target); + return curState.getResource(resPath).getState().getValue(); + } + }; + + curState = nextState; return nextState; } diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java b/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java index 7461e67..62c1a30 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java @@ -5,6 +5,8 @@ import java.util.List; import java.util.Set; +import models.dataConstraintModel.ResourcePath; + public class SystemState { private Set rootResources = new HashSet<>(); private List events = new ArrayList<>(); @@ -31,4 +33,8 @@ public void addEvent(Event event) { events.add(event); } + + public Resource getResource(ConcreteResourcePath concreteResourcePath) { + return null; + } }