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 80cc5df commit 8c5e2aa
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1189,10 +1189,11 @@ private static void combineSimilarJobs(Scenario scenario) {
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.getTo() == thisShipment.getTo()) {
if (baseShipment.getPickupStartsTimeWindow() == thisShipment.getPickupStartsTimeWindow()) {
if (baseShipment.getDeliveryStartsTimeWindow() == thisShipment.getDeliveryStartsTimeWindow()) shipmentsToConnect.put(thisShipmentId, thisShipment);
}
}
}
}
Id<CarrierShipment> idNewShipment = baseShipment.getId();
Expand All @@ -1201,16 +1202,16 @@ private static void combineSimilarJobs(Scenario scenario) {
double serviceTimeDelivery = 0;
for (CarrierShipment carrierShipment : shipmentsToConnect.values()) {
demandForThisLink = demandForThisLink + carrierShipment.getDemand();
serviceTimePickup = serviceTimePickup + carrierShipment.getPickupServiceTime();
serviceTimeDelivery = serviceTimeDelivery + carrierShipment.getDeliveryServiceTime();
serviceTimePickup = serviceTimePickup + carrierShipment.getPickupDuration();
serviceTimeDelivery = serviceTimeDelivery + carrierShipment.getDeliveryDuration();
shipmentsToRemove.put(carrierShipment.getId(), carrierShipment);
}
CarrierShipment newShipment = CarrierShipment.Builder
.newInstance(idNewShipment, baseShipment.getFrom(), baseShipment.getTo(), demandForThisLink)
.setPickupDuration(serviceTimePickup)
.setPickupStartsTimeWindow(baseShipment.getPickupTimeWindow())
.setPickupStartsTimeWindow(baseShipment.getPickupStartsTimeWindow())
.setDeliveryDuration(serviceTimeDelivery)
.setDeliveryStartsTimeWindow(baseShipment.getDeliveryTimeWindow()).build();
.setDeliveryStartsTimeWindow(baseShipment.getDeliveryStartsTimeWindow()).build();
shipmentsToAdd.add(newShipment);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ void demandCreationWithSampleWithChangeNumberOfLocations() throws IOException {
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());
Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryTimeWindow());
Assertions.assertEquals(2000, shipment.getPickupDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(1250, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON);
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());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
Expand Down Expand Up @@ -171,10 +171,10 @@ void demandCreationWithSampleWithDemandOnLocation() throws IOException {
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());
Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryTimeWindow());
Assertions.assertEquals(4000, shipment.getPickupDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(2500, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON);
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());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
Expand Down Expand Up @@ -238,10 +238,10 @@ void demandCreationWithSampleWithDemandOnLocationWithCombiningJobs() throws IOEx
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());
Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryTimeWindow());
Assertions.assertEquals(4000, shipment.getPickupDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(2500, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON);
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());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
Expand Down Expand Up @@ -308,10 +308,10 @@ void demandCreationNoSampling() throws IOException {
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());
Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryTimeWindow());
Assertions.assertEquals(4000, shipment.getPickupDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(2500, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON);
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());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
Expand Down Expand Up @@ -525,29 +525,29 @@ private static void checkCarrier1and2(Scenario scenario, Network network, ShpOpt
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());
Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getDeliveryTimeWindow());
Assertions.assertEquals(300, shipment.getPickupDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(350, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON);
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());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
} 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());
Assertions.assertEquals(TimeWindow.newInstance(20000, 40000), shipment.getDeliveryTimeWindow());
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());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
} 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());
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());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_delivery", (k) -> new HashSet<>())
Expand Down Expand Up @@ -624,19 +624,19 @@ private static void checkCarrier1and2WithCombiningJobs(Scenario scenario, Networ
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());
Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getDeliveryTimeWindow());
Assertions.assertEquals(300, shipment.getPickupDuration(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(350, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON);
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());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>())
.add(shipment.getTo().toString());
} else {
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());
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());
locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_delivery", (k) -> new HashSet<>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,17 @@ 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.getDemand()),
createTuple(START_PICKUP, getTime(s.getPickupTimeWindow().getStart())),
createTuple(END_PICKUP, getTime(s.getPickupTimeWindow().getEnd())),
createTuple(START_DELIVERY, getTime(s.getDeliveryTimeWindow().getStart())),
createTuple(END_DELIVERY, getTime(s.getDeliveryTimeWindow().getEnd())),
createTuple(PICKUP_SERVICE_TIME, getTime(s.getPickupServiceTime())),
createTuple(DELIVERY_SERVICE_TIME, getTime(s.getDeliveryServiceTime()))), closeElement, lineBreak
createTuple(START_PICKUP, getTime(s.getPickupStartsTimeWindow().getStart())),
createTuple(END_PICKUP, getTime(s.getPickupStartsTimeWindow().getEnd())),
createTuple(START_DELIVERY, getTime(s.getDeliveryStartsTimeWindow().getStart())),
createTuple(END_DELIVERY, getTime(s.getDeliveryStartsTimeWindow().getEnd())),
createTuple(PICKUP_SERVICE_TIME, getTime(s.getPickupDuration())),
createTuple(DELIVERY_SERVICE_TIME, getTime(s.getDeliveryDuration()))), closeElement, lineBreak
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,35 @@ private CarrierShipment(Builder builder) {
deliveryStartsTimeWindow = builder.deliveryStartsTimeWindow;
}

