Skip to main content

Stochastic simulation report

These scripts, written in Groovy, are executed at the end of a stochastic simulation (even if executed by a Script)

The script must extend .report and must be saved in the simulation directory.

The script's structure is very simple on purpose: the variable stochasticTimetables is a single-use iterable, in other words, the method .iterator() can be called at most once. Therefore, also the method each or other extension methods of iterable have the same limitation. Thanks to this it is possible to iterate over the simulated timetable of each run, without the need to load them into the memory, and thus they perform well in results aggregation.

The outputFile method takes as an argument a file name and returns a File with the same name present in the destination directory (normally it's the directory of the simulation output)

The method csvPrinter takes as an argument a file name and returns a CSVPrinter

def data = [:].withDefault{[]}

stochasticTimetables.each { stochasticTimetable ->
stochasticTimetable.actualCourses.each { actualCourse ->
def key = [ actualCourse.bundle.folder, actualCourse.bundle.name ]
def delayAtDestination = actualCourse.delayAtDestination ?: 0;
data[key] << delayAtDestination
}
}

try (def printer = csvPrinter('BundlesSummary.csv')) {
printer.printRecord("Folder", "Bundle", "Count", "P5", "Mean delay");

data.each { key, values ->
int count = values.size()
int p5 = 100.0 * values.count { it < 5*60 } / values.size()
int meanDelay = values.sum() / values.size()
printer.printRecord(key[0], key[1], count, p5, meanDelay)
}
}

Usage in combination with Scripted simulation

The params variable is initialized only if the script is being executed in a Scripted simulation context and contains the parameters used to construct the simulation, if present. See the usage of withTimetableTransformations, withParameter, withParameters e runScenario in Scripted simulation.