Search in sources :

Example 26 with SimulationModel

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;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) DiscreteDistEmpirical(desmoj.core.dist.DiscreteDistEmpirical) 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 27 with SimulationModel

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;
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) GatewayType(de.hpi.bpt.scylla.model.process.node.GatewayType) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 28 with SimulationModel

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);
        }
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 29 with SimulationModel

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.");
        }
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent) MultipleStartNodesException(de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException) TimeSpan(desmoj.core.simulator.TimeSpan) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) BPMNStartEvent(de.hpi.bpt.scylla.simulation.event.BPMNStartEvent) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) TimeInstant(desmoj.core.simulator.TimeInstant) NoStartNodeException(de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)

Example 30 with SimulationModel

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);
        }
    }
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) TaskCancelEvent(de.hpi.bpt.scylla.simulation.event.TaskCancelEvent) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent) 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