Search in sources :

Example 16 with ProcessModel

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

the class InclusiveGatewayDistributionConversionPlugin method convertToDesmoJDistributions.

@SuppressWarnings("unchecked")
@Override
public Map<Integer, Object> convertToDesmoJDistributions(ProcessSimulationComponents pSimComponents) {
    Map<Integer, Object> branchingDistributionsInclusive = 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();
        Map<Integer, BoolDistBernoulli> inclusiveDistributions = new HashMap<Integer, BoolDistBernoulli>();
        for (Integer nextNodeId : branchingProbabilities.keySet()) {
            Double probability = branchingProbabilities.get(nextNodeId);
            BoolDistBernoulli desmojDist = new BoolDistBernoulli(model, name, probability, showInReport, showInTrace);
            desmojDist.setSeed(randomSeed);
            inclusiveDistributions.put(nextNodeId, desmojDist);
        }
        branchingDistributionsInclusive.put(nodeId, inclusiveDistributions);
    }
    return branchingDistributionsInclusive;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) BoolDistBernoulli(desmoj.core.dist.BoolDistBernoulli) 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 17 with ProcessModel

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

the class SimulationModel method doInitialSchedules.

@Override
public void doInitialSchedules() {
    TimeUnit timeUnit = DateTimeUtils.getReferenceTimeUnit();
    for (String processId : pSimMap.keySet()) {
        ProcessSimulationComponents desmojObj = pSimMap.get(processId);
        // schedule for end of simulation (if defined), aligned to global start time
        ZonedDateTime endDateOfSimulationConf = desmojObj.getSimulationConfiguration().getEndDateTime();
        Long endTimeRelativeToGlobalStart = Long.MAX_VALUE;
        if (endDateOfSimulationConf != null) {
            endTimeRelativeToGlobalStart = DateTimeUtils.getDuration(startDateTime, endDateOfSimulationConf);
            ProcessSimulationStopEvent endEvent = new ProcessSimulationStopEvent(this, processId, traceIsOn());
            // java.util.Date getTime() returns milliseconds
            endEvent.schedule(new TimeSpan(endTimeRelativeToGlobalStart, timeUnit));
        }
        // schedule for start of simulation, aligned to global start time
        ZonedDateTime startDateOfSimulationConf = desmojObj.getSimulationConfiguration().getStartDateTime();
        long startTimeRelativeToGlobalStart = DateTimeUtils.getDuration(startDateTime, startDateOfSimulationConf);
        ProcessModel processModel = desmojObj.getProcessModel();
        int processInstanceId = desmojObj.incrementProcessInstancesStarted();
        ProcessInstance firstProcessInstance = new ProcessInstance(this, processModel, processInstanceId, traceIsOn());
        ProcessInstanceGenerationEvent startEvent = new ProcessInstanceGenerationEvent(this, processId, endTimeRelativeToGlobalStart, traceIsOn());
        startEvent.schedule(firstProcessInstance, new TimeSpan(startTimeRelativeToGlobalStart, timeUnit));
    }
    if (endDateTime != null) {
        // / java.util.Date getTime() returns milliseconds
        long simulationDuration = DateTimeUtils.getDuration(startDateTime, endDateTime);
        TimeInstant timeInstant = new TimeInstant(simulationDuration, DateTimeUtils.getReferenceTimeUnit());
        for (String processId : pSimMap.keySet()) {
            ProcessSimulationStopEvent abortEvent = new ProcessSimulationStopEvent(this, processId, traceIsOn());
            abortEvent.schedule(timeInstant);
        }
    }
}
Also used : ProcessInstanceGenerationEvent(de.hpi.bpt.scylla.simulation.event.ProcessInstanceGenerationEvent) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessSimulationStopEvent(de.hpi.bpt.scylla.simulation.event.ProcessSimulationStopEvent) TimeSpan(desmoj.core.simulator.TimeSpan) ZonedDateTime(java.time.ZonedDateTime) TimeUnit(java.util.concurrent.TimeUnit) TimeInstant(desmoj.core.simulator.TimeInstant)

