Skip to content

Commit

Permalink
more forward
Browse files Browse the repository at this point in the history
  • Loading branch information
kt86 committed Oct 11, 2024
1 parent 1ea559b commit a087058
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,23 +233,23 @@ protected void updateShipments() {
if (Objects.equals(lspShipment.getId().toString(), serviceActivity.getService().getId().toString())) {
addShipmentLoadElement(lspShipment, tour);
addShipmentTransportElement(lspShipment, tour, serviceActivity);
addShipmentUnloadElement(lspShipment, tour, serviceActivity);
addDistributionTourStartEventHandler(serviceActivity.getService(), lspShipment, resource, tour);
addDistributionServiceEventHandler(serviceActivity.getService(), lspShipment, resource);
addShipmentUnloadElement(lspShipment, serviceActivity);
addDistributionTourStartEventHandler(serviceActivity, lspShipment, resource, tour);
addDistributionServiceEventHandler(serviceActivity, lspShipment, resource);
}
}
}
}
case shipmentBased -> {
//TODO needs fixture
//TODO needs to get fixed. KMT'Aug'24
for (TourElement element : tour.getTourElements()) {
if (element instanceof Tour.Delivery deliveryActivity) {
if (Objects.equals(lspShipment.getId().toString(), deliveryActivity.getShipment().getId().toString())) {
addShipmentLoadElement(lspShipment, tour);
addShipmentTransportElement(lspShipment, tour, deliveryActivity);
addShipmentUnloadElement(lspShipment, tour, deliveryActivity);
addDistributionTourStartEventHandler(deliveryActivity.getShipment(), lspShipment, resource, tour);
addDistributionServiceEventHandler(deliveryActivity.getShipment(), lspShipment, resource);
addShipmentUnloadElement(lspShipment, deliveryActivity);
addDistributionTourStartEventHandler(deliveryActivity, lspShipment, resource, tour);
addDistributionServiceEventHandler(deliveryActivity, lspShipment, resource);
}
}
}
Expand Down Expand Up @@ -344,8 +344,7 @@ private void addShipmentTransportElement(
.addPlanElement(id, transport);
}

private void addShipmentUnloadElement(
LspShipment tuple, Tour tour, Tour.TourActivity tourActivity) {
private void addShipmentUnloadElement(LspShipment tuple, Tour.TourActivity tourActivity) {

LspShipmentUtils.ScheduledShipmentUnloadBuilder builder =
LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance();
Expand Down Expand Up @@ -430,66 +429,53 @@ private Carrier createAuxiliaryCarrier(ArrayList<LspShipment> shipmentsInCurrent
}

private void addDistributionServiceEventHandler(
CarrierService carrierService,
Tour.TourActivity tourActivity,
LspShipment lspShipment,
LSPCarrierResource resource) {

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

//TODO: Kann man das wieder zusammenfassen mitt der Methode fpr die Services?
private void addDistributionServiceEventHandler(
CarrierShipment carrierShipment,
LspShipment lspShipment,
LSPCarrierResource resource) {
DistributionServiceStartEventHandler handler;
switch (tourActivity) {
case Tour.ServiceActivity serviceActivity-> {
handler = new DistributionServiceStartEventHandler(serviceActivity.getService(), lspShipment, element, resource, null);
}
case Tour.ShipmentBasedActivity shipmentBasedActivity-> {
handler = new DistributionServiceStartEventHandler(null, lspShipment, element, resource, shipmentBasedActivity.getShipment());
}
default -> throw new IllegalStateException("Unexpected value: " + tourActivity);
}

for (LogisticChainElement element : this.resource.getClientElements()) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) {
DistributionServiceStartEventHandler handler =
new DistributionServiceStartEventHandler(null, lspShipment, element, resource, carrierShipment);
lspShipment.addSimulationTracker(handler);
break;
}
}
}

private void addDistributionTourStartEventHandler(
CarrierService carrierService,
Tour.TourActivity tourActivity,
LspShipment lspShipment,
LSPCarrierResource resource,
Tour tour) {

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

private void addDistributionTourStartEventHandler(
CarrierShipment carrierShipment,
LspShipment lspShipment,
LSPCarrierResource resource,
Tour tour) {
LSPTourStartEventHandler handler;
switch (tourActivity) {
case Tour.ServiceActivity serviceActivity-> {
handler = new LSPTourStartEventHandler(lspShipment, serviceActivity.getService(), element, resource, tour, null);
}
case Tour.ShipmentBasedActivity shipmentBasedActivity-> {
handler = new LSPTourStartEventHandler(lspShipment, null , element, resource, tour, shipmentBasedActivity.getShipment());
}
default -> throw new IllegalStateException("Unexpected value: " + tourActivity);
}

for (LogisticChainElement element : this.resource.getClientElements()) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) {
LSPTourStartEventHandler handler =
new LSPTourStartEventHandler(lspShipment, null, element, resource, tour); //FIXME: Hier müsste eigentlich das CarrierShipment übergeben werden in anaolger Logic zu Services... arghhh.
lspShipment.addSimulationTracker(handler);
break;
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
CarrierService carrierService,
LspShipment lspShipment,
LogisticChainElement element,
LSPCarrierResource resource, CarrierShipment carrierShipment) {
LSPCarrierResource resource,
CarrierShipment carrierShipment) {
this.carrierShipment = carrierShipment;
this.carrierService = carrierService;
this.lspShipment = lspShipment;
Expand Down Expand Up @@ -96,7 +97,7 @@ private void logTransport(CarrierServiceStartEvent event) {
}
}

//TODO: Inahltlich ansehen, was hier passiert. Ist aktuell nur Copy und Paste aus Service-Variante
//TODO: Inhaltlich ansehen, was hier passiert. Ist aktuell nur Copy und Paste aus Service-Variante
private void logTransport(CarrierShipmentDeliveryStartEvent event) {
String idString = resource.getId() + "" + logisticChainElement.getId() + "TRANSPORT";
Id<LspShipmentPlanElement> id = Id.create(idString, LspShipmentPlanElement.class);
Expand Down Expand Up @@ -126,7 +127,7 @@ private void logUnload(CarrierServiceStartEvent event) {
lspShipment.getShipmentLog().addPlanElement(unloadId, unload);
}

//TODO: Inahltlich ansehen, was hier passiert. Ist aktuell nur Copy und Paste aus Service-Variante
//TODO: Inhaltlich ansehen, was hier passiert. Ist aktuell nur Copy und Paste aus Service-Variante
private void logUnload(CarrierShipmentDeliveryStartEvent event) {
LspShipmentUtils.LoggedShipmentUnloadBuilder builder =
LspShipmentUtils.LoggedShipmentUnloadBuilder.newInstance();
Expand All @@ -146,6 +147,8 @@ private void logUnload(CarrierShipmentDeliveryStartEvent event) {
lspShipment.getShipmentLog().addPlanElement(unloadId, unload);
}

//Todo: Wird das auch inhaltlich irgendwo genutzt,oder ist das nur für die Tests da?
//todo ctd. Brauchen wir den CarrierService hier eigentlich wirklich oder kann das zurück gebaut werden? KMT Okt'24
public CarrierService getCarrierService() {
return carrierService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.matsim.api.core.v01.network.Link;
import org.matsim.freight.carriers.Carrier;
import org.matsim.freight.carriers.CarrierService;
import org.matsim.freight.carriers.CarrierShipment;
import org.matsim.freight.carriers.Tour;
import org.matsim.freight.carriers.Tour.ServiceActivity;
import org.matsim.freight.carriers.Tour.TourElement;
Expand All @@ -44,6 +45,7 @@

private final Tour tour;
private final CarrierService carrierService;
private final CarrierShipment carrierShipment;
private final LogisticChainElement logisticChainElement;
private final LSPCarrierResource resource;
private LspShipment lspShipment;
Expand All @@ -53,9 +55,12 @@ public LSPTourStartEventHandler(
CarrierService carrierService,
LogisticChainElement logisticChainElement,
LSPCarrierResource resource,
Tour tour) {
Tour tour,
CarrierShipment carrierShipment)
{
this.lspShipment = lspShipment;
this.carrierService = carrierService;
this.carrierShipment = carrierShipment;
this.logisticChainElement = logisticChainElement;
this.resource = resource;
this.tour = tour;
Expand All @@ -68,6 +73,7 @@ public void reset(int iteration) {

@Override
public void handleEvent(CarrierTourStartEvent event) {
//Todo: Ablauf für CarrierShipment einbauen. Das fehlt aktuell noch.
if (event.getTourId().equals(tour.getId())) {
for (TourElement tourElement : tour.getTourElements()) {
if (tourElement instanceof ServiceActivity serviceActivity) {
Expand Down Expand Up @@ -99,8 +105,7 @@ public void handleEvent(CarrierTourStartEvent event) {
}
}

private void logLoad(Id<Carrier> carrierId, Id<Link> linkId,
double startTime, double endTime) {
private void logLoad(Id<Carrier> carrierId, Id<Link> linkId, double startTime, double endTime) {
LspShipmentUtils.LoggedShipmentLoadBuilder builder =
LspShipmentUtils.LoggedShipmentLoadBuilder.newInstance();
builder.setCarrierId(carrierId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private void addMainTourRunStartEventHandler(
for (LogisticChainElement element : this.resource.getClientElements()) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) {
LSPTourStartEventHandler handler =
new LSPTourStartEventHandler(lspShipment, carrierService, element, resource, tour);
new LSPTourStartEventHandler(lspShipment, carrierService, element, resource, tour, null);
lspShipment.addSimulationTracker(handler);
break;
}
Expand Down

0 comments on commit a087058

Please sign in to comment.