動作確認していないがひとまずコミット.
1 parent f96a1d4 commit d49a01b0f134c13bd2c8eb90d2ad46a09309d16a
Naoya Nitta authored on 17 Jun
Showing 4 changed files
View
121
AlgebraicDataflowArchitectureModel/src/simulator/ChannelState.java
 
public class ChannelState {
private DataTransferChannel channel;
private Map<Expression, List<Expression>> childrenMap;
private Map<List<Constant>, Map<Selector, Constant>> referenceStructure;
private ReferenceStructure referenceStructure;
public ChannelState(DataTransferChannel channel) {
this.channel = channel;
}
 
public Map<Selector, Constant> getDependentParams(Map<Selector, Constant> channelParameters) {
Map<Selector, Constant> dependentParams = new HashMap<>();
if (referenceStructure != null) {
List<Expression> channelParams = new ArrayList<>();
for (Selector sel: channel.getAllSelectors()) {
channelParams.add(channelParameters.get(sel));
public DataTransferChannel getChannel() {
return channel;
}
 
public Map<Expression, Expression> getDependentParams(Map<Selector, Constant> channelParameters) {
if (referenceStructure == null) {
return null;
}
return referenceStructure.getDependentParams(channelParameters);
}
public void addDependantParam(Map<Selector, Constant> channelParameters, Expression variable, Expression value) {
referenceStructure.addDependantParam(channelParameters, variable, value);
}
private static class ReferenceStructure {
private Map<Expression, Expression> dependentParams = null;
private Map<Constant, ReferenceStructure> referenceStructure;
public Map<Expression, Expression> getDependentParams() {
return dependentParams;
}
public Map<Expression, Expression> getDependentParams(Map<Selector, Constant> channelParameters) {
ReferenceStructure subStructure = this;
for (Selector sel: channelParameters.keySet()) {
if (subStructure.getDependentParams() == null) {
subStructure = subStructure.getReferenceStructure(channelParameters.get(sel));
} else {
return null;
}
}
for (Map.Entry<Selector, Constant> paramEnt: referenceStructure.get(channelParams).entrySet()) {
dependentParams.put(paramEnt.getKey(), paramEnt.getValue());
return subStructure.getDependentParams();
}
public void addDependantParam(Expression variable, Expression value) {
if (dependentParams == null) {
dependentParams = new HashMap<>();
}
dependentParams.put(variable, value);
}
return dependentParams;
public void addDependantParam(Map<Selector, Constant> channelParameters, Expression variable, Expression value) {
ReferenceStructure subStructure = this;
for (Selector sel: channelParameters.keySet()) {
Constant chParam = channelParameters.get(sel);
if (subStructure.referenceStructure == null) {
subStructure.referenceStructure = new HashMap<>();
}
ReferenceStructure nextStructure = subStructure.referenceStructure.get(chParam);
if (nextStructure == null) {
nextStructure = new ReferenceStructure();
subStructure.referenceStructure.put(chParam, nextStructure);
}
subStructure = nextStructure;
}
subStructure.addDependantParam(variable, value);
}
public ReferenceStructure getReferenceStructure(Constant channelParam) {
return referenceStructure.get(channelParam);
}
}
}
View
63
AlgebraicDataflowArchitectureModel/src/simulator/Event.java
import models.dataConstraintModel.Selector;
import models.dataFlowModel.DataTransferChannel;
 
public class Event {
private DataTransferChannel channel;
private ChannelState channelState;
private Expression message;
private boolean isInput = false;
private ResourcePath inputResourcePath = null;
private Map<Selector, Constant> channelParameters = new HashMap<>();
private Set<Resource> inputResources;
private Set<Resource> outputResources;
private Map<Expression, Expression> dependentParameters = new HashMap<>();
private Set<Resource> inputResources = new HashSet<>();
private Set<Resource> outputResources = new HashSet<>();
private Set<Event> succEvents = new HashSet<>();
private Map<Selector, Map<ResourcePath, Integer>> channelSelectorToInputResourcePathParam = new HashMap<>();
private Map<Selector, Map<ResourcePath, Integer>> channelSelectorToOutputResourcePathParam = new HashMap<>();
public Event(DataTransferChannel channel, ChannelState channelState, Expression message, Resource outputResource) {
this.channel = channel;
public Event(ChannelState channelState, Expression message, Resource outputResource) {
this.channelState = channelState;
this.message = message;
this.isInput = true;
this.outputResources.add(outputResource);
connectChannelSelectorAndPathParameters();
// Extract channel parameters from the output resource.
DataTransferChannel channel = channelState.getChannel();
List<Selector> channelSelectors = channel.getAllSelectors();
Set<ResourcePath> outputResPathSet = null;
for (Selector sel: channelSelectors) {
if (outputResPathSet == null) {
}
}
}
public Event(DataTransferChannel channel, ChannelState channelState, ResourcePath inputResPath, Resource inputResource) {
this.channel = channel;
public Event(ChannelState channelState, ResourcePath inputResPath, Resource inputResource) {
this.channelState = channelState;
this.isInput = false;
this.inputResourcePath = inputResPath;
this.inputResources.add(inputResource);
connectChannelSelectorAndPathParameters();
 
// Extract channel parameters from the input resource.
DataTransferChannel channel = channelState.getChannel();
List<Selector> channelSelectors = channel.getAllSelectors();
for (Selector sel: channelSelectors) {
if (inputResPath != null) {
int paramIdx = channelSelectorToInputResourcePathParam.get(sel).get(inputResPath);
}
channelParameters.put(sel, ancestor.getParameter());
}
}
channelParameters.putAll(channelState.getDependentParams(channelParameters));
updateAllDependentParameters(channelState);
}
 
private void connectChannelSelectorAndPathParameters() {
DataTransferChannel channel = channelState.getChannel();
List<Selector> channelSelectors = channel.getAllSelectors();
for (Selector sel: channelSelectors) {
for (ResourcePath resPath: channel.getInputResources()) {
int paramIdx = resPath.getPathParams().indexOf(sel.getExpression());
}
}
}
}
 
public DataTransferChannel getChannel() {
return channel;
return channelState.getChannel();
}
public ChannelState getChannelState() {
return channelState;
}
 
public Expression getMessage() {
return message;
public boolean isInput() {
return isInput;
}
 
public Map<Selector, Constant> getChannelParameters() {
return channelParameters;
}
public void updateDependentParameter(Expression variable, Expression value) {
dependentParameters.put(variable, value);
}
public void updateAllDependentParameters(ChannelState channelState) {
dependentParameters.putAll(channelState.getDependentParams(channelParameters));
}
 
public ResourcePath getInputResourcePath() {
return inputResourcePath;
}
 
public Set<Resource> getInputResources() {
return inputResources;
}
 
for (Selector sel: channelParameters.keySet()) {
int paramIdx = channelSelectorToInputResourcePathParam.get(sel).get(inputResPath);
resId.setPathParam(paramIdx, channelParameters.get(sel));
}
for (Expression var: dependentParameters.keySet()) {
int paramIdx = resId.getPathParams().indexOf(var);
if (paramIdx >= 0) {
resId.setPathParam(paramIdx, (Constant) dependentParameters.get(var));
}
}
return resId;
}
 
public ResourceIdentifier getOutputResourceIdentifier(ResourcePath outputResPath) {
for (Selector sel: channelParameters.keySet()) {
int paramIdx = channelSelectorToOutputResourcePathParam.get(sel).get(outputResPath);
resId.setPathParam(paramIdx, channelParameters.get(sel));
}
for (Expression var: dependentParameters.keySet()) {
int paramIdx = resId.getPathParams().indexOf(var);
if (paramIdx >= 0) {
resId.setPathParam(paramIdx, (Constant) dependentParameters.get(var));
}
}
return resId;
}
}
View
AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java
View
AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java