From 76a5bdd0c232e173699053bd7b32030002b14548 Mon Sep 17 00:00:00 2001 From: "Dr. Steffen Axer" <26229392+steffenaxer@users.noreply.github.com> Date: Thu, 30 Nov 2023 13:35:27 +0100 Subject: [PATCH] Bugfix edrt failIfNotStarted (#2972) * Fix edrt failIfNotStarted --- .../EDrtVehicleDataEntryFactory.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/optimizer/EDrtVehicleDataEntryFactory.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/optimizer/EDrtVehicleDataEntryFactory.java index f552fb3ecae..76d84a09e32 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/optimizer/EDrtVehicleDataEntryFactory.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/optimizer/EDrtVehicleDataEntryFactory.java @@ -71,16 +71,23 @@ public VehicleEntry create(DvrpVehicle vehicle, double currentTime) { Battery battery = ((EvDvrpVehicle)vehicle).getElectricVehicle().getBattery(); int nextTaskIdx; double chargeBeforeNextTask; - if (schedule.getStatus() == ScheduleStatus.PLANNED) { - nextTaskIdx = 0; - chargeBeforeNextTask = battery.getCharge(); - } else { // STARTED - Task currentTask = schedule.getCurrentTask(); - ETaskTracker eTracker = (ETaskTracker)currentTask.getTaskTracker(); - chargeBeforeNextTask = eTracker.predictChargeAtEnd(); - nextTaskIdx = currentTask.getTaskIdx() + 1; + + switch (schedule.getStatus()) { + case PLANNED: + nextTaskIdx = 0; + chargeBeforeNextTask = battery.getCharge(); + break; + case STARTED: + Task currentTask = schedule.getCurrentTask(); + ETaskTracker eTracker = (ETaskTracker) currentTask.getTaskTracker(); + chargeBeforeNextTask = eTracker.predictChargeAtEnd(); + nextTaskIdx = currentTask.getTaskIdx() + 1; + break; + default: + return null; } + List tasks = schedule.getTasks(); for (int i = nextTaskIdx; i < tasks.size() - 1; i++) { chargeBeforeNextTask -= ((ETask)tasks.get(i)).getTotalEnergy();