Search in sources :

Example 1 with ScyllaEvent

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

the class BatchBPMNEEPlugin method eventRoutine.

@Override
public void eventRoutine(BPMNEndEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
    BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
    pluginInstance.logBPMNEventForNonResponsiblePI(event, processInstance);
    // Schedule parental end events
    ProcessInstance parentProcessInstance = processInstance.getParent();
    if (parentProcessInstance != null) {
        ProcessModel processModel = processInstance.getProcessModel();
        int parentNodeId = processModel.getNodeIdInParent();
        BatchCluster cluster = pluginInstance.getRunningCluster(parentProcessInstance, parentNodeId);
        if (cluster != null) {
            cluster.setProcessInstanceToFinished();
            // Schedule them only if either all process instances has passed the last event of the batch activity or the execution type is parallel
            if (cluster.areAllProcessInstancesFinished() || cluster.hasExecutionType(BatchClusterExecutionType.PARALLEL)) {
                if (pluginInstance.isProcessInstanceCompleted(processInstance)) {
                    List<TaskTerminateEvent> parentalEndEvents = cluster.getParentalEndEvents();
                    for (TaskTerminateEvent pee : parentalEndEvents) {
                        ProcessInstance pi = pee.getProcessInstance();
                        pee.schedule(pi);
                    }
                    parentalEndEvents.clear();
                    pluginInstance.setClusterToTerminated(parentProcessInstance, parentNodeId);
                }
                // Prevent parental task terminate event from scheduling, if there is any (from subprocess plugin)
                Map<Integer, ScyllaEvent> nextEventMap = event.getNextEventMap();
                if (!nextEventMap.isEmpty()) {
                    Map<Integer, TimeSpan> timeSpanToNextEventMap = event.getTimeSpanToNextEventMap();
                    int indexOfParentalTaskTerminateEvent = 0;
                    nextEventMap.remove(indexOfParentalTaskTerminateEvent);
                    timeSpanToNextEventMap.remove(indexOfParentalTaskTerminateEvent);
                }
            } else if (cluster.hasExecutionType(BatchClusterExecutionType.SEQUENTIAL_CASEBASED)) {
                // Schedule the next start event
                pluginInstance.scheduleNextCaseInBatchProcess(cluster);
            }
        }
    }
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)

Example 2 with ScyllaEvent

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

the class BatchClusterStartEvent method eventRoutine.

@Override
public void eventRoutine(BatchCluster cluster) throws SuspendExecution {
    BatchActivity activity = cluster.getBatchActivity();
    int nodeId = activity.getNodeId();
    List<TaskBeginEvent> parentalStartEvents = cluster.getParentalStartEvents();
    // Schedule all task begin events of the process instance
    for (TaskBeginEvent pse : parentalStartEvents) {
        ProcessInstance pi = pse.getProcessInstance();
        pse.schedule(pi);
    }
    // schedule subprocess start events for all process instances in parent
    // processInstances and parentalStartEvents are ordered the same way
    // Set the responsible process instance in the batch cluster, first one by default
    cluster.setResponsibleProcessInstance(parentalStartEvents.get(0).getProcessInstance());
    // Go through all process instances. If it's the first one, schedule it. If not, save it to be scheduled later on
    for (int j = 0; j < parentalStartEvents.size(); j++) {
        TaskBeginEvent startEvent = parentalStartEvents.get(j);
        ProcessInstance responsibleProcessInstance = startEvent.getProcessInstance();
        int processInstanceId = responsibleProcessInstance.getId();
        boolean showInTrace = responsibleProcessInstance.traceIsOn();
        SimulationModel model = (SimulationModel) responsibleProcessInstance.getModel();
        String source = startEvent.getSource();
        TimeInstant currentSimulationTime = cluster.presentTime();
        ProcessSimulationComponents pSimComponentsOfSubprocess = cluster.getProcessSimulationComponents().getChildren().get(nodeId);
        ProcessModel subprocess = pSimComponentsOfSubprocess.getProcessModel();
        try {
            Integer startNodeId = subprocess.getStartNode();
            ProcessInstance subprocessInstance = new ProcessInstance(model, subprocess, processInstanceId, showInTrace);
            subprocessInstance.setParent(responsibleProcessInstance);
            ScyllaEvent subprocessEvent = new BPMNStartEvent(model, source, currentSimulationTime, pSimComponentsOfSubprocess, subprocessInstance, startNodeId);
            System.out.println("Created BPMNStartEvent for PI " + subprocessInstance.getId() + " / " + responsibleProcessInstance.getId() + " in Batch Cluster");
            if (j == 0) {
                // If it is the first process instance, schedule it...
                subprocessEvent.schedule(subprocessInstance);
                cluster.setStartNodeId(startNodeId);
            } else {
                // ...if not, save them for later
                cluster.addPIEvent(startNodeId, subprocessEvent, subprocessInstance);
            }
        } catch (NodeNotFoundException | MultipleStartNodesException | NoStartNodeException e) {
            DebugLogger.log("Start node of process model " + subprocess.getId() + " not found.");
            System.err.println(e.getMessage());
            e.printStackTrace();
            SimulationUtils.abort(model, responsibleProcessInstance, nodeId, traceIsOn());
            return;
        }
    }
    // move batch cluster from list of not started ones to running ones
    BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
    pluginInstance.setClusterToRunning(cluster);
// next node and timespan to next event determined by responsible process instance
// tasks resources only assigned to responsible subprocess instance
// only responsible subprocess instance is simulated
// other subprocess instances of batch are covered in process logs
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) TaskBeginEvent(de.hpi.bpt.scylla.simulation.event.TaskBeginEvent) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) MultipleStartNodesException(de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException) 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 3 with ScyllaEvent

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

