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

Create hub handling events #103

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c24e2d6
Add Abstract Logistics Event
kt86 Dec 16, 2022
f303f56
more infrastructure for logistic events
kt86 Dec 16, 2022
8a360cf
towards a handling in hub has started event
kt86 Dec 16, 2022
2945804
towards a handling in hub has ended event
kt86 Dec 16, 2022
fe03e46
Merge remote-tracking branch 'origin/main' into kmt_create_HubHandlin…
kt86 Dec 19, 2022
89a2293
Update MATSim version and fix one issue: Attributes is an interface s…
kt86 Dec 21, 2022
788cb54
WIP: small step forward for throwing hub events
kt86 Dec 21, 2022
4705106
eventsManager needed for the hub...
kt86 Dec 21, 2022
6e369df
new method for asserting EventFiles are equal.
kt86 Dec 20, 2022
23c083a
update MATSim version
kt86 Dec 21, 2022
16b4d2e
Merge remote-tracking branch 'origin/main' into kmt_create_HubHandlin…
kt86 Dec 21, 2022
c16fb18
Merge remote-tracking branch 'origin/main' into kmt_create_HubHandlin…
kt86 Dec 28, 2022
62a1d69
Merge remote-tracking branch 'origin/main' into kmt_create_HubHandlin…
kt86 May 9, 2023
a2cb192
try with injection
kt86 May 10, 2023
21b2d3f
chained builder and some reorganization
kt86 May 10, 2023
503ed3d
cleanup and documentation
kt86 May 22, 2023
99c47e5
Merge remote-tracking branch 'origin/main' into kmt_create_HubHandlin…
kt86 May 22, 2023
fb3b060
move creation of events to own creator class
kt86 May 23, 2023
a3ffb4e
add LogisticsEventCreatorUtils
kt86 May 23, 2023
25075d0
typos
kt86 May 23, 2023
c59539d
dead end
kainagel May 24, 2023
5aca1a1
try to generate log output (does not work even with simple example). …
kainagel May 24, 2023
81d6682
renaming of LogisticEvents* -> LspEvents*
kt86 May 24, 2023
2b8a025
HubEvents are thrown, BUT issues with chronological order of event-st…
kt86 May 26, 2023
895607f
comment by kn
kt86 Jun 28, 2023
fa884f9
Merge remote-tracking branch 'origin/main' into kmt_create_HubHandlin…
kt86 Jun 29, 2023
bd254ef
fix errors after merging
kt86 Jun 29, 2023
348ff3f
cleanup
kt86 Jun 29, 2023
bbec6e3
cleanup
kt86 Jun 29, 2023
ea39b92
Merge remote-tracking branch 'origin/main' into kmt_create_HubHandlin…
kt86 Jul 21, 2023
566b558
remove hub handling end events. We will not track this. Some date wil…
kt86 Jul 21, 2023
ff6ee6a
start adding expected handling duration
kt86 Jul 22, 2023
d140322
delete a class; make several classes non-public; a comment
kainagel Jul 27, 2023
f2e4ad5
Merge remote-tracking branch 'origin/main' into kmt_create_HubHandlin…
kt86 Sep 25, 2023
a0118f0
cleanup: remove unused method
kt86 Sep 25, 2023
caa4727
Merge remote-tracking branch 'origin/main' into kmt_create_HubHandlin…
kt86 Sep 26, 2023
eda6c35
Update test inputs: The contain hubHandling events now.
kt86 Nov 13, 2023
117aea1
Do registration as simulationTracker only once.
kt86 Nov 13, 2023
68e4d2b
rename a test
kt86 Nov 13, 2023
1da2d99
logHub also after collection run
kt86 Nov 13, 2023
e6bca2f
set buffer time to 0 (hard coded) and remove setter method
kt86 Nov 13, 2023
5fd5b31
try to ensure order of SimTracker. Still WIP
kt86 Nov 14, 2023
e0603b8
Merge remote-tracking branch 'origin/main' into kmt_create_HubHandlin…
kt86 Nov 14, 2023
6b2b1ca
add missing test input.
kt86 Nov 15, 2023
7787373
fix dir name
kt86 Nov 15, 2023
d5ca42e
Merge remote-tracking branch 'origin/main' into kmt_create_HubHandlin…
kt86 Nov 15, 2023
7823346
towards centralizing the LSP(Events)Tracker/Handler
kainagel Nov 15, 2023
9010209
Merge remote-tracking branch 'origin/main' into kmt_create_HubHandlin…
kt86 Nov 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*/
private final ArrayList<ResourceNeighbours> neighbourList;
private LSP lsp;
private int bufferTime;
private int bufferTime = 0;