Example 18 with ProcessModel

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

the class BPMNEvent method addToLog.

protected void addToLog(ProcessInstance processInstance) {
    long timestamp = Math.round(getModel().presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
    String taskName = displayName;
    Set<String> resources = new HashSet<String>();
    SimulationModel model = (SimulationModel) getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
    ProcessNodeInfo info;
    info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources, ProcessNodeTransitionType.EVENT_BEGIN);
    model.addNodeInfo(processModel, processInstance, info);
    info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources, ProcessNodeTransitionType.EVENT_TERMINATE);
    model.addNodeInfo(processModel, processInstance, info);
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 19 with ProcessModel

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

the class GatewayEvent method eventRoutine.

@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
    SimulationModel model = (SimulationModel) getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    try {
        Set<Integer> idsOfPreviousNodes = processModel.getIdsOfPreviousNodes(nodeId);
        Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
        String message = null;
        GatewayType type = processModel.getGateways().get(nodeId);
        String convergeDivergeName = "Join and Split";
        if (idsOfPreviousNodes.size() == 1) {
            convergeDivergeName = "Split";
        } else if (idsOfNextNodes.size() == 1) {
            convergeDivergeName = "Join";
        }
        if (type == GatewayType.DEFAULT) {
            message = "Default " + convergeDivergeName + " Gateway: " + displayName;
        }
        if (type == GatewayType.EXCLUSIVE) {
            message = "Exclusive " + convergeDivergeName + " Gateway: " + displayName;
        } else if (type == GatewayType.EVENT_BASED) {
            message = "Eventbased " + convergeDivergeName + " Gateway: " + displayName;
        } else if (type == GatewayType.INCLUSIVE) {
            message = "Inclusive " + convergeDivergeName + " Gateway: " + displayName;
        } else if (type == GatewayType.PARALLEL) {
            message = "Parallel " + convergeDivergeName + " Gateway: " + displayName;
        } else if (type == GatewayType.COMPLEX) {
            message = "Complex " + convergeDivergeName + " Gateway: " + displayName;
        } else {
            // TODO write to log because element not supported
            SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
            return;
        }
        sendTraceNote(message);
        // i.e. for splits: default behavior is the one of a parallel gateway
        for (Integer nextNodeId : idsOfNextNodes) {
            List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(this, pSimComponents, processInstance, nextNodeId);
            // next DesmoJ event occurs immediately after start event
            TimeSpan timeSpan = new TimeSpan(0);
            for (ScyllaEvent event : events) {
                int index = getNewEventIndex();
                nextEventMap.put(index, event);
                timeSpanToNextEventMap.put(index, timeSpan);
            }
        }
        GatewayEventPluggable.runPlugins(this, processInstance);
        scheduleNextEvents();
    } catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
        return;
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) GatewayType(de.hpi.bpt.scylla.model.process.node.GatewayType) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 20 with ProcessModel

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

the class TaskBeginEvent method addToLog.

@Override
protected void addToLog(ProcessInstance processInstance) {
    long timestamp = Math.round(getModel().presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
    String taskName = displayName;
    Set<String> resources = new HashSet<String>();
    Set<ResourceObject> resourceObjects = processInstance.getAssignedResources().get(source).getResourceObjects();
    for (ResourceObject res : resourceObjects) {
        String resourceName = res.getResourceType() + "_" + res.getId();
        resources.add(resourceName);
    }
    ProcessNodeTransitionType transition = ProcessNodeTransitionType.BEGIN;
    SimulationModel model = (SimulationModel) getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
    ProcessNodeInfo info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources, transition);
    model.addNodeInfo(processModel, processInstance, info);
}
Also used : ResourceObject(de.hpi.bpt.scylla.simulation.ResourceObject) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeTransitionType(de.hpi.bpt.scylla.logger.ProcessNodeTransitionType) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) HashSet(java.util.HashSet)

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