Search in sources :

Example 21 with SimulationModel

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

the class DataObjectBPMNStartEvent method eventRoutine.

@Override
public void eventRoutine(BPMNStartEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessModel processModel = processInstance.getProcessModel();
    // int processInstanceId = processInstance.getId();
    try {
        if (processModel.getDataObjectsGraph().getNodes().containsKey(desmojEvent.getNodeId())) {
            Set<Integer> refferingObjects = processModel.getDataObjectsGraph().getTargetObjects(desmojEvent.getNodeId());
            Collection<Object> allFields = desmojEvent.getDesmojObjects().getExtensionDistributions().get("dataobject").values();
            for (Object fields : allFields) {
                Integer i = 0;
                while (((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray().length - i != 0) {
                    DataObjectField field = (DataObjectField) ((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray()[i];
                    if (refferingObjects.contains(field.getNodeId())) {
                        // System.out.println(processInstance.getId() + " " + desmojEvent.getDisplayName() + " " + processModel.getDisplayNames().get(field.getNodeId()) + " " + field.getDataDistributionWrapper().getSample());
                        SimulationModel model = (SimulationModel) desmojEvent.getModel();
                        Collection<Map<Integer, java.util.List<ProcessNodeInfo>>> allProcesses = model.getProcessNodeInfos().values();
                        for (Map<Integer, java.util.List<ProcessNodeInfo>> process : allProcesses) {
                            List<ProcessNodeInfo> currentProcess = process.get(processInstance.getId());
                            for (ProcessNodeInfo task : currentProcess) {
                                // System.out.println(processModel.getDisplayNames().get(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[0]) + " " + task.getTaskName());
                                for (Integer j = 0; j < processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray().length; j++) {
                                    if (task.getId().equals(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[j]) && task.getTransition() == ProcessNodeTransitionType.EVENT_TERMINATE) {
                                        // check all tasks and find the ones that may be looged; already logged ones will get ignored next line
                                        if (!task.getDataObjectField().containsKey(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName())) {
                                            // don't log if task already has this field logged
                                            Map<String, Object> fieldSample = new HashMap<String, Object>();
                                            Object currentSample = field.getDataDistributionWrapper().getSample();
                                            // log Value at TaskTerminate
                                            fieldSample.put(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName(), currentSample);
                                            task.SetDataObjectField(fieldSample);
                                            // set current DataObjectFieldValue
                                            DataObjectField.addDataObjectValue(processInstance.getId(), fieldSample.keySet().toArray()[0].toString(), currentSample);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    i++;
                }
            }
        } else {
        // do nothing and continue with the next task because Node has no dataobejcts
        }
    } catch (ScyllaRuntimeException | ScyllaValidationException | NodeNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) java.util(java.util) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 22 with SimulationModel

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

the class DataObjectDistributionConversionPlugin method convertToDesmoJDistributions.

@SuppressWarnings("unchecked")
@Override
public Map<Integer, Object> convertToDesmoJDistributions(ProcessSimulationComponents pSimComponents) {
    SimulationConfiguration simulationConfiguration = pSimComponents.getSimulationConfiguration();
    Map<Integer, Object> dataObjects = (Map<Integer, Object>) simulationConfiguration.getExtensionValue(getName(), "dataObjects");
    Long randomSeed = simulationConfiguration.getRandomSeed();
    ProcessModel processModel = pSimComponents.getProcessModel();
    SimulationModel model = pSimComponents.getModel();
    boolean showInReport = model.reportIsOn();
    boolean showInTrace = model.traceIsOn();
    for (Integer nodeId : dataObjects.keySet()) {
        Map<String, DataObjectField> dataObjectFields = (Map<String, DataObjectField>) dataObjects.get(nodeId);
        String name = processModel.getModelScopeId() + "_" + nodeId.toString();
        for (String fieldName : dataObjectFields.keySet()) {
            DataObjectField dataObjectField = dataObjectFields.get(fieldName);
            DataDistributionWrapper distWrapper = dataObjectField.getDataDistributionWrapper();
            Distribution dist = distWrapper.getDistribution();
            if (dist == null)
                continue;
            NumericalDist<?> desmojDist = null;
            try {
                desmojDist = SimulationUtils.getDistribution(dist, model, name, nodeId, showInReport, showInTrace);
            } catch (InstantiationException e) {
                DebugLogger.error(e.getMessage());
                DebugLogger.error("Instantiation of dmn model failed.");
                return null;
            }
            desmojDist.setSeed(randomSeed);
            distWrapper.setDesmojDistribution(desmojDist);
        }
    }
    return dataObjects;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) SimulationConfiguration(de.hpi.bpt.scylla.model.configuration.SimulationConfiguration) Distribution(de.hpi.bpt.scylla.model.configuration.distribution.Distribution) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 23 with SimulationModel

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

the class EventArrivalRateDistributionConversionPlugin method convertToDesmoJDistributions.

/**
 * Converts scylla distributions from extension to desmoJ distributions to be stored als distribution extension.
 * @see {@link de.hpi.bpt.scylla.simulation.utils.SimulationUtils#getDistribution(Distribution, SimulationModel, String, Integer, boolean, boolean)}
 */
@Override
public Map<Integer, Object> convertToDesmoJDistributions(ProcessSimulationComponents pSimComponents) {
    Map<Integer, Object> arrivalRateDistributions = new HashMap<Integer, Object>();
    SimulationConfiguration simulationConfiguration = pSimComponents.getSimulationConfiguration();
    Long randomSeed = simulationConfiguration.getRandomSeed();
    /**
     *Get saved extension from sc parser
     */
    @SuppressWarnings("unchecked") HashMap<Integer, TimeDistributionWrapper> arrivalRates = (HashMap<Integer, TimeDistributionWrapper>) simulationConfiguration.getExtensionValue(getName(), EventArrivalRatePluginUtils.ARRIVALRATES_KEY);
    ProcessModel processModel = pSimComponents.getProcessModel();
    SimulationModel model = pSimComponents.getModel();
    boolean showInReport = model.reportIsOn();
    boolean showInTrace = model.traceIsOn();
    for (Entry<Integer, TimeDistributionWrapper> entry : arrivalRates.entrySet()) {
        Integer nodeId = entry.getKey();
        TimeDistributionWrapper arrivalRate = entry.getValue();
        TimeUnit timeUnit = arrivalRate.getTimeUnit();
        Distribution distribution = arrivalRate.getDistribution();
        String name = processModel.getModelScopeId() + "_" + nodeId.toString();
        try {
            NumericalDist<?> desmojDist = SimulationUtils.getDistribution(distribution, model, name, nodeId, showInReport, showInTrace);
            desmojDist.setSeed(randomSeed);
            arrivalRateDistributions.put(nodeId, new SimpleEntry<NumericalDist<?>, TimeUnit>(desmojDist, timeUnit));
        } catch (InstantiationException e) {
            e.printStackTrace();
            continue;
        }
    }
    return arrivalRateDistributions;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) HashMap(java.util.HashMap) NumericalDist(desmoj.core.dist.NumericalDist) SimulationConfiguration(de.hpi.bpt.scylla.model.configuration.SimulationConfiguration) Distribution(de.hpi.bpt.scylla.model.configuration.distribution.Distribution) TimeUnit(java.util.concurrent.TimeUnit) TimeDistributionWrapper(de.hpi.bpt.scylla.model.configuration.distribution.TimeDistributionWrapper) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 24 with SimulationModel

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

the class EventOrderPriority method compare.

@Override
public int compare(String resourceId, ScyllaEvent e1, ScyllaEvent e2) throws ScyllaRuntimeException {
    SimulationModel model = (SimulationModel) e1.getModel();
    if (!model.equals((SimulationModel) e2.getModel())) {
        throw new ScyllaRuntimeException("New event for queue is attached to another simulation model.");
    }
    Integer priorityOfFirstEvent = null;
    Set<ResourceReference> resourceRefsOfFirstEvent = e1.getDesmojObjects().getSimulationConfiguration().getResourceReferenceSet(e1.getNodeId());
    for (ResourceReference resourceRef : resourceRefsOfFirstEvent) {
        if (resourceId.equals(resourceRef.getResourceId())) {
            String priorityString = resourceRef.getAssignmentDefinition().get("priority");
            if (priorityString == null) {
                priorityOfFirstEvent = -1;
            } else {
                priorityOfFirstEvent = Integer.parseInt(resourceRef.getAssignmentDefinition().get("priority"));
            }
        }
    }
    Integer priorityOfSecondEvent = null;
    Set<ResourceReference> resourceRefsOfSecondEvent = e2.getDesmojObjects().getSimulationConfiguration().getResourceReferenceSet(e2.getNodeId());
    for (ResourceReference resourceRef : resourceRefsOfSecondEvent) {
        if (resourceId.equals(resourceRef.getResourceId())) {
            String priorityString = resourceRef.getAssignmentDefinition().get("priority");
            if (priorityString == null) {
                priorityOfSecondEvent = -1;
            } else {
                priorityOfSecondEvent = Integer.parseInt(resourceRef.getAssignmentDefinition().get("priority"));
            }
        }
    }
    // higher value is sorted first
    return priorityOfSecondEvent - priorityOfFirstEvent;
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ResourceReference(de.hpi.bpt.scylla.model.configuration.ResourceReference) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 25 with SimulationModel

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

the class EventbasedGatewayEventPlugin method eventRoutine.

/**
 * Handles a gateway event, if it is an event based gateway
 * Changes scheduling behavior by already scheduling the next events of the given gateway event (if event based)
 */
@Override
public void eventRoutine(GatewayEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    SimulationModel model = (SimulationModel) desmojEvent.getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    int nodeId = desmojEvent.getNodeId();
    GatewayType type = processModel.getGateways().get(nodeId);
    try {
        Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
        if (type == GatewayType.EVENT_BASED && idsOfNextNodes.size() > 1) {
            // Schedule all following events
            List<ScyllaEvent> nextEvents = new ArrayList<ScyllaEvent>(desmojEvent.getNextEventMap().values());
            desmojEvent.scheduleNextEvents();
            // and look which is scheduled first.
            ScyllaEvent first = nextEvents.get(0);
            for (ScyllaEvent e : nextEvents) {
                if (TimeInstant.isBefore(e.scheduledNext(), first.scheduledNext())) {
                    first = e;
                }
            }
            // Cancel all other events except the one that is scheduled first.
            nextEvents.remove(first);
            for (ScyllaEvent e : nextEvents) {
                e.cancel();
            }
        }
    } catch (NodeNotFoundException | ScyllaValidationException | SuspendExecution e) {
        e.printStackTrace();
        // Critical error (following nodes not found or validation error), abort the instance.
        SimulationUtils.abort(model, processInstance, nodeId, desmojEvent.traceIsOn());
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) SuspendExecution(co.paralleluniverse.fibers.SuspendExecution) ArrayList(java.util.ArrayList) GatewayType(de.hpi.bpt.scylla.model.process.node.GatewayType) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) 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