use of de.hpi.bpt.scylla.simulation.event.ResourceAvailabilityEvent in project scylla by bptlab.
the class SimulationUtils method scheduleNextResourceAvailableEvent.
/**
* Creates and schedules a DesmoJ event which represents a resource instance which returns from idle.
*
* @param model
* the simulation model
* @param resourceObject
* the resource instance returning from idle
* @param currentDateTime
* the current date time
* @param currentlyInTimetableItem
* true if the resource instance is currently active
*/
public static void scheduleNextResourceAvailableEvent(SimulationModel model, ResourceObject resourceObject, ZonedDateTime currentDateTime, boolean currentlyInTimetableItem) {
boolean showInTrace = model.traceIsOn();
TimeUnit timeUnit = DateTimeUtils.getReferenceTimeUnit();
long currentTime = DateTimeUtils.getTimeInstant(currentDateTime).getTimeRounded(timeUnit);
List<TimetableItem> timetable = resourceObject.getTimetable();
if (timetable == null) {
return;
}
int index = DateTimeUtils.getTimeTableIndexWithinOrNext(currentDateTime, timetable);
if (currentlyInTimetableItem) {
index++;
if (index == timetable.size()) {
index = 0;
}
}
TimetableItem nextTimetableItem = timetable.get(index);
DayOfWeek weekday = nextTimetableItem.getWeekdayFrom();
LocalTime time = nextTimetableItem.getBeginTime();
ZonedDateTime nextDateTime = DateTimeUtils.getNextZonedDateTime(currentDateTime, weekday, time);
long durationToNextResourceAvailableEvent = DateTimeUtils.getDuration(currentDateTime, nextDateTime);
if (model.getEndDateTime() != null) {
long endTimeRelativeToGlobalStart = DateTimeUtils.getDuration(model.getStartDateTime(), model.getEndDateTime());
if (currentTime + durationToNextResourceAvailableEvent >= endTimeRelativeToGlobalStart) {
return;
}
}
ResourceAvailabilityEvent event = new ResourceAvailabilityEvent(model, resourceObject, showInTrace);
event.schedule(new TimeSpan(durationToNextResourceAvailableEvent, timeUnit));
}
Aggregations