the class BatchTBPlugin method eventRoutine.

@SuppressWarnings("unchecked")
@Override
public void eventRoutine(TaskBeginEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
    // System.out.println(event + " with display name " + event.getDisplayName() + " || " + event.getNextEventMap() + " and source " + event.getSource());
    BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
    pluginInstance.logTaskEventForNonResponsiblePI(event, processInstance);
    ProcessSimulationComponents desmojObjects = event.getDesmojObjects();
    // SimulationModel model = (SimulationModel) desmojEvent.getModel();
    int nodeId = event.getNodeId();
    ProcessModel processModel = processInstance.getProcessModel();
    ProcessInstance parentProcessInstance = processInstance.getParent();
    if (parentProcessInstance != null) {
        int parentNodeId = processModel.getNodeIdInParent();
        BatchCluster cluster = pluginInstance.getRunningCluster(parentProcessInstance, parentNodeId);
        // If we are the representative (first executed) process instance we add the setUp time for this task
        if (cluster != null && parentProcessInstance == cluster.getResponsibleProcessInstance()) {
            // therefore we fist take a sample of the setUp distribution
            double setUpTimeToAdd = desmojObjects.getSetUpDistributionSample(nodeId);
            TimeUnit unit = desmojObjects.getSetUpDistributionTimeUnit(nodeId);
            TimeSpan setUpTimeToAddAsTimeSpan = new TimeSpan(setUpTimeToAdd, unit);
            // get the old value (this will always be the entry 0 in our map, because it's always the next)
            double standardTime = event.getTimeSpanToNextEventMap().get(0).getTimeAsDouble(TimeUnit.SECONDS);
            // and overwrite the time to the next task in the timeSpanToNextEventMap (=set the calculated time as the new time)
            TimeSpan timeForTaskWithSetUp = new TimeSpan(standardTime + setUpTimeToAddAsTimeSpan.getTimeAsDouble(TimeUnit.SECONDS), TimeUnit.SECONDS);
            event.getTimeSpanToNextEventMap().put(0, timeForTaskWithSetUp);
        }
    }
    // SimulationConfiguration simulationConfiguration = desmojObjects.getSimulationConfiguration();
    /*Map<Integer, BatchActivity> batchActivities = (Map<Integer, BatchActivity>) simulationConfiguration
                .getExtensionValue(getName(), "batchActivities");*/
    Map<Integer, BatchActivity> batchActivities = processModel.getBatchActivities();
    if (batchActivities.containsKey(nodeId) && processModel.getSubProcesses().containsKey(nodeId)) {
        // subprocess plugin wants to schedule BPMNStartEvents for subprocess
        // we prevent it
        Map<Integer, ScyllaEvent> nextEventMap = event.getNextEventMap();
        Map<Integer, TimeSpan> timeSpanToNextEventMap = event.getTimeSpanToNextEventMap();
        for (Integer indexOfSubprocessBPMNStartEvent : nextEventMap.keySet()) {
            ScyllaEvent eventToSchedule = nextEventMap.get(indexOfSubprocessBPMNStartEvent);
            if (eventToSchedule instanceof BPMNStartEvent || eventToSchedule instanceof TaskTerminateEvent) {
                nextEventMap.remove(indexOfSubprocessBPMNStartEvent);
                timeSpanToNextEventMap.remove(indexOfSubprocessBPMNStartEvent);
                break;
            }
        }
    }
}
Also used : 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) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) TimeUnit(java.util.concurrent.TimeUnit) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) BPMNStartEvent(de.hpi.bpt.scylla.simulation.event.BPMNStartEvent)

