Skip to content

Commit

Permalink
Merge pull request #3645 from matsim-org/3509-rename-things-in-carrie…
Browse files Browse the repository at this point in the history
…rJobs

Freight (carrier): Rename internal variables and getter/setter to make them more consitent
  • Loading branch information
kt86 authored Dec 20, 2024
2 parents ca2af6b + 9e65b09 commit 1691f8a
Show file tree
Hide file tree
Showing 53 changed files with 839 additions and 604 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ else if (samplingOption.equals("changeNumberOfLocationsWithDemand")) {
createJobId(scenario, newDemandInformationElement, link.getId(), null),
CarrierService.class);
CarrierService thisService = CarrierService.Builder.newInstance(idNewService, link.getId())
.setCapacityDemand(demandForThisLink).setServiceDuration(serviceTime)
.setDemand(demandForThisLink).setServiceDuration(serviceTime)
.setServiceStartTimeWindow(newDemandInformationElement.getFirstJobElementTimeWindow())
.build();
CarriersUtils.getCarriers(scenario).getCarriers()
Expand Down Expand Up @@ -696,7 +696,7 @@ else if (samplingOption.equals("changeNumberOfLocationsWithDemand")) {
CarrierService.class);
if (demandToDistribute > 0 && singleDemandForThisLink > 0) {
CarrierService thisService = CarrierService.Builder.newInstance(idNewService, link.getId())
.setCapacityDemand(singleDemandForThisLink).setServiceDuration(serviceTime)
.setDemand(singleDemandForThisLink).setServiceDuration(serviceTime)
.setServiceStartTimeWindow(newDemandInformationElement.getFirstJobElementTimeWindow())
.build();
thisCarrier.getServices().put(thisService.getId(), thisService);
Expand Down Expand Up @@ -747,7 +747,7 @@ else if (samplingOption.equals("changeNumberOfLocationsWithDemand")) {
createJobId(scenario, newDemandInformationElement, link.getId(), null), CarrierService.class);
if ((demandToDistribute > 0 && singleDemandForThisLink > 0) || demandToDistribute == 0) {
CarrierService thisService = CarrierService.Builder.newInstance(idNewService, link.getId())
.setCapacityDemand(singleDemandForThisLink).setServiceDuration(serviceTime)
.setDemand(singleDemandForThisLink).setServiceDuration(serviceTime)
.setServiceStartTimeWindow(newDemandInformationElement.getFirstJobElementTimeWindow())
.build();
CarriersUtils.getCarriers(scenario).getCarriers()
Expand Down Expand Up @@ -1051,8 +1051,8 @@ private static void createSingleShipment(Scenario scenario, DemandInformationEle

CarrierShipment thisShipment = CarrierShipment.Builder
.newInstance(idNewShipment, linkPickup.getId(), linkDelivery.getId(), singleDemandForThisLink)
.setPickupServiceTime(serviceTimePickup).setPickupTimeWindow(timeWindowPickup)
.setDeliveryServiceTime(serviceTimeDelivery).setDeliveryTimeWindow(timeWindowDelivery)
.setPickupDuration(serviceTimePickup).setPickupStartsTimeWindow(timeWindowPickup)
.setDeliveryDuration(serviceTimeDelivery).setDeliveryStartsTimeWindow(timeWindowDelivery)
.build();
thisCarrier.getShipments().put(thisShipment.getId(), thisShipment);
if (demandForThisLink == 0)
Expand Down Expand Up @@ -1188,29 +1188,30 @@ private static void combineSimilarJobs(Scenario scenario) {
if (!shipmentsToRemove.containsKey(thisShipmentId)) {
CarrierShipment thisShipment = thisCarrier.getShipments().get(thisShipmentId);
if (baseShipment.getId() != thisShipment.getId()
&& baseShipment.getFrom() == thisShipment.getFrom()
&& baseShipment.getTo() == thisShipment.getTo()
&& baseShipment.getPickupTimeWindow() == thisShipment.getPickupTimeWindow()
&& baseShipment.getDeliveryTimeWindow() == thisShipment.getDeliveryTimeWindow())
shipmentsToConnect.put(thisShipmentId, thisShipment);
&& baseShipment.getPickupLinkId() == thisShipment.getPickupLinkId()
&& baseShipment.getDeliveryLinkId() == thisShipment.getDeliveryLinkId()) {
if (baseShipment.getPickupStartsTimeWindow() == thisShipment.getPickupStartsTimeWindow()) {
if (baseShipment.getDeliveryStartsTimeWindow() == thisShipment.getDeliveryStartsTimeWindow()) shipmentsToConnect.put(thisShipmentId, thisShipment);
}
}
}
}
Id<CarrierShipment> idNewShipment = baseShipment.getId();
int demandForThisLink = 0;
double serviceTimePickup = 0;
double serviceTimeDelivery = 0;
for (CarrierShipment carrierShipment : shipmentsToConnect.values()) {
demandForThisLink = demandForThisLink + carrierShipment.getSize();
serviceTimePickup = serviceTimePickup + carrierShipment.getPickupServiceTime();
serviceTimeDelivery = serviceTimeDelivery + carrierShipment.getDeliveryServiceTime();
demandForThisLink = demandForThisLink + carrierShipment.getDemand();
serviceTimePickup = serviceTimePickup + carrierShipment.getPickupDuration();
serviceTimeDelivery = serviceTimeDelivery + carrierShipment.getDeliveryDuration();
shipmentsToRemove.put(carrierShipment.getId(), carrierShipment);
}
CarrierShipment newShipment = CarrierShipment.Builder
.newInstance(idNewShipment, baseShipment.getFrom(), baseShipment.getTo(), demandForThisLink)
.setPickupServiceTime(serviceTimePickup)
.setPickupTimeWindow(baseShipment.getPickupTimeWindow())
.setDeliveryServiceTime(serviceTimeDelivery)
.setDeliveryTimeWindow(baseShipment.getDeliveryTimeWindow()).build();
.newInstance(idNewShipment, baseShipment.getPickupLinkId(), baseShipment.getDeliveryLinkId(), demandForThisLink)
.setPickupDuration(serviceTimePickup)
.setPickupStartsTimeWindow(baseShipment.getPickupStartsTimeWindow())
.setDeliveryDuration(serviceTimeDelivery)
.setDeliveryStartsTimeWindow(baseShipment.getDeliveryStartsTimeWindow()).build();
shipmentsToAdd.add(newShipment);
}
}
Expand All @@ -1236,7 +1237,7 @@ private static void combineSimilarJobs(Scenario scenario) {
if (!servicesToRemove.containsKey(thisServiceId)) {
CarrierService thisService = thisCarrier.getServices().get(thisServiceId);
if (baseService.getId() != thisService.getId()
&& baseService.getLocationLinkId() == thisService.getLocationLinkId() && baseService
&& baseService.getServiceLinkId() == thisService.getServiceLinkId() && baseService
.getServiceStartTimeWindow() == thisService.getServiceStartTimeWindow())
servicesToConnect.put(thisServiceId, thisService);
}
Expand All @@ -1245,15 +1246,15 @@ private static void combineSimilarJobs(Scenario scenario) {
int demandForThisLink = 0;
double serviceTimeService = 0;
for (CarrierService carrierService : servicesToConnect.values()) {
demandForThisLink = demandForThisLink + carrierService.getCapacityDemand();
demandForThisLink = demandForThisLink + carrierService.getDemand();
serviceTimeService = serviceTimeService + carrierService.getServiceDuration();
servicesToRemove.put(carrierService.getId(), carrierService);
}
CarrierService newService = CarrierService.Builder
.newInstance(idNewService, baseService.getLocationLinkId())
.newInstance(idNewService, baseService.getServiceLinkId())
.setServiceDuration(serviceTimeService)
.setServiceStartTimeWindow(baseService.getServiceStartTimeWindow())
.setCapacityDemand(demandForThisLink).build();
.setDemand(demandForThisLink).build();
servicesToAdd.add(newService);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,23 @@ static void createDemandLocationsFile(Controler controler) {
for (Carrier thisCarrier : CarriersUtils.getCarriers(controler.getScenario()).getCarriers().values()) {
for (CarrierService thisService : thisCarrier.getServices().values()) {
Coord coord = FreightDemandGenerationUtils
.getCoordOfMiddlePointOfLink(network.getLinks().get(thisService.getLocationLinkId()));
.getCoordOfMiddlePointOfLink(network.getLinks().get(thisService.getServiceLinkId()));
writer.write(thisCarrier.getId().toString() + thisService.getId().toString() + " " + coord.getX()
+ " " + coord.getY() + " " + "Service" + " "
+ thisService.getLocationLinkId().toString() + " " + "\n");
+ thisService.getServiceLinkId().toString() + " " + "\n");
}
for (CarrierShipment thisShipment : thisCarrier.getShipments().values()) {
Coord coordFrom = FreightDemandGenerationUtils
.getCoordOfMiddlePointOfLink(network.getLinks().get(thisShipment.getFrom()));
.getCoordOfMiddlePointOfLink(network.getLinks().get(thisShipment.getPickupLinkId()));
Coord coordTo = FreightDemandGenerationUtils
.getCoordOfMiddlePointOfLink(network.getLinks().get(thisShipment.getTo()));
.getCoordOfMiddlePointOfLink(network.getLinks().get(thisShipment.getDeliveryLinkId()));

writer.write(thisCarrier.getId().toString() + thisShipment.getId().toString() + " "
+ coordFrom.getX() + " " + coordFrom.getY() + " " + "Pickup" + " "
+ thisShipment.getFrom().toString() + " " + thisShipment.getTo().toString() + "\n");
+ thisShipment.getPickupLinkId().toString() + " " + thisShipment.getDeliveryLinkId().toString() + "\n");
writer.write(thisCarrier.getId().toString() + thisShipment.getId() + " "
+ coordTo.getX() + " " + coordTo.getY() + " " + "Delivery" + " "
+ thisShipment.getFrom() + " " + thisShipment.getTo() + "\n");
+ thisShipment.getPickupLinkId() + " " + thisShipment.getDeliveryLinkId() + "\n");
}
}
writer.flush();
Expand Down
Loading

0 comments on commit 1691f8a

Please sign in to comment.