Skip to content

Commit

Permalink
Merge branch 'master' into maps-in-config-group
Browse files Browse the repository at this point in the history
  • Loading branch information
marecabo authored Oct 13, 2023
2 parents 1bf5062 + 68e9527 commit 11c9e5e
Show file tree
Hide file tree
Showing 333 changed files with 3,081 additions and 6,791 deletions.
3 changes: 0 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ updates:
directory: "/"
schedule:
interval: "daily"
groups:
maven:
patterns: ["*"]

- package-ecosystem: "github-actions"
directory: "/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.freight.FreightConfigGroup;
import org.matsim.contrib.freight.carrier.*;
import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize;
import org.matsim.contrib.freight.controler.FreightUtils;
import org.matsim.freight.carriers.*;
import org.matsim.freight.carriers.CarrierCapabilities.FleetSize;
import org.matsim.core.utils.geometry.CoordinateTransformation;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType;
Expand Down Expand Up @@ -236,22 +234,22 @@ public void setFixedNumberOfVehiclePerTypeAndLocation(int fixedNumberOfVehiclePe
* Reads and create the carriers with reading the information from the csv file.
*
* @param scenario
* @param freightConfigGroup
* @param freightCarriersConfigGroup
* @param csvLocationCarrier
* @param polygonsInShape
* @param defaultJspritIterations
* @param crsTransformationNetworkAndShape
* @param shapeCategory
* @throws IOException
*/
public static void readAndCreateCarrierFromCSV(Scenario scenario, FreightConfigGroup freightConfigGroup,
public static void readAndCreateCarrierFromCSV(Scenario scenario, FreightCarriersConfigGroup freightCarriersConfigGroup,
Path csvLocationCarrier, Collection<SimpleFeature> polygonsInShape, int defaultJspritIterations,
CoordinateTransformation crsTransformationNetworkAndShape, String shapeCategory) throws IOException {

Set<CarrierInformationElement> allNewCarrierInformation = readCarrierInformation(csvLocationCarrier);
checkNewCarrier(allNewCarrierInformation, freightConfigGroup, scenario, polygonsInShape, shapeCategory);
checkNewCarrier(allNewCarrierInformation, freightCarriersConfigGroup, scenario, polygonsInShape, shapeCategory);
log.info("The read carrier information from the csv are checked without errors.");
createNewCarrierAndAddVehicleTypes(scenario, allNewCarrierInformation, freightConfigGroup, polygonsInShape,
createNewCarrierAndAddVehicleTypes(scenario, allNewCarrierInformation, freightCarriersConfigGroup, polygonsInShape,
defaultJspritIterations, crsTransformationNetworkAndShape);
}

Expand Down Expand Up @@ -307,23 +305,23 @@ else if (!record.get("fleetSize").isBlank())
* Checks if the read carrier information are consistent.
*
* @param allNewCarrierInformation
* @param freightConfigGroup
* @param freightCarriersConfigGroup
* @param scenario
* @param polygonsInShape
* @param shapeCategory
*/
static void checkNewCarrier(Set<CarrierInformationElement> allNewCarrierInformation,
FreightConfigGroup freightConfigGroup, Scenario scenario, Collection<SimpleFeature> polygonsInShape, String shapeCategory) {
FreightCarriersConfigGroup freightCarriersConfigGroup, Scenario scenario, Collection<SimpleFeature> polygonsInShape, String shapeCategory) {

FreightUtils.addOrGetCarriers(scenario);
CarriersUtils.addOrGetCarriers(scenario);
for (CarrierInformationElement carrierElement : allNewCarrierInformation) {
if (FreightUtils.getCarriers(scenario).getCarriers()
if (CarriersUtils.getCarriers(scenario).getCarriers()
.containsKey(Id.create(carrierElement.getName(), Carrier.class)))
throw new RuntimeException("The Carrier " + carrierElement.getName()
+ " being loaded from the csv is already in the given Carrier file. It is not possible to add to an existing Carrier. Please check!");
CarrierVehicleTypes carrierVehicleTypes = new CarrierVehicleTypes();
new CarrierVehicleTypeReader(carrierVehicleTypes)
.readFile(freightConfigGroup.getCarriersVehicleTypesFile());
.readFile(freightCarriersConfigGroup.getCarriersVehicleTypesFile());
if (carrierElement.getVehicleTypes() != null)
for (String type : carrierElement.getVehicleTypes()) {
if (!carrierVehicleTypes.getVehicleTypes().containsKey(Id.create(type, VehicleType.class)))
Expand Down Expand Up @@ -410,20 +408,20 @@ static void checkNewCarrier(Set<CarrierInformationElement> allNewCarrierInformat
*
* @param scenario
* @param allNewCarrierInformation
* @param freightConfigGroup
* @param freightCarriersConfigGroup
* @param polygonsInShape
* @param defaultJspritIterations
* @param crsTransformationNetworkAndShape
*/
static void createNewCarrierAndAddVehicleTypes(Scenario scenario,
Set<CarrierInformationElement> allNewCarrierInformation, FreightConfigGroup freightConfigGroup,
Set<CarrierInformationElement> allNewCarrierInformation, FreightCarriersConfigGroup freightCarriersConfigGroup,
Collection<SimpleFeature> polygonsInShape, int defaultJspritIterations,
CoordinateTransformation crsTransformationNetworkAndShape) {

Carriers carriers = FreightUtils.addOrGetCarriers(scenario);
Carriers carriers = CarriersUtils.addOrGetCarriers(scenario);
CarrierVehicleTypes carrierVehicleTypes = new CarrierVehicleTypes();
CarrierVehicleTypes usedCarrierVehicleTypes = FreightUtils.getCarrierVehicleTypes(scenario);
new CarrierVehicleTypeReader(carrierVehicleTypes).readFile(freightConfigGroup.getCarriersVehicleTypesFile());
CarrierVehicleTypes usedCarrierVehicleTypes = CarriersUtils.getCarrierVehicleTypes(scenario);
new CarrierVehicleTypeReader(carrierVehicleTypes).readFile(freightCarriersConfigGroup.getCarriersVehicleTypesFile());

for (CarrierInformationElement singleNewCarrier : allNewCarrierInformation) {
if (singleNewCarrier.getVehicleTypes() == null) {
Expand All @@ -437,11 +435,11 @@ static void createNewCarrierAndAddVehicleTypes(Scenario scenario,
if (carrierCapabilities.getFleetSize() == null && singleNewCarrier.getFleetSize() != null)
carrierCapabilities.setFleetSize(singleNewCarrier.getFleetSize());
if (singleNewCarrier.getJspritIterations() > 0)
CarrierUtils.setJspritIterations(thisCarrier, singleNewCarrier.getJspritIterations());
CarriersUtils.setJspritIterations(thisCarrier, singleNewCarrier.getJspritIterations());
} else {
thisCarrier = CarrierUtils.createCarrier(Id.create(singleNewCarrier.getName(), Carrier.class));
thisCarrier = CarriersUtils.createCarrier(Id.create(singleNewCarrier.getName(), Carrier.class));
if (singleNewCarrier.getJspritIterations() > 0)
CarrierUtils.setJspritIterations(thisCarrier, singleNewCarrier.getJspritIterations());
CarriersUtils.setJspritIterations(thisCarrier, singleNewCarrier.getJspritIterations());
carrierCapabilities = CarrierCapabilities.Builder.newInstance()
.setFleetSize(singleNewCarrier.getFleetSize()).build();
carriers.addCarrier(thisCarrier);
Expand Down Expand Up @@ -497,8 +495,8 @@ static void createNewCarrierAndAddVehicleTypes(Scenario scenario,
thisCarrier.setCarrierCapabilities(carrierCapabilities);
}
for (Carrier carrier : carriers.getCarriers().values()) {
if (CarrierUtils.getJspritIterations(carrier) == Integer.MIN_VALUE) {
CarrierUtils.setJspritIterations(carrier, defaultJspritIterations);
if (CarriersUtils.getJspritIterations(carrier) == Integer.MIN_VALUE) {
CarriersUtils.setJspritIterations(carrier, defaultJspritIterations);
log.warn("The jspritIterations are now set to the default value of " + defaultJspritIterations
+ " in this simulation!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.Population;
import org.matsim.contrib.freight.carrier.*;
import org.matsim.contrib.freight.controler.FreightUtils;
import org.matsim.freight.carriers.*;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.utils.geometry.CoordinateTransformation;
import org.matsim.core.utils.geometry.geotools.MGC;
Expand Down Expand Up @@ -648,7 +647,7 @@ else if (samplingOption.equals("changeDemandOnLocation")) {
.setCapacityDemand(demandForThisLink).setServiceDuration(serviceTime)
.setServiceStartTimeWindow(newDemandInformationElement.getFirstJobElementTimeWindow())
.build();
FreightUtils.getCarriers(scenario).getCarriers()
CarriersUtils.getCarriers(scenario).getCarriers()
.get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)).getServices()
.put(thisService.getId(), thisService);
}
Expand Down Expand Up @@ -688,7 +687,7 @@ else if (samplingOption.equals("changeDemandOnLocation")) {
.setCapacityDemand(demandForThisLink).setServiceDuration(serviceTime)
.setServiceStartTimeWindow(newDemandInformationElement.getFirstJobElementTimeWindow())
.build();
FreightUtils.getCarriers(scenario).getCarriers().values().iterator().next().getServices()
CarriersUtils.getCarriers(scenario).getCarriers().values().iterator().next().getServices()
.put(thisService.getId(), thisService);
}
distributedDemand = distributedDemand + demandForThisLink;
Expand Down Expand Up @@ -740,7 +739,7 @@ else if (samplingOption.equals("changeDemandOnLocation")) {
.setCapacityDemand(demandForThisLink).setServiceDuration(serviceTime)
.setServiceStartTimeWindow(newDemandInformationElement.getFirstJobElementTimeWindow())
.build();
FreightUtils.getCarriers(scenario).getCarriers()
CarriersUtils.getCarriers(scenario).getCarriers()
.get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)).getServices()
.put(thisService.getId(), thisService);
}
Expand Down Expand Up @@ -919,7 +918,7 @@ else if (population == null)
.setPickupServiceTime(serviceTimePickup).setPickupTimeWindow(timeWindowPickup)
.setDeliveryServiceTime(serviceTimeDelivery).setDeliveryTimeWindow(timeWindowDelivery)
.build();
FreightUtils.getCarriers(scenario).getCarriers()
CarriersUtils.getCarriers(scenario).getCarriers()
.get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)).getShipments()
.put(thisShipment.getId(), thisShipment);
}
Expand Down Expand Up @@ -1021,7 +1020,7 @@ else if (numberOfPickupLocations != null) {
.setPickupServiceTime(serviceTimePickup).setPickupTimeWindow(timeWindowPickup)
.setDeliveryServiceTime(serviceTimeDelivery).setDeliveryTimeWindow(timeWindowDelivery)
.build();
FreightUtils.getCarriers(scenario).getCarriers()
CarriersUtils.getCarriers(scenario).getCarriers()
.get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class))
.getShipments().put(thisShipment.getId(), thisShipment);
}
Expand Down Expand Up @@ -1078,7 +1077,7 @@ else if (numberOfPickupLocations != null) {
.newInstance(idNewShipment, linkPickup.getId(), linkDelivery.getId(), demandForThisLink)
.setPickupServiceTime(serviceTimePickup).setPickupTimeWindow(timeWindowPickup)
.setDeliveryServiceTime(serviceTimeDelivery).setDeliveryTimeWindow(timeWindowDelivery).build();
FreightUtils.getCarriers(scenario).getCarriers()
CarriersUtils.getCarriers(scenario).getCarriers()
.get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)).getShipments()
.put(thisShipment.getId(), thisShipment);
distributedDemand = distributedDemand + demandForThisLink;
Expand All @@ -1103,21 +1102,21 @@ private static String createJobId(Scenario scenario, DemandInformationElement ne
String newJobId;
if (linkDelivery != null) {
newJobId = "Shipment_" + linkPickup + "_" + linkDelivery;
if (FreightUtils.getCarriers(scenario).getCarriers()
if (CarriersUtils.getCarriers(scenario).getCarriers()
.get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)).getShipments()
.containsKey(Id.create(newJobId, CarrierShipment.class))) {
for (int x = 1; FreightUtils.getCarriers(scenario).getCarriers()
for (int x = 1; CarriersUtils.getCarriers(scenario).getCarriers()
.get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)).getShipments()
.containsKey(Id.create(newJobId, CarrierShipment.class)); x++) {
newJobId = "Shipment_" + linkPickup + "_" + linkDelivery + "_" + x;
}
}
} else {
newJobId = "Service_" + linkPickup;
if (FreightUtils.getCarriers(scenario).getCarriers()
if (CarriersUtils.getCarriers(scenario).getCarriers()
.get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)).getServices()
.containsKey(Id.create(newJobId, CarrierShipment.class))) {
for (int x = 1; FreightUtils.getCarriers(scenario).getCarriers()
for (int x = 1; CarriersUtils.getCarriers(scenario).getCarriers()
.get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)).getServices()
.containsKey(Id.create(newJobId, CarrierShipment.class)); x++) {
newJobId = "Service_" + linkPickup + "_" + x;
Expand All @@ -1143,7 +1142,7 @@ private static void reduceNumberOfJobsIfSameCharacteristics(Scenario scenario,
if (newDemandInformationElement.getTypeOfDemand().equals("shipment")) {
HashMap<Id<CarrierShipment>, CarrierShipment> shipmentsToRemove = new HashMap<Id<CarrierShipment>, CarrierShipment>();
ArrayList<CarrierShipment> shipmentsToAdd = new ArrayList<CarrierShipment>();
Carrier thisCarrier = FreightUtils.getCarriers(scenario).getCarriers()
Carrier thisCarrier = CarriersUtils.getCarriers(scenario).getCarriers()
.get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class));
for (Id<CarrierShipment> baseShipmentId : thisCarrier.getShipments().keySet()) {
if (!shipmentsToRemove.containsKey(baseShipmentId)) {
Expand Down Expand Up @@ -1194,7 +1193,7 @@ private static void reduceNumberOfJobsIfSameCharacteristics(Scenario scenario,
if (newDemandInformationElement.getTypeOfDemand().equals("service")) {
HashMap<Id<CarrierService>, CarrierService> servicesToRemove = new HashMap<Id<CarrierService>, CarrierService>();
ArrayList<CarrierService> servicesToAdd = new ArrayList<CarrierService>();
Carrier thisCarrier = FreightUtils.getCarriers(scenario).getCarriers()
Carrier thisCarrier = CarriersUtils.getCarriers(scenario).getCarriers()
.get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class));
for (Id<CarrierService> baseServiceId : thisCarrier.getServices().keySet()) {
if (!servicesToRemove.containsKey(baseServiceId)) {
Expand Down
Loading

0 comments on commit 11c9e5e

Please sign in to comment.