Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Jul 1, 2024
2 parents c1e3a0a + 7a7a3d5 commit 380073b
Show file tree
Hide file tree
Showing 21 changed files with 802 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,24 @@
<param name="marginalUtilityOfMoney" value="1.0"/>
<!-- car prices 2012->2022: inflation (110.2-91.7)/91.7 = 0.2017448
Euro/m: 0.000124*(1+0.2017448) = 0.00014901635 -->
<!-- 6.0 -> inflation adjusted (2017->2022) -->
<param name="performing" value="6.88"/>
<!-- use value from bvwp zeitwertstudie: 4,56 -> inflation adjusted (2012->2022) -->
<param name="performing" value="5.48"/>
<parameterset type="modeParams" >
<param name="mode" value="car" />
<!-- see: https://docs.google.com/spreadsheets/d/1HzWpmmws1dBJuo-1Z0TnJ6-w4vD7eXBTUUEu68Hl9Q4/edit#gid=550988004 -->
<param name="dailyMonetaryConstant" value="-14.13" />
<!-- We use the same value as for Berlin. See: https://docs.google.com/spreadsheets/d/1HzWpmmws1dBJuo-1Z0TnJ6-w4vD7eXBTUUEu68Hl9Q4/edit#gid=550988004 -->
<param name="dailyMonetaryConstant" value="-5" />
<param name="constant" value="0.8379675427416293" />
<param name="marginalUtilityOfTraveling_util_hr" value="0.0" />
<param name="monetaryDistanceRate" value="-0.000268" />
<param name="monetaryDistanceRate" value="-0.000149" />
</parameterset>
<parameterset type="modeParams" >
<param name="mode" value="ride" />
<param name="constant" value="-2.2644332732845336" />
<!-- alpha=2, gamma=1.0 -->
<!-- (alpha+gamma)*beta_performing+(alpha+1)*car_marginalUtilityOfDistance_util_m -->
<param name="marginalUtilityOfTraveling_util_hr" value="-20.64" />
<!-- alpha*car_monetaryDistanceRate -->
<param name="monetaryDistanceRate" value="-0.00536" />
<!-- alpha=2, gamma=0.0 -->
<!-- adapted in code -->
<param name="marginalUtilityOfTraveling_util_hr" value="0" />
<!-- adapted in code -->
<param name="monetaryDistanceRate" value="0" />
</parameterset>
<parameterset type="modeParams" >
<param name="mode" value="pt" />
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/org/matsim/prepare/ConvertLinkIdsToCoords.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.matsim.prepare;

import org.matsim.api.core.v01.population.Activity;
import org.matsim.api.core.v01.population.Plan;
import org.matsim.application.MATSimAppCommand;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.population.PopulationUtils;
import picocli.CommandLine;

