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);
}
}
}
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);
}
}
}
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() + ".");
}
}
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);
}
}
}
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;
}
Aggregations