ForwardLogisticChainSchedulerImpl() {
this.sortedResourceList = new ArrayList<>();
Expand Down Expand Up @@ -147,11 +147,6 @@ private LogisticChainElement getFirstElement(LogisticChain solution) {
return null;
}

@Override
public void setBufferTime(int bufferTime) {
this.bufferTime = bufferTime;
}

/**
* The relationship between different {@link LSPResource}s allows to handle various supply
* structures that the {@link LSP} might decide to maintain. Thus, a {@link LSPResource} can have several
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/org/matsim/freight/logistics/HasLspShipmentId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* *********************************************************************** *
* project: org.matsim.* *
* *
* *********************************************************************** *
* *
* copyright : (C) 2008 by the members listed in the COPYING, *
* LICENSE and WARRANTY file. *
* email : info at matsim dot org *
* *
* *********************************************************************** *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* See also COPYING, LICENSE and WARRANTY file *
* *
* *********************************************************************** */
package org.matsim.freight.logistics;


import org.matsim.api.core.v01.Id;
import org.matsim.freight.logistics.shipment.LSPShipment;

/**
* @author Kai Martins-Turner (kturner)
*/
public interface HasLspShipmentId {

String ATTRIBUTE_LSP_SHIPMENT_ID = "lspShipmentId";
Id<LSPShipment> getLspShipmentId();

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ public void notifyBeforeMobsim(BeforeMobsimEvent event) {
for (LSP lsp : lsps.getLSPs().values()) {
((LSPImpl) lsp).setScorer( lspScoringFunctionFactory.createScoringFunction() );


// simulation trackers of lsp:
registerSimulationTrackers(lsp );

// simulation trackers of resources:
for (LSPResource resource : lsp.getResources()) {
registerSimulationTrackers(resource);
}

// simulation trackers of shipments:
for (LSPShipment shipment : lsp.getShipments()) {
registerSimulationTrackers(shipment );
Expand All @@ -94,15 +100,16 @@ public void notifyBeforeMobsim(BeforeMobsimEvent event) {
}
}

private void registerSimulationTrackers( HasSimulationTrackers<?> lsp ) {
private void registerSimulationTrackers( HasSimulationTrackers<?> hasSimulationTrackers) {
// get all simulation trackers ...
for (LSPSimulationTracker<?> simulationTracker : lsp.getSimulationTrackers()) {
for (LSPSimulationTracker<?> simulationTracker : hasSimulationTrackers.getSimulationTrackers()) {
// ... register them ...
if (!registeredHandlers.contains(simulationTracker)) {
log.warn("adding eventsHandler: " + simulationTracker);
eventsManager.addHandler(simulationTracker);
registeredHandlers.add(simulationTracker);
matsimServices.addControlerListener(simulationTracker);
simulationTracker.setEventsManager( eventsManager );
} else {
log.warn("not adding eventsHandler since already added: " + simulationTracker);
}
Expand Down Expand Up @@ -181,4 +188,5 @@ public void notifyShutdown(ShutdownEvent event) {
new LSPPlanXmlWriter(LSPUtils.getLSPs(scenario)).write(controlerIO.getOutputPath() + "/output_lsps.xml.gz");
new CarrierPlanWriter(CarriersUtils.getCarriers(scenario)).write(controlerIO.getOutputPath() + "/output_carriers.xml.gz");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

public class LSPDataObject<T> implements HasSimulationTrackers<T>, Attributable, Identifiable<T> {

private final Collection<LSPSimulationTracker<T>> trackers = new ArrayList<>();
private final Collection<LSPSimulationTracker<T>> trackers = new LinkedList<>();
private final Attributes attributes = new AttributesImpl();
private final Id<T> id;

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/matsim/freight/logistics/LSPModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public void install() {
bind( CarrierAgentTracker.class ).in( Singleton.class );
addEventHandlerBinding().to( CarrierAgentTracker.class );

// Multibinder<FreightEventCreator> freightEventCreatorMultibinder = Multibinder.newSetBinder( this.binder(), FreightEventCreator.class );
// for( FreightEventCreator freightEventCreator : FreightEventCreatorUtils.getStandardEventCreators() ){
// freightEventCreatorMultibinder.addBinding().toInstance( freightEventCreator );
// }
//
// Multibinder<LspEventCreator> logisticEventCreatorMultibinder = Multibinder.newSetBinder( this.binder(), LspEventCreator.class );
// for( LspEventCreator logisticEventCreator : LspEventCreatorUtils.getStandardEventCreators() ){
// logisticEventCreatorMultibinder.addBinding().toInstance( logisticEventCreator );
// }

// this switches on certain qsim components:
QSimComponentsConfigGroup qsimComponents = ConfigUtils.addOrGetModule(getConfig(), QSimComponentsConfigGroup.class);
List<String> abc = qsimComponents.getActiveComponents();
Expand Down
78 changes: 0 additions & 78 deletions src/main/java/org/matsim/freight/logistics/LSPRescheduler.java
Original file line number Diff line number Diff line change
@@ -1,78 +0,0 @@
/*
* *********************************************************************** *
* * project: org.matsim.*
* * *********************************************************************** *
* * *
* * copyright : (C) 2022 by the members listed in the COPYING, *
* * LICENSE and WARRANTY file. *
* * email : info at matsim dot org *
* * *
* * *********************************************************************** *
* * *
* * This program is free software; you can redistribute it and/or modify *
* * it under the terms of the GNU General Public License as published by *
* * the Free Software Foundation; either version 2 of the License, or *
* * (at your option) any later version. *
* * See also COPYING, LICENSE and WARRANTY file *
* * *
* * ***********************************************************************
*/

package org.matsim.freight.logistics;

/**
* There is a possibility and also sometimes a need for rescheduling before each
* new iteration. This need results from changes to the plan of the LSP during
* the re-planning process. There, changes of the structure and/or number of the
* active LogisticsSolutions or to the assignment of the LSPShipments to the
* LogisticsSolutions can happen. Consequently, the transport operations that
* result from this change in behavior of the corresponding LSP will also change
* and thus the preparation of the simulation has to be redone.
* <p>
* The rescheduling process is triggered in the BeforeMobsimEvent of the following iteration which has
* a LSPRescheduler as one of its listeners.
* <p>
* In this case, all LogisticsSolutions,
* LogisticsSolutionElements and Resources are cleared of all shipments that
* were assigned to them in the previous iteration in order to allow a new assignment.
* <p>
* Then, all LSPShipments of each LSP are assigned to the corresponding
* LogisticsSolutions by the Assigner of the LSP in order to account for possible
* changes in the LogisticsSolutions as well as in the assignment itself due to
* the re-planning that took place before. After this assignment is done, the actual
* scheduling takes place. In cases, where no re-planning takes place (further details of
* the re-planning algorithm follow in 3.8), rescheduling will nevertheless take place.
* This is reasonable for example in cases where also other traffic takes place on the
* network, for example passenger traffic, and the network conditions change between
* subsequent iterations of the simulation due to congestion.
* <p>
* ---
* Let's do it in re-planning.
* If doing so, we have the time to handle the result (on Carrier level) in the beforeMobsim step of the CarrierControlerListener.
* kmt sep'22
*/
final class LSPRescheduler {
private LSPRescheduler() {
}

// static void notifyReplanning(LSPs lsps, ReplanningEvent event) {
// if (event.getIteration() != 0) {
// for (LSP lsp : lsps.getLSPs().values()) {
// for (LogisticChain solution : lsp.getSelectedPlan().getLogisticChains()) {
// solution.getShipmentIds().clear();
// for (LogisticChainElement element : solution.getLogisticChainElements()) {
// element.getIncomingShipments().clear();
// element.getOutgoingShipments().clear();
// }
// }
//
// for (LSPShipment shipment : lsp.getShipments()) {
// ShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId()).clear();
// shipment.getShipmentLog().clear();
// lsp.getSelectedPlan().getAssigner().assignToPlan(shipment);
// }
// lsp.scheduleLogisticChains();
// }
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

package org.matsim.freight.logistics;

import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.controler.listener.ControlerListener;
import org.matsim.core.events.handler.EventHandler;

public interface LSPSimulationTracker<T> extends ControlerListener, EventHandler, HasBackpointer<T> {
// In general, we set backpointers when we add to the container. So specifically, we set the backpointer to which the tracker points when the tracker is added.
default void setEventsManager( EventsManager eventsManager ){};
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ public interface LogisticChainScheduler extends HasBackpointer<LSP> {

void scheduleLogisticChain();

void setBufferTime(int bufferTime);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.matsim.freight.logistics.events;

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.events.Event;
import org.matsim.api.core.v01.events.HasLinkId;
import org.matsim.api.core.v01.network.Link;
import org.matsim.freight.logistics.HasLspShipmentId;
import org.matsim.freight.logistics.shipment.LSPShipment;

import java.util.Map;

import static org.matsim.freight.logistics.HasLspShipmentId.ATTRIBUTE_LSP_SHIPMENT_ID;

/**
* A general logistic event contains the information (= {@link Id}) of the
* - the location (= {@link Link})
* - the lspShipment (= {@link LSPShipment})
* belonging to it.
* <p>
* Please note, that general _freight_ events can be found in the freight contrib.
*
* @author Kai Martins-Turner (kturner)
*/
public abstract class AbstractLspEvent extends Event implements HasLinkId, HasLspShipmentId {

private final Id<Link> linkId;
private final Id<LSPShipment> lspShipmentId;

public AbstractLspEvent(double time, Id<Link> linkId, Id<LSPShipment> lspShipmentId) {
super(time);
this.linkId = linkId;
this.lspShipmentId = lspShipmentId;
}

/**
* @return id of the {@link LSPShipment}
*/
@Override public final Id<LSPShipment> getLspShipmentId() {
return lspShipmentId;
}

@Override public final Id<Link> getLinkId() {
return linkId;
}

/**
* Adds the {@link Id<LSPShipment>} to the list of attributes.
* {@link Id<Link>} is handled by superclass {@link Event}
*
* @return The map of attributes
*/
@Override
public Map<String, String> getAttributes() {
Map<String, String> attr = super.getAttributes();
attr.put(ATTRIBUTE_LSP_SHIPMENT_ID, lspShipmentId.toString());
return attr;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* *********************************************************************** *
* project: org.matsim.*
* *********************************************************************** *
* *
* copyright : (C) by the members listed in the COPYING, *
* LICENSE and WARRANTY file. *
* email : info at matsim dot org *
* *
* *********************************************************************** *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* See also COPYING, LICENSE and WARRANTY file *
* *
* ***********************************************************************
*
*/

package org.matsim.freight.logistics.events;


import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.freight.logistics.LSPResource;
import org.matsim.freight.logistics.shipment.LSPShipment;
import java.util.Map;
import static org.matsim.freight.logistics.events.LspEventAttributes.ATTRIBUTE_EXP_HANDLING_DURATION;
import static org.matsim.freight.logistics.events.LspEventAttributes.ATTRIBUTE_HUB_ID;

/**
* An event, that informs that the handling of a {@link LSPShipment} in a hub has started.
*
* @author Kai Martins-Turner (kturner)
*/
public final class HandlingInHubStartsEvent extends AbstractLspEvent {

public static final String EVENT_TYPE = "Handling_started";
private final Id<LSPResource> hubId;
private final double expHandlingDuration;

//TODO: Add more information about the handling, e.g. expected duration of handling. KMT after mtg with kn, jul' 23

public HandlingInHubStartsEvent(double time, Id<Link> linkId, Id<LSPShipment> lspShipmentId, Id<LSPResource> hubId, double expHandlingDuration) {
super(time, linkId, lspShipmentId);
this.hubId = hubId;
this.expHandlingDuration = expHandlingDuration;
}

@Override public String getEventType() {
return EVENT_TYPE;
}

public Id<LSPResource> getHubId() {
return hubId;
}

public double getExpHandlingDuration(){
return expHandlingDuration;
}

@Override
public Map<String, String> getAttributes() {
Map<String, String> attr = super.getAttributes();
attr.put(ATTRIBUTE_HUB_ID, hubId.toString());
attr.put(ATTRIBUTE_EXP_HANDLING_DURATION, String.valueOf(expHandlingDuration));
return attr;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.matsim.freight.logistics.events;

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.events.Event;
import org.matsim.api.core.v01.population.Activity;
import org.matsim.freight.logistics.LSPResource;
import org.matsim.freight.logistics.shipment.LSPShipment;

/**
* @author Kai Martins-Turner (kturner)
*/
public class HandlingInHubStartsEventCreator implements LspEventCreator {

@Override
public Event createEvent(Event event, Id<LSPShipment> lspShipmentId, Activity activity) {
//TODO: This is just a first dummy implementation, KMT May'23
//TODO: expHandlingDuration is temporarily set to minValue. Will decide later wether this creater is needed anyways or not. KMT jul'23
return new HandlingInHubStartsEvent(event.getTime(), activity.getLinkId(), lspShipmentId, Id.create("DummyHubId", LSPResource.class), Double.MIN_VALUE);
}
}
Loading
Loading