Search in sources :

Example 1 with BPMNStartEvent

use of de.hpi.bpt.scylla.simulation.event.BPMNStartEvent 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 2 with BPMNStartEvent

use of de.hpi.bpt.scylla.simulation.event.BPMNStartEvent 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 3 with BPMNStartEvent

use of de.hpi.bpt.scylla.simulation.event.BPMNStartEvent 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)

Aggregations

ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)3 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)3 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)3 BPMNStartEvent (de.hpi.bpt.scylla.simulation.event.BPMNStartEvent)3 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)3 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)2 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)2 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)2 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)2 TaskTerminateEvent (de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)2 TimeInstant (desmoj.core.simulator.TimeInstant)2 TimeSpan (desmoj.core.simulator.TimeSpan)2 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)1 TaskBeginEvent (de.hpi.bpt.scylla.simulation.event.TaskBeginEvent)1 TimeUnit (java.util.concurrent.TimeUnit)1