@CommandLine.Command(name = "convert-link-ids-to-coords")
public class ConvertLinkIdsToCoords implements MATSimAppCommand {

@CommandLine.Option(names = "--input-network", description = "Path to input network", required = true)
private String inputNetwork;

@CommandLine.Option(names = "--input-plans", description = "Path to input plans", required = true)
private String inputPlans;

@CommandLine.Option(names = "--output", description = "Path to output network", required = true)
private String output;

@Override
public Integer call() throws Exception {
var pop = PopulationUtils.readPopulation(inputPlans);
var net = NetworkUtils.readNetwork(inputNetwork);

pop.getPersons().values().stream()
.flatMap(p -> p.getPlans().stream())
.flatMap(p -> p.getPlanElements().stream())
.filter(e -> e instanceof Activity)
.forEach(e -> {
var act = (Activity) e;
if(act.getLinkId() == null) return;

var link = net.getLinks().get(act.getLinkId());
if(link == null) throw new RuntimeException("Link not found: " + act.getLinkId());
act.setCoord(link.getCoord());
act.setLinkId(null);
});

PopulationUtils.writePopulation(pop, output);

return 0;
}

public static void main(String[] args) {
new ConvertLinkIdsToCoords().execute(args);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/matsim/prepare/DeleteRoutesFromPlans.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class DeleteRoutesFromPlans {

public static void main(String[] args) throws Exception {
String[] argsForRemoveRoutesFromPlans = new String[]{
"--plans=../../shared-svn/projects/matsim-metropole-ruhr/metropole-ruhr-v1.0/input/metropole-ruhr-v1.4-3pct.plans.xml.gz",
"--output=../../shared-svn/projects/matsim-metropole-ruhr/metropole-ruhr-v1.0/input/metropole-ruhr-v1.4-3pct.plans-withoutRoutes.xml.gz",
"--plans=../../../public-svn/matsim/scenarios/countries/de/metropole-ruhr/metropole-ruhr-v2.0/input/metropole-ruhr-v2.0-3pct.plans-commercial.xml.gz",
"--output=../../../public-svn/matsim/scenarios/countries/de/metropole-ruhr/metropole-ruhr-v2.0/input/no-routes/metropole-ruhr-v2.0-3pct.plans-commercial.xml.gz",
"--remove-routes=true",
"--remove-unselected-plans=true",
"--remove-activity-location=true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.util.List;

public interface CommercialVehicleSelector {
List<String> getPossibleVehicleTypes(Person freightDemandDataRelation, String string);
String getVehicleTypeForPlan(Person freightDemandDataRelation, String carrierId);

List<String> getPossibleVehicleTypes(Person freightDemandDataRelation, String carrierId);

String getModeForFTLTrip(Person freightDemandDataRelation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,48 @@

import org.matsim.api.core.v01.population.Person;

/**
* Default implementation of the {@link CommercialServiceTimeCalculator}.
* Calculates the service time of a job at a tour for a given freight demand data relation.
*
* @Author Ricardo Ewert
*/
public class DefaultCommercialServiceTimeCalculator implements CommercialServiceTimeCalculator {
/**
* @param freightDemandDataRelation this relation data
* @param demand demand of teh good
* @return time in seconds
*/
@Override
public int calculateDeliveryTime(Person freightDemandDataRelation, int demand) {
if (CommercialTrafficUtils.getGoodsType(freightDemandDataRelation) == 150) { // parcel delivery
// assumption: for large amount of parcels a fast delivery is possible (B2B), 30min is an assumption
if (demand > 100)
return (int) (0.5 * 3600); //TODO
int timePerParcel = 180;
return (demand * timePerParcel);
}
if (CommercialTrafficUtils.getGoodsType(freightDemandDataRelation) == 140) // waste collection
return (int) ((double) demand / 11000 * 45 * 60); // assuming that the delivery time is 45 minutes (lunch break) and the vehicle is full when driving to the dump;
return (int) (0.5 * 3600); //TODO
}

/**
* @param freightDemandDataRelation this relation data
* @return time in seconds
*/
@Override
public int calculatePickupTime(Person freightDemandDataRelation, int demand) {
if (CommercialTrafficUtils.getGoodsType(freightDemandDataRelation) == 140) { // waste collection
double maxLoadPerBinInKilogramm = 110; //bin with 1100l and density 100kg/m^3
int timePerBin = 41;
return timePerBin * (int) Math.ceil(demand / maxLoadPerBinInKilogramm);
}
// assuming that the vehicle is already loaded and the driver only has to drive to the customer
return 0;
}
/**
* Calculates the delivery time of a shipment for a given freight demand data relation.
*
* @param freightDemandDataRelation this relation data
* @param demand demand of teh good
* @return time in seconds
*/
@Override
public int calculateDeliveryTime(Person freightDemandDataRelation, int demand) {
if (CommercialTrafficUtils.getGoodsType(freightDemandDataRelation) == 150) { // parcel delivery
// assumption: for large amount of parcels a fast delivery is possible (B2B), 30min is an assumption
if (demand > 100) return (int) (0.5 * 3600); //TODO perhaps find better assumption
int timePerParcel = 180;
return (demand * timePerParcel);
}
if (CommercialTrafficUtils.getGoodsType(freightDemandDataRelation) == 140) // waste collection
return (int) ((double) demand / 11000 * 45 * 60); // assuming that the delivery time is 45 minutes (lunch break) and the vehicle is full when driving to the dump;
return (int) (0.5 * 3600); //TODO perhaps find better assumption
}

/**
* Calculates the pickup time of a shipment for a given freight demand data relation.
*
* @param freightDemandDataRelation this relation data
* @return time in seconds
*/
@Override
public int calculatePickupTime(Person freightDemandDataRelation, int demand) {
if (CommercialTrafficUtils.getGoodsType(freightDemandDataRelation) == 140) { // waste collection
double maxLoadPerBinInKilogramm = 110; //bin with 1100l and density 100kg/m^3
int timePerBin = 41;
return timePerBin * (int) Math.ceil(demand / maxLoadPerBinInKilogramm);
}
// assuming that the vehicle is already loaded and the driver only has to drive to the customer
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,107 @@
package org.matsim.prepare.commercial;

import org.apache.commons.math3.distribution.EnumeratedDistribution;
import org.apache.commons.math3.random.MersenneTwister;
import org.apache.commons.math3.random.RandomGenerator;
import org.apache.commons.math3.util.Pair;
import org.matsim.api.core.v01.population.Person;

import java.util.ArrayList;
import java.util.List;

public class DefaultCommercialVehicleSelector implements CommercialVehicleSelector {
// TODO perhaps vehicleTypes to constructor to get relevant data
@Override
public List<String> getPossibleVehicleTypes(Person freightDemandDataRelation, String carrierId) {
private final RandomGenerator rnd = new MersenneTwister(4711);
EnumeratedDistribution<VehicleSelection> vehicleDistributionFTL;
EnumeratedDistribution<VehicleSelection> vehicleDistributionWaste;
EnumeratedDistribution<VehicleSelection> vehicleDistributionParcel;
EnumeratedDistribution<VehicleSelection> vehicleDistributionParcel_truck;
EnumeratedDistribution<VehicleSelection> vehicleDistributionRest;

public DefaultCommercialVehicleSelector() {
createVehicleTypeDistribution();
}

/**
* Creates the vehicle type distribution for the different transport types.
*/
private void createVehicleTypeDistribution() {
List<Pair<VehicleSelection, Double>> vehicleSelectionProbabilityDistributionFTL = new ArrayList<>();
vehicleSelectionProbabilityDistributionFTL.add(new Pair<>(new VehicleSelection("heavy40t"), 1.0));
vehicleDistributionFTL = new EnumeratedDistribution<>(rnd, vehicleSelectionProbabilityDistributionFTL);

List<Pair<VehicleSelection, Double>> vehicleSelectionProbabilityDistributionWaste = new ArrayList<>();
vehicleSelectionProbabilityDistributionWaste.add(new Pair<>(new VehicleSelection("waste_collection_diesel"), 1.0));
vehicleDistributionWaste = new EnumeratedDistribution<>(rnd, vehicleSelectionProbabilityDistributionWaste);

List<Pair<VehicleSelection, Double>> vehicleSelectionProbabilityDistributionParcel = new ArrayList<>();
vehicleSelectionProbabilityDistributionParcel.add(new Pair<>(new VehicleSelection("mercedes313_parcel"), 1.0));
vehicleDistributionParcel = new EnumeratedDistribution<>(rnd, vehicleSelectionProbabilityDistributionParcel);

List<Pair<VehicleSelection, Double>> vehicleSelectionProbabilityDistributionParcel_truck = new ArrayList<>();
vehicleSelectionProbabilityDistributionParcel_truck.add(new Pair<>(new VehicleSelection("medium18t_parcel"), 1.0));
vehicleDistributionParcel_truck = new EnumeratedDistribution<>(rnd, vehicleSelectionProbabilityDistributionParcel_truck);

List<Pair<VehicleSelection, Double>> vehicleSelectionProbabilityDistributionRest = new ArrayList<>();
vehicleSelectionProbabilityDistributionRest.add(new Pair<>(new VehicleSelection("medium18t"), 1.0));
vehicleDistributionRest = new EnumeratedDistribution<>(rnd, vehicleSelectionProbabilityDistributionRest);
}

/**
* Gets the possible vehicle type for the given freight demand data relation.
*
* @param freightDemandDataRelation the freight demand data relation
* @param carrierId the carrier id
* @return the possible vehicle type
*/
@Override
public String getVehicleTypeForPlan(Person freightDemandDataRelation, String carrierId) {

if (CommercialTrafficUtils.getTransportType(freightDemandDataRelation).equals("FTL"))
return List.of("heavy40t");
return vehicleDistributionFTL.sample().vehicleType;
else if (CommercialTrafficUtils.getGoodsType(freightDemandDataRelation) == 140) // waste collection
return List.of("waste_collection_diesel");
return vehicleDistributionWaste.sample().vehicleType;
if (CommercialTrafficUtils.getGoodsType(freightDemandDataRelation) == 150) // parcel delivery
if (carrierId.contains("_truck18t"))
return List.of("medium18t_parcel");
return vehicleDistributionParcel_truck.sample().vehicleType;
else
return List.of("mercedes313_parcel");
return List.of("medium18t");
return vehicleDistributionParcel.sample().vehicleType;
return vehicleDistributionRest.sample().vehicleType;
}

@Override
/**
* Gets the possible vehicle types for the given carrier.
*
* @param freightDemandDataRelation the freight demand data relation
* @param carrierId the carrier id
* @return the possible vehicle types for this carrier
*/
@Override
public List<String> getPossibleVehicleTypes(Person freightDemandDataRelation, String carrierId) {
List<String> allVehicleTypes = new ArrayList<>();
if (CommercialTrafficUtils.getTransportType(freightDemandDataRelation).equals("FTL"))
allVehicleTypes.addAll(vehicleDistributionFTL.getPmf().stream().map(Pair::getFirst).map(VehicleSelection::vehicleType).toList());
else if (CommercialTrafficUtils.getGoodsType(freightDemandDataRelation) == 140) // waste collection
allVehicleTypes.addAll(vehicleDistributionWaste.getPmf().stream().map(Pair::getFirst).map(VehicleSelection::vehicleType).toList());
else if (CommercialTrafficUtils.getGoodsType(freightDemandDataRelation) == 150) // parcel delivery
if (carrierId.contains("_truck18t"))
allVehicleTypes.addAll(
vehicleDistributionParcel_truck.getPmf().stream().map(Pair::getFirst).map(VehicleSelection::vehicleType).toList());
else
allVehicleTypes.addAll(vehicleDistributionParcel.getPmf().stream().map(Pair::getFirst).map(VehicleSelection::vehicleType).toList());
else allVehicleTypes.addAll(vehicleDistributionRest.getPmf().stream().map(Pair::getFirst).map(VehicleSelection::vehicleType).toList());

return allVehicleTypes;
}

@Override
public String getModeForFTLTrip(Person freightDemandDataRelation) {
// the current assumption is that all FTL trips are done by 40 tones trucks
if (CommercialTrafficUtils.getTransportType(freightDemandDataRelation).equals("FTL") || CommercialTrafficUtils.getTransportType(freightDemandDataRelation).equals(
CommercialTrafficUtils.TransportType.FTL_kv.toString()))
return "truck40t";
return null;
}

private record VehicleSelection(String vehicleType) {}

}
Loading

0 comments on commit 380073b

Please sign in to comment.