Search in sources :

Example 6 with SimulationModel

use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.

the class ExclusiveGatewayEventPlugin 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);
    ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
    try {
        Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
        if (idsOfNextNodes.size() > 1) {
            // split
            if (type == GatewayType.DEFAULT || type == GatewayType.EXCLUSIVE) {
                Map<Integer, Object> branchingDistributions = desmojObjects.getExtensionDistributions().get(getName());
                DiscreteDistEmpirical<Integer> distribution = (DiscreteDistEmpirical<Integer>) branchingDistributions.get(nodeId);
                // decide on next node
                if (distribution != null) {
                    // if a distribution is given take this
                    Integer nextFlowId = distribution.sample().intValue();
                    if (!processModel.getIdentifiers().keySet().contains(nextFlowId)) {
                        throw new ScyllaValidationException("Flow with id " + nextFlowId + " does not exist.");
                    }
                    scheduleNextEvent(desmojEvent, processInstance, processModel, nextFlowId);
                } else {
                    // otherwise try to get information out of the describing branches and branch on the basis of this
                    Map<Class<?>, ArrayList<PluginWrapper>> a = PluginLoader.getDefaultPluginLoader().getExtensions();
                    Collection<ArrayList<PluginWrapper>> plugins = a.values();
                    Boolean dataObjectPluginOn = false;
                    for (ArrayList<PluginWrapper> plugin : plugins) {
                        for (PluginWrapper p : plugin) {
                            if (p.toString().equals("DataObjectSCParserPlugin")) {
                                dataObjectPluginOn = true;
                            }
                        }
                    }
                    if (dataObjectPluginOn) {
                        Object[] outgoingRefs = processModel.getGraph().getTargetObjects(nodeId).toArray();
                        Integer DefaultPath = null;
                        Boolean foundAWay = false;
                        for (Object or : outgoingRefs) {
                            // go through all outgoing references
                            if (or.equals(getKeyByValue(processModel.getIdentifiers(), processModel.getNodeAttributes().get(desmojEvent.getNodeId()).get("default")))) {
                                // if it's the default path jump it
                                DefaultPath = (Integer) or;
                                continue;
                            }
                            String[] conditions = processModel.getDisplayNames().get(or).split("&&");
                            Integer nextFlowId = (Integer) or;
                            List<Boolean> test = new ArrayList<>();
                            for (String condition : conditions) {
                                condition = condition.trim();
                                String field = null;
                                String value = null;
                                String comparison = null;
                                if (condition.contains("==")) {
                                    field = condition.split("==")[0];
                                    value = condition.split("==")[1];
                                    // value = processModel.getDisplayNames().get(or).substring(2, processModel.getDisplayNames().get(or).length());
                                    comparison = "equal";
                                } else if (condition.contains(">=")) {
                                    field = condition.split(">=")[0];
                                    value = condition.split(">=")[1];
                                    comparison = "greaterOrEqual";
                                } else if (condition.contains("<=")) {
                                    field = condition.split("<=")[0];
                                    value = condition.split("<=")[1];
                                    comparison = "lessOrEqual";
                                } else if (condition.contains("!=")) {
                                    field = condition.split("!=")[0];
                                    value = condition.split("!=")[1];
                                    comparison = "notEqual";
                                } else if (condition.contains("=")) {
                                    field = condition.split("=")[0];
                                    value = condition.split("=")[1];
                                    comparison = "equal";
                                } else if (condition.contains("<")) {
                                    field = condition.split("<")[0];
                                    value = condition.split("<")[1];
                                    comparison = "less";
                                } else if (condition.contains(">")) {
                                    field = condition.split(">")[0];
                                    value = condition.split(">")[1];
                                    comparison = "greater";
                                } else {
                                    throw new ScyllaValidationException("Condition " + condition + " does not have a comparison-operator");
                                }
                                value = value.trim();
                                field = field.trim();
                                Object fieldValue = DataObjectField.getDataObjectValue(processInstance.getId(), field);
                                if (!isParsableAsLong(value) || !isParsableAsLong((String.valueOf(fieldValue)))) {
                                    // try a long comparison
                                    Integer comparisonResult = (String.valueOf(fieldValue)).trim().compareTo(String.valueOf(value));
                                    if (comparison.equals("equal") && comparisonResult == 0) {
                                        break;
                                    } else if (comparison.equals("notEqual") && comparisonResult != 0) {
                                        break;
                                    } else {
                                        test.add(false);
                                    }
                                } else {
                                    // otherwise do a string compare
                                    Long LongValue = Long.valueOf(value);
                                    Long dOValue = Long.valueOf((String.valueOf(fieldValue)));
                                    Integer comparisonResult = (dOValue.compareTo(LongValue));
                                    if (comparison.equals("equal") && comparisonResult == 0) {
                                    } else if (comparison.equals("less") && comparisonResult < 0) {
                                    } else if (comparison.equals("greater") && comparisonResult > 0) {
                                    } else if (comparison.equals("greaterOrEqual") && comparisonResult >= 0) {
                                    } else if (comparison.equals("lessOrEqual") && comparisonResult <= 0) {
                                    } else {
                                        test.add(false);
                                    }
                                }
                            }
                            if (test.size() == 0) {
                                scheduleNextEvent(desmojEvent, processInstance, processModel, nextFlowId);
                                foundAWay = true;
                            }
                        }
                        if (!foundAWay && DefaultPath != null) {
                            scheduleNextEvent(desmojEvent, processInstance, processModel, DefaultPath);
                        } else if (!foundAWay && DefaultPath == null) {
                            // everything will be killed, logical error
                            throw new ScyllaValidationException("No Default Path for " + desmojEvent.getDisplayName() + " given and outgoing branches not complete. No branch matches, abort.");
                        }
                    } else {
                        Object[] outgoingRefs = processModel.getGraph().getTargetObjects(nodeId).toArray();
                        Integer DefaultPath = null;
                        for (Object or : outgoingRefs) {
                            // try to find default path
                            if (or.equals(getKeyByValue(processModel.getIdentifiers(), processModel.getNodeAttributes().get(desmojEvent.getNodeId()).get("default")))) {
                                DefaultPath = (Integer) or;
                                break;
                            }
                        }
                        if (DefaultPath != null) {
                            scheduleNextEvent(desmojEvent, processInstance, processModel, DefaultPath);
                        } else {
                            throw new ScyllaValidationException("No Distribution for " + desmojEvent.getDisplayName() + " given, no DefaultPath given and DataObject PlugIn not activated.");
                        }
                    }
                }
            }
        }
    } catch (NodeNotFoundException | ScyllaValidationException e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
        return;
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ArrayList(java.util.ArrayList) GatewayType(de.hpi.bpt.scylla.model.process.node.GatewayType) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) PluginWrapper(de.hpi.bpt.scylla.plugin_loader.PluginLoader.PluginWrapper) DiscreteDistEmpirical(desmoj.core.dist.DiscreteDistEmpirical) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 7 with SimulationModel

