Search in sources :

Example 16 with TimeSpan

use of desmoj.core.simulator.TimeSpan in project scylla by bptlab.

the class BPMNTimerBPMNSEPlugin method eventRoutine.

@Override
public void eventRoutine(BPMNStartEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessModel processModel = processInstance.getProcessModel();
    Map<Integer, ScyllaEvent> nextEvents = desmojEvent.getNextEventMap();
    for (int index : nextEvents.keySet()) {
        ScyllaEvent event = nextEvents.get(index);
        int nextNodeId = event.getNodeId();
        TimeSpan timeSpan = BPMNTimerPluginUtils.getTimeSpanUntilNextEvent(processModel, nextNodeId);
        if (timeSpan != null) {
            desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
        }
    }
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent)

Example 17 with TimeSpan

use of desmoj.core.simulator.TimeSpan in project scylla by bptlab.

the class BPMNTimerGEPlugin method eventRoutine.

@Override
public void eventRoutine(GatewayEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessModel processModel = processInstance.getProcessModel();
    Map<Integer, ScyllaEvent> nextEvents = desmojEvent.getNextEventMap();
    for (int index : nextEvents.keySet()) {
        ScyllaEvent event = nextEvents.get(index);
        int nextNodeId = event.getNodeId();
        TimeSpan timeSpan = BPMNTimerPluginUtils.getTimeSpanUntilNextEvent(processModel, nextNodeId);
        if (timeSpan != null) {
            desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
        }
    }
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent)

Example 18 with TimeSpan

use of desmoj.core.simulator.TimeSpan in project scylla by bptlab.

the class BPMNTimerPIGEPlugin method eventRoutine.

@Override
public void eventRoutine(ProcessInstanceGenerationEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    SimulationModel model = (SimulationModel) desmojEvent.getModel();
    String processId = desmojEvent.getProcessId();
    ProcessSimulationComponents desmojObjects = model.getDesmojObjectsMap().get(processId);
    ProcessModel processModel = desmojObjects.getProcessModel();
    Integer startNodeId;
    try {
        startNodeId = processModel.getStartNode();
        if (desmojObjects.getDistributions().get(startNodeId) == null) {
            // no arrival rate defined, check if start event is timer event and use value from there
            Map<EventDefinitionType, Map<String, String>> eventDefinitions = processModel.getEventDefinitions().get(startNodeId);
            Map<String, String> definitionAttributes = eventDefinitions.get(EventDefinitionType.TIMER);
            if (definitionAttributes != null) {
                // if start event is timer event
                // ISO 8601 duration
                String timeDuration = definitionAttributes.get("timeCycle");
                if (timeDuration == null) {
                    String identifier = processModel.getIdentifiers().get(startNodeId);
                    DebugLogger.log("Timer event " + identifier + " has no timer definition, skip.");
                } else // TODO support timeDate and timeDuration attributes?
                {
                    Duration javaDuration = Duration.parse(timeDuration);
                    long duration = javaDuration.get(ChronoUnit.SECONDS);
                    TimeUnit unit = TimeUnit.SECONDS;
                    TimeSpan timeSpan = new TimeSpan(duration, unit);
                    desmojEvent.setTimeSpanToNextProcessInstance(timeSpan);
                }
            }
        }
    } catch (NodeNotFoundException | MultipleStartNodesException | NoStartNodeException e) {
        DebugLogger.error(e.getMessage());
        DebugLogger.log("Error during instantiation of process model " + processModel.getId() + ".");
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) EventDefinitionType(de.hpi.bpt.scylla.model.process.node.EventDefinitionType) Duration(java.time.Duration) 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) TimeUnit(java.util.concurrent.TimeUnit) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) NoStartNodeException(de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)

Example 19 with TimeSpan

use of desmoj.core.simulator.TimeSpan in project scylla by bptlab.

the class BPMNTimerTTPlugin method eventRoutine.

@Override
public void eventRoutine(TaskTerminateEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessModel processModel = processInstance.getProcessModel();
    Map<Integer, ScyllaEvent> nextEvents = desmojEvent.getNextEventMap();
    for (int index : nextEvents.keySet()) {
        ScyllaEvent event = nextEvents.get(index);
        int nextNodeId = event.getNodeId();
        TimeSpan timeSpan = BPMNTimerPluginUtils.getTimeSpanUntilNextEvent(processModel, nextNodeId);
        if (timeSpan != null) {
            desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
        }
    }
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent)

Example 20 with TimeSpan

use of desmoj.core.simulator.TimeSpan in project scylla by bptlab.

the class EventArrivalRateSchedulingPlugin method scheduleEvent.

/**
 * Gets a sample of the arrival rate distribution for this event, if existing,
 * and schedules the event displaced by this value.
 */
@Override
public boolean scheduleEvent(ScyllaEvent event, TimeSpan timeSpan) throws ScyllaRuntimeException {
    ProcessSimulationComponents pSimComponents = event.getDesmojObjects();
    Map<Integer, Object> arrivalRates = pSimComponents.getExtensionDistributions().get(getName());
    @SuppressWarnings("unchecked") SimpleEntry<NumericalDist<?>, TimeUnit> arrivalRate = (SimpleEntry<NumericalDist<?>, TimeUnit>) arrivalRates.get(event.getNodeId());
    if (arrivalRate != null) {
        NumericalDist<?> distribution = arrivalRate.getKey();
        TimeUnit timeUnit = arrivalRate.getValue();
        ProcessInstance processInstance = event.getProcessInstance();
        TimeSpan offset = new TimeSpan(distribution.sample().doubleValue(), timeUnit);
        TimeSpan newTime = new TimeSpan(timeSpan.getTimeAsDouble() + offset.getTimeAsDouble());
        event.schedule(processInstance, newTime);
        return false;
    }
    return true;
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) NumericalDist(desmoj.core.dist.NumericalDist) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) SimpleEntry(java.util.AbstractMap.SimpleEntry) TimeUnit(java.util.concurrent.TimeUnit) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance)

Aggregations

TimeSpan (desmoj.core.simulator.TimeSpan)34 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)25 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)17 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)15 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)12 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)11 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)11 TimeUnit (java.util.concurrent.TimeUnit)11 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)10 TimeInstant (desmoj.core.simulator.TimeInstant)9 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)8 Map (java.util.Map)7 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)6 TaskTerminateEvent (de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)5 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)4 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)3 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)3 TaskType (de.hpi.bpt.scylla.model.process.node.TaskType)3 Duration (java.time.Duration)3