Skip to content

Commit

Permalink
Merge pull request #2888 from matsim-org/evMaintenance
Browse files Browse the repository at this point in the history
reduce public footprint of ev contrib
  • Loading branch information
kainagel authored Oct 23, 2023
2 parents be45159 + 4cbbf73 commit 5695f63
Show file tree
Hide file tree
Showing 52 changed files with 368 additions and 271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import org.matsim.contrib.dvrp.schedule.ScheduleTimingUpdater;
import org.matsim.contrib.dvrp.vrpagent.VrpAgentLogic;
import org.matsim.contrib.ev.infrastructure.ChargingInfrastructure;
import org.matsim.contrib.ev.infrastructure.ChargingInfrastructures;
import org.matsim.contrib.ev.infrastructure.ChargingInfrastructureUtils;
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.mobsim.framework.MobsimTimer;
import org.matsim.core.modal.ModalProviders;
Expand Down Expand Up @@ -95,8 +95,8 @@ protected void configureQSim() {
getter.getModal(DrtRequestInsertionRetryQueue.class)))).asEagerSingleton();

bindModal(ChargingInfrastructure.class).toProvider(modalProvider(
getter -> ChargingInfrastructures.createModalNetworkChargers(getter.get(ChargingInfrastructure.class),
getter.getModal(Network.class), getMode()))).asEagerSingleton();
getter -> ChargingInfrastructureUtils.createModalNetworkChargers(getter.get(ChargingInfrastructure.class ),
getter.getModal(Network.class), getMode() ))).asEagerSingleton();

