use of de.hpi.bpt.scylla.model.process.ProcessModel in project scylla by bptlab.
the class DataObjectSCParserPlugin method parse.
@Override
public /* pasrses the datobjects and creates the distWrapper*/
Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
Namespace simNamespace = sim.getNamespace();
ProcessModel processModel = simulationInput.getProcessModel();
Map<Integer, Map<String, DataObjectField>> dataObjects = new HashMap<Integer, Map<String, DataObjectField>>();
for (Element el : sim.getChildren()) {
String elementName = el.getName();
if (elementName.equals("dataObject") || elementName.equals("dataInput")) {
String identifier = el.getAttributeValue("id");
if (identifier == null) {
DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
// no matching element in process, so skip definition
continue;
}
Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
if (nodeId == null) {
DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
// no matching element in process, so skip definition
continue;
}
Map<String, DataObjectField> dataObjectFields = new HashMap<String, DataObjectField>();
for (Element field : el.getChildren("field", simNamespace)) {
String fieldName = field.getAttributeValue("name");
String fieldType = field.getAttributeValue("type");
DataDistributionType dataDistributionType = DataDistributionType.getEnum(fieldType);
DataDistributionWrapper distWrapper = new DataDistributionWrapper(dataDistributionType);
for (Element fieldElement : field.getChildren()) {
if (fieldElement.getName().endsWith("Distribution")) {
Distribution distribution = SimulationConfigurationParser.getDistribution(field, simNamespace, fieldType);
distWrapper.setDistribution(distribution);
}
/*else if (fieldElement.getName().equals("range")) {
try{
double min = Double.parseDouble(fieldElement.getAttributeValue("min"));
distWrapper.setMin(min);
} catch (NumberFormatException e) {
// do nothing: min was not set and is automatically -Double.MAX_VALUE
}
try{
double max = Double.parseDouble(fieldElement.getAttributeValue("max"));
distWrapper.setMax(max);
} catch (NumberFormatException e) {
// do nothing: max was not set and is automatically Double.MAX_VALUE
}
Distribution distribution = new UniformDistribution(distWrapper.getMin(), distWrapper.getMax());
distWrapper.setDistribution(distribution);
}*/
}
dataObjectFields.put(fieldName, new DataObjectField(distWrapper, nodeId, fieldName, fieldType));
}
dataObjects.put(nodeId, dataObjectFields);
}
}
// System.out.println(processModel.getDataObjectsGraph().print());
HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
extensionAttributes.put("dataObjects", dataObjects);
return extensionAttributes;
}
use of de.hpi.bpt.scylla.model.process.ProcessModel 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.model.process.ProcessModel 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());
}
}
use of de.hpi.bpt.scylla.model.process.ProcessModel 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.model.process.ProcessModel in project scylla by bptlab.
the class ExclusiveGatewaySCParserPlugin method parse.
@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
Map<Integer, BranchingBehavior> branchingBehaviors = new HashMap<Integer, BranchingBehavior>();
Namespace simNamespace = sim.getNamespace();
ProcessModel processModel = simulationInput.getProcessModel();
for (Element el : sim.getChildren()) {
String elementName = el.getName();
if (elementName.equals("exclusiveGateway")) {
String identifier = el.getAttributeValue("id");
if (identifier == null) {
DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
// no matching element in process, so skip definition
continue;
}
Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
if (nodeId == null) {
DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
// no matching element in process, so skip definition
continue;
}
List<Element> outgoingSequenceFlows = el.getChildren("outgoingSequenceFlow", simNamespace);
if (outgoingSequenceFlows.size() > 0) {
Map<Integer, Double> branchingProbabilities = new HashMap<Integer, Double>();
Double probabilitySum = 0d;
for (Element elem : outgoingSequenceFlows) {
Integer nodeIdOfSequenceFlow = processModel.getIdentifiersToNodeIds().get(elem.getAttributeValue("id"));
if (nodeIdOfSequenceFlow != null) {
Double branchingProbability = Double.parseDouble(elem.getChildText("branchingProbability", simNamespace));
if (branchingProbability < 0 || branchingProbability > 1) {
throw new ScyllaValidationException("Exclusive gateway branching probability for " + identifier + " is out of bounds [0,1].");
}
probabilitySum += branchingProbability;
branchingProbabilities.put(nodeIdOfSequenceFlow, branchingProbability);
}
}
if (probabilitySum <= 0) {
throw new ScyllaValidationException("Simulation configuration defines branching probabilities for exclusive gateway " + identifier + ", where the sum of probabilities is negative or zero.");
}
if (probabilitySum > 1) {
// XXX imprecision by IEEE 754 floating point representation
throw new ScyllaValidationException("Simulation configuration defines branching probabilities for exclusive gateway " + identifier + ", exceeding 1 in total.");
}
// complete probabilities with the default flow probability
if (probabilitySum > 0 && probabilitySum <= 1) {
Map<String, String> gatewayAttributes = processModel.getNodeAttributes().get(nodeId);
String defaultFlowIdentifier = gatewayAttributes.get("default");
if (defaultFlowIdentifier != null) {
double probabilityOfDefaultFlow = 1 - probabilitySum;
int defaultFlowNodeId = processModel.getIdentifiersToNodeIds().get(defaultFlowIdentifier);
if (!branchingProbabilities.containsKey(defaultFlowNodeId)) {
branchingProbabilities.put(defaultFlowNodeId, probabilityOfDefaultFlow);
} else {
branchingProbabilities.put(defaultFlowNodeId, branchingProbabilities.get(defaultFlowNodeId) + probabilityOfDefaultFlow);
}
;
}
}
try {
if (branchingProbabilities.keySet().size() != processModel.getIdsOfNextNodes(nodeId).size()) {
throw new ScyllaValidationException("Number of branching probabilities defined in simulation configuration " + "does not match to number of outgoing flows of exclusive gateway " + identifier + ".");
}
} catch (NodeNotFoundException e) {
throw new ScyllaValidationException("Node not found: " + e.getMessage());
}
BranchingBehavior branchingBehavior = new BranchingBehavior(branchingProbabilities);
branchingBehaviors.put(nodeId, branchingBehavior);
}
}
}
HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
extensionAttributes.put("branchingBehaviors", branchingBehaviors);
return extensionAttributes;
}
Aggregations