use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class DataObjectBPMNStartEvent method eventRoutine.
@Override
public void eventRoutine(BPMNStartEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
ProcessModel processModel = processInstance.getProcessModel();
// int processInstanceId = processInstance.getId();
try {
if (processModel.getDataObjectsGraph().getNodes().containsKey(desmojEvent.getNodeId())) {
Set<Integer> refferingObjects = processModel.getDataObjectsGraph().getTargetObjects(desmojEvent.getNodeId());
Collection<Object> allFields = desmojEvent.getDesmojObjects().getExtensionDistributions().get("dataobject").values();
for (Object fields : allFields) {
Integer i = 0;
while (((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray().length - i != 0) {
DataObjectField field = (DataObjectField) ((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray()[i];
if (refferingObjects.contains(field.getNodeId())) {
// System.out.println(processInstance.getId() + " " + desmojEvent.getDisplayName() + " " + processModel.getDisplayNames().get(field.getNodeId()) + " " + field.getDataDistributionWrapper().getSample());
SimulationModel model = (SimulationModel) desmojEvent.getModel();
Collection<Map<Integer, java.util.List<ProcessNodeInfo>>> allProcesses = model.getProcessNodeInfos().values();
for (Map<Integer, java.util.List<ProcessNodeInfo>> process : allProcesses) {
List<ProcessNodeInfo> currentProcess = process.get(processInstance.getId());
for (ProcessNodeInfo task : currentProcess) {
// System.out.println(processModel.getDisplayNames().get(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[0]) + " " + task.getTaskName());
for (Integer j = 0; j < processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray().length; j++) {
if (task.getId().equals(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[j]) && task.getTransition() == ProcessNodeTransitionType.EVENT_TERMINATE) {
// check all tasks and find the ones that may be looged; already logged ones will get ignored next line
if (!task.getDataObjectField().containsKey(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName())) {
// don't log if task already has this field logged
Map<String, Object> fieldSample = new HashMap<String, Object>();
Object currentSample = field.getDataDistributionWrapper().getSample();
// log Value at TaskTerminate
fieldSample.put(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName(), currentSample);
task.SetDataObjectField(fieldSample);
// set current DataObjectFieldValue
DataObjectField.addDataObjectValue(processInstance.getId(), fieldSample.keySet().toArray()[0].toString(), currentSample);
}
}
}
}
}
}
i++;
}
}
} else {
// do nothing and continue with the next task because Node has no dataobejcts
}
} catch (ScyllaRuntimeException | ScyllaValidationException | NodeNotFoundException e) {
e.printStackTrace();
}
}
use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class DataObjectDistributionConversionPlugin method convertToDesmoJDistributions.
@SuppressWarnings("unchecked")
@Override
public Map<Integer, Object> convertToDesmoJDistributions(ProcessSimulationComponents pSimComponents) {
SimulationConfiguration simulationConfiguration = pSimComponents.getSimulationConfiguration();
Map<Integer, Object> dataObjects = (Map<Integer, Object>) simulationConfiguration.getExtensionValue(getName(), "dataObjects");
Long randomSeed = simulationConfiguration.getRandomSeed();
ProcessModel processModel = pSimComponents.getProcessModel();
SimulationModel model = pSimComponents.getModel();
boolean showInReport = model.reportIsOn();
boolean showInTrace = model.traceIsOn();
for (Integer nodeId : dataObjects.keySet()) {
Map<String, DataObjectField> dataObjectFields = (Map<String, DataObjectField>) dataObjects.get(nodeId);
String name = processModel.getModelScopeId() + "_" + nodeId.toString();
for (String fieldName : dataObjectFields.keySet()) {
DataObjectField dataObjectField = dataObjectFields.get(fieldName);
DataDistributionWrapper distWrapper = dataObjectField.getDataDistributionWrapper();
Distribution dist = distWrapper.getDistribution();
if (dist == null)
continue;
NumericalDist<?> desmojDist = null;
try {
desmojDist = SimulationUtils.getDistribution(dist, model, name, nodeId, showInReport, showInTrace);
} catch (InstantiationException e) {
DebugLogger.error(e.getMessage());
DebugLogger.error("Instantiation of dmn model failed.");
return null;
}
desmojDist.setSeed(randomSeed);
distWrapper.setDesmojDistribution(desmojDist);
}
}
return dataObjects;
}
use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class EventArrivalRateDistributionConversionPlugin method convertToDesmoJDistributions.
/**
* Converts scylla distributions from extension to desmoJ distributions to be stored als distribution extension.
* @see {@link de.hpi.bpt.scylla.simulation.utils.SimulationUtils#getDistribution(Distribution, SimulationModel, String, Integer, boolean, boolean)}
*/
@Override
public Map<Integer, Object> convertToDesmoJDistributions(ProcessSimulationComponents pSimComponents) {
Map<Integer, Object> arrivalRateDistributions = new HashMap<Integer, Object>();
SimulationConfiguration simulationConfiguration = pSimComponents.getSimulationConfiguration();
Long randomSeed = simulationConfiguration.getRandomSeed();
/**
*Get saved extension from sc parser
*/
@SuppressWarnings("unchecked") HashMap<Integer, TimeDistributionWrapper> arrivalRates = (HashMap<Integer, TimeDistributionWrapper>) simulationConfiguration.getExtensionValue(getName(), EventArrivalRatePluginUtils.ARRIVALRATES_KEY);
ProcessModel processModel = pSimComponents.getProcessModel();
SimulationModel model = pSimComponents.getModel();
boolean showInReport = model.reportIsOn();
boolean showInTrace = model.traceIsOn();
for (Entry<Integer, TimeDistributionWrapper> entry : arrivalRates.entrySet()) {
Integer nodeId = entry.getKey();
TimeDistributionWrapper arrivalRate = entry.getValue();
TimeUnit timeUnit = arrivalRate.getTimeUnit();
Distribution distribution = arrivalRate.getDistribution();
String name = processModel.getModelScopeId() + "_" + nodeId.toString();
try {
NumericalDist<?> desmojDist = SimulationUtils.getDistribution(distribution, model, name, nodeId, showInReport, showInTrace);
desmojDist.setSeed(randomSeed);
arrivalRateDistributions.put(nodeId, new SimpleEntry<NumericalDist<?>, TimeUnit>(desmojDist, timeUnit));
} catch (InstantiationException e) {
e.printStackTrace();
continue;
}
}
return arrivalRateDistributions;
}
use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class EventOrderPriority method compare.
@Override
public int compare(String resourceId, ScyllaEvent e1, ScyllaEvent e2) throws ScyllaRuntimeException {
SimulationModel model = (SimulationModel) e1.getModel();
if (!model.equals((SimulationModel) e2.getModel())) {
throw new ScyllaRuntimeException("New event for queue is attached to another simulation model.");
}
Integer priorityOfFirstEvent = null;
Set<ResourceReference> resourceRefsOfFirstEvent = e1.getDesmojObjects().getSimulationConfiguration().getResourceReferenceSet(e1.getNodeId());
for (ResourceReference resourceRef : resourceRefsOfFirstEvent) {
if (resourceId.equals(resourceRef.getResourceId())) {
String priorityString = resourceRef.getAssignmentDefinition().get("priority");
if (priorityString == null) {
priorityOfFirstEvent = -1;
} else {
priorityOfFirstEvent = Integer.parseInt(resourceRef.getAssignmentDefinition().get("priority"));
}
}
}
Integer priorityOfSecondEvent = null;
Set<ResourceReference> resourceRefsOfSecondEvent = e2.getDesmojObjects().getSimulationConfiguration().getResourceReferenceSet(e2.getNodeId());
for (ResourceReference resourceRef : resourceRefsOfSecondEvent) {
if (resourceId.equals(resourceRef.getResourceId())) {
String priorityString = resourceRef.getAssignmentDefinition().get("priority");
if (priorityString == null) {
priorityOfSecondEvent = -1;
} else {
priorityOfSecondEvent = Integer.parseInt(resourceRef.getAssignmentDefinition().get("priority"));
}
}
}
// higher value is sorted first
return priorityOfSecondEvent - priorityOfFirstEvent;
}
use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.
the class EventbasedGatewayEventPlugin method eventRoutine.
/**
* Handles a gateway event, if it is an event based gateway
* Changes scheduling behavior by already scheduling the next events of the given gateway event (if event based)
*/
@Override
public void eventRoutine(GatewayEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
SimulationModel model = (SimulationModel) desmojEvent.getModel();
ProcessModel processModel = processInstance.getProcessModel();
int nodeId = desmojEvent.getNodeId();
GatewayType type = processModel.getGateways().get(nodeId);
try {
Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
if (type == GatewayType.EVENT_BASED && idsOfNextNodes.size() > 1) {
// Schedule all following events
List<ScyllaEvent> nextEvents = new ArrayList<ScyllaEvent>(desmojEvent.getNextEventMap().values());
desmojEvent.scheduleNextEvents();
// and look which is scheduled first.
ScyllaEvent first = nextEvents.get(0);
for (ScyllaEvent e : nextEvents) {
if (TimeInstant.isBefore(e.scheduledNext(), first.scheduledNext())) {
first = e;
}
}
// Cancel all other events except the one that is scheduled first.
nextEvents.remove(first);
for (ScyllaEvent e : nextEvents) {
e.cancel();
}
}
} catch (NodeNotFoundException | ScyllaValidationException | SuspendExecution e) {
e.printStackTrace();
// Critical error (following nodes not found or validation error), abort the instance.
SimulationUtils.abort(model, processInstance, nodeId, desmojEvent.traceIsOn());
}
}
Aggregations