use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.

the class InclusiveGatewayDistributionConversionPlugin method convertToDesmoJDistributions.

@SuppressWarnings("unchecked")
@Override
public Map<Integer, Object> convertToDesmoJDistributions(ProcessSimulationComponents pSimComponents) {
    Map<Integer, Object> branchingDistributionsInclusive = 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();
        Map<Integer, BoolDistBernoulli> inclusiveDistributions = new HashMap<Integer, BoolDistBernoulli>();
        for (Integer nextNodeId : branchingProbabilities.keySet()) {
            Double probability = branchingProbabilities.get(nextNodeId);
            BoolDistBernoulli desmojDist = new BoolDistBernoulli(model, name, probability, showInReport, showInTrace);
            desmojDist.setSeed(randomSeed);
            inclusiveDistributions.put(nextNodeId, desmojDist);
        }
        branchingDistributionsInclusive.put(nodeId, inclusiveDistributions);
    }
    return branchingDistributionsInclusive;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) BoolDistBernoulli(desmoj.core.dist.BoolDistBernoulli) HashMap(java.util.HashMap) BranchingBehavior(de.hpi.bpt.scylla.model.configuration.BranchingBehavior) SimulationConfiguration(de.hpi.bpt.scylla.model.configuration.SimulationConfiguration) Map(java.util.Map) HashMap(java.util.HashMap) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 8 with SimulationModel