// XXX if overridden to something else, make sure that the depots are equipped with chargers
// otherwise vehicles will not re-charge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.matsim.contrib.ev.fleet.ElectricVehicle;
import org.matsim.contrib.ev.infrastructure.Charger;
import org.matsim.contrib.ev.infrastructure.ChargingInfrastructure;
import org.matsim.contrib.ev.infrastructure.ChargingInfrastructures;
import org.matsim.contrib.ev.infrastructure.ChargingInfrastructureUtils;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.core.events.MobsimScopeEventHandler;
import org.matsim.vehicles.Vehicle;
Expand Down Expand Up @@ -73,7 +73,7 @@ public class VehicleChargingHandler
VehicleChargingHandler(ChargingInfrastructure chargingInfrastructure, ElectricFleet electricFleet) {
this.chargingInfrastructure = chargingInfrastructure;
this.electricFleet = electricFleet;
chargersAtLinks = ChargingInfrastructures.getChargersAtLinks(chargingInfrastructure);
chargersAtLinks = ChargingInfrastructureUtils.getChargersAtLinks(chargingInfrastructure );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* @author Michal Maciejewski (michalm)
*/
public class DischargingModule extends AbstractModule {
public final class DischargingModule extends AbstractModule {
@Override
public void install() {
bind(DriveEnergyConsumption.Factory.class).toInstance(ev -> new OhdeSlaskiDriveEnergyConsumption());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* calculating the drive-related energy consumption. However, the time spent on the first link is used by the time-based
* idle discharge process (see {@link IdleDischargingHandler}).
*/
public class DriveDischargingHandler
public final class DriveDischargingHandler
implements LinkLeaveEventHandler, VehicleEntersTrafficEventHandler, VehicleLeavesTrafficEventHandler, MobsimScopeEventHandler {
private static class EvDrive {
private final Id<Vehicle> vehicleId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* @author Michal Maciejewski (michalm)
*/
public class DrivingEnergyConsumptionEvent extends AbstractEnergyConsumptionEvent {
public final class DrivingEnergyConsumptionEvent extends AbstractEnergyConsumptionEvent {
public static final String EVENT_TYPE = "drivingEnergyConsumption";

public DrivingEnergyConsumptionEvent(double time, Id<Vehicle> vehicleId, Id<Link> linkId, double energy, double endCharge) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* VehicleProvider is responsible to decide if AUX discharging applies to a given vehicle based on information from
* ActivityStartEvent.
*/
public class IdleDischargingHandler
public final class IdleDischargingHandler
implements MobsimAfterSimStepListener, ActivityStartEventHandler, ActivityEndEventHandler, MobsimScopeEventHandler {
public interface VehicleProvider {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* @author Michal Maciejewski (michalm)
*/
public class IdlingEnergyConsumptionEvent extends AbstractEnergyConsumptionEvent {
public final class IdlingEnergyConsumptionEvent extends AbstractEnergyConsumptionEvent {
public static final String EVENT_TYPE = "idlingEnergyConsumption";

public IdlingEnergyConsumptionEvent(double time, Id<Vehicle> vehicleId, Id<Link> linkId, double energy, double endCharge) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import com.google.common.primitives.Doubles;

public class LTHDriveEnergyConsumption implements DriveEnergyConsumption {
public final class LTHDriveEnergyConsumption implements DriveEnergyConsumption {

private final PiecewiseBicubicSplineInterpolatingFunction function;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.matsim.api.core.v01.network.Link;
import org.matsim.vehicles.Vehicle;

public class MissingEnergyEvent extends Event {
public final class MissingEnergyEvent extends Event {
public static final String EVENT_TYPE = "missing_energy";
public static final String ATTRIBUTE_VEHICLE = "vehicle";
public static final String ATTRIBUTE_ENERGY = "energy";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.google.common.base.Preconditions;
import com.google.inject.Inject;

public class OhdeSlaskiAuxEnergyConsumption implements AuxEnergyConsumption {
public final class OhdeSlaskiAuxEnergyConsumption implements AuxEnergyConsumption {
private static final double a = 1.3;// [W]
private static final double b = -63.4;// [W]
private static final double c = 1748.1;// [W]
Expand All @@ -46,7 +46,7 @@ private static double calcPower(double temp) {

private final TemperatureService temperatureService;

public OhdeSlaskiAuxEnergyConsumption(TemperatureService temperatureService) {
OhdeSlaskiAuxEnergyConsumption(TemperatureService temperatureService) {
this.temperatureService = temperatureService;
}

Expand All @@ -59,7 +59,7 @@ public static class Factory implements AuxEnergyConsumption.Factory {
private final TemperatureService temperatureService;

@Inject
public Factory(TemperatureService temperatureService) {
Factory(TemperatureService temperatureService) {
this.temperatureService = temperatureService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* https://www.researchgate.net/profile/Michal-Maciejewski-3/publication/312393169_Statistical_analysis_of_real-world_urban_driving_cycles_for_modelling_energy_consumption_of_electric_vehicles/links/59b7a17faca2722453a5fc7f/Statistical-analysis-of-real-world-urban-driving-cycles-for-modelling-energy-consumption-of-electric-vehicles.pdf
* TODO Add (dis-)charging efficiency relative to SOC, temperature, etc...
*/
public class OhdeSlaskiDriveEnergyConsumption implements DriveEnergyConsumption {
public final class OhdeSlaskiDriveEnergyConsumption implements DriveEnergyConsumption {
private static final double g = 9.81; // g [m/s^2]
private static final double m = 1525; // vehicle mass [kg]
private static final double m_s = m + 100; // vehicle mass + extra mass [kg]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.matsim.contrib.ev.fleet.ElectricVehicle;
import org.matsim.vehicles.VehicleType;

public class VehicleTypeSpecificDriveEnergyConsumptionFactory implements DriveEnergyConsumption.Factory {
public final class VehicleTypeSpecificDriveEnergyConsumptionFactory implements DriveEnergyConsumption.Factory {

private final Map<Id<VehicleType>, DriveEnergyConsumption.Factory> consumptionMap = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ public void run( String[] args ) {
install( new EvModule() );

addRoutingModuleBinding( TransportMode.car ).toProvider(new EvNetworkRoutingProvider(TransportMode.car) );
// a router that inserts charging activities when the battery is run empty. there may be some other way to insert
// charging activities, based on the situation. kai, dec'22
// a router that inserts charging activities INTO THE ROUTE when the battery is run empty. This assumes that a full
// charge at the start of the route is not sufficient to drive the route. There are other settings where the
// situation is different, e.g. urban, where there may be a CHAIN of activities, and charging in general is done in
// parallel with some of these activities. That second situation is adressed by some "ev" code in the vsp contrib.
// kai, dec'22
}
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void run( String[] args ) {
VehicleTypeSpecificDriveEnergyConsumptionFactory driveEnergyConsumptionFactory = new VehicleTypeSpecificDriveEnergyConsumptionFactory();
var vehicleType = Id.create( "EV_65.0kWh", VehicleType.class );
driveEnergyConsumptionFactory.addEnergyConsumptionModelFactory( vehicleType,
new LTHConsumptionModelReader( vehicleType ).readURL( ConfigGroup.getInputFileURL( config.getContext(), "MidCarMap.csv" ) ) );
new LTHConsumptionModelReader().readURL( ConfigGroup.getInputFileURL( config.getContext(), "MidCarMap.csv" ) ) );

controler.addOverridingModule( new EvModule() );
controler.addOverridingModule( new AbstractModule(){
Expand All @@ -106,6 +106,7 @@ public void install(){
} );
}


controler.run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/* *********************************************************************** *
* project: org.matsim.*
* *
* *********************************************************************** *
* *
* copyright : (C) 2016 by the members listed in the COPYING, *
* LICENSE and WARRANTY file. *
* email : info at matsim dot org *
* *
* *********************************************************************** *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* See also COPYING, LICENSE and WARRANTY file *
* *
* *********************************************************************** */

package org.matsim.contrib.ev.example;
/*
* created by jbischoff, 19.03.2019
*/

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.ev.EvConfigGroup;
import org.matsim.contrib.ev.EvModule;
import org.matsim.contrib.ev.discharging.AuxEnergyConsumption;
import org.matsim.contrib.ev.discharging.DriveEnergyConsumption;
import org.matsim.contrib.ev.discharging.LTHDriveEnergyConsumption;
import org.matsim.contrib.ev.fleet.ElectricVehicle;
import org.matsim.contrib.ev.infrastructure.LTHConsumptionModelReader;
import org.matsim.contrib.ev.routing.EvNetworkRoutingProvider;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.scenario.ScenarioUtils;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

/**
* Runs a sample EV run using a vehicle consumption model designed at LTH in Lund which takes the speed and the slope of a link into account.
* Link slopes may be added using a double array on the network.
* The consumption maps are based on Domingues, Gabriel. / Modeling, Optimization and Analysis of Electromobility Systems. Lund : Department of Biomedical Engineering, Lund university, 2018. 169 p., PhD thesis
*/
public class RunEvExampleWithOwnConsumptionModel{
static final String DEFAULT_CONFIG_FILE = "test/input/org/matsim/contrib/ev/example/RunEvExample/config.xml";
private static final Logger log = LogManager.getLogger( RunEvExampleWithOwnConsumptionModel.class );

public static void main(String[] args) throws IOException {
if (args.length > 0) {
log.info("Starting simulation run with the following arguments:");
log.info("args=" + Arrays.toString( args ) );
} else {
File localConfigFile = new File(DEFAULT_CONFIG_FILE);
if (localConfigFile.exists()) {
log.info("Starting simulation run with the local example config file");
args = new String[]{ DEFAULT_CONFIG_FILE };
} else {
log.info("Starting simulation run with the example config file from GitHub repository");
args = new String[]{"https://raw.githubusercontent.com/matsim-org/matsim/master/contribs/ev/"
+ DEFAULT_CONFIG_FILE };
}
}
new RunEvExampleWithOwnConsumptionModel().run(args );
}

public void run( String[] args ) {
Config config = ConfigUtils.loadConfig(args, new EvConfigGroup());
config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);

// ===

Scenario scenario = ScenarioUtils.loadScenario(config);

// ===

Controler controler = new Controler(scenario);
{
DriveEnergyConsumption.Factory driveEnergyConsumptionFactory = new DriveEnergyConsumption.Factory(){
@Override public DriveEnergyConsumption create( ElectricVehicle electricVehicle ){
DriveEnergyConsumption.Factory factory = new LTHConsumptionModelReader().readURL( ConfigGroup.getInputFileURL( config.getContext(), "MidCarMap.csv" ) );
DriveEnergyConsumption delegate = factory.create( electricVehicle );

DriveEnergyConsumption consumption = new DriveEnergyConsumption(){
@Override public double calcEnergyConsumption( Link link, double travelTime, double linkEnterTime ){

// discharge because the link must be driven:
double delta = delegate.calcEnergyConsumption( link, travelTime, linkEnterTime );

double desiredSocAtEndOfLink = (double) electricVehicle.getVehicleSpecification().getMatsimVehicle().getAttributes().getAttribute( "whatever" );

return electricVehicle.getBattery().getSoc() - desiredSocAtEndOfLink;
// * above will often be negative; this is the purpose: discharging is negative i.e. we are
// charging on the link. ((This is why I am in general against hiding the sign in the method
// name. kai))

// * above is in SOC space, needs to be translated into kWh space

// * need to make sure that the above charging is physically possible

// * need to make sure that we are not discharging beyond what is needed to drive the link

}
};
return consumption;
}
};

controler.addOverridingModule( new EvModule() );
controler.addOverridingModule( new AbstractModule(){
@Override
public void install(){
bind( DriveEnergyConsumption.Factory.class ).toInstance( driveEnergyConsumptionFactory );
bind( AuxEnergyConsumption.Factory.class ).toInstance(
electricVehicle -> ( beginTime, duration, linkId ) -> 0 ); //a dummy factory, as aux consumption is part of the drive consumption in the model

addRoutingModuleBinding( TransportMode.car ).toProvider( new EvNetworkRoutingProvider( TransportMode.car ) );
// a router that inserts charging activities when the battery is run empty. there may be some other way to insert
// charging activities, based on the situation. kai, dec'22
}
} );
}


controler.run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;

public class BatteryImpl implements Battery {
final class BatteryDefaultImpl implements Battery {
private final double capacity;
private double charge;

public BatteryImpl(double capacity, double charge) {
BatteryDefaultImpl( double capacity, double charge ) {
this.capacity = capacity;
this.charge = charge;
}
Expand Down

This file was deleted.

Loading

0 comments on commit 5695f63

Please sign in to comment.