Skip to content

Commit

Permalink
add fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoerl committed Nov 10, 2023
1 parent bb3f1cd commit 5aa1f73
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void install() {
protected void configureQSim() {
this.bind(DriveDischargingHandler.class).in( Singleton.class );
addMobsimScopeEventHandlerBinding().to(DriveDischargingHandler.class);
addMobsimListenerBinding().to(DriveDischargingHandler.class);
// event handlers are not qsim components

this.bind(IdleDischargingHandler.class).in( Singleton.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
package org.matsim.contrib.ev.discharging;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.events.Event;
import org.matsim.api.core.v01.events.LinkLeaveEvent;
import org.matsim.api.core.v01.events.VehicleEntersTrafficEvent;
import org.matsim.api.core.v01.events.VehicleLeavesTrafficEvent;
Expand All @@ -35,6 +38,8 @@
import org.matsim.contrib.ev.fleet.ElectricVehicle;
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.events.MobsimScopeEventHandler;
import org.matsim.core.mobsim.framework.events.MobsimAfterSimStepEvent;
import org.matsim.core.mobsim.framework.listeners.MobsimAfterSimStepListener;
import org.matsim.vehicles.Vehicle;

import com.google.inject.Inject;
Expand All @@ -45,7 +50,7 @@
* idle discharge process (see {@link IdleDischargingHandler}).
*/
public class DriveDischargingHandler
implements LinkLeaveEventHandler, VehicleEntersTrafficEventHandler, VehicleLeavesTrafficEventHandler, MobsimScopeEventHandler {
implements LinkLeaveEventHandler, VehicleEntersTrafficEventHandler, VehicleLeavesTrafficEventHandler, MobsimScopeEventHandler, MobsimAfterSimStepListener {
private static class EvDrive {
private final Id<Vehicle> vehicleId;
private final ElectricVehicle ev;
Expand All @@ -66,6 +71,7 @@ private boolean isOnFirstLink() {
private final EventsManager eventsManager;
private final Map<Id<Vehicle>, ? extends ElectricVehicle> eVehicles;
private final Map<Id<Vehicle>, EvDrive> evDrives;
private final List<Event> eventQueue = new LinkedList<>();

@Inject
DriveDischargingHandler(ElectricFleet data, Network network, EventsManager eventsManager) {
Expand Down Expand Up @@ -115,9 +121,15 @@ private EvDrive dischargeVehicle(Id<Vehicle> vehicleId, Id<Link> linkId, double
//Energy consumption may be negative on links with negative slope
ev.getBattery()
.dischargeEnergy(energy,
missingEnergy -> eventsManager.processEvent(new MissingEnergyEvent(eventTime, ev.getId(), link.getId(), missingEnergy)));
eventsManager.processEvent(new DrivingEnergyConsumptionEvent(eventTime, vehicleId, linkId, energy, ev.getBattery().getCharge()));
missingEnergy -> eventQueue.add(new MissingEnergyEvent(eventTime, ev.getId(), link.getId(), missingEnergy)));
eventQueue.add(new DrivingEnergyConsumptionEvent(eventTime, vehicleId, linkId, energy, ev.getBattery().getCharge()));
}
return evDrive;
}

@Override
public void notifyMobsimAfterSimStep(MobsimAfterSimStepEvent e) {
eventQueue.forEach(eventsManager::processEvent);
eventQueue.clear();
}
}

0 comments on commit 5aa1f73

Please sign in to comment.