Skip to content

Commit

Permalink
adds method to calculate variable vehicle costs based on energy prices
Browse files Browse the repository at this point in the history
  • Loading branch information
rewertvsp committed May 10, 2024
1 parent b6e8a35 commit 8dc924b
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/main/java/org/matsim/vsp/freight/food/RunFood.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import org.matsim.freight.carriers.analysis.RunFreightAnalysisEventBased;
import org.matsim.freight.carriers.controler.CarrierModule;
import org.matsim.freight.carriers.controler.CarrierScoringFunctionFactory;
import org.matsim.vehicles.EngineInformation;
import org.matsim.vehicles.VehicleUtils;
import picocli.CommandLine;

import java.nio.file.Path;
Expand Down Expand Up @@ -73,16 +75,37 @@ class RunFood implements MATSimAppCommand {
@CommandLine.Option(names = "--useDistanceConstraint", description = "Use distance constraint for tour planning.")
private static boolean useDistanceConstraint;

@CommandLine.Option(names = "--calculateVariableConsumptionCosts", description = "Recalculate variable costs based on the given.")
private static boolean calculateVariableConsumptionCosts;

@CommandLine.Option(names = "--fuelCosts_EUR_per_l", description = "Fuel costs in EUR per liter.", required = true, defaultValue = "1.23") //TODO check: vwlich oder gewerbl.??
private static double fuelCosts_EUR_per_l;

@CommandLine.Option(names = "--energyCosts_EUR_per_kWh", description = "Energy costs in EUR per kWh.", required = true, defaultValue = "0.2216") //TODO check: vwlich oder gewerbl.??
private static double energyCosts_EUR_per_kWh;

public static void main(String[] args) {
System.exit(new CommandLine(new RunFood()).execute(args));
}

@Override
public Integer call() throws Exception {

// calculateVariableConsumptionCosts = true;

Config config = prepareConfig();
Scenario scenario = prepareScenario(config);

if (calculateVariableConsumptionCosts) {
log.warn("We assume that the variable costs in the vehicleTypes don't contain fuel and energy costs.");
log.warn("Recalculating variable costs based on the given fuel and energy costs.");
log.warn("Fuel costs: {} EUR per liter.", fuelCosts_EUR_per_l);
log.warn("Energy costs: {} EUR per kWh.", energyCosts_EUR_per_kWh);
calculateVariableConsumptionCosts(scenario, fuelCosts_EUR_per_l, energyCosts_EUR_per_kWh);
outputLocation = outputLocation + "_fuel" + fuelCosts_EUR_per_l + "_energy" + energyCosts_EUR_per_kWh + "/";
config.controller().setOutputDirectory(outputLocation);
}

Controler controler = prepareControler(scenario);

CarriersUtils.runJsprit(scenario);
Expand All @@ -99,6 +122,36 @@ public Integer call() throws Exception {
return 0;
}

/**
* Recalculates the variable costs based on the given fuel and energy costs.
* Assumes that the variable costs in the vehicleTypes don't contain fuel and energy costs.
*
* @param scenario the scenario
* @param fuelCostsEurPerL fuel costs in EUR per liter
* @param energyCostsEurPerKWh energy costs in EUR per kWh
*/
private void calculateVariableConsumptionCosts(Scenario scenario, double fuelCostsEurPerL, double energyCostsEurPerKWh) {
CarriersUtils.getCarrierVehicleTypes(scenario).getVehicleTypes().values().forEach(vehicleType -> {
EngineInformation engineInformation = vehicleType.getEngineInformation();
String engineType = VehicleUtils.getHbefaTechnology(engineInformation);
double basicVariableCostsPerMeter = vehicleType.getCostInformation().getCostsPerMeter(); // existing variable costs based on Kostensätze file
double energieCostsPerMeter;
if (engineType.equals("electricity")){
double energyConsumptionKWhPerMeter = VehicleUtils.getEnergyConsumptionKWhPerMeter(engineInformation);
energieCostsPerMeter = energyConsumptionKWhPerMeter * energyCostsEurPerKWh;

} else if (engineType.equals("diesel")) {
double fuelConsumptionLitersPerMeter = VehicleUtils.getFuelConsumption(vehicleType);
energieCostsPerMeter = fuelConsumptionLitersPerMeter * fuelCostsEurPerL;

} else
throw new IllegalArgumentException("EngineType not supported: " + engineType);

double newVariableCosts = basicVariableCostsPerMeter + energieCostsPerMeter;
vehicleType.getCostInformation().setCostsPerMeter(newVariableCosts);
});
}


private static Config prepareConfig() {
// String algorithmFileLocation = args[2]; //TODO: Read in Algorithm -> Put into freightCarriersConfigGroup?
Expand Down

0 comments on commit 8dc924b

Please sign in to comment.