From af632099d05636af3274ee95ada6b962703a67f0 Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Sat, 29 Mar 2025 13:59:35 +0100 Subject: Fixed a small problem with getForeCast (#328) * Fixed a small problem with carbon forecasts that would cause problems when the simulation would leave the coverage of the carbon Trace * Fixed a small problem with carbon forecasts that would cause problems when the simulation would leave the coverage of the carbon Trace * Fixed a bug * spotless applied --- .../main/java/org/opendc/simulator/compute/power/CarbonModel.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'opendc-simulator') diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonModel.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonModel.java index 3cf36ece..e1c99071 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonModel.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonModel.java @@ -134,7 +134,11 @@ public class CarbonModel extends FlowNode { } public double[] getForecast(int forecastSize) { - return this.fragments.subList(this.fragment_index + 1, this.fragment_index + forecastSize).stream() + return this.fragments + .subList( + Math.min(this.fragment_index + 1, this.fragments.size() - 1), + Math.min(this.fragment_index + forecastSize, this.fragments.size())) + .stream() .mapToDouble(CarbonFragment::getCarbonIntensity) .toArray(); } -- cgit v1.2.3