Skip to content

Commit

Permalink
differentiate vehicle selection for finite or infinite fleets
Browse files Browse the repository at this point in the history
  • Loading branch information
rewertvsp committed Jul 8, 2024
1 parent b0e4027 commit 1405da1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.matsim.prepare.commercial;

import org.matsim.api.core.v01.population.Person;
import org.matsim.freight.carriers.CarrierCapabilities;

import java.util.List;

public interface CommercialVehicleSelector {
String getVehicleTypeForPlan(Person freightDemandDataRelation, String carrierId);

List<String> getPossibleVehicleTypes(Person freightDemandDataRelation, String carrierId);
List<String> getPossibleVehicleTypes(Person freightDemandDataRelation, String carrierId, CarrierCapabilities.FleetSize fleetSize);

String getModeForFTLTrip(Person freightDemandDataRelation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.math3.random.RandomGenerator;
import org.apache.commons.math3.util.Pair;
import org.matsim.api.core.v01.population.Person;
import org.matsim.freight.carriers.CarrierCapabilities;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -69,28 +70,41 @@ else if (CommercialTrafficUtils.getGoodsType(freightDemandDataRelation) == 140)
}

/**
* Gets the possible vehicle types for the given carrier.
* Gets the possible vehicle types for the given carrier. If the fleet size is finite, only one vehicle type based on the distribution is returned.
* Otherwise, all possible vehicle types are returned.
* TODO perhaps add vehicleTypes file to this implementation to get the mode from the selected vehicle type
*
* @param freightDemandDataRelation the freight demand data relation
* @param carrierId the carrier id
* @param fleetSize the fleet size
* @return the possible vehicle types for this carrier
*/
@Override
public List<String> getPossibleVehicleTypes(Person freightDemandDataRelation, String carrierId) {
public List<String> getPossibleVehicleTypes(Person freightDemandDataRelation, String carrierId, CarrierCapabilities.FleetSize fleetSize) {
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());
if (fleetSize == CarrierCapabilities.FleetSize.FINITE)
allVehicleTypes.add(vehicleDistributionWaste.sample().vehicleType);
else
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());
if (fleetSize == CarrierCapabilities.FleetSize.FINITE)
allVehicleTypes.add(vehicleDistributionParcel_truck.sample().vehicleType);
else
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());

if (fleetSize == CarrierCapabilities.FleetSize.FINITE)
allVehicleTypes.add(vehicleDistributionParcel.sample().vehicleType);
else
allVehicleTypes.addAll(vehicleDistributionParcel.getPmf().stream().map(Pair::getFirst).map(VehicleSelection::vehicleType).toList());
else
if (fleetSize == CarrierCapabilities.FleetSize.FINITE)
allVehicleTypes.add(vehicleDistributionRest.sample().vehicleType);
else
allVehicleTypes.addAll(vehicleDistributionRest.getPmf().stream().map(Pair::getFirst).map(VehicleSelection::vehicleType).toList());
return allVehicleTypes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.population.Person;
import org.matsim.core.population.PopulationUtils;
import org.matsim.freight.carriers.CarrierCapabilities;

import java.util.List;

Expand Down Expand Up @@ -49,23 +50,45 @@ void testGetVehicleTypeForPlan() {

@Test
void testGetPossibleVehicleTypes() {
List<String> vehicleTypesFTL = selector.getPossibleVehicleTypes(freightDemandDataRelationFTL, "");
List<String> vehicleTypesFTL = selector.getPossibleVehicleTypes(freightDemandDataRelationFTL, "", CarrierCapabilities.FleetSize.INFINITE);
assertEquals(1, vehicleTypesFTL.size());
assertTrue(vehicleTypesFTL.contains("heavy40t"));

List<String> vehicleTypesWaste = selector.getPossibleVehicleTypes(freightDemandDataRelationWaste, "");
vehicleTypesFTL = selector.getPossibleVehicleTypes(freightDemandDataRelationFTL, "", CarrierCapabilities.FleetSize.FINITE);
assertEquals(1, vehicleTypesFTL.size());
assertTrue(vehicleTypesFTL.contains("heavy40t"));

List<String> vehicleTypesWaste = selector.getPossibleVehicleTypes(freightDemandDataRelationWaste, "", CarrierCapabilities.FleetSize.INFINITE);
assertEquals(1, vehicleTypesWaste.size());
assertTrue(vehicleTypesWaste.contains("waste_collection_diesel"));

vehicleTypesWaste = selector.getPossibleVehicleTypes(freightDemandDataRelationWaste, "", CarrierCapabilities.FleetSize.FINITE);
assertEquals(1, vehicleTypesWaste.size());
assertTrue(vehicleTypesWaste.contains("waste_collection_diesel"));

List<String> vehicleTypesParcel = selector.getPossibleVehicleTypes(freightDemandDataRelationParcel, "");
List<String> vehicleTypesParcel = selector.getPossibleVehicleTypes(freightDemandDataRelationParcel, "", CarrierCapabilities.FleetSize.INFINITE);
assertEquals(1, vehicleTypesParcel.size());
assertTrue(vehicleTypesParcel.contains("mercedes313_parcel"));

List<String> vehicleTypesParcelTruck18t = selector.getPossibleVehicleTypes(freightDemandDataRelationParcelTruck18t, "_truck18t");
vehicleTypesParcel = selector.getPossibleVehicleTypes(freightDemandDataRelationParcel, "", CarrierCapabilities.FleetSize.FINITE);
assertEquals(1, vehicleTypesParcel.size());
assertTrue(vehicleTypesParcel.contains("mercedes313_parcel"));

List<String> vehicleTypesParcelTruck18t = selector.getPossibleVehicleTypes(freightDemandDataRelationParcelTruck18t, "_truck18t",
CarrierCapabilities.FleetSize.INFINITE);
assertEquals(1, vehicleTypesParcelTruck18t.size());
assertTrue(vehicleTypesParcelTruck18t.contains("medium18t_parcel"));

vehicleTypesParcelTruck18t = selector.getPossibleVehicleTypes(freightDemandDataRelationParcelTruck18t, "_truck18t",
CarrierCapabilities.FleetSize.FINITE);
assertEquals(1, vehicleTypesParcelTruck18t.size());
assertTrue(vehicleTypesParcelTruck18t.contains("medium18t_parcel"));

List<String> vehicleTypesRest = selector.getPossibleVehicleTypes(freightDemandDataRelationRest, "");
List<String> vehicleTypesRest = selector.getPossibleVehicleTypes(freightDemandDataRelationRest, "", CarrierCapabilities.FleetSize.INFINITE);
assertEquals(1, vehicleTypesRest.size());
assertTrue(vehicleTypesRest.contains("medium18t"));

vehicleTypesRest = selector.getPossibleVehicleTypes(freightDemandDataRelationRest, "", CarrierCapabilities.FleetSize.FINITE);
assertEquals(1, vehicleTypesRest.size());
assertTrue(vehicleTypesRest.contains("medium18t"));
}
Expand Down

0 comments on commit 1405da1

Please sign in to comment.