public double getPickupServiceTime() {
//* getters and setters

public double getPickupDuration() {
return pickupDuration;
}

public void setPickupServiceTime(double pickupDuration) {
this.pickupDuration = pickupDuration;
public double getDeliveryDuration() {
return deliveryDuration;
}

public double getDeliveryServiceTime() {
return deliveryDuration;
/**
* Do we really need the setter? We do have it in the builder.
* I do not see, why we should be able to update it, since most of the values are immutable.
* @deprecated Consider setting it using the Builder. This will maybe be removed and the field gets immutable..
* kturner, dec'24
*/
@Deprecated(since = "dec'24")
public void setPickupDuration(double pickupDuration) {
this.pickupDuration = pickupDuration;
}

public void setDeliveryServiceTime(double deliveryDuration) {
/**
* Do we really need the setter? We do have it in the builder.
* I do not see, why we should be able to update it, since most of the values are immutable.
* @deprecated Consider setting it using the Builder. This will maybe be removed and the field gets immutable..
* kturner, dec'24
*/
@Deprecated(since = "dec'24")
public void setDeliveryDuration(double deliveryDuration) {
this.deliveryDuration = deliveryDuration;
}

Expand All @@ -270,14 +286,6 @@ public Id<Link> getTo() {
return deliveryLinkId;
}

/**
* @deprecated please inline and use {@link #getDemand()} instead
*/
@Deprecated(since = "dec'24")
public int getSize() {
return getDemand();
}

/**
* @return the demand (size; capacity needed) of the shipment.
*/
Expand All @@ -286,11 +294,11 @@ public int getDemand() {
return demand;
}

public TimeWindow getPickupTimeWindow() {
public TimeWindow getPickupStartsTimeWindow() {
return pickupStartsTimeWindow;
}

public TimeWindow getDeliveryTimeWindow() {
public TimeWindow getDeliveryStartsTimeWindow() {
return deliveryStartsTimeWindow;
}

Expand All @@ -299,6 +307,67 @@ public Attributes getAttributes() {
return attributes;
}

//*** deprecated methods ***

/**
* @deprecated please inline and use {@link #getDemand()} instead
*/
@Deprecated(since = "dec'24")
public int getSize() {
return getDemand();
}

/**
* @deprecated please inline and use {@link #getPickupStartsTimeWindow()} instead
*/
@Deprecated(since = "dec'24")
public TimeWindow getPickupTimeWindow() {
return getPickupStartsTimeWindow();
}


/**
* @deprecated please inline and use {@link #getDeliveryStartsTimeWindow()} instead
*/
@Deprecated(since = "dec'24")
public TimeWindow getDeliveryTimeWindow() {
return getDeliveryStartsTimeWindow();
}

/**
* @deprecated please inline and use {@link #getPickupDuration()} instead
*/
@Deprecated(since = "dec'24")
public double getPickupServiceTime() {
return getPickupDuration();
}

/**
* @deprecated please inline and use {@link #setPickupDuration(double)} instead
*/
@Deprecated(since = "dec'24")
public void setPickupServiceTime(double pickupDuration) {
setPickupDuration(pickupDuration);
}

/**
* @deprecated please inline and use {@link #getDeliveryDuration()} instead
*/
@Deprecated(since = "dec'24")
public double getDeliveryServiceTime() {
return getDeliveryDuration();
}

/**
* @deprecated please inline and use {@link #setDeliveryDuration(double)} instead
*/
@Deprecated(since = "dec'24")
public void setDeliveryServiceTime(double deliveryDuration) {
setDeliveryDuration(deliveryDuration);
}

// *** general methods ***

@Override
public String toString() {
return "[id= "+ id.toString() + "][hash=" + this.hashCode() + "][from=" + pickupLinkId.toString() + "][to=" + deliveryLinkId.toString() + "][size=" + demand + "][pickupServiceTime=" + pickupDuration + "]" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public String getActivityType() {

@Override
public TimeWindow getTimeWindow() {
return shipment.getPickupTimeWindow();
return shipment.getPickupStartsTimeWindow();
}

@Override
Expand All @@ -549,7 +549,7 @@ public Id<Link> getLocation() {

@Override
public double getDuration() {
return shipment.getPickupServiceTime();
return shipment.getPickupDuration();
}

@Override
Expand Down Expand Up @@ -592,7 +592,7 @@ public Delivery(CarrierShipment shipment) {

@Override
public TimeWindow getTimeWindow() {
return shipment.getDeliveryTimeWindow();
return shipment.getDeliveryStartsTimeWindow();
}

@Override
Expand All @@ -607,7 +607,7 @@ public Id<Link> getLocation() {

@Override
public double getDuration() {
return shipment.getDeliveryServiceTime();
return shipment.getDeliveryDuration();
}

@Override
Expand Down
Loading

0 comments on commit 8c5e2aa

Please sign in to comment.