use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.

the class BPMNEvent method addToLog.

protected void addToLog(ProcessInstance processInstance) {
    long timestamp = Math.round(getModel().presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
    String taskName = displayName;
    Set<String> resources = new HashSet<String>();
    SimulationModel model = (SimulationModel) getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
    ProcessNodeInfo info;
    info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources, ProcessNodeTransitionType.EVENT_BEGIN);
    model.addNodeInfo(processModel, processInstance, info);
    info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources, ProcessNodeTransitionType.EVENT_TERMINATE);
    model.addNodeInfo(processModel, processInstance, info);
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 9 with SimulationModel

use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.

the class BPMNEvent method eventRoutine.

@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
    SimulationModel model = (SimulationModel) getModel();
    boolean outputLoggingIsOn = model.isOutputLoggingOn();
    if (outputLoggingIsOn) {
        addToLog(processInstance);
    }
}
Also used : SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 10 with SimulationModel

use of de.hpi.bpt.scylla.simulation.SimulationModel in project scylla by bptlab.

the class GatewayEvent method eventRoutine.

@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
    SimulationModel model = (SimulationModel) getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    try {
        Set<Integer> idsOfPreviousNodes = processModel.getIdsOfPreviousNodes(nodeId);
        Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
        String message = null;
        GatewayType type = processModel.getGateways().get(nodeId);
        String convergeDivergeName = "Join and Split";
        if (idsOfPreviousNodes.size() == 1) {
            convergeDivergeName = "Split";
        } else if (idsOfNextNodes.size() == 1) {
            convergeDivergeName = "Join";
        }
        if (type == GatewayType.DEFAULT) {
            message = "Default " + convergeDivergeName + " Gateway: " + displayName;
        }
        if (type == GatewayType.EXCLUSIVE) {
            message = "Exclusive " + convergeDivergeName + " Gateway: " + displayName;
        } else if (type == GatewayType.EVENT_BASED) {
            message = "Eventbased " + convergeDivergeName + " Gateway: " + displayName;
        } else if (type == GatewayType.INCLUSIVE) {
            message = "Inclusive " + convergeDivergeName + " Gateway: " + displayName;
        } else if (type == GatewayType.PARALLEL) {
            message = "Parallel " + convergeDivergeName + " Gateway: " + displayName;
        } else if (type == GatewayType.COMPLEX) {
            message = "Complex " + convergeDivergeName + " Gateway: " + displayName;
        } else {
            // TODO write to log because element not supported
            SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
            return;
        }
        sendTraceNote(message);
        // i.e. for splits: default behavior is the one of a parallel gateway
        for (Integer nextNodeId : idsOfNextNodes) {
            List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(this, pSimComponents, processInstance, nextNodeId);
            // next DesmoJ event occurs immediately after start event
            TimeSpan timeSpan = new TimeSpan(0);
            for (ScyllaEvent event : events) {
                int index = getNewEventIndex();
                nextEventMap.put(index, event);
                timeSpanToNextEventMap.put(index, timeSpan);
            }
        }
        GatewayEventPluggable.runPlugins(this, processInstance);
        scheduleNextEvents();
    } catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
        return;
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) GatewayType(de.hpi.bpt.scylla.model.process.node.GatewayType) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Aggregations

SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)48 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)41 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)21 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)17 TimeSpan (desmoj.core.simulator.TimeSpan)17 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)15 Map (java.util.Map)15 ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)13 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)12 HashSet (java.util.HashSet)12 TimeInstant (desmoj.core.simulator.TimeInstant)11 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)10 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)8 HashMap (java.util.HashMap)8 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)7 ProcessNodeTransitionType (de.hpi.bpt.scylla.logger.ProcessNodeTransitionType)6 SimulationConfiguration (de.hpi.bpt.scylla.model.configuration.SimulationConfiguration)6 ResourceObject (de.hpi.bpt.scylla.simulation.ResourceObject)6 GatewayType (de.hpi.bpt.scylla.model.process.node.GatewayType)5 TimeUnit (java.util.concurrent.TimeUnit)5