use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class ExclusiveGatewayDistributionConversionPlugin method convertToDesmoJDistributions.
@SuppressWarnings("unchecked")
@Override
public Map<Integer, Object> convertToDesmoJDistributions(ProcessSimulationComponents pSimComponents) {
Map<Integer, Object> branchingDistributionsExclusive = new HashMap<Integer, Object>();
SimulationConfiguration simulationConfiguration = pSimComponents.getSimulationConfiguration();
Map<Integer, BranchingBehavior> branchingBehaviors = (Map<Integer, BranchingBehavior>) simulationConfiguration.getExtensionValue(getName(), "branchingBehaviors");
Long randomSeed = simulationConfiguration.getRandomSeed();
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);
branchingDistributionsExclusive.put(nodeId, desmojDist);
}
return branchingDistributionsExclusive;
}
use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class InclusiveGatewayEventPlugin method eventRoutine.
// @SuppressWarnings("unchecked")
@Override
public void eventRoutine(GatewayEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
SimulationModel model = (SimulationModel) desmojEvent.getModel();
ProcessModel processModel = processInstance.getProcessModel();
int nodeId = desmojEvent.getNodeId();
boolean showInTrace = desmojEvent.traceIsOn();
GatewayType type = processModel.getGateways().get(nodeId);
try {
Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
if (idsOfNextNodes.size() > 1) {
// split
if (type == GatewayType.INCLUSIVE) {
// TODO this is incomplete, must find corresponding join gateway and define behavior for it
// Map<Integer, Object> branchingDistributions = desmojObjects.getDistributionsExtensional()
// .get(getName());
// Map<Integer, BoolDistBernoulli> distributions = (Map<Integer, BoolDistBernoulli>)
// branchingDistributions
// .get(nodeId);
// Set<Integer> idsOfNodesToBeActivated = new HashSet<Integer>();
// for (Integer nextFlowId : distributions.keySet()) {
// BoolDistBernoulli distribution = distributions.get(nextFlowId);
// if (!processModel.getIdentifiers().keySet().contains(nextFlowId)) {
// throw new ScyllaValidationException("Flow with id " + nextFlowId + " does not exist.");
// }
// boolean activateOutgoingFlow = distribution.sample();
// if (activateOutgoingFlow) {
// Set<Integer> nodeIds = processModel.getTargetObjectIds(nextFlowId);
// if (nodeIds.size() != 1) {
// throw new ScyllaValidationException("Flow " + nextFlowId
// + " does not connect to 1 node, but" + nodeIds.size() + " .");
// }
// int nextNodeId = nodeIds.iterator().next();
//
// idsOfNodesToBeActivated.add(nextNodeId);
// }
// // TODO default flow
// }
//
// Map<Integer, ScyllaEvent> nextEventMap = desmojEvent.getNextEventMap();
// List<Integer> indicesOfEventsToKeep = new ArrayList<Integer>();
// for (int index : nextEventMap.keySet()) {
// ScyllaEvent eventCandidate = nextEventMap.get(index);
// int nodeIdOfCandidate = eventCandidate.getNodeId();
// if (idsOfNodesToBeActivated.contains(nodeIdOfCandidate)) {
// indicesOfEventsToKeep.add(index);
// }
// }
// Map<Integer, TimeSpan> timeSpanToNextEventMap = desmojEvent.getTimeSpanToNextEventMap();
// nextEventMap.keySet().retainAll(indicesOfEventsToKeep);
// timeSpanToNextEventMap.keySet().retainAll(indicesOfEventsToKeep);
}
}
} catch (NodeNotFoundException | ScyllaValidationException e) {
System.err.println(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
return;
}
}
use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class SubprocessBPMNEEPlugin method eventRoutine.
@Override
public void eventRoutine(BPMNEndEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
ProcessModel processModel = processInstance.getProcessModel();
if (processModel.getParent() != null && processInstanceIsCompleted(processInstance)) {
// works
try {
ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
ProcessSimulationComponents parentDesmojObjects = desmojObjects.getParent();
ProcessModel parentModel = processModel.getParent();
int nodeIdInParent = processModel.getNodeIdInParent();
ProcessInstance parentProcessInstance = processInstance.getParent();
// behavior when sub-process sends events:
// none -> back to normal flow
// message -> "send it"
// error -> to parent
// escalation -> to parent
// cancel -> nonono!
// compensation -> ... not now
// signal -> ... not now
// terminate -> terminate sub-process (kill all events of sub-process instance (MI sub-process
// not affected))
// ...
// timer -> special treatment
Set<Integer> idsOfNextNodes = parentModel.getIdsOfNextNodes(nodeIdInParent);
// normal flow: must not have more than one successor
if (idsOfNextNodes.size() != 1) {
int nodeId = desmojEvent.getNodeId();
throw new ScyllaValidationException("Subprocess " + nodeId + " does not have 1 successor, but " + idsOfNextNodes.size() + ".");
}
Integer nextNodeId = idsOfNextNodes.iterator().next();
// TODO let the parent create the next node, so remove the lines below
List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(desmojEvent, parentDesmojObjects, parentProcessInstance, nextNodeId);
// next event occurs immediately after start event
TimeSpan timeSpan = new TimeSpan(0);
String parentProcessInstanceName = parentProcessInstance.getName();
SubprocessPluginUtils pluginInstance = SubprocessPluginUtils.getInstance();
TaskTerminateEvent eventOfParent = pluginInstance.getEventsOnHold().get(parentProcessInstanceName).get(nodeIdInParent);
if (eventOfParent != null) {
events.add(eventOfParent);
pluginInstance.getEventsOnHold().get(parentProcessInstanceName).remove(nodeIdInParent);
pluginInstance.getNameOfEventsThatWereOnHold().add(eventOfParent.getName());
}
for (ScyllaEvent event : events) {
int index = desmojEvent.getNewEventIndex();
desmojEvent.getNextEventMap().put(index, event);
desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
}
} catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
SimulationModel model = (SimulationModel) desmojEvent.getModel();
int nodeId = desmojEvent.getNodeId();
boolean showInTrace = model.traceIsOn();
DebugLogger.error(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
}
}
}
use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class SubprocessTBPlugin method eventRoutine.
@Override
public void eventRoutine(TaskBeginEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
ProcessModel processModel = processInstance.getProcessModel();
int nodeId = desmojEvent.getNodeId();
ProcessModel subProcess = processModel.getSubProcesses().get(nodeId);
if (subProcess != null) {
int indexOfTaskTerminateEvent = 0;
desmojEvent.getTimeSpanToNextEventMap().remove(indexOfTaskTerminateEvent);
TaskTerminateEvent event = (TaskTerminateEvent) desmojEvent.getNextEventMap().get(indexOfTaskTerminateEvent);
String name = processInstance.getName();
SubprocessPluginUtils pluginInstance = SubprocessPluginUtils.getInstance();
Map<Integer, TaskTerminateEvent> eventsOnHoldMap = pluginInstance.getEventsOnHold().get(name);
if (eventsOnHoldMap == null) {
pluginInstance.getEventsOnHold().put(name, new HashMap<Integer, TaskTerminateEvent>());
}
pluginInstance.getEventsOnHold().get(name).put(nodeId, event);
desmojEvent.getNextEventMap().remove(indexOfTaskTerminateEvent);
String source = desmojEvent.getSource();
ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
SimulationModel model = (SimulationModel) desmojEvent.getModel();
TimeInstant currentSimulationTime = model.presentTime();
boolean showInTrace = model.traceIsOn();
int processInstanceId = processInstance.getId();
try {
ProcessSimulationComponents desmojObjectsOfSubProcess = desmojObjects.getChildren().get(nodeId);
Integer startNodeId = subProcess.getStartNode();
ProcessInstance subProcessInstance = new ProcessInstance(model, subProcess, processInstanceId, showInTrace);
subProcessInstance.setParent(processInstance);
ScyllaEvent subProcessEvent = new BPMNStartEvent(model, source, currentSimulationTime, desmojObjectsOfSubProcess, subProcessInstance, startNodeId);
TimeSpan timeSpan = new TimeSpan(0);
int index = desmojEvent.getNewEventIndex();
desmojEvent.getNextEventMap().put(index, subProcessEvent);
desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
} catch (NodeNotFoundException | MultipleStartNodesException | NoStartNodeException e) {
DebugLogger.error(e.getMessage());
DebugLogger.log("Start node of process model " + subProcess.getId() + " not found.");
throw new ScyllaRuntimeException("Start node of process model " + subProcess.getId() + " not found.");
}
}
}
use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class SubprocessTCPlugin method eventRoutine.
@Override
public void eventRoutine(TaskCancelEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
ProcessModel processModel = processInstance.getProcessModel();
if (processModel.getParent() != null) {
int nodeIdInParent = processModel.getNodeIdInParent();
ProcessInstance parentProcessInstance = processInstance.getParent();
String parentProcessInstanceName = parentProcessInstance.getName();
SubprocessPluginUtils pluginInstance = SubprocessPluginUtils.getInstance();
Map<Integer, TaskTerminateEvent> eventsOnHoldMap = pluginInstance.getEventsOnHold().get(parentProcessInstanceName);
TaskTerminateEvent event = eventsOnHoldMap.get(nodeIdInParent);
if (event != null) {
SimulationModel model = (SimulationModel) event.getModel();
String source = event.getSource();
TaskCancelEvent cancelEvent = new TaskCancelEvent(model, source, event.getSimulationTimeOfSource(), event.getDesmojObjects(), event.getProcessInstance(), event.getNodeId());
cancelEvent.schedule(parentProcessInstance, new TimeSpan(0));
eventsOnHoldMap.remove(nodeIdInParent);
}
}
}
Aggregations