Example 4 with ScyllaEvent

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

the class BatchTEPlugin method eventRoutine.

@SuppressWarnings("unchecked")
@Override
public void eventRoutine(TaskEnableEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
    BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
    pluginInstance.logTaskEventForNonResponsiblePI(event, processInstance);
    // ProcessSimulationComponents desmojObjects = event.getDesmojObjects();
    // SimulationModel model = (SimulationModel) desmojEvent.getModel();
    int nodeId = event.getNodeId();
    ProcessModel processModel = processInstance.getProcessModel();
    // SimulationConfiguration simulationConfiguration = desmojObjects.getSimulationConfiguration();
    /*Map<Integer, BatchActivity> batchActivities = (Map<Integer, BatchActivity>) simulationConfiguration
                .getExtensionValue(getName(), "batchActivities");*/
    Map<Integer, BatchActivity> batchActivities = processModel.getBatchActivities();
    if (batchActivities.containsKey(nodeId) && processModel.getSubProcesses().containsKey(nodeId)) {
        // in any case: put taskbeginevent of subprocess container on hold
        // String source = desmojEvent.getSource();
        int indexOfSubprocessBeginEvent = 0;
        Map<Integer, ScyllaEvent> nextEventMap = event.getNextEventMap();
        Map<Integer, TimeSpan> timeSpanToNextEventMap = event.getTimeSpanToNextEventMap();
        // Map<String, TaskBeginEvent> subprocessStartEventsOnHold =
        // pluginInstance.getSubprocessStartEventsOnHold();
        TaskBeginEvent subprocessBeginEvent = (TaskBeginEvent) nextEventMap.get(indexOfSubprocessBeginEvent);
        pluginInstance.assignToBatchCluster(processInstance, nodeId, subprocessBeginEvent);
        nextEventMap.remove(indexOfSubprocessBeginEvent);
        timeSpanToNextEventMap.remove(indexOfSubprocessBeginEvent);
    }
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) TaskBeginEvent(de.hpi.bpt.scylla.simulation.event.TaskBeginEvent) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent)

Example 5 with ScyllaEvent

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

the class ExclusiveGatewayEventPlugin method scheduleNextEvent.

private void scheduleNextEvent(GatewayEvent desmojEvent, ProcessInstance processInstance, ProcessModel processModel, Integer nextFlowId) {
    Set<Integer> nodeIds = null;
    try {
        nodeIds = processModel.getTargetObjectIds(nextFlowId);
    } catch (NodeNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (nodeIds.size() != 1) {
        try {
            throw new ScyllaValidationException("Flow " + nextFlowId + " does not connect to 1 node, but" + nodeIds.size() + " .");
        } catch (ScyllaValidationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    int nextNodeId = nodeIds.iterator().next();
    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 (nodeIdOfCandidate == nextNodeId) {
            indicesOfEventsToKeep.add(index);
            break;
        }
    }
    Map<Integer, TimeSpan> timeSpanToNextEventMap = desmojEvent.getTimeSpanToNextEventMap();
    nextEventMap.keySet().retainAll(indicesOfEventsToKeep);
    timeSpanToNextEventMap.keySet().retainAll(indicesOfEventsToKeep);
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) ArrayList(java.util.ArrayList) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent)

Aggregations

ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)21 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)15 TimeSpan (desmoj.core.simulator.TimeSpan)15 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)7 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)7 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)7 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)6 ArrayList (java.util.ArrayList)6 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)5 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)4 TaskTerminateEvent (de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)4 TimeInstant (desmoj.core.simulator.TimeInstant)4 BPMNStartEvent (de.hpi.bpt.scylla.simulation.event.BPMNStartEvent)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)2 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)2 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)2 GatewayType (de.hpi.bpt.scylla.model.process.node.GatewayType)2 TaskBeginEvent (de.hpi.bpt.scylla.simulation.event.TaskBeginEvent)2