-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into develop
- Loading branch information
Showing
21 changed files
with
802 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/org/matsim/prepare/ConvertLinkIdsToCoords.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 84 additions & 9 deletions
93
src/main/java/org/matsim/prepare/commercial/DefaultCommercialVehicleSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} | ||
|
||
} |
Oops, something went wrong.