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

Commit

Permalink
rename tuple to lspShipment, because the tuple "ShipmentWithTime" no …
Browse files Browse the repository at this point in the history
…longer exists
  • Loading branch information
kt86 committed Aug 14, 2024
1 parent 1476110 commit 9b2e27c
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,42 +74,42 @@ public void initializeValues(LSPResource resource) {

@Override
public void scheduleResource() {
for (LspShipment tupleToBeAssigned : lspShipmentsToSchedule) {
CarrierService carrierService = convertToCarrierService(tupleToBeAssigned);
for (LspShipment lspShipmentToBeAssigned : lspShipmentsToSchedule) {
CarrierService carrierService = convertToCarrierService(lspShipmentToBeAssigned);
carrier.getServices().put(carrierService.getId(), carrierService);
}
CarrierSchedulerUtils.solveVrpWithJsprit(carrier, scenario);
}

private CarrierService convertToCarrierService(LspShipment tuple) {
private CarrierService convertToCarrierService(LspShipment lspShipment) {
Id<CarrierService> serviceId =
Id.create(tuple.getId().toString(), CarrierService.class);
Id.create(lspShipment.getId().toString(), CarrierService.class);
CarrierService.Builder builder =
CarrierService.Builder.newInstance(serviceId, tuple.getFrom());
builder.setServiceStartTimeWindow(tuple.getPickupTimeWindow());
builder.setCapacityDemand(tuple.getSize());
builder.setServiceDuration(tuple.getDeliveryServiceTime());
CarrierService.Builder.newInstance(serviceId, lspShipment.getFrom());
builder.setServiceStartTimeWindow(lspShipment.getPickupTimeWindow());
builder.setCapacityDemand(lspShipment.getSize());
builder.setServiceDuration(lspShipment.getDeliveryServiceTime());
CarrierService carrierService = builder.build();
pairs.add(new LSPCarrierPair(tuple, carrierService));
pairs.add(new LSPCarrierPair(lspShipment, carrierService));
return carrierService;
}

@Override
protected void updateShipments() {
for (LspShipment tuple : lspShipmentsToSchedule) {
for (LspShipment lspShipment : lspShipmentsToSchedule) {
for (ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) {
Tour tour = scheduledTour.getTour();
for (TourElement element : tour.getTourElements()) {
if (element instanceof Tour.ServiceActivity serviceActivity) {
LSPCarrierPair carrierPair = new LSPCarrierPair(tuple, serviceActivity.getService());
LSPCarrierPair carrierPair = new LSPCarrierPair(lspShipment, serviceActivity.getService());
for (LSPCarrierPair pair : pairs) {
if (pair.tuple == carrierPair.tuple
if (pair.lspShipment == carrierPair.lspShipment
&& pair.carrierService.getId() == carrierPair.carrierService.getId()) {
addShipmentLoadElement(tuple, tour, serviceActivity);
addShipmentTransportElement(tuple, tour, serviceActivity);
addShipmentUnloadElement(tuple, tour, serviceActivity);
addCollectionTourEndEventHandler(pair.carrierService, tuple, resource, tour);
addCollectionServiceEventHandler(pair.carrierService, tuple, resource);
addShipmentLoadElement(lspShipment, tour, serviceActivity);
addShipmentTransportElement(lspShipment, tour, serviceActivity);
addShipmentUnloadElement(lspShipment, tour, serviceActivity);
addCollectionTourEndEventHandler(pair.carrierService, lspShipment, resource, tour);
addCollectionServiceEventHandler(pair.carrierService, lspShipment, resource);
}
}
}
Expand All @@ -119,47 +119,52 @@ protected void updateShipments() {
}

private void addShipmentLoadElement(
LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) {
LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) {

LspShipmentUtils.ScheduledShipmentLoadBuilder builder =
LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance();
builder.setResourceId(resource.getId());

for (LogisticChainElement element : resource.getClientElements()) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) {
builder.setLogisticChainElement(element);
}
}

int serviceIndex = tour.getTourElements().indexOf(serviceActivity);
Leg legBeforeService = (Leg) tour.getTourElements().get(serviceIndex - 1);
double startTimeOfLoading =
legBeforeService.getExpectedDepartureTime() + legBeforeService.getExpectedTransportTime();
builder.setStartTime(startTimeOfLoading);
builder.setEndTime(startTimeOfLoading + tuple.getDeliveryServiceTime());
builder.setEndTime(startTimeOfLoading + lspShipment.getDeliveryServiceTime());

LspShipmentPlanElement load = builder.build();
String idString =
load.getResourceId() + "" + load.getLogisticChainElement().getId() + load.getElementType();
Id<LspShipmentPlanElement> id = Id.create(idString, LspShipmentPlanElement.class);
LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId())
LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId())
.addPlanElement(id, load);
}

private void addShipmentTransportElement(
LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) {
LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) {

LspShipmentUtils.ScheduledShipmentTransportBuilder builder =
LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance();
builder.setResourceId(resource.getId());

for (LogisticChainElement element : resource.getClientElements()) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) {
builder.setLogisticChainElement(element);
}
}

int serviceIndex = tour.getTourElements().indexOf(serviceActivity);
Leg legAfterService = (Leg) tour.getTourElements().get(serviceIndex + 1);
double startTimeOfTransport = legAfterService.getExpectedDepartureTime();
builder.setStartTime(startTimeOfTransport);
Leg lastLeg = (Leg) tour.getTourElements().getLast();
double endTimeOfTransport =
lastLeg.getExpectedDepartureTime() + lastLeg.getExpectedTransportTime();
double endTimeOfTransport = lastLeg.getExpectedDepartureTime() + lastLeg.getExpectedTransportTime();
builder.setEndTime(endTimeOfTransport);
builder.setCarrierId(carrier.getId());
builder.setFromLinkId(serviceActivity.getLocation());
Expand All @@ -172,46 +177,48 @@ private void addShipmentTransportElement(
+ transport.getLogisticChainElement().getId()
+ transport.getElementType();
Id<LspShipmentPlanElement> id = Id.create(idString, LspShipmentPlanElement.class);
LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId())
LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId())
.addPlanElement(id, transport);
}

private void addCollectionServiceEventHandler(
CarrierService carrierService, LspShipment tuple, LSPCarrierResource resource) {
CarrierService carrierService, LspShipment lspShipment, LSPCarrierResource resource) {

for (LogisticChainElement element : this.resource.getClientElements()) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) {
CollectionServiceEndEventHandler endHandler =
new CollectionServiceEndEventHandler(
carrierService, tuple, element, resource);
tuple.addSimulationTracker(endHandler);
carrierService, lspShipment, element, resource);
lspShipment.addSimulationTracker(endHandler);
break;
}
}
}

private void addCollectionTourEndEventHandler(
CarrierService carrierService,
LspShipment tuple,
LspShipment lspShipment,
LSPCarrierResource resource,
Tour tour) {
for (LogisticChainElement element : this.resource.getClientElements()) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) {
LSPTourEndEventHandler handler =
new LSPTourEndEventHandler(
tuple, carrierService, element, resource, tour);
tuple.addSimulationTracker(handler);
lspShipment, carrierService, element, resource, tour);
lspShipment.addSimulationTracker(handler);
break;
}
}
}

private void addShipmentUnloadElement(
LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) {
LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) {

LspShipmentUtils.ScheduledShipmentUnloadBuilder builder =
LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance();
builder.setResourceId(resource.getId());
for (LogisticChainElement element : resource.getClientElements()) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) {
builder.setLogisticsChainElement(element);
}
}
Expand All @@ -227,7 +234,7 @@ private void addShipmentUnloadElement(
+ unload.getLogisticChainElement().getId()
+ unload.getElementType();
Id<LspShipmentPlanElement> id = Id.create(idString, LspShipmentPlanElement.class);
LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId())
LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId())
.addPlanElement(id, unload);
}

Expand All @@ -241,5 +248,5 @@ private double getUnloadEndTime(Tour tour) {
return unloadEndTime;
}

private record LSPCarrierPair(LspShipment tuple, CarrierService carrierService) {}
private record LSPCarrierPair(LspShipment lspShipment, CarrierService carrierService) {}
}
Loading

0 comments on commit 9b2e27c

Please sign in to comment.