@@ -89,7 +89,7 @@ public boolean hasVehicle(Id<Vehicle> vehicleId) {
8989 public void onVehicleLeavesPartition (DistributedMobsimVehicle vehicle , int toPartition ) {
9090 if (electricVehicles .containsKey (vehicle .getId ())) {
9191 var ev = electricVehicles .remove (vehicle .getId ());
92- partitionTransfer .collect (new ElectricVehicleMessage (ev .getVehicleSpecification (), ev .getBattery ()), toPartition );
92+ partitionTransfer .collect (new ElectricVehicleMessage (ev .getId (), ev .getBattery (). getCharge ()), toPartition );
9393 }
9494 }
9595
@@ -107,16 +107,19 @@ private void handleMessages(List<Message> messages, double now) {
107107 for (var m : messages ) {
108108 // SAFETY: we have only registered ElectricVehicleMessage.class as the message type to receive.
109109 ElectricVehicleMessage evMessage = (ElectricVehicleMessage ) m ;
110- var id = evMessage .spec . getMatsimVehicle (). getId () ;
110+ var id = evMessage .vehicleId ;
111111
112112 if (electricVehicles .containsKey (id )) {
113113 throw new IllegalStateException ("Received ElectricVehicleMessage for vehicle " + id + ". We already have" +
114114 " this vehicle in the fleet. This indicates, that some component has queried the fleet for this vehicle, even though no corresponding" +
115115 " MobsimVehicle is present on this partition. This is most probably a programming bug." );
116116 }
117- // TODO When recreating the vehicle some attributes from the engine information are looked up. I guess we can send those in the message
118- // directly.
119- var ev = ElectricFleetUtils .create (evMessage .spec (), driveEnergyConsumptionFactory , auxEnergyConsumptionFactory , chargingPowerFactory );
117+
118+ var vehicle = scenarioVehicles .getVehicles ().get (id );
119+ var spec = new ElectricVehicleSpecificationDefaultImpl (vehicle );
120+ var ev = ElectricFleetUtils .create (spec , driveEnergyConsumptionFactory , auxEnergyConsumptionFactory , chargingPowerFactory );
121+ ev .getBattery ().setCharge (evMessage .charge );
122+
120123 electricVehicles .put (ev .getId (), ev );
121124 }
122125 }
@@ -134,5 +137,5 @@ private boolean isElectricVehicle(String hbefaTechnology) {
134137 /**
135138 * The state of the ev actually is the specification and the battery, which contains the charging state.
136139 */
137- public record ElectricVehicleMessage (ElectricVehicleSpecification spec , Battery battery ) implements Message {}
140+ public record ElectricVehicleMessage (Id < Vehicle > vehicleId , double charge ) implements Message {}
138141}
0 commit comments