Skip to content

Commit

Permalink
rename getters and setters to make it more consistent. old setters re…
Browse files Browse the repository at this point in the history
…main as deprecated
  • Loading branch information
kt86 committed Dec 20, 2024
1 parent 8c5e2aa commit 1eac344
Show file tree
Hide file tree
Showing 38 changed files with 185 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1188,8 +1188,8 @@ 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.getPickupLinkId() == thisShipment.getPickupLinkId()
&& baseShipment.getDeliveryLinkId() == thisShipment.getDeliveryLinkId()) {
if (baseShipment.getPickupStartsTimeWindow() == thisShipment.getPickupStartsTimeWindow()) {
if (baseShipment.getDeliveryStartsTimeWindow() == thisShipment.getDeliveryStartsTimeWindow()) shipmentsToConnect.put(thisShipmentId, thisShipment);
}
Expand All @@ -1207,7 +1207,7 @@ private static void combineSimilarJobs(Scenario scenario) {
shipmentsToRemove.put(carrierShipment.getId(), carrierShipment);
}
CarrierShipment newShipment = CarrierShipment.Builder
.newInstance(idNewShipment, baseShipment.getFrom(), baseShipment.getTo(), demandForThisLink)
.newInstance(idNewShipment, baseShipment.getPickupLinkId(), baseShipment.getDeliveryLinkId(), demandForThisLink)
.setPickupDuration(serviceTimePickup)
.setPickupStartsTimeWindow(baseShipment.getPickupStartsTimeWindow())
.setDeliveryDuration(serviceTimeDelivery)
Expand Down Expand Up @@ -1237,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 @@ -1251,7 +1251,7 @@ private static void combineSimilarJobs(Scenario scenario) {
servicesToRemove.put(carrierService.getId(), carrierService);
}
CarrierService newService = CarrierService.Builder
.newInstance(idNewService, baseService.getLocationLinkId())
.newInstance(idNewService, baseService.getServiceLinkId())
.setServiceDuration(serviceTimeService)
.setServiceStartTimeWindow(baseService.getServiceStartTimeWindow())
.setDemand(demandForThisLink).build();
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ void demandCreationWithSampleWithChangeNumberOfLocations() throws IOException {
Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupStartsTimeWindow());
Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryStartsTimeWindow());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_pickup", (k) -> new HashSet<>())
.add(shipment.getFrom().toString());
.add(shipment.getPickupLinkId().toString());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
.add(shipment.getDeliveryLinkId().toString());
}
Assertions.assertEquals(20, countDemand);
Assertions.assertEquals(4, countShipmentsWithCertainDemand.getInt(5));
Expand Down Expand Up @@ -176,9 +176,9 @@ void demandCreationWithSampleWithDemandOnLocation() throws IOException {
Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupStartsTimeWindow());
Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryStartsTimeWindow());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_pickup", (k) -> new HashSet<>())
.add(shipment.getFrom().toString());
.add(shipment.getPickupLinkId().toString());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
.add(shipment.getDeliveryLinkId().toString());
}
Assertions.assertEquals(20, countDemand);
Assertions.assertEquals(2, countShipmentsWithCertainDemand.getInt(10));
Expand Down Expand Up @@ -243,9 +243,9 @@ void demandCreationWithSampleWithDemandOnLocationWithCombiningJobs() throws IOEx
Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupStartsTimeWindow());
Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryStartsTimeWindow());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_pickup", (k) -> new HashSet<>())
.add(shipment.getFrom().toString());
.add(shipment.getPickupLinkId().toString());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
.add(shipment.getDeliveryLinkId().toString());
}
Assertions.assertEquals(20, countDemand);
Assertions.assertEquals(2, countShipmentsWithCertainDemand.getInt(10));
Expand Down Expand Up @@ -313,9 +313,9 @@ void demandCreationNoSampling() throws IOException {
Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupStartsTimeWindow());
Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryStartsTimeWindow());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_pickup", (k) -> new HashSet<>())
.add(shipment.getFrom().toString());
.add(shipment.getPickupLinkId().toString());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
.add(shipment.getDeliveryLinkId().toString());
}
Assertions.assertEquals(20, countDemand);
Assertions.assertEquals(2, countShipmentsWithCertainDemand.getInt(10));
Expand Down Expand Up @@ -480,18 +480,18 @@ private static void checkCarrier1and2(Scenario scenario, Network network, ShpOpt
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());
.add(service.getServiceLinkId().toString());
} 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());
.add(service.getServiceLinkId().toString());
} 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());
.add(service.getServiceLinkId().toString());
} else
Assertions.fail("Service has a wrong demand.");
}
Expand Down Expand Up @@ -530,28 +530,28 @@ private static void checkCarrier1and2(Scenario scenario, Network network, ShpOpt
Assertions.assertEquals(TimeWindow.newInstance(10000, 45000), shipment.getPickupStartsTimeWindow());
Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getDeliveryStartsTimeWindow());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_pickup", (k) -> new HashSet<>())
.add(shipment.getFrom().toString());
.add(shipment.getPickupLinkId().toString());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
.add(shipment.getDeliveryLinkId().toString());
} else if (shipment.getDemand() == 2) {
Assertions.assertEquals(400, shipment.getPickupDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(400, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getPickupStartsTimeWindow());
Assertions.assertEquals(TimeWindow.newInstance(20000, 40000), shipment.getDeliveryStartsTimeWindow());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_pickup", (k) -> new HashSet<>())
.add(shipment.getFrom().toString());
.add(shipment.getPickupLinkId().toString());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
.add(shipment.getDeliveryLinkId().toString());
} else {
if (shipment.getDemand() == 3) {
Assertions.assertEquals(600, shipment.getPickupDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(600, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getPickupStartsTimeWindow());
Assertions.assertEquals(TimeWindow.newInstance(20000, 40000), shipment.getDeliveryStartsTimeWindow());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_pickup", (k) -> new HashSet<>())
.add(shipment.getFrom().toString());
.add(shipment.getPickupLinkId().toString());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
.add(shipment.getDeliveryLinkId().toString());
} else
Assertions.fail("Shipment has an unexpected demand.");
}
Expand Down Expand Up @@ -589,12 +589,12 @@ private static void checkCarrier1and2WithCombiningJobs(Scenario scenario, Networ
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());
.add(service.getServiceLinkId().toString());
} else {
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());
.add(service.getServiceLinkId().toString());
}
}
Assertions.assertEquals(12, countDemand);
Expand Down Expand Up @@ -629,18 +629,18 @@ private static void checkCarrier1and2WithCombiningJobs(Scenario scenario, Networ
Assertions.assertEquals(TimeWindow.newInstance(10000, 45000), shipment.getPickupStartsTimeWindow());
Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getDeliveryStartsTimeWindow());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_pickup", (k) -> new HashSet<>())
.add(shipment.getFrom().toString());
.add(shipment.getPickupLinkId().toString());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
.add(shipment.getDeliveryLinkId().toString());
} else {
Assertions.assertEquals(shipment.getDemand() * 200, shipment.getPickupDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(shipment.getDemand() * 200, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getPickupStartsTimeWindow());
Assertions.assertEquals(TimeWindow.newInstance(20000, 40000), shipment.getDeliveryStartsTimeWindow());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_pickup", (k) -> new HashSet<>())
.add(shipment.getFrom().toString());
.add(shipment.getPickupLinkId().toString());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
.add(shipment.getDeliveryLinkId().toString());
}
}
Assertions.assertEquals(15, countDemand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,16 @@ public void startTag(String name, Attributes attributes, Stack<String> context)
case "pickup" -> {
String id = attributes.getValue(SHIPMENT_ID);
CarrierShipment s = currentShipments.get(id);
finishLeg(s.getFrom());
finishLeg(s.getPickupLinkId());
currentTourBuilder.schedulePickup(s);
previousActLoc = s.getFrom();
previousActLoc = s.getPickupLinkId();
}
case "delivery" -> {
String id = attributes.getValue(SHIPMENT_ID);
CarrierShipment s = currentShipments.get(id);
finishLeg(s.getTo());
finishLeg(s.getDeliveryLinkId());
currentTourBuilder.scheduleDelivery(s);
previousActLoc = s.getTo();
previousActLoc = s.getDeliveryLinkId();
}
case "end" -> {
finishLeg(currentVehicle.getLinkId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,26 +261,26 @@ public void startTag(String name, Attributes atts, Stack<String> context) {
String id = atts.getValue(SHIPMENT_ID);
if (id == null) throw new IllegalStateException("pickup.shipmentId is missing.");
CarrierShipment s = currentShipments.get(id);
finishLeg(s.getFrom());
finishLeg(s.getPickupLinkId());
currentTourBuilder.schedulePickup(s);
previousActLoc = s.getFrom();
previousActLoc = s.getPickupLinkId();
}
case "delivery" -> {
String id = atts.getValue(SHIPMENT_ID);
if (id == null) throw new IllegalStateException("delivery.shipmentId is missing.");
CarrierShipment s = currentShipments.get(id);
finishLeg(s.getTo());
finishLeg(s.getDeliveryLinkId());
currentTourBuilder.scheduleDelivery(s);
previousActLoc = s.getTo();
previousActLoc = s.getDeliveryLinkId();
}
case "service" -> {
String id = atts.getValue("serviceId");
if (id == null) throw new IllegalStateException("act.serviceId is missing.");
CarrierService s = serviceMap.get(Id.create(id, CarrierService.class));
if (s == null) throw new IllegalStateException("serviceId is not known.");
finishLeg(s.getLocationLinkId());
finishLeg(s.getServiceLinkId());
currentTourBuilder.scheduleService(s);
previousActLoc = s.getLocationLinkId();
previousActLoc = s.getServiceLinkId();
}
case "end" -> {
finishLeg(currentVehicle.getLinkId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,26 +263,26 @@ public void startTag(String name, Attributes atts, Stack<String> context) {
String id = atts.getValue(SHIPMENT_ID);
if (id == null) throw new IllegalStateException("pickup.shipmentId is missing.");
CarrierShipment s = currentShipments.get(id);
finishLeg(s.getFrom());
finishLeg(s.getPickupLinkId());
currentTourBuilder.schedulePickup(s);
previousActLoc = s.getFrom();
previousActLoc = s.getPickupLinkId();
}
case "delivery" -> {
String id = atts.getValue(SHIPMENT_ID);
if (id == null) throw new IllegalStateException("delivery.shipmentId is missing.");
CarrierShipment s = currentShipments.get(id);
finishLeg(s.getTo());
finishLeg(s.getDeliveryLinkId());
currentTourBuilder.scheduleDelivery(s);
previousActLoc = s.getTo();
previousActLoc = s.getDeliveryLinkId();
}
case "service" -> {
String id = atts.getValue("serviceId");
if (id == null) throw new IllegalStateException("act.serviceId is missing.");
CarrierService s = serviceMap.get(Id.create(id, CarrierService.class));
if (s == null) throw new IllegalStateException("serviceId is not known.");
finishLeg(s.getLocationLinkId());
finishLeg(s.getServiceLinkId());
currentTourBuilder.scheduleService(s);
previousActLoc = s.getLocationLinkId();
previousActLoc = s.getServiceLinkId();
}
case "end" -> {
finishLeg(currentVehicle.getLinkId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ private void writeShipments(Carrier carrier, BufferedWriter writer) {
private void writeShipment(CarrierShipment s, Id<CarrierShipment> shipmentId, boolean closeElement, boolean lineBreak) {
this.writeStartTag(SHIPMENT, List.of(
createTuple(ID, shipmentId.toString()),
createTuple(FROM, s.getFrom().toString()),
createTuple(TO, s.getTo().toString()),
createTuple(FROM, s.getPickupLinkId().toString()),
createTuple(TO, s.getDeliveryLinkId().toString()),
createTuple(SIZE, s.getDemand()),
createTuple(START_PICKUP, getTime(s.getPickupStartsTimeWindow().getStart())),
createTuple(END_PICKUP, getTime(s.getPickupStartsTimeWindow().getEnd())),
Expand Down Expand Up @@ -190,7 +190,7 @@ private void writeServices(Carrier carrier, BufferedWriter writer) {
private void writeService(CarrierService s, boolean closeElement, boolean lineBreak) {
this.writeStartTag(SERVICE, List.of(
createTuple(ID, s.getId().toString()),
createTuple(TO, s.getLocationLinkId().toString()),
createTuple(TO, s.getServiceLinkId().toString()),
createTuple(CAPACITY_DEMAND, s.getDemand()),
createTuple(EARLIEST_START, getTime(s.getServiceStartTimeWindow().getStart())),
createTuple(LATEST_END, getTime(s.getServiceStartTimeWindow().getEnd())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,18 @@ public Id<CarrierService> getId() {
return id;
}

public Id<Link> getLocationLinkId() {
public Id<Link> getServiceLinkId() {
return serviceLinkId;
}

/**
* @deprecated please inline and use {@link #getServiceLinkId()} instead
*/
@Deprecated(since = "dec'24")
public Id<Link> getLocationLinkId() {
return getServiceLinkId();
}

public double getServiceDuration() {
return serviceDuration;
}
Expand Down
Loading

0 comments on commit 1eac344

Please sign in to comment.