Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freight (carrier): Rename internal variables and getter/setter to make them more consitent #3645

Merged
merged 15 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
replace getSize() and getCapacityDemand() by new method getDemand()
  • Loading branch information
kt86 committed Dec 20, 2024
commit 9e964e0c937bec769766c15c8c039545b219e166
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ private static void combineSimilarJobs(Scenario scenario) {
double serviceTimePickup = 0;
double serviceTimeDelivery = 0;
for (CarrierShipment carrierShipment : shipmentsToConnect.values()) {
demandForThisLink = demandForThisLink + carrierShipment.getSize();
demandForThisLink = demandForThisLink + carrierShipment.getDemand();
serviceTimePickup = serviceTimePickup + carrierShipment.getPickupServiceTime();
serviceTimeDelivery = serviceTimeDelivery + carrierShipment.getDeliveryServiceTime();
shipmentsToRemove.put(carrierShipment.getId(), carrierShipment);
Expand Down Expand Up @@ -1245,7 +1245,7 @@ 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ void demandCreationWithSampleWithChangeNumberOfLocations() throws IOException {
locationsPerShipmentElement = new HashMap<>();
countDemand = 0;
for (CarrierShipment shipment : testCarrier3.getShipments().values()) {
countShipmentsWithCertainDemand.merge((Integer) shipment.getSize(), 1, Integer::sum);
countDemand = countDemand + shipment.getSize();
Assertions.assertEquals(5, shipment.getSize());
countShipmentsWithCertainDemand.merge((Integer) shipment.getDemand(), 1, Integer::sum);
countDemand = countDemand + shipment.getDemand();
Assertions.assertEquals(5, shipment.getDemand());
Assertions.assertEquals(2000, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(1250, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupTimeWindow());
Expand Down Expand Up @@ -168,9 +168,9 @@ void demandCreationWithSampleWithDemandOnLocation() throws IOException {
locationsPerShipmentElement = new HashMap<>();
countDemand = 0;
for (CarrierShipment shipment : testCarrier3.getShipments().values()) {
countShipmentsWithCertainDemand.merge((Integer) shipment.getSize(), 1, Integer::sum);
countDemand = countDemand + shipment.getSize();
Assertions.assertEquals(10, shipment.getSize());
countShipmentsWithCertainDemand.merge((Integer) shipment.getDemand(), 1, Integer::sum);
countDemand = countDemand + shipment.getDemand();
Assertions.assertEquals(10, shipment.getDemand());
Assertions.assertEquals(4000, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(2500, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupTimeWindow());
Expand Down Expand Up @@ -235,9 +235,9 @@ void demandCreationWithSampleWithDemandOnLocationWithCombiningJobs() throws IOEx
locationsPerShipmentElement = new HashMap<>();
countDemand = 0;
for (CarrierShipment shipment : testCarrier3.getShipments().values()) {
countShipmentsWithCertainDemand.merge((Integer) shipment.getSize(), 1, Integer::sum);
countDemand = countDemand + shipment.getSize();
Assertions.assertEquals(10, shipment.getSize());
countShipmentsWithCertainDemand.merge((Integer) shipment.getDemand(), 1, Integer::sum);
countDemand = countDemand + shipment.getDemand();
Assertions.assertEquals(10, shipment.getDemand());
Assertions.assertEquals(4000, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(2500, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupTimeWindow());
Expand Down Expand Up @@ -305,9 +305,9 @@ void demandCreationNoSampling() throws IOException {
locationsPerShipmentElement = new HashMap<>();
countDemand = 0;
for (CarrierShipment shipment : testCarrier3.getShipments().values()) {
countShipmentsWithCertainDemand.merge((Integer) shipment.getSize(), 1, Integer::sum);
countDemand = countDemand + shipment.getSize();
Assertions.assertEquals(10, shipment.getSize());
countShipmentsWithCertainDemand.merge((Integer) shipment.getDemand(), 1, Integer::sum);
countDemand = countDemand + shipment.getDemand();
Assertions.assertEquals(10, shipment.getDemand());
Assertions.assertEquals(4000, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(2500, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupTimeWindow());
Expand Down Expand Up @@ -474,25 +474,27 @@ private static void checkCarrier1and2(Scenario scenario, Network network, ShpOpt
Map<String, Set<String>> locationsPerServiceElement = new HashMap<>();
int countDemand = 0;
for (CarrierService service : testCarrier1.getServices().values()) {
countServicesWithCertainDemand.merge((Integer) service.getCapacityDemand(), 1, Integer::sum);
countDemand = countDemand + service.getCapacityDemand();
if (service.getCapacityDemand() == 0) {
countServicesWithCertainDemand.merge((Integer) service.getDemand(), 1, Integer::sum);
countDemand = countDemand + service.getDemand();
if (service.getDemand() == 0) {
Assertions.assertEquals(180, service.getServiceDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(3000, 13000), service.getServiceStartTimeWindow());
locationsPerServiceElement.computeIfAbsent("serviceElement1", (k) -> new HashSet<>())
.add(service.getLocationLinkId().toString());
} else if (service.getCapacityDemand() == 1) {
} else if (service.getDemand() == 1) {
Assertions.assertEquals(100, service.getServiceDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(5000, 20000), service.getServiceStartTimeWindow());
locationsPerServiceElement.computeIfAbsent("serviceElement2", (k) -> new HashSet<>())
.add(service.getLocationLinkId().toString());
} else if (service.getCapacityDemand() == 2) {
Assertions.assertEquals(200, service.getServiceDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(5000, 20000), service.getServiceStartTimeWindow());
locationsPerServiceElement.computeIfAbsent("serviceElement2", (k) -> new HashSet<>())
.add(service.getLocationLinkId().toString());
} else
Assertions.fail("Service has a wrong demand.");
} else {
if (service.getDemand() == 2) {
Assertions.assertEquals(200, service.getServiceDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(5000, 20000), service.getServiceStartTimeWindow());
locationsPerServiceElement.computeIfAbsent("serviceElement2", (k) -> new HashSet<>())
.add(service.getLocationLinkId().toString());
} else
Assertions.fail("Service has a wrong demand.");
}
}
Assertions.assertEquals(12, countDemand);
Assertions.assertEquals(4, countServicesWithCertainDemand.getInt(0));
Expand Down Expand Up @@ -520,9 +522,9 @@ private static void checkCarrier1and2(Scenario scenario, Network network, ShpOpt
Map<String, Set<String>> locationsPerShipmentElement = new HashMap<>();
countDemand = 0;
for (CarrierShipment shipment : testCarrier2.getShipments().values()) {
countShipmentsWithCertainDemand.merge((Integer) shipment.getSize(), 1, Integer::sum);
countDemand = countDemand + shipment.getSize();
if (shipment.getSize() == 0) {
countShipmentsWithCertainDemand.merge((Integer) shipment.getDemand(), 1, Integer::sum);
countDemand = countDemand + shipment.getDemand();
if (shipment.getDemand() == 0) {
Assertions.assertEquals(300, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(350, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(10000, 45000), shipment.getPickupTimeWindow());
Expand All @@ -531,7 +533,7 @@ private static void checkCarrier1and2(Scenario scenario, Network network, ShpOpt
.add(shipment.getFrom().toString());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
} else if (shipment.getSize() == 2) {
} else if (shipment.getDemand() == 2) {
Assertions.assertEquals(400, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(400, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getPickupTimeWindow());
Expand All @@ -540,17 +542,19 @@ private static void checkCarrier1and2(Scenario scenario, Network network, ShpOpt
.add(shipment.getFrom().toString());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
} else if (shipment.getSize() == 3) {
Assertions.assertEquals(600, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(600, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getPickupTimeWindow());
Assertions.assertEquals(TimeWindow.newInstance(20000, 40000), shipment.getDeliveryTimeWindow());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_pickup", (k) -> new HashSet<>())
.add(shipment.getFrom().toString());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
} else
Assertions.fail("Shipment has an unexpected demand.");
} else {
if (shipment.getDemand() == 3) {
Assertions.assertEquals(600, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(600, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getPickupTimeWindow());
Assertions.assertEquals(TimeWindow.newInstance(20000, 40000), shipment.getDeliveryTimeWindow());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_pickup", (k) -> new HashSet<>())
.add(shipment.getFrom().toString());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
} else
Assertions.fail("Shipment has an unexpected demand.");
}
}
Assertions.assertEquals(15, countDemand);
Assertions.assertEquals(4, countShipmentsWithCertainDemand.getInt(0));
Expand Down Expand Up @@ -579,15 +583,15 @@ private static void checkCarrier1and2WithCombiningJobs(Scenario scenario, Networ
Map<String, Set<String>> locationsPerServiceElement = new HashMap<>();
int countDemand = 0;
for (CarrierService service : testCarrier1.getServices().values()) {
countServicesWithCertainDemand.merge((Integer) service.getCapacityDemand(), 1, Integer::sum);
countDemand = countDemand + service.getCapacityDemand();
if (service.getCapacityDemand() == 0) {
countServicesWithCertainDemand.merge((Integer) service.getDemand(), 1, Integer::sum);
countDemand = countDemand + service.getDemand();
if (service.getDemand() == 0) {
Assertions.assertEquals(180, service.getServiceDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(3000, 13000), service.getServiceStartTimeWindow());
locationsPerServiceElement.computeIfAbsent("serviceElement1", (k) -> new HashSet<>())
.add(service.getLocationLinkId().toString());
} else {
Assertions.assertEquals(service.getCapacityDemand() * 100, service.getServiceDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(service.getDemand() * 100, service.getServiceDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(5000, 20000), service.getServiceStartTimeWindow());
locationsPerServiceElement.computeIfAbsent("serviceElement2", (k) -> new HashSet<>())
.add(service.getLocationLinkId().toString());
Expand Down Expand Up @@ -617,9 +621,9 @@ private static void checkCarrier1and2WithCombiningJobs(Scenario scenario, Networ
Map<String, Set<String>> locationsPerShipmentElement = new HashMap<>();
countDemand = 0;
for (CarrierShipment shipment : testCarrier2.getShipments().values()) {
countShipmentsWithCertainDemand.merge((Integer) shipment.getSize(), 1, Integer::sum);
countDemand = countDemand + shipment.getSize();
if (shipment.getSize() == 0) {
countShipmentsWithCertainDemand.merge((Integer) shipment.getDemand(), 1, Integer::sum);
countDemand = countDemand + shipment.getDemand();
if (shipment.getDemand() == 0) {
Assertions.assertEquals(300, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(350, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(10000, 45000), shipment.getPickupTimeWindow());
Expand All @@ -629,8 +633,8 @@ private static void checkCarrier1and2WithCombiningJobs(Scenario scenario, Networ
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
} else {
Assertions.assertEquals(shipment.getSize() * 200, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(shipment.getSize() * 200, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(shipment.getDemand() * 200, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(shipment.getDemand() * 200, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getPickupTimeWindow());
Assertions.assertEquals(TimeWindow.newInstance(20000, 40000), shipment.getDeliveryTimeWindow());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_pickup", (k) -> new HashSet<>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ private void writeShipments(Carrier carrier, BufferedWriter writer) {
}

private void writeShipment(CarrierShipment s, Id<CarrierShipment> shipmentId, boolean closeElement, boolean lineBreak) {
this.writeStartTag(SHIPMENT, List.of(
this.writeStartTag(SHIPMENT, List.of(
createTuple(ID, shipmentId.toString()),
createTuple(FROM, s.getFrom().toString()),
createTuple(TO, s.getTo().toString()),
createTuple(SIZE, s.getSize()),
createTuple(SIZE, s.getDemand()),
createTuple(START_PICKUP, getTime(s.getPickupTimeWindow().getStart())),
createTuple(END_PICKUP, getTime(s.getPickupTimeWindow().getEnd())),
createTuple(START_DELIVERY, getTime(s.getDeliveryTimeWindow().getStart())),
Expand Down Expand Up @@ -191,7 +191,7 @@ private void writeService(CarrierService s, boolean closeElement, boolean lineBr
this.writeStartTag(SERVICE, List.of(
createTuple(ID, s.getId().toString()),
createTuple(TO, s.getLocationLinkId().toString()),
createTuple(CAPACITY_DEMAND, s.getCapacityDemand()),
createTuple(CAPACITY_DEMAND, s.getDemand()),
createTuple(EARLIEST_START, getTime(s.getServiceStartTimeWindow().getStart())),
createTuple(LATEST_END, getTime(s.getServiceStartTimeWindow().getEnd())),
createTuple(SERVICE_DURATION, getTime(s.getServiceDuration()))), closeElement, lineBreak
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private static void createShipmentsFromServices(Carrier carrierWS, Carrier carri
CarrierShipment carrierShipment = CarrierShipment.Builder
.newInstance(Id.create(carrierService.getId().toString(), CarrierShipment.class),
depotServiceIsDeliveredFrom.get(carrierService.getId()), carrierService.getLocationLinkId(),
carrierService.getCapacityDemand())
carrierService.getDemand())
.setDeliveryServiceTime(carrierService.getServiceDuration())
// .setPickupServiceTime(pickupServiceTime) //Not set yet, because in service we
// have now time for that. Maybe change it later, kmt sep18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ public void runAnalysisAndWriteStats(String analysisOutputDirectory) throws IOEx
int numberOfHandledDemandSize;
int notHandledJobs;
if (numberOfPlanedShipments > 0) {
numberOfPlanedDemandSize = carrier.getShipments().values().stream().mapToInt(CarrierShipment::getSize).sum();
numberOfPlanedDemandSize = carrier.getShipments().values().stream().mapToInt(carrierShipment -> carrierShipment.getDemand()).sum();
numberOfHandledDemandSize = carrier.getSelectedPlan().getScheduledTours().stream().mapToInt(
t -> t.getTour().getTourElements().stream().filter(te -> te instanceof Tour.Pickup).mapToInt(
te -> (((Tour.Pickup) te).getShipment().getSize())).sum()).sum();
te -> ((Tour.Pickup) te).getShipment().getDemand()).sum()).sum();
notHandledJobs = numberOfPlanedShipments - numberOfHandledPickups;
} else {
numberOfPlanedDemandSize = carrier.getServices().values().stream().mapToInt(CarrierService::getCapacityDemand).sum();
numberOfPlanedDemandSize = carrier.getServices().values().stream().mapToInt(carrierService -> carrierService.getDemand()).sum();
numberOfHandledDemandSize = carrier.getSelectedPlan().getScheduledTours().stream().mapToInt(
t -> t.getTour().getTourElements().stream().filter(te -> te instanceof Tour.ServiceActivity).mapToInt(
te -> ((Tour.ServiceActivity) te).getService().getCapacityDemand()).sum()).sum();
te -> ((Tour.ServiceActivity) te).getService().getDemand()).sum()).sum();
notHandledJobs = numberOfPlanedServices - nuOfServiceHandled;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CarrierServiceStartEvent(double time, Id<Carrier> carrierId, CarrierServi
super(time, carrierId, service.getLocationLinkId(), vehicleId);
this.serviceId = service.getId();
this.serviceDuration = service.getServiceDuration();
this.capacityDemand = service.getCapacityDemand();
this.capacityDemand = service.getDemand();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CarrierShipmentDeliveryEndEvent(double time, Id<Carrier> carrierId, Carri
super(time, carrierId, shipment.getTo(), vehicleId);
this.shipmentId = shipment.getId();
this.deliveryDuration = shipment.getDeliveryServiceTime();
this.capacityDemand = shipment.getSize();
this.capacityDemand = shipment.getDemand();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public CarrierShipmentDeliveryStartEvent(double time, Id<Carrier> carrierId, Car
super(time, carrierId, shipment.getTo(), vehicleId);
this.shipmentId = shipment.getId();
this.deliveryDuration = shipment.getDeliveryServiceTime();
this.capacityDemand = shipment.getSize();
this.capacityDemand = shipment.getDemand();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public CarrierShipmentPickupEndEvent(double time, Id<Carrier> carrierId, Carrier
super(time, carrierId, shipment.getFrom(), vehicleId);
this.shipmentId = shipment.getId();
this.pickupDuration = shipment.getPickupServiceTime();
this.capacityDemand = shipment.getSize();
this.capacityDemand = shipment.getDemand();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CarrierShipmentPickupStartEvent(double time, Id<Carrier> carrierId, Carri
super(time, carrierId, shipment.getFrom(), vehicleId);
this.shipmentId = shipment.getId();
this.pickupDuration = shipment.getPickupServiceTime();
this.capacityDemand = shipment.getSize();
this.capacityDemand = shipment.getDemand();
}


Expand Down
Loading