use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class BoundaryDistributionConversionPlugin method convertToDesmoJDistributions.
// Took the branching behaviour also used in exclusive gateways. I did not touch it for now, have a look on it later. Should just be needed for event probability...
// TODO: Resolve redundancy.
@SuppressWarnings("unchecked")
@Override
public Map<Integer, Object> convertToDesmoJDistributions(ProcessSimulationComponents pSimComponents) {
Map<Integer, Object> boundaryEventDistributions = new HashMap<Integer, Object>();
SimulationConfiguration simulationConfiguration = pSimComponents.getSimulationConfiguration();
Long randomSeed = simulationConfiguration.getRandomSeed();
Map<Integer, BranchingBehavior> branchingBehaviors = (Map<Integer, BranchingBehavior>) simulationConfiguration.getExtensionValue(getName(), "branchingBehaviors");
ProcessModel processModel = pSimComponents.getProcessModel();
SimulationModel model = pSimComponents.getModel();
boolean showInReport = model.reportIsOn();
boolean showInTrace = model.traceIsOn();
for (Integer nodeId : branchingBehaviors.keySet()) {
BranchingBehavior branchingBehavior = branchingBehaviors.get(nodeId);
Map<Integer, Double> branchingProbabilities = branchingBehavior.getBranchingProbabilities();
String name = processModel.getModelScopeId() + "_" + nodeId.toString();
DiscreteDistEmpirical<Integer> desmojDist = new DiscreteDistEmpirical<Integer>(model, name, showInReport, showInTrace);
for (Integer nextNodeId : branchingProbabilities.keySet()) {
Double probability = branchingProbabilities.get(nextNodeId);
desmojDist.addEntry(nextNodeId, probability);
}
desmojDist.setSeed(randomSeed);
boundaryEventDistributions.put(nodeId, desmojDist);
}
return boundaryEventDistributions;
}
use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class BoundaryTBPlugin method eventRoutine.
@Override
public void eventRoutine(TaskBeginEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
SimulationModel model = (SimulationModel) desmojEvent.getModel();
ProcessModel processModel = processInstance.getProcessModel();
int nodeId = desmojEvent.getNodeId();
BoundaryEventPluginUtils pluginInstance = BoundaryEventPluginUtils.getInstance();
// At the begin of each task check for corresponding boundary events. If there are some, create and schedule them.
List<Integer> referenceToBoundaryEvents = processModel.getReferencesToBoundaryEvents().get(nodeId);
if (referenceToBoundaryEvents != null) {
double startTimeOfTask = model.presentTime().getTimeAsDouble(TimeUnit.SECONDS);
// Create the corresponding boundary object for this task, which contains all necessary information.
pluginInstance.initializeBoundaryObject(startTimeOfTask, desmojEvent, referenceToBoundaryEvents);
// We usually do that in the event scheduling part, but in BoundaryEventSchedulingPlugin, it might not be called, if the TaskBeginEvent is put on a queue.
// That is the reason why the eventroutine in the BoundaryEventSchedulingPlugin class is commented out and so on never used. We should not need it anymore and it could be deleted.
// Create and schedule all boundary events this boundary object has for the current instance.
pluginInstance.createAndScheduleBoundaryEvents(desmojEvent, new TimeSpan(0));
}
}
use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class BPMNErrorBPMNEEPlugin method eventRoutine.
@Override
public void eventRoutine(BPMNEndEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
SimulationModel model = (SimulationModel) desmojEvent.getModel();
ProcessModel processModel = processInstance.getProcessModel();
int nodeId = desmojEvent.getNodeId();
Map<EventDefinitionType, Map<String, String>> definitions = processModel.getEventDefinitions().get(nodeId);
ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
boolean showInTrace = model.traceIsOn();
try {
for (EventDefinitionType definition : definitions.keySet()) {
if (definition == EventDefinitionType.ERROR) {
if (processModel.getParent() != null) {
Map<String, String> eventAttributes = processModel.getEventDefinitions().get(nodeId).get(definition);
String errorRef = eventAttributes.get("errorRef");
// Map<String, Map<String, String>> errors = model.getCommonProcessElements().getErrors();
// Map<String, String> error = errors.get("errorRef");
ProcessSimulationComponents parentDesmojObjects = desmojObjects.getParent();
ProcessModel parentModel = processModel.getParent();
int nodeIdInParent = processModel.getNodeIdInParent();
Integer nextNodeId = null;
// find boundary event of parentModel which has the same errorRef
List<Integer> referencesToBoundaryEvents = parentModel.getReferencesToBoundaryEvents().get(nodeIdInParent);
for (int nId : referencesToBoundaryEvents) {
Map<EventDefinitionType, Map<String, String>> boundaryEventDefinitions = parentModel.getEventDefinitions().get(nId);
Map<String, String> boundaryErrorEventDefinition = boundaryEventDefinitions.get(EventDefinitionType.ERROR);
if (boundaryErrorEventDefinition != null) {
if (errorRef.equals(boundaryErrorEventDefinition.get("errorRef"))) {
nextNodeId = nId;
break;
}
}
}
if (nextNodeId == null) {
DebugLogger.error("Could not find referenced error " + errorRef + ".");
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
return;
}
ProcessInstance parentProcessInstance = processInstance.getParent();
List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(desmojEvent, parentDesmojObjects, parentProcessInstance, nextNodeId);
TimeSpan timeSpan = new TimeSpan(0);
/**
* first event in the map is the node that comes after the subprocess when normal behavior
* applies, so remove it;
*/
int indexOfTaskTerminateEvent = 0;
desmojEvent.getNextEventMap().remove(indexOfTaskTerminateEvent);
desmojEvent.getTimeSpanToNextEventMap().remove(indexOfTaskTerminateEvent);
for (ScyllaEvent event : events) {
int index = desmojEvent.getNewEventIndex();
desmojEvent.getNextEventMap().put(index, event);
desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
}
processInstance.cancel();
}
}
}
} catch (NodeNotFoundException | ScyllaValidationException e) {
DebugLogger.error(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
}
}
Aggregations