Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
integrate MainRunTourStartEventHandler into centralized LSPTourStartE…
Browse files Browse the repository at this point in the history
…ventHandler
  • Loading branch information
kt86 committed Jan 12, 2024
1 parent d8f00f2 commit 6b768eb
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public class LSPTourStartEventHandler
// Todo: I have made it (temporarily) public because of junit tests :( -- need to find another way
// to do the junit testing. kmt jun'23

private final Tour tour;
private final CarrierService carrierService;
private final LogisticChainElement logisticChainElement;
private final LSPCarrierResource resource;
private final Tour tour;
private LSPShipment lspShipment;

LSPTourStartEventHandler(
public LSPTourStartEventHandler(
LSPShipment lspShipment,
CarrierService carrierService,
LogisticChainElement logisticChainElement,
Expand All @@ -95,18 +95,26 @@ public void handleEvent(CarrierTourStartEvent event) {
if (tourElement instanceof ServiceActivity serviceActivity) {
if (serviceActivity.getService().getId() == carrierService.getId()
&& event.getCarrierId() == resource.getCarrier().getId()) {
if (resource instanceof DistributionCarrierResource) {
if (resource instanceof DistributionCarrierResource) { //DistributionTourStarts
logLoad(
event.getCarrierId(),
event.getLinkId(),
event.getTime() - getCumulatedLoadingTime(tour),
event.getTime());
logTransport(
event.getCarrierId(), event.getLinkId(), tour.getEndLinkId(), event.getTime());
} // else if (resource instanceof MainRunCarrierResource) {
//....
// }

event.getCarrierId(),
event.getLinkId(), tour.getEndLinkId(),
event.getTime());
} else if (resource instanceof MainRunCarrierResource) { //MainRunTourStarts
logLoad(event.getCarrierId(),
event.getLinkId(),
event.getTime() - getCumulatedLoadingTime(tour),
event.getTime());
logTransport(event.getCarrierId(),
event.getLinkId(),
tour.getEndLinkId(),
event.getTime());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ private void addMainTourRunStartEventHandler(
Tour tour) {
for (LogisticChainElement element : this.resource.getClientElements()) {
if (element.getIncomingShipments().getShipments().contains(tuple)) {
MainRunTourStartEventHandler handler =
new MainRunTourStartEventHandler(
LSPTourStartEventHandler handler =
new LSPTourStartEventHandler(
tuple.getShipment(), carrierService, element, resource, tour);
tuple.getShipment().addSimulationTracker(handler);
break;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public void testCompletedLSPScheduling() {
assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId());
assertSame(endHandler.getResourceId(), resources.get(0).getId());

//CollectionServiceEnd
assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler);
CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1);
assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom());
Expand All @@ -518,8 +519,9 @@ public void testCompletedLSPScheduling() {
assertSame(serviceHandler.getResourceId(), planElements.get(2).getResourceId());
assertSame(serviceHandler.getResourceId(), resources.get(0).getId());

assertTrue(eventHandlers.get(2) instanceof MainRunTourStartEventHandler);
MainRunTourStartEventHandler mainRunStartHandler = (MainRunTourStartEventHandler) eventHandlers.get(2);
//MainRunStart
assertTrue(eventHandlers.get(2) instanceof LSPTourStartEventHandler);
LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2);
assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId);
assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
assertEquals(mainRunStartHandler.getCarrierService().getCapacityDemand(), shipment.getSize());
Expand All @@ -535,6 +537,7 @@ public void testCompletedLSPScheduling() {
assertSame(mainRunStartHandler.getResourceId(), planElements.get(6).getResourceId());
assertSame(mainRunStartHandler.getResourceId(), resources.get(2).getId());

//MainRunEnd
assertTrue(eventHandlers.get(3) instanceof LSPTourEndEventHandler);
LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3);
assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId);
Expand All @@ -552,6 +555,7 @@ public void testCompletedLSPScheduling() {
assertSame(mainRunEndHandler.getResourceId(), planElements.get(6).getResourceId());
assertSame(mainRunEndHandler.getResourceId(), resources.get(2).getId());

//DistributionRunStart
assertTrue(eventHandlers.get(4) instanceof LSPTourStartEventHandler);
LSPTourStartEventHandler lspTourStartEventHandler = (LSPTourStartEventHandler) eventHandlers.get(4);
assertSame(lspTourStartEventHandler.getCarrierService().getLocationLinkId(), shipment.getTo());
Expand All @@ -569,6 +573,7 @@ public void testCompletedLSPScheduling() {
assertSame(lspTourStartEventHandler.getResourceId(), planElements.get(10).getResourceId());
assertSame(lspTourStartEventHandler.getResourceId(), resources.get(4).getId());

//DistributionServiceStart
assertTrue(eventHandlers.get(5) instanceof DistributionServiceStartEventHandler);
DistributionServiceStartEventHandler distributionServiceHandler = (DistributionServiceStartEventHandler) eventHandlers.get(5);
assertSame(distributionServiceHandler.getCarrierService().getLocationLinkId(), shipment.getTo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ public void testMainRunLSPScheduling() {
assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId());
assertSame(endHandler.getResourceId(), resources.get(0).getId());

//CollectionServiceEnd
assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler);
CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1);
assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom());
Expand All @@ -382,8 +383,9 @@ public void testMainRunLSPScheduling() {
assertSame(serviceHandler.getResourceId(), planElements.get(2).getResourceId());
assertSame(serviceHandler.getResourceId(), resources.get(0).getId());

assertTrue(eventHandlers.get(2) instanceof MainRunTourStartEventHandler);
MainRunTourStartEventHandler mainRunStartHandler = (MainRunTourStartEventHandler) eventHandlers.get(2);
//MainRunTourStart
assertTrue(eventHandlers.get(2) instanceof LSPTourStartEventHandler);
LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2);
assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId);
assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
assertEquals(mainRunStartHandler.getCarrierService().getCapacityDemand(), shipment.getSize());
Expand All @@ -399,6 +401,7 @@ public void testMainRunLSPScheduling() {
assertSame(mainRunStartHandler.getResourceId(), planElements.get(6).getResourceId());
assertSame(mainRunStartHandler.getResourceId(), resources.get(2).getId());

//MainRunTourEnd
assertTrue(eventHandlers.get(3) instanceof LSPTourEndEventHandler);
LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3);
assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ public void testCompletedLSPScheduling() {
assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId());
assertSame(endHandler.getResourceId(), resources.get(0).getId());

//CollectionServiceEnd
assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler);
CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1);
assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom());
Expand All @@ -521,8 +522,9 @@ public void testCompletedLSPScheduling() {
assertSame(serviceHandler.getResourceId(), planElements.get(2).getResourceId());
assertSame(serviceHandler.getResourceId(), resources.get(0).getId());

assertTrue(eventHandlers.get(2) instanceof MainRunTourStartEventHandler);
MainRunTourStartEventHandler mainRunStartHandler = (MainRunTourStartEventHandler) eventHandlers.get(2);
//MainRunTourStart
assertTrue(eventHandlers.get(2) instanceof LSPTourStartEventHandler);
LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2);
assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId);
assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
assertEquals(mainRunStartHandler.getCarrierService().getCapacityDemand(), shipment.getSize());
Expand All @@ -538,6 +540,7 @@ public void testCompletedLSPScheduling() {
assertSame(mainRunStartHandler.getResourceId(), planElements.get(6).getResourceId());
assertSame(mainRunStartHandler.getResourceId(), resources.get(2).getId());

//MainRunTourEnd
assertTrue(eventHandlers.get(3) instanceof LSPTourEndEventHandler);
LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3);
assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId);
Expand All @@ -555,6 +558,7 @@ public void testCompletedLSPScheduling() {
assertSame(mainRunEndHandler.getResourceId(), planElements.get(6).getResourceId());
assertSame(mainRunEndHandler.getResourceId(), resources.get(2).getId());

//DistributionTourStart
assertTrue(eventHandlers.get(4) instanceof LSPTourStartEventHandler);
LSPTourStartEventHandler lspTourStartEventHandler = (LSPTourStartEventHandler) eventHandlers.get(4);
assertSame(lspTourStartEventHandler.getCarrierService().getLocationLinkId(), shipment.getTo());
Expand All @@ -572,6 +576,7 @@ public void testCompletedLSPScheduling() {
assertSame(lspTourStartEventHandler.getResourceId(), planElements.get(10).getResourceId());
assertSame(lspTourStartEventHandler.getResourceId(), resources.get(4).getId());

//DistributionServiceStart
assertTrue(eventHandlers.get(5) instanceof DistributionServiceStartEventHandler);
DistributionServiceStartEventHandler distributionServiceHandler = (DistributionServiceStartEventHandler) eventHandlers.get(5);
assertSame(distributionServiceHandler.getCarrierService().getLocationLinkId(), shipment.getTo());
Expand Down
Loading

0 comments on commit 6b768eb

Please sign in to comment.