Search in sources :

Example 66 with ProcessModel

use of de.hpi.bpt.scylla.model.process.ProcessModel in project scylla by bptlab.

the class BatchPluginUtils method logTaskEventForNonResponsiblePI.

// If the execution type is parallel this makes the entry for the not really simulated process instances for tasks
void logTaskEventForNonResponsiblePI(TaskEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessInstance parentProcessInstance = processInstance.getParent();
    if (parentProcessInstance != null) {
        ProcessModel processModel = processInstance.getProcessModel();
        int parentNodeId = processModel.getNodeIdInParent();
        BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
        BatchCluster cluster = pluginInstance.getRunningCluster(parentProcessInstance, parentNodeId);
        if (cluster != null && cluster.getBatchActivity().getExecutionType().equals(BatchClusterExecutionType.PARALLEL)) {
            SimulationModel model = (SimulationModel) event.getModel();
            long timestamp = Math.round(model.presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
            String taskName = event.getDisplayName();
            int nodeId = event.getNodeId();
            String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
            String source = event.getSource();
            ProcessNodeTransitionType transition;
            Set<String> resources = new HashSet<String>();
            if (event instanceof TaskEnableEvent) {
                transition = ProcessNodeTransitionType.ENABLE;
            } else if (event instanceof TaskBeginEvent) {
                transition = ProcessNodeTransitionType.BEGIN;
                Set<ResourceObject> resourceObjects = processInstance.getAssignedResources().get(source).getResourceObjects();
                for (ResourceObject res : resourceObjects) {
                    String resourceName = res.getResourceType() + "_" + res.getId();
                    resources.add(resourceName);
                }
                tasksAndResources.put(source, resources);
            } else if (event instanceof TaskCancelEvent) {
                transition = ProcessNodeTransitionType.CANCEL;
                resources = tasksAndResources.get(source);
                tasksAndResources.remove(source);
            } else if (event instanceof TaskTerminateEvent) {
                transition = ProcessNodeTransitionType.TERMINATE;
                resources = tasksAndResources.get(source);
                tasksAndResources.remove(source);
            } else {
                throw new ScyllaRuntimeException("Task event type not supported.");
            }
            int sourceSuffix = 0;
            List<ProcessInstance> processInstances = cluster.getProcessInstances();
            for (ProcessInstance pi : processInstances) {
                if (!processInstance.getParent().equals(pi)) {
                    // the source attribute comes from an event, but we did not really simulate the events for the
                    // non-responsible process instances, so we mock a source attribute value
                    String mockSource = source + "##" + ++sourceSuffix;
                    ProcessNodeInfo info;
                    info = new ProcessNodeInfo(nodeId, processScopeNodeId, mockSource, timestamp, taskName, resources, transition);
                    model.addNodeInfo(processModel, pi, info);
                }
            }
        }
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ResourceObject(de.hpi.bpt.scylla.simulation.ResourceObject) HashSet(java.util.HashSet) Set(java.util.Set) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) ProcessNodeTransitionType(de.hpi.bpt.scylla.logger.ProcessNodeTransitionType) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) HashSet(java.util.HashSet)

Example 67 with ProcessModel

use of de.hpi.bpt.scylla.model.process.ProcessModel in project scylla by bptlab.

the class BatchPluginUtils method assignToBatchCluster.

@SuppressWarnings("unchecked")
void assignToBatchCluster(ProcessInstance processInstance, int nodeId, TaskBeginEvent parentalBeginEvent) {
    ProcessModel processModel = processInstance.getProcessModel();
    ProcessSimulationComponents pSimComponents = parentalBeginEvent.getDesmojObjects();
    /*Map<Integer, BatchActivity> batchActivities_old = (Map<Integer, BatchActivity>) pSimComponents.getSimulationConfiguration()
                .getExtensionValue(PLUGIN_NAME, "batchActivities");*/
    Map<Integer, BatchActivity> batchActivities = processModel.getBatchActivities();
    BatchActivity activity = batchActivities.get(nodeId);
    BatchCluster cluster = null;
    // (1) select the right batch cluster
    // (1a) check if there is already a batch with the data view
    String processId = processModel.getId();
    Map<Integer, List<BatchCluster>> batchClustersOfProcess = batchClusters.get(processId);
    if (batchClustersOfProcess != null) {
        List<BatchCluster> clusters = batchClustersOfProcess.get(nodeId);
        if (clusters != null) {
            for (BatchCluster bc : clusters) {
                if (batchClusterHasNotStarted(bc.getState()) && isProcessInstanceMatchingToDataView(parentalBeginEvent, processInstance, bc)) {
                    cluster = bc;
                    // clusters.remove(bc);
                    break;
                }
            }
        }
    }
    // (1b) if not, create a new one
    if (cluster == null) {
        Model model = processInstance.getModel();
        boolean showInTrace = processInstance.traceIsOn();
        Map<String, Object> dataView = this.getDataViewOfInstance(parentalBeginEvent, processInstance, activity);
        TimeInstant currentSimulationTime = processInstance.presentTime();
        cluster = new BatchCluster(model, currentSimulationTime, pSimComponents, activity, nodeId, dataView, showInTrace);
        // schedule BatchClusterStart at current time plus maximum timeout
        BatchClusterStartEvent clusterStartEvent = new BatchClusterStartEvent(model, cluster.getName(), showInTrace);
        Duration timeout = activity.getActivationRule().getTimeOut(parentalBeginEvent, processInstance);
        cluster.setCurrentTimeOut(timeout);
        long timeoutInSeconds = timeout.get(ChronoUnit.SECONDS);
        TimeSpan timeSpan = new TimeSpan(timeoutInSeconds, TimeUnit.SECONDS);
        clusterStartEvent.schedule(cluster, timeSpan);
        if (batchClustersOfProcess == null) {
            batchClustersOfProcess = new HashMap<Integer, List<BatchCluster>>();
            batchClusters.put(processId, batchClustersOfProcess);
            List<BatchCluster> clusters = batchClustersOfProcess.get(nodeId);
            if (clusters == null) {
                clusters = new ArrayList<BatchCluster>();
                batchClustersOfProcess.put(nodeId, clusters);
            }
        }
        batchClustersOfProcess.get(nodeId).add(cluster);
    }
    // (2) add process instance to cluster
    cluster.addProcessInstance(processInstance, parentalBeginEvent);
    // TODO check whether timeout should be updated
    if (cluster.getState() == BatchClusterState.INIT && cluster.getProcessInstances().size() > 1) {
        // if the dueDate of the current instance is earlier as of the instances added before, the cluster begin event is rescheduled
        Duration timeoutForCurrentInstance = activity.getActivationRule().getTimeOut(parentalBeginEvent, processInstance);
        // testing
        TimeUnit epsilon = TimeUnit.SECONDS;
        Duration durationBtwClusterStartAndInstanceTaskBegin = Duration.ofSeconds((long) (parentalBeginEvent.getSimulationTimeOfSource().getTimeAsDouble(epsilon) - cluster.getCreationTime().getTimeAsDouble(epsilon)));
        // System.out.println("InstanceEnable: "+parentalBeginEvent.getSimulationTimeOfSource().getTimeAsDouble(epsilon)+" ClusterCreation: "+cluster.getCreationTime().getTimeAsDouble(epsilon)+" Duration "+durationBtwClusterStartAndInstanceTaskBegin);
        if (timeoutForCurrentInstance.plus(durationBtwClusterStartAndInstanceTaskBegin).compareTo(cluster.getCurrentTimeOut()) < 0) {
            // set new timeout for the cluster for comparison
            cluster.setCurrentTimeOut(timeoutForCurrentInstance);
            // reschedule the cluster beginEvent
            long timeoutInSeconds = timeoutForCurrentInstance.get(ChronoUnit.SECONDS);
            TimeSpan timeSpan = new TimeSpan(timeoutInSeconds, TimeUnit.SECONDS);
            BatchClusterStartEvent clusterStartEvent = (BatchClusterStartEvent) cluster.getScheduledEvents().get(0);
            cluster.cancel();
            clusterStartEvent.schedule(cluster, timeSpan);
        }
    }
    if (cluster.getState() == BatchClusterState.MAXLOADED) {
        // (2a) if bc is maxloaded, reschedule BatchClusterStart
        // there is only one event already scheduled for the cluster which is the BatchClusterStart
        BatchClusterStartEvent clusterStartEvent = (BatchClusterStartEvent) cluster.getScheduledEvents().get(0);
        cluster.cancel();
        // schedule for immediate execution
        clusterStartEvent.schedule(cluster);
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) Duration(java.time.Duration) TimeSpan(desmoj.core.simulator.TimeSpan) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) Model(desmoj.core.simulator.Model) TimeUnit(java.util.concurrent.TimeUnit) ArrayList(java.util.ArrayList) List(java.util.List) ResourceObject(de.hpi.bpt.scylla.simulation.ResourceObject) TimeInstant(desmoj.core.simulator.TimeInstant)

Example 68 with ProcessModel

use of de.hpi.bpt.scylla.model.process.ProcessModel in project scylla by bptlab.

the class BatchPluginUtils method logBPMNEventForNonResponsiblePI.

// If the execution type is parallel this makes the entry for the not really simulated process instances for events
void logBPMNEventForNonResponsiblePI(BPMNEvent event, ProcessInstance processInstance) {
    ProcessInstance parentProcessInstance = processInstance.getParent();
    if (parentProcessInstance != null) {
        ProcessModel processModel = processInstance.getProcessModel();
        int parentNodeId = processModel.getNodeIdInParent();
        BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
        BatchCluster cluster = pluginInstance.getRunningCluster(parentProcessInstance, parentNodeId);
        if (cluster != null && cluster.hasExecutionType(BatchClusterExecutionType.PARALLEL)) {
            SimulationModel model = (SimulationModel) event.getModel();
            long timestamp = Math.round(model.presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
            Set<String> resources = new HashSet<String>();
            String taskName = event.getDisplayName();
            int nodeId = event.getNodeId();
            String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
            String source = event.getSource();
            int sourceSuffix = 0;
            List<ProcessInstance> processInstances = cluster.getProcessInstances();
            for (ProcessInstance pi : processInstances) {
                if (!processInstance.getParent().equals(pi)) {
                    // the source attribute comes from an event, but we did not really simulate the events for the
                    // non-responsible process instances, so we mock a source attribute value
                    String mockSource = source + "##" + ++sourceSuffix;
                    ProcessNodeInfo info;
                    info = new ProcessNodeInfo(nodeId, processScopeNodeId, mockSource, timestamp, taskName, resources, ProcessNodeTransitionType.EVENT_BEGIN);
                    model.addNodeInfo(processModel, pi, info);
                    info = new ProcessNodeInfo(nodeId, processScopeNodeId, mockSource, timestamp, taskName, resources, ProcessNodeTransitionType.EVENT_TERMINATE);
                    model.addNodeInfo(processModel, pi, info);
                }
            }
        }
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) HashSet(java.util.HashSet)

Example 69 with ProcessModel

use of de.hpi.bpt.scylla.model.process.ProcessModel in project scylla by bptlab.

the class BoundaryDistributionConversionPlugin method convertToDesmoJDistributions.

// Took the branching behaviour also used in exclusive gateways. I did not touch it for now, have a look on it later. Should just be needed for event probability...
// TODO: Resolve redundancy.
@SuppressWarnings("unchecked")
@Override
public Map<Integer, Object> convertToDesmoJDistributions(ProcessSimulationComponents pSimComponents) {
    Map<Integer, Object> boundaryEventDistributions = new HashMap<Integer, Object>();
    SimulationConfiguration simulationConfiguration = pSimComponents.getSimulationConfiguration();
    Long randomSeed = simulationConfiguration.getRandomSeed();
    Map<Integer, BranchingBehavior> branchingBehaviors = (Map<Integer, BranchingBehavior>) simulationConfiguration.getExtensionValue(getName(), "branchingBehaviors");
    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);
        boundaryEventDistributions.put(nodeId, desmojDist);
    }
    return boundaryEventDistributions;
}
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 70 with ProcessModel

use of de.hpi.bpt.scylla.model.process.ProcessModel in project scylla by bptlab.

the class BoundaryIntermediateEventPlugin method eventRoutine.

// This will be called always when an intermediate event occurs.
@Override
public void eventRoutine(BPMNIntermediateEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
    Integer nodeId = event.getNodeId();
    ProcessModel processModel = processInstance.getProcessModel();
    // If this (boundary-)event is interrupting cancel the corresponding task (and thus the process instance)
    Boolean isCancelActivity = processModel.getCancelActivities().get(nodeId);
    if (isCancelActivity != null && isCancelActivity) {
        processInstance.cancel();
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel)

Aggregations

ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)73 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)42 TimeSpan (desmoj.core.simulator.TimeSpan)26 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)22 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)19 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)18 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)18 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)16 Map (java.util.Map)16 HashMap (java.util.HashMap)14 ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)13 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)13 Element (org.jdom2.Element)13 TimeInstant (desmoj.core.simulator.TimeInstant)12 HashSet (java.util.HashSet)12 SimulationConfiguration (de.hpi.bpt.scylla.model.configuration.SimulationConfiguration)10 TimeUnit (java.util.concurrent.TimeUnit)10 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)8 ArrayList (java.util.ArrayList)8 Namespace (org.jdom2.Namespace)8