diff --git a/src/main/assembly/assembly-release.xml b/src/main/assembly/assembly-release.xml
index 4c23e958..101ad60c 100644
--- a/src/main/assembly/assembly-release.xml
+++ b/src/main/assembly/assembly-release.xml
@@ -1,34 +1,34 @@
- release
-
-
- zip
-
+ xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+
+
+ /libs/
+ false
+ false
+
+
+
+
+
+ ./scenarios/
+ scenarios
+
+
-
-
- ./scenarios/
- scenarios
-
-
+
+
+ /
+
+
+
-
-
-
- /
-
-
+
+ zip
+
-
-
- false
- /libs/
- false
-
-
+ release
diff --git a/src/main/java/org/matsim/freight/logistics/ForwardLogisticChainSchedulerImpl.java b/src/main/java/org/matsim/freight/logistics/ForwardLogisticChainSchedulerImpl.java
index d5f5b42f..52eb84ac 100644
--- a/src/main/java/org/matsim/freight/logistics/ForwardLogisticChainSchedulerImpl.java
+++ b/src/main/java/org/matsim/freight/logistics/ForwardLogisticChainSchedulerImpl.java
@@ -20,167 +20,170 @@
package org.matsim.freight.logistics;
-import org.matsim.freight.logistics.shipment.LSPShipment;
-import org.matsim.api.core.v01.Id;
-
import java.util.ArrayList;
+import org.matsim.api.core.v01.Id;
+import org.matsim.freight.logistics.shipment.LSPShipment;
/**
- * ....
- * Macht 3 Schritte:
- * 1.) the LSPShipments are handed over to the first {@link LogisticChainElement} of their {@link LogisticChain}
- * 2.) the neighbors, i.e. the predecessors and successors of all {@link LSPResource}s are determined
- * 3.) the Resources are brought into the right sequence according to the algorithm.
- *
- * When traversing this list of {@link LSPResource}s, the operations in
- * each {@link LSPResource} are scheduled individually by calling their {@link LSPResourceScheduler}.
+ * .... Macht 3 Schritte: 1.) the LSPShipments are handed over to the first {@link
+ * LogisticChainElement} of their {@link LogisticChain} 2.) the neighbors, i.e. the predecessors and
+ * successors of all {@link LSPResource}s are determined 3.) the Resources are brought into the
+ * right sequence according to the algorithm.
+ *
+ *
When traversing this list of {@link LSPResource}s, the operations in each {@link LSPResource}
+ * are scheduled individually by calling their {@link LSPResourceScheduler}.
*/
/* package-private */ class ForwardLogisticChainSchedulerImpl implements LogisticChainScheduler {
- /**
- * The Resources are brought into the right sequence according to the algorithm.
- * The result of this algorithm is a list of Resources that is later
- * traversed from the front to the back, i.e. starting with the entry at index 0. In the algorithm,
- * this list is called sortedResourceList.
- */
- private final ArrayList sortedResourceList;
- /**
- * The determination of the neighborhood structure among the Resources resulted in the neighborList.
- */
- private final ArrayList neighbourList;
- private LSP lsp;
- private int bufferTime;
-
- ForwardLogisticChainSchedulerImpl() {
- this.sortedResourceList = new ArrayList<>();
- this.neighbourList = new ArrayList<>();
- }
-
- @Override
- public void scheduleLogisticChain() {
- insertShipmentsAtBeginning();
- setResourceNeighbours();
- sortResources();
- for (LSPResource resource : sortedResourceList) {
- resource.schedule(bufferTime, lsp.getSelectedPlan() );
- }
- }
-
- @Override
- public void setEmbeddingContainer(LSP lsp) {
- this.lsp = lsp;
- }
-
- private void setResourceNeighbours() {
- // internal data structure, try to ignore when looking from outside. kai/kai, jan'22
- neighbourList.clear();
- for (LSPResource resource : lsp.getResources()) {
- ResourceNeighbours neighbours = new ResourceNeighbours(resource);
- for (LogisticChainElement element : resource.getClientElements()) {
- LogisticChainElement predecessor = element.getPreviousElement();
- LSPResource previousResource = predecessor.getResource();
- neighbours.addPredecessor(previousResource);
- LogisticChainElement successor = element.getNextElement();
- LSPResource nextResource = successor.getResource();
- neighbours.addSuccessor(nextResource);
- }
- neighbourList.add(neighbours);
- }
- }
-
- private void sortResources() {
- sortedResourceList.clear();
- while (!neighbourList.isEmpty()) {
- for (ResourceNeighbours neighbours : neighbourList) {
- if (allPredecessorsAlreadyScheduled(neighbours) && noSuccessorAlreadyScheduled(neighbours)) {
- sortedResourceList.add(neighbours.resource);
- neighbourList.remove(neighbours);
- }
- }
- }
- }
-
- private boolean allPredecessorsAlreadyScheduled(ResourceNeighbours neighbours) {
- if (neighbours.predecessors.isEmpty()) {
- return true;
- }
-
- for (LSPResource predecessor : neighbours.predecessors) {
- if (!sortedResourceList.contains(predecessor)) {
- return true;
- }
- }
- return false;
- }
-
- private boolean noSuccessorAlreadyScheduled(ResourceNeighbours neighbours) {
- if (neighbours.successors.isEmpty()) {
- return true;
- }
-
- for (LSPResource successor : neighbours.successors) {
- if (!sortedResourceList.contains(successor)) {
- return true;
- }
- }
- return false;
- }
-
- private void insertShipmentsAtBeginning() {
- for (LogisticChain solution : lsp.getSelectedPlan().getLogisticChains()) {
- LogisticChainElement firstElement = getFirstElement(solution);
- assert firstElement != null;
- for (Id lspShipmentId : solution.getShipmentIds()) {
- var shipment = LSPUtils.findLspShipment(lsp, lspShipmentId);
- assert shipment != null;
- firstElement.getIncomingShipments().addShipment(shipment.getPickupTimeWindow().getStart(), shipment);
- }
- }
- }
-
- private LogisticChainElement getFirstElement(LogisticChain solution) {
- for (LogisticChainElement element : solution.getLogisticChainElements()) {
- if (element.getPreviousElement() == null) {
- return element;
- }
- }
- 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
- * successors or predecessors or can be used by several different {@link LogisticChain}s.
- * The neighborhood structure among the {@link LSPResource}s is stored in instances of the class
- * {@link ResourceNeighbours} which contain references on the considered {@link LSPResource} and on the set
- * of immediate successors respective predecessors. As the result of this step, a collection of
- * {@link ResourceNeighbours} called neighborList is created that contains the neighbors of all
- * {@link LSPResource}s in the plan of the considered {@link LSP}.
- */
- private static class ResourceNeighbours {
- // internal data structure, try to ignore when looking from outside. kai/kai, jan'22
-
- private final ArrayList predecessors;
- private final ArrayList successors;
- private final LSPResource resource;
-
- private ResourceNeighbours(LSPResource resource) {
- this.resource = resource;
- this.predecessors = new ArrayList<>();
- this.successors = new ArrayList<>();
- }
-
- private void addPredecessor(LSPResource resource) {
- this.predecessors.add(resource);
- }
-
- private void addSuccessor(LSPResource resource) {
- this.successors.add(resource);
- }
- }
+ /**
+ * The Resources are brought into the right sequence according to the algorithm. The result of
+ * this algorithm is a list of Resources that is later traversed from the front to the back, i.e.
+ * starting with the entry at index 0. In the algorithm, this list is called sortedResourceList.
+ */
+ private final ArrayList sortedResourceList;
+
+ /**
+ * The determination of the neighborhood structure among the Resources resulted in the
+ * neighborList.
+ */
+ private final ArrayList neighbourList;
+
+ private LSP lsp;
+ private int bufferTime;
+
+ ForwardLogisticChainSchedulerImpl() {
+ this.sortedResourceList = new ArrayList<>();
+ this.neighbourList = new ArrayList<>();
+ }
+
+ @Override
+ public void scheduleLogisticChain() {
+ insertShipmentsAtBeginning();
+ setResourceNeighbours();
+ sortResources();
+ for (LSPResource resource : sortedResourceList) {
+ resource.schedule(bufferTime, lsp.getSelectedPlan());
+ }
+ }
+
+ @Override
+ public void setEmbeddingContainer(LSP lsp) {
+ this.lsp = lsp;
+ }
+
+ private void setResourceNeighbours() {
+ // internal data structure, try to ignore when looking from outside. kai/kai, jan'22
+ neighbourList.clear();
+ for (LSPResource resource : lsp.getResources()) {
+ ResourceNeighbours neighbours = new ResourceNeighbours(resource);
+ for (LogisticChainElement element : resource.getClientElements()) {
+ LogisticChainElement predecessor = element.getPreviousElement();
+ LSPResource previousResource = predecessor.getResource();
+ neighbours.addPredecessor(previousResource);
+ LogisticChainElement successor = element.getNextElement();
+ LSPResource nextResource = successor.getResource();
+ neighbours.addSuccessor(nextResource);
+ }
+ neighbourList.add(neighbours);
+ }
+ }
+
+ private void sortResources() {
+ sortedResourceList.clear();
+ while (!neighbourList.isEmpty()) {
+ for (ResourceNeighbours neighbours : neighbourList) {
+ if (allPredecessorsAlreadyScheduled(neighbours)
+ && noSuccessorAlreadyScheduled(neighbours)) {
+ sortedResourceList.add(neighbours.resource);
+ neighbourList.remove(neighbours);
+ }
+ }
+ }
+ }
+
+ private boolean allPredecessorsAlreadyScheduled(ResourceNeighbours neighbours) {
+ if (neighbours.predecessors.isEmpty()) {
+ return true;
+ }
+
+ for (LSPResource predecessor : neighbours.predecessors) {
+ if (!sortedResourceList.contains(predecessor)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean noSuccessorAlreadyScheduled(ResourceNeighbours neighbours) {
+ if (neighbours.successors.isEmpty()) {
+ return true;
+ }
+
+ for (LSPResource successor : neighbours.successors) {
+ if (!sortedResourceList.contains(successor)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void insertShipmentsAtBeginning() {
+ for (LogisticChain solution : lsp.getSelectedPlan().getLogisticChains()) {
+ LogisticChainElement firstElement = getFirstElement(solution);
+ assert firstElement != null;
+ for (Id lspShipmentId : solution.getShipmentIds()) {
+ var shipment = LSPUtils.findLspShipment(lsp, lspShipmentId);
+ assert shipment != null;
+ firstElement
+ .getIncomingShipments()
+ .addShipment(shipment.getPickupTimeWindow().getStart(), shipment);
+ }
+ }
+ }
+
+ private LogisticChainElement getFirstElement(LogisticChain solution) {
+ for (LogisticChainElement element : solution.getLogisticChainElements()) {
+ if (element.getPreviousElement() == null) {
+ return element;
+ }
+ }
+ 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 successors or predecessors or can be used by several different {@link LogisticChain}s.
+ * The neighborhood structure among the {@link LSPResource}s is stored in instances of the class
+ * {@link ResourceNeighbours} which contain references on the considered {@link LSPResource} and
+ * on the set of immediate successors respective predecessors. As the result of this step, a
+ * collection of {@link ResourceNeighbours} called neighborList is created that contains the
+ * neighbors of all {@link LSPResource}s in the plan of the considered {@link LSP}.
+ */
+ private static class ResourceNeighbours {
+ // internal data structure, try to ignore when looking from outside. kai/kai, jan'22
+
+ private final ArrayList predecessors;
+ private final ArrayList successors;
+ private final LSPResource resource;
+
+ private ResourceNeighbours(LSPResource resource) {
+ this.resource = resource;
+ this.predecessors = new ArrayList<>();
+ this.successors = new ArrayList<>();
+ }
+
+ private void addPredecessor(LSPResource resource) {
+ this.predecessors.add(resource);
+ }
+
+ private void addSuccessor(LSPResource resource) {
+ this.successors.add(resource);
+ }
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/HasBackpointer.java b/src/main/java/org/matsim/freight/logistics/HasBackpointer.java
index a7c98fc4..73f97386 100644
--- a/src/main/java/org/matsim/freight/logistics/HasBackpointer.java
+++ b/src/main/java/org/matsim/freight/logistics/HasBackpointer.java
@@ -2,11 +2,11 @@
@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
public interface HasBackpointer {
- // In general, we set backpointers when we add to the container.
+ // In general, we set backpointers when we add to the container.
- // yy maybe also have interface HasSettableBackpointer?
- void setEmbeddingContainer(T pointer);
+ // yy maybe also have interface HasSettableBackpointer?
+ void setEmbeddingContainer(T pointer);
-// T getEmbeddingContainer();
+ // T getEmbeddingContainer();
}
diff --git a/src/main/java/org/matsim/freight/logistics/HasLspShipmentId.java b/src/main/java/org/matsim/freight/logistics/HasLspShipmentId.java
index 35fae734..7fe90472 100644
--- a/src/main/java/org/matsim/freight/logistics/HasLspShipmentId.java
+++ b/src/main/java/org/matsim/freight/logistics/HasLspShipmentId.java
@@ -18,7 +18,6 @@
* *********************************************************************** */
package org.matsim.freight.logistics;
-
import org.matsim.api.core.v01.Id;
import org.matsim.freight.logistics.shipment.LSPShipment;
@@ -27,7 +26,7 @@
*/
public interface HasLspShipmentId {
- String ATTRIBUTE_LSP_SHIPMENT_ID = "lspShipmentId";
- Id getLspShipmentId();
+ String ATTRIBUTE_LSP_SHIPMENT_ID = "lspShipmentId";
+ Id getLspShipmentId();
}
diff --git a/src/main/java/org/matsim/freight/logistics/HasSimulationTrackers.java b/src/main/java/org/matsim/freight/logistics/HasSimulationTrackers.java
index f89dc015..33ba5007 100644
--- a/src/main/java/org/matsim/freight/logistics/HasSimulationTrackers.java
+++ b/src/main/java/org/matsim/freight/logistics/HasSimulationTrackers.java
@@ -2,12 +2,13 @@
import java.util.Collection;
-// One could say that the simulation trackers are the decorators that convert the data objects into behavioral objects. In core matsim, we instead
-// create behavioral objects, which contain the data objects. E.g. MobsimAgent, DriverAgent, CarrierAgent, etc. kai, may'22
+// One could say that the simulation trackers are the decorators that convert the data objects into
+// behavioral objects. In core matsim, we instead
+// create behavioral objects, which contain the data objects. E.g. MobsimAgent, DriverAgent,
+// CarrierAgent, etc. kai, may'22
public interface HasSimulationTrackers {
- void addSimulationTracker(LSPSimulationTracker tracker);
-
- Collection> getSimulationTrackers();
+ void addSimulationTracker(LSPSimulationTracker tracker);
+ Collection> getSimulationTrackers();
}
diff --git a/src/main/java/org/matsim/freight/logistics/KnowsLSP.java b/src/main/java/org/matsim/freight/logistics/KnowsLSP.java
index 1f9270ca..60a9c8ea 100644
--- a/src/main/java/org/matsim/freight/logistics/KnowsLSP.java
+++ b/src/main/java/org/matsim/freight/logistics/KnowsLSP.java
@@ -1,7 +1,7 @@
package org.matsim.freight.logistics;
interface KnowsLSP {
- void setLSP(LSP lsp);
+ LSP getLSP();
- LSP getLSP();
+ void setLSP(LSP lsp);
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSP.java b/src/main/java/org/matsim/freight/logistics/LSP.java
index e153a513..e91ea87f 100644
--- a/src/main/java/org/matsim/freight/logistics/LSP.java
+++ b/src/main/java/org/matsim/freight/logistics/LSP.java
@@ -20,56 +20,46 @@
package org.matsim.freight.logistics;
-import org.matsim.freight.logistics.shipment.LSPShipment;
-import org.matsim.api.core.v01.population.HasPlansAndId;
-
import java.util.Collection;
+import org.matsim.api.core.v01.population.HasPlansAndId;
+import org.matsim.freight.logistics.shipment.LSPShipment;
/**
- * In the class library, the interface LSP has the following tasks:
- * 1. Maintain one or several transport chains through which {@link LSPShipment}s are routed.
- * 2. Assign {@link LSPShipment}s to the suitable transport chain. --> {@link ShipmentAssigner}.
- * 3. Interact with the agents that embody the demand side of the freight transport market, if they are specified in the setting.
- * 4. Coordinate carriers that are in charge of the physical transport.
+ * In the class library, the interface LSP has the following tasks: 1. Maintain one or several
+ * transport chains through which {@link LSPShipment}s are routed. 2. Assign {@link LSPShipment}s to
+ * the suitable transport chain. --> {@link ShipmentAssigner}. 3. Interact with the agents that
+ * embody the demand side of the freight transport market, if they are specified in the setting. 4.
+ * Coordinate carriers that are in charge of the physical transport.
*/
public interface LSP extends HasPlansAndId, HasSimulationTrackers {
- /**
- * yyyy does this have to be exposed?
- */
- Collection getShipments();
-
- /**
- * ok (behavioral method)
- */
- void scheduleLogisticChains();
-
-
- /**
- * yyyy does this have to be exposed?
- */
- Collection getResources();
+ /** yyyy does this have to be exposed? */
+ Collection getShipments();
+ /** ok (behavioral method) */
+ void scheduleLogisticChains();
- /**
- * ok (behavioral method)
- *
- */
- void scoreSelectedPlan();
+ /** yyyy does this have to be exposed? */
+ Collection getResources();
+ /** ok (behavioral method) */
+ void scoreSelectedPlan();
- /**
- * @param shipment ok (LSP needs to be told that it is responsible for shipment)
- */
- void assignShipmentToLSP(LSPShipment shipment);
+ /**
+ * @param shipment ok (LSP needs to be told that it is responsible for shipment)
+ */
+ void assignShipmentToLSP(LSPShipment shipment);
-// void replan(ReplanningEvent arg0);
-//
-// /**
-// * @deprecated -- It feels attractive to attach this to the "agent". A big disadvantage with this approach, however, is that
-// * we cannot use injection ... since we cannot inject as many replanners as we have agents. (At least this is what I think.) yyyyyy So
-// * this needs to be changed. kai, jul'22 yyyy Need to understand how this is done in core matsim. kai, jul'22
-// */
-// void setReplanner(LSPReplanner replanner);
+ // void replan(ReplanningEvent arg0);
+ //
+ // /**
+ // * @deprecated -- It feels attractive to attach this to the "agent". A big disadvantage with
+ // this approach, however, is that
+ // * we cannot use injection ... since we cannot inject as many replanners as we have agents.
+ // (At least this is what I think.) yyyyyy So
+ // * this needs to be changed. kai, jul'22 yyyy Need to understand how this is done in core
+ // matsim. kai, jul'22
+ // */
+ // void setReplanner(LSPReplanner replanner);
-}
+}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPCarrierResource.java b/src/main/java/org/matsim/freight/logistics/LSPCarrierResource.java
index 1fdbcc63..1a26be79 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPCarrierResource.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPCarrierResource.java
@@ -24,6 +24,5 @@
public interface LSPCarrierResource extends LSPResource {
- Carrier getCarrier();
-
+ Carrier getCarrier();
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPConstants.java b/src/main/java/org/matsim/freight/logistics/LSPConstants.java
index 5e743c78..1d9d1b7b 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPConstants.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPConstants.java
@@ -2,53 +2,52 @@
public abstract class LSPConstants {
- public static final String LSPS_DEFINITIONS = "lspsDefinitions";
- public static final String LSPS = "LSPs";
- public static final String LSP = "lsp";
- public static final String HUB = "hub";
- public static final String LOCATION = "location";
- public static final String FIXED_COST = "fixedCost";
- public static final String SCHEDULER = "scheduler";
- public static final String CAPACITY_NEED_FIXED = "capacityNeedFixed";
- public static final String CAPACITY_NEED_LINEAR = "capacityNeedLinear";
- public static final String CARRIER = "carrier";
- public static final String ATTRIBUTES = "attributes";
- public static final String ATTRIBUTE = "attribute";
- public static final String CAPABILITIES = "capabilities";
- public static final String FLEET_SIZE = "fleetSize";
- public static final String VEHICLE = "vehicle";
- public static final String DEPOT_LINK_ID = "depotLinkId";
- public static final String TYPE_ID = "typeId";
- public static final String VEHICLE_EARLIEST_START = "earliestStart";
- public static final String VEHICLE_LATEST_END = "latestEnd";
- public static final String SHIPMENTS = "shipments";
- public static final String SHIPMENT = "shipment";
- public static final String ID = "id";
- public static final String FROM = "from";
- public static final String TO = "to";
- public static final String SIZE = "size";
- public static final String START_PICKUP = "startPickup";
- public static final String END_PICKUP = "endPickup";
- public static final String START_DELIVERY = "startDelivery";
- public static final String END_DELIVERY = "endDelivery";
- public static final String PICKUP_SERVICE_TIME = "pickupServiceTime";
- public static final String DELIVERY_SERVICE_TIME = "deliveryServiceTime";
- public static final String LSP_PLANS = "LspPlans";
- public static final String LSP_PLAN = "LspPlan";
- public static final String SCORE = "score";
- public static final String SELECTED = "selected";
- public static final String RESOURCES = "resources";
- public static final String LOGISTIC_CHAINS = "logisticChains";
- public static final String LOGISTIC_CHAIN = "logisticChain";
- public static final String LOGISTIC_CHAIN_ELEMENT = "logisticChainElement";
- public static final String SHIPMENT_PLANS = "shipmentPlans";
- public static final String SHIPMENT_PLAN = "shipmentPlan";
- public static final String SHIPMENT_ID = "shipmentId";
- public static final String CHAIN_ID = "chainId";
- public static final String ELEMENT = "element";
- public static final String TYPE = "type";
- public static final String START_TIME = "startTime";
- public static final String END_TIME = "endTime";
- public static final String RESOURCE_ID = "resourceId";
-
+ public static final String LSPS_DEFINITIONS = "lspsDefinitions";
+ public static final String LSPS = "LSPs";
+ public static final String LSP = "lsp";
+ public static final String HUB = "hub";
+ public static final String LOCATION = "location";
+ public static final String FIXED_COST = "fixedCost";
+ public static final String SCHEDULER = "scheduler";
+ public static final String CAPACITY_NEED_FIXED = "capacityNeedFixed";
+ public static final String CAPACITY_NEED_LINEAR = "capacityNeedLinear";
+ public static final String CARRIER = "carrier";
+ public static final String ATTRIBUTES = "attributes";
+ public static final String ATTRIBUTE = "attribute";
+ public static final String CAPABILITIES = "capabilities";
+ public static final String FLEET_SIZE = "fleetSize";
+ public static final String VEHICLE = "vehicle";
+ public static final String DEPOT_LINK_ID = "depotLinkId";
+ public static final String TYPE_ID = "typeId";
+ public static final String VEHICLE_EARLIEST_START = "earliestStart";
+ public static final String VEHICLE_LATEST_END = "latestEnd";
+ public static final String SHIPMENTS = "shipments";
+ public static final String SHIPMENT = "shipment";
+ public static final String ID = "id";
+ public static final String FROM = "from";
+ public static final String TO = "to";
+ public static final String SIZE = "size";
+ public static final String START_PICKUP = "startPickup";
+ public static final String END_PICKUP = "endPickup";
+ public static final String START_DELIVERY = "startDelivery";
+ public static final String END_DELIVERY = "endDelivery";
+ public static final String PICKUP_SERVICE_TIME = "pickupServiceTime";
+ public static final String DELIVERY_SERVICE_TIME = "deliveryServiceTime";
+ public static final String LSP_PLANS = "LspPlans";
+ public static final String LSP_PLAN = "LspPlan";
+ public static final String SCORE = "score";
+ public static final String SELECTED = "selected";
+ public static final String RESOURCES = "resources";
+ public static final String LOGISTIC_CHAINS = "logisticChains";
+ public static final String LOGISTIC_CHAIN = "logisticChain";
+ public static final String LOGISTIC_CHAIN_ELEMENT = "logisticChainElement";
+ public static final String SHIPMENT_PLANS = "shipmentPlans";
+ public static final String SHIPMENT_PLAN = "shipmentPlan";
+ public static final String SHIPMENT_ID = "shipmentId";
+ public static final String CHAIN_ID = "chainId";
+ public static final String ELEMENT = "element";
+ public static final String TYPE = "type";
+ public static final String START_TIME = "startTime";
+ public static final String END_TIME = "endTime";
+ public static final String RESOURCE_ID = "resourceId";
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPControlerListener.java b/src/main/java/org/matsim/freight/logistics/LSPControlerListener.java
index bcbcab6e..01954cdf 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPControlerListener.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPControlerListener.java
@@ -20,10 +20,10 @@
package org.matsim.freight.logistics;
-
import jakarta.inject.Inject;
-import org.matsim.freight.logistics.io.LSPPlanXmlWriter;
-import org.matsim.freight.logistics.shipment.LSPShipment;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Nullable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
@@ -35,158 +35,164 @@
import org.matsim.core.events.handler.EventHandler;
import org.matsim.freight.carriers.Carrier;
import org.matsim.freight.carriers.CarrierPlanWriter;
-import org.matsim.freight.carriers.CarriersUtils;
import org.matsim.freight.carriers.Carriers;
+import org.matsim.freight.carriers.CarriersUtils;
import org.matsim.freight.carriers.controler.CarrierAgentTracker;
+import org.matsim.freight.logistics.io.LSPPlanXmlWriter;
+import org.matsim.freight.logistics.shipment.LSPShipment;
-import javax.annotation.Nullable;
-import java.util.ArrayList;
-import java.util.List;
-
-
-class LSPControlerListener implements BeforeMobsimListener, AfterMobsimListener, ScoringListener,
- ReplanningListener, IterationStartsListener, IterationEndsListener, ShutdownListener {
- private static final Logger log = LogManager.getLogger( LSPControlerListener.class );
- private final Scenario scenario;
- private final List registeredHandlers = new ArrayList<>();
-
- @Inject private EventsManager eventsManager;
- @Inject private MatsimServices matsimServices;
- @Inject private LSPScorerFactory lspScoringFunctionFactory;
- @Inject @Nullable private LSPStrategyManager strategyManager;
- @Inject private OutputDirectoryHierarchy controlerIO;
- @Inject private CarrierAgentTracker carrierAgentTracker;
- @Inject LSPControlerListener( Scenario scenario ) {
- this.scenario = scenario;
- }
-
- @Override
- public void notifyBeforeMobsim(BeforeMobsimEvent event) {
- LSPs lsps = LSPUtils.getLSPs(scenario);
-
- //TODO: Why do we add all simTrackers in every iteration beforeMobsim starts?
- // Doing so results in a lot of "not adding eventsHandler since already added" warnings.
- // @KN: Would it be possible to do it in (simulation) startup and therefor only oce?
- 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 );
- }
-
- // simulation trackers of solutions:
- for (LogisticChain solution : lsp.getSelectedPlan().getLogisticChains()) {
- registerSimulationTrackers(solution );
-
- // simulation trackers of solution elements:
- for (LogisticChainElement element : solution.getLogisticChainElements()) {
- registerSimulationTrackers(element );
-
- // simulation trackers of resources:
- registerSimulationTrackers(element.getResource() );
-
- }
- }
- }
- }
-
- private void registerSimulationTrackers( HasSimulationTrackers> hasSimulationTrackers) {
- // get all simulation trackers ...
- 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);
- }
- }
- }
-
-
- @Override
- public void notifyReplanning(ReplanningEvent event) {
- if ( strategyManager==null ) {
- throw new RuntimeException( "You need to set LSPStrategyManager to something meaningful to run iterations." );
- }
-
- LSPs lsps = LSPUtils.getLSPs(scenario);
- strategyManager.run(lsps.getLSPs().values(), event.getIteration(), event.getReplanningContext());
-
- for (LSP lsp : lsps.getLSPs().values()) {
- lsp.getSelectedPlan().getShipmentPlans().clear(); //clear ShipmentPlans to start with clear(n) state. Otherwise, some times were accumulating over the time. :(
- lsp.scheduleLogisticChains();
- }
-
- //Update carriers in scenario and CarrierAgentTracker
- carrierAgentTracker.getCarriers().getCarriers().clear();
- for (Carrier carrier : getCarriersFromLSP().getCarriers().values()) {
- CarriersUtils.getCarriers(scenario).addCarrier(carrier);
- carrierAgentTracker.getCarriers().addCarrier(carrier);
- }
-
- }
-
- @Override
- public void notifyScoring(ScoringEvent scoringEvent) {
- for (LSP lsp : LSPUtils.getLSPs(scenario).getLSPs().values()) {
- lsp.scoreSelectedPlan();
- }
- // yyyyyy might make more sense to register the lsps directly as scoring controler listener (??)
- }
-
- @Override
- public void notifyAfterMobsim(AfterMobsimEvent event) {
- }
-
-
- Carriers getCarriersFromLSP() {
- LSPs lsps = LSPUtils.getLSPs(scenario);
- assert ! lsps.getLSPs().isEmpty();
-
- Carriers carriers = new Carriers();
- for (LSP lsp : lsps.getLSPs().values()) {
- LSPPlan selectedPlan = lsp.getSelectedPlan();
- for (LogisticChain solution : selectedPlan.getLogisticChains()) {
- for (LogisticChainElement element : solution.getLogisticChainElements()) {
- if( element.getResource() instanceof LSPCarrierResource carrierResource ) {
- Carrier carrier = carrierResource.getCarrier();
- if (!carriers.getCarriers().containsKey(carrier.getId())) {
- carriers.addCarrier(carrier);
- }
- }
- }
- }
- }
- return carriers;
- }
-
- @Override
- public void notifyIterationStarts(IterationStartsEvent event) {
- }
-
- @Override
- public void notifyIterationEnds(IterationEndsEvent event) {
- new LSPPlanXmlWriter(LSPUtils.getLSPs(scenario)).write(controlerIO.getIterationFilename(event.getIteration(), "lsps.xml"));
- }
-
- @Override
- 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");
- }
-
+class LSPControlerListener
+ implements BeforeMobsimListener,
+ AfterMobsimListener,
+ ScoringListener,
+ ReplanningListener,
+ IterationStartsListener,
+ IterationEndsListener,
+ ShutdownListener {
+ private static final Logger log = LogManager.getLogger(LSPControlerListener.class);
+ private final Scenario scenario;
+ private final List registeredHandlers = new ArrayList<>();
+
+ @Inject private EventsManager eventsManager;
+ @Inject private MatsimServices matsimServices;
+ @Inject private LSPScorerFactory lspScoringFunctionFactory;
+ @Inject @Nullable private LSPStrategyManager strategyManager;
+ @Inject private OutputDirectoryHierarchy controlerIO;
+ @Inject private CarrierAgentTracker carrierAgentTracker;
+
+ @Inject
+ LSPControlerListener(Scenario scenario) {
+ this.scenario = scenario;
+ }
+
+ @Override
+ public void notifyBeforeMobsim(BeforeMobsimEvent event) {
+ LSPs lsps = LSPUtils.getLSPs(scenario);
+
+ // TODO: Why do we add all simTrackers in every iteration beforeMobsim starts?
+ // Doing so results in a lot of "not adding eventsHandler since already added" warnings.
+ // @KN: Would it be possible to do it in (simulation) startup and therefor only oce?
+ 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);
+ }
+
+ // simulation trackers of solutions:
+ for (LogisticChain solution : lsp.getSelectedPlan().getLogisticChains()) {
+ registerSimulationTrackers(solution);
+
+ // simulation trackers of solution elements:
+ for (LogisticChainElement element : solution.getLogisticChainElements()) {
+ registerSimulationTrackers(element);
+
+ // simulation trackers of resources:
+ registerSimulationTrackers(element.getResource());
+ }
+ }
+ }
+ }
+
+ private void registerSimulationTrackers(HasSimulationTrackers> hasSimulationTrackers) {
+ // get all simulation trackers ...
+ 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);
+ }
+ }
+ }
+
+ @Override
+ public void notifyReplanning(ReplanningEvent event) {
+ if (strategyManager == null) {
+ throw new RuntimeException(
+ "You need to set LSPStrategyManager to something meaningful to run iterations.");
+ }
+
+ LSPs lsps = LSPUtils.getLSPs(scenario);
+ strategyManager.run(
+ lsps.getLSPs().values(), event.getIteration(), event.getReplanningContext());
+
+ for (LSP lsp : lsps.getLSPs().values()) {
+ lsp.getSelectedPlan()
+ .getShipmentPlans()
+ .clear(); // clear ShipmentPlans to start with clear(n) state. Otherwise, some times were
+ // accumulating over the time. :(
+ lsp.scheduleLogisticChains();
+ }
+
+ // Update carriers in scenario and CarrierAgentTracker
+ carrierAgentTracker.getCarriers().getCarriers().clear();
+ for (Carrier carrier : getCarriersFromLSP().getCarriers().values()) {
+ CarriersUtils.getCarriers(scenario).addCarrier(carrier);
+ carrierAgentTracker.getCarriers().addCarrier(carrier);
+ }
+ }
+
+ @Override
+ public void notifyScoring(ScoringEvent scoringEvent) {
+ for (LSP lsp : LSPUtils.getLSPs(scenario).getLSPs().values()) {
+ lsp.scoreSelectedPlan();
+ }
+ // yyyyyy might make more sense to register the lsps directly as scoring controler listener (??)
+ }
+
+ @Override
+ public void notifyAfterMobsim(AfterMobsimEvent event) {}
+
+ Carriers getCarriersFromLSP() {
+ LSPs lsps = LSPUtils.getLSPs(scenario);
+ assert !lsps.getLSPs().isEmpty();
+
+ Carriers carriers = new Carriers();
+ for (LSP lsp : lsps.getLSPs().values()) {
+ LSPPlan selectedPlan = lsp.getSelectedPlan();
+ for (LogisticChain solution : selectedPlan.getLogisticChains()) {
+ for (LogisticChainElement element : solution.getLogisticChainElements()) {
+ if (element.getResource() instanceof LSPCarrierResource carrierResource) {
+ Carrier carrier = carrierResource.getCarrier();
+ if (!carriers.getCarriers().containsKey(carrier.getId())) {
+ carriers.addCarrier(carrier);
+ }
+ }
+ }
+ }
+ }
+ return carriers;
+ }
+
+ @Override
+ public void notifyIterationStarts(IterationStartsEvent event) {}
+
+ @Override
+ public void notifyIterationEnds(IterationEndsEvent event) {
+ new LSPPlanXmlWriter(LSPUtils.getLSPs(scenario))
+ .write(controlerIO.getIterationFilename(event.getIteration(), "lsps.xml"));
+ }
+
+ @Override
+ 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");
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPDataObject.java b/src/main/java/org/matsim/freight/logistics/LSPDataObject.java
index 6789e7d9..ff150a79 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPDataObject.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPDataObject.java
@@ -1,42 +1,45 @@
package org.matsim.freight.logistics;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Identifiable;
import org.matsim.utils.objectattributes.attributable.Attributable;
import org.matsim.utils.objectattributes.attributable.Attributes;
import org.matsim.utils.objectattributes.attributable.AttributesImpl;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-
public class LSPDataObject implements HasSimulationTrackers, Attributable, Identifiable {
- private final Collection> trackers = new LinkedList<>();
- private final Attributes attributes = new AttributesImpl();
- private final Id id;
-
- public LSPDataObject(Id id) {
- this.id = id;
- }
-
- @Override public final void addSimulationTracker( LSPSimulationTracker tracker ){
- this.trackers.add( tracker );
- tracker.setEmbeddingContainer( (T) this );
- // It may not be possible to do this without this cast. Since "this" only knows that it is at least an LSPDataObject, and only we
- // know that it is truly of type T. kai, jun'22
- }
-
- @Override public final Collection> getSimulationTrackers(){
- return Collections.unmodifiableCollection( this.trackers );
- }
-
- @Override public final Attributes getAttributes() {
- return attributes;
- }
-
- @Override public final Id getId() {
- return id;
- }
+ private final Collection> trackers = new LinkedList<>();
+ private final Attributes attributes = new AttributesImpl();
+ private final Id id;
+
+ public LSPDataObject(Id id) {
+ this.id = id;
+ }
+
+ @Override
+ public final void addSimulationTracker(LSPSimulationTracker tracker) {
+ this.trackers.add(tracker);
+ tracker.setEmbeddingContainer((T) this);
+ // It may not be possible to do this without this cast. Since "this" only knows that it is at
+ // least an LSPDataObject, and only we
+ // know that it is truly of type T. kai, jun'22
+ }
+
+ @Override
+ public final Collection> getSimulationTrackers() {
+ return Collections.unmodifiableCollection(this.trackers);
+ }
+
+ @Override
+ public final Attributes getAttributes() {
+ return attributes;
+ }
+
+ @Override
+ public final Id getId() {
+ return id;
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPImpl.java b/src/main/java/org/matsim/freight/logistics/LSPImpl.java
index 6293586f..530ef40b 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPImpl.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPImpl.java
@@ -20,146 +20,144 @@
package org.matsim.freight.logistics;
-import org.matsim.freight.logistics.shipment.LSPShipment;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.matsim.freight.logistics.shipment.LSPShipment;
-/* package-private */class LSPImpl extends LSPDataObject implements LSP {
- private static final Logger log = LogManager.getLogger(LSPImpl.class);
-
- private final Collection shipments;
- private final ArrayList plans;
- private final LogisticChainScheduler logisticChainScheduler;
- private final Collection resources;
- private LSPPlan selectedPlan;
- private LSPScorer scorer;
-// private LSPReplanner replanner;
-
-
- LSPImpl(LSPUtils.LSPBuilder builder) {
- super(builder.id);
- this.shipments = new ArrayList<>();
- this.plans = new ArrayList<>();
- this.logisticChainScheduler = builder.logisticChainScheduler;
- this.logisticChainScheduler.setEmbeddingContainer(this);
- this.selectedPlan = builder.initialPlan;
- this.selectedPlan.setLSP(this);
- this.plans.add(builder.initialPlan);
- this.resources = builder.resources;
- }
-
- /**
- * This is used from {@link LSPControlerListener} and not meant to be used from user code. Users should bind {@link LSPScorerFactory}.
- */
- /* package-private */ void setScorer(LSPScorer scorer){
- this.scorer = scorer;
- scorer.setEmbeddingContainer(this);
- this.addSimulationTracker(scorer);
- }
-
- public static LSPPlan copyPlan(LSPPlan plan2copy) {
- List newPlanChains = new ArrayList<>();
- for (LogisticChain initialPlanChain : plan2copy.getLogisticChains()) {
- LogisticChain newPlanChain = LSPUtils.LogisticChainBuilder.newInstance(initialPlanChain.getId()).build();
- newPlanChain.getLogisticChainElements().addAll(initialPlanChain.getLogisticChainElements());
- newPlanChain.getShipmentIds().addAll(initialPlanChain.getShipmentIds());
- newPlanChains.add(newPlanChain);
- }
-
-
- LSPPlan copiedPlan = LSPUtils.createLSPPlan();
- copiedPlan.setAssigner(plan2copy.getAssigner());
- copiedPlan.setLSP(plan2copy.getLSP());
- copiedPlan.setScore(plan2copy.getScore());
- copiedPlan.setType(plan2copy.getType());
- copiedPlan.getLogisticChains().addAll(newPlanChains);
- return copiedPlan;
- }
-
- @Override
- public void scheduleLogisticChains() {
- logisticChainScheduler.scheduleLogisticChain();
- }
-
- @Override
- public boolean addPlan(LSPPlan plan) {
- for (LogisticChain solution : plan.getLogisticChains()) {
- for (LogisticChainElement element : solution.getLogisticChainElements()) {
- if (!resources.contains(element.getResource())) {
- resources.add(element.getResource());
- }
- }
- }
- plan.setLSP(this);
- return plans.add(plan);
- }
-
- @Override
- public LSPPlan createCopyOfSelectedPlanAndMakeSelected() {
- LSPPlan newPlan = LSPImpl.copyPlan(this.selectedPlan);
- this.setSelectedPlan(newPlan);
- return newPlan;
- }
-
- @Override
- public ArrayList getPlans() {
- return plans;
- }
-
- @Override
- public LSPPlan getSelectedPlan() {
- return selectedPlan;
- }
-
- @Override
- public void setSelectedPlan(LSPPlan selectedPlan) {
- if (!plans.contains(selectedPlan)) {
- plans.add(selectedPlan);
- }
- this.selectedPlan = selectedPlan;
-
- }
-
- @Override
- public boolean removePlan(LSPPlan plan) {
- if (plans.contains(plan)) {
- plans.remove(plan);
- return true;
- } else {
- return false;
- }
- }
-
- @Override
- public Collection getResources() {
- return resources;
- }
-
- public void scoreSelectedPlan() {
- if (this.scorer != null) {
- this.selectedPlan.setScore(scorer.getScoreForCurrentPlan() );
- } else {
- throw new RuntimeException("trying to score the current LSP plan, but scorer is not set.");
- }
- }
-
-
- @Override
- public void assignShipmentToLSP(LSPShipment shipment) {
-// shipment.setLspId(this.getId()); // und rückweg dann auch darüber und dann lsp.getselectedPlan.getShipment...
- shipments.add(shipment);
- for (LSPPlan lspPlan : plans) {
- lspPlan.getAssigner().assignToPlan(lspPlan, shipment);
- }
- }
-
- @Override
- public Collection getShipments() {
- return this.shipments;
- }
-
+/* package-private */ class LSPImpl extends LSPDataObject implements LSP {
+ private static final Logger log = LogManager.getLogger(LSPImpl.class);
+
+ private final Collection shipments;
+ private final ArrayList plans;
+ private final LogisticChainScheduler logisticChainScheduler;
+ private final Collection resources;
+ private LSPPlan selectedPlan;
+ private LSPScorer scorer;
+
+ // private LSPReplanner replanner;
+
+ LSPImpl(LSPUtils.LSPBuilder builder) {
+ super(builder.id);
+ this.shipments = new ArrayList<>();
+ this.plans = new ArrayList<>();
+ this.logisticChainScheduler = builder.logisticChainScheduler;
+ this.logisticChainScheduler.setEmbeddingContainer(this);
+ this.selectedPlan = builder.initialPlan;
+ this.selectedPlan.setLSP(this);
+ this.plans.add(builder.initialPlan);
+ this.resources = builder.resources;
+ }
+
+ public static LSPPlan copyPlan(LSPPlan plan2copy) {
+ List newPlanChains = new ArrayList<>();
+ for (LogisticChain initialPlanChain : plan2copy.getLogisticChains()) {
+ LogisticChain newPlanChain =
+ LSPUtils.LogisticChainBuilder.newInstance(initialPlanChain.getId()).build();
+ newPlanChain.getLogisticChainElements().addAll(initialPlanChain.getLogisticChainElements());
+ newPlanChain.getShipmentIds().addAll(initialPlanChain.getShipmentIds());
+ newPlanChains.add(newPlanChain);
+ }
+
+ LSPPlan copiedPlan = LSPUtils.createLSPPlan();
+ copiedPlan.setAssigner(plan2copy.getAssigner());
+ copiedPlan.setLSP(plan2copy.getLSP());
+ copiedPlan.setScore(plan2copy.getScore());
+ copiedPlan.setType(plan2copy.getType());
+ copiedPlan.getLogisticChains().addAll(newPlanChains);
+ return copiedPlan;
+ }
+
+ /**
+ * This is used from {@link LSPControlerListener} and not meant to be used from user code. Users
+ * should bind {@link LSPScorerFactory}.
+ */
+ /* package-private */ void setScorer(LSPScorer scorer) {
+ this.scorer = scorer;
+ scorer.setEmbeddingContainer(this);
+ this.addSimulationTracker(scorer);
+ }
+
+ @Override
+ public void scheduleLogisticChains() {
+ logisticChainScheduler.scheduleLogisticChain();
+ }
+
+ @Override
+ public boolean addPlan(LSPPlan plan) {
+ for (LogisticChain solution : plan.getLogisticChains()) {
+ for (LogisticChainElement element : solution.getLogisticChainElements()) {
+ if (!resources.contains(element.getResource())) {
+ resources.add(element.getResource());
+ }
+ }
+ }
+ plan.setLSP(this);
+ return plans.add(plan);
+ }
+
+ @Override
+ public LSPPlan createCopyOfSelectedPlanAndMakeSelected() {
+ LSPPlan newPlan = LSPImpl.copyPlan(this.selectedPlan);
+ this.setSelectedPlan(newPlan);
+ return newPlan;
+ }
+
+ @Override
+ public ArrayList getPlans() {
+ return plans;
+ }
+
+ @Override
+ public LSPPlan getSelectedPlan() {
+ return selectedPlan;
+ }
+
+ @Override
+ public void setSelectedPlan(LSPPlan selectedPlan) {
+ if (!plans.contains(selectedPlan)) {
+ plans.add(selectedPlan);
+ }
+ this.selectedPlan = selectedPlan;
+ }
+
+ @Override
+ public boolean removePlan(LSPPlan plan) {
+ if (plans.contains(plan)) {
+ plans.remove(plan);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public Collection getResources() {
+ return resources;
+ }
+
+ public void scoreSelectedPlan() {
+ if (this.scorer != null) {
+ this.selectedPlan.setScore(scorer.getScoreForCurrentPlan());
+ } else {
+ throw new RuntimeException("trying to score the current LSP plan, but scorer is not set.");
+ }
+ }
+
+ @Override
+ public void assignShipmentToLSP(LSPShipment shipment) {
+ // shipment.setLspId(this.getId()); // und rückweg dann auch darüber und dann
+ // lsp.getselectedPlan.getShipment...
+ shipments.add(shipment);
+ for (LSPPlan lspPlan : plans) {
+ lspPlan.getAssigner().assignToPlan(lspPlan, shipment);
+ }
+ }
+
+ @Override
+ public Collection getShipments() {
+ return this.shipments;
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPModule.java b/src/main/java/org/matsim/freight/logistics/LSPModule.java
index 1f581551..afe76ac6 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPModule.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPModule.java
@@ -23,6 +23,7 @@
import com.google.inject.Provides;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
+import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
@@ -40,153 +41,207 @@
import org.matsim.core.replanning.ReplanningContext;
import org.matsim.core.replanning.selectors.PlanSelector;
import org.matsim.core.scoring.ScoringFunction;
-import org.matsim.freight.carriers.FreightCarriersConfigGroup;
import org.matsim.freight.carriers.Carrier;
import org.matsim.freight.carriers.Carriers;
+import org.matsim.freight.carriers.FreightCarriersConfigGroup;
import org.matsim.freight.carriers.controler.*;
-import java.util.List;
-
-
public class LSPModule extends AbstractModule {
- private static final Logger log = LogManager.getLogger(LSPModule.class);
-
-// private final FreightCarriersConfigGroup carrierConfig = new FreightCarriersConfigGroup();
-
- @Override
- public void install() {
- FreightCarriersConfigGroup freightConfig = ConfigUtils.addOrGetModule(getConfig(), FreightCarriersConfigGroup.class);
-
- bind(LSPControlerListener.class).in(Singleton.class);
- addControlerListenerBinding().to(LSPControlerListener.class);
-
- bind(CarrierControlerListener.class).in( Singleton.class );
- addControlerListenerBinding().to(CarrierControlerListener.class);
-
- bind( CarrierAgentTracker.class ).in( Singleton.class );
- addEventHandlerBinding().to( CarrierAgentTracker.class );
-
- // this switches on certain qsim components:
- QSimComponentsConfigGroup qsimComponents = ConfigUtils.addOrGetModule(getConfig(), QSimComponentsConfigGroup.class);
- List abc = qsimComponents.getActiveComponents();
- abc.add(FreightAgentSource.COMPONENT_NAME);
- switch (freightConfig.getTimeWindowHandling()) {
- case ignore:
- break;
- case enforceBeginnings:
-//// abc.add( WithinDayActivityReScheduling.COMPONENT_NAME );
- log.warn("LSP has never hedged against time window openings; this is probably wrong; but I don't know what to do ...");
-// break;
- default:
- throw new IllegalStateException("Unexpected value: " + freightConfig.getTimeWindowHandling());
- }
- qsimComponents.setActiveComponents(abc);
-
- // this installs qsim components, which are switched on (or not) via the above syntax:
- this.installQSimModule(new AbstractQSimModule() {
- @Override
- protected void configureQSim() {
- this.bind(FreightAgentSource.class).in(Singleton.class);
- this.addQSimComponentBinding(FreightAgentSource.COMPONENT_NAME).to(FreightAgentSource.class);
- switch (freightConfig.getTimeWindowHandling()) {
- case ignore:
- break;
- case enforceBeginnings:
-//// this.addQSimComponentBinding(WithinDayActivityReScheduling.COMPONENT_NAME).to( WithinDayActivityReScheduling.class );
- log.warn("LSP has never hedged against time window openings; this is probably wrong; but I don't know what to do ...");
-// break;
- default:
- throw new IllegalStateException("Unexpected value: " + freightConfig.getTimeWindowHandling());
- }
- }
- });
-
- // the scorers are necessary to run a zeroth iteration to the end:
- bind( CarrierScoringFunctionFactory.class ).to( CarrierScoringFactoryDummyImpl.class );
- bind( LSPScorerFactory.class ).to( LSPScoringFunctionFactoryDummyImpl.class );
-
- // for iterations, one needs to replace the following with something meaningful. If nothing else, there are "empty implementations" that do nothing. kai, jul'22
- bind( CarrierStrategyManager.class ).toProvider( ()->null );
- bind( LSPStrategyManager.class ).toProvider( ()->null );
-
- this.addControlerListenerBinding().to( DumpLSPPlans.class );
- }
-
- @Provides Carriers provideCarriers(LSPControlerListener lspControlerListener ) {
- return lspControlerListener.getCarriersFromLSP();
- }
-
- private static class LSPScoringFunctionFactoryDummyImpl implements LSPScorerFactory{
- @Override public LSPScorer createScoringFunction( ){
- return new LSPScorer(){
- @Override public double getScoreForCurrentPlan(){
- return Double.NEGATIVE_INFINITY;
- }
- @Override public void setEmbeddingContainer( LSP pointer ){
- }
- };
- }
- }
- private static class CarrierScoringFactoryDummyImpl implements CarrierScoringFunctionFactory {
- @Override public ScoringFunction createScoringFunction( Carrier carrier ){
- return new ScoringFunction(){
- @Override public void handleActivity( Activity activity ){
- }
- @Override public void handleLeg( Leg leg ){
- }
- @Override public void agentStuck( double time ){
- }
- @Override public void addMoney( double amount ){
- }
- @Override public void addScore( double amount ){
- }
- @Override public void finish(){
- }
- @Override public double getScore(){
- return Double.NEGATIVE_INFINITY;
- }
- @Override public void handleEvent( Event event ){
- }
- };
- }
- }
- public static final class LSPStrategyManagerEmptyImpl implements LSPStrategyManager {
-
- @Override public void addStrategy( GenericPlanStrategy strategy, String subpopulation, double weight ){
- throw new RuntimeException( "not implemented" );
- }
- @Override public void run( Iterable extends HasPlansAndId> persons, int iteration, ReplanningContext replanningContext ){
- log.warn("Running iterations without a strategy may lead to unclear results.");// "run" is possible, but will not do anything. kai, jul'22
- }
- @Override public void setMaxPlansPerAgent( int maxPlansPerAgent ){
- throw new RuntimeException( "not implemented" );
- }
- @Override public void addChangeRequest( int iteration, GenericPlanStrategy strategy, String subpopulation, double newWeight ){
- throw new RuntimeException( "not implemented" );
- }
- @Override public void setPlanSelectorForRemoval( PlanSelector planSelector ){
- throw new RuntimeException( "not implemented" );
- }
- @Override public List> getStrategies( String subpopulation ){
- throw new RuntimeException( "not implemented" );
- }
- @Override public List getWeights( String subpopulation ){
- throw new RuntimeException( "not implemented" );
- }
- }
-
- public static final class DumpLSPPlans implements BeforeMobsimListener {
- @Inject Scenario scenario;
- @Override public void notifyBeforeMobsim( BeforeMobsimEvent event ){
- LSPs lsps = LSPUtils.getLSPs( scenario );
- for( LSP lsp : lsps.getLSPs().values() ){
- log.warn("Dumping plan(s) of [LSP="+lsp.getId() + "] ; [No of plans=" + lsp.getPlans().size() + "]");
- for( LSPPlan plan : lsp.getPlans() ){
- log.warn( "[LSPPlan: " + plan.toString() + "]") ;
- }
- log.warn("Plan(s) of [LSP="+lsp.getId() + "] dumped.");
- }
- }
- }
-
+ private static final Logger log = LogManager.getLogger(LSPModule.class);
+
+ // private final FreightCarriersConfigGroup carrierConfig = new FreightCarriersConfigGroup();
+
+ @Override
+ public void install() {
+ FreightCarriersConfigGroup freightConfig =
+ ConfigUtils.addOrGetModule(getConfig(), FreightCarriersConfigGroup.class);
+
+ bind(LSPControlerListener.class).in(Singleton.class);
+ addControlerListenerBinding().to(LSPControlerListener.class);
+
+ bind(CarrierControlerListener.class).in(Singleton.class);
+ addControlerListenerBinding().to(CarrierControlerListener.class);
+
+ bind(CarrierAgentTracker.class).in(Singleton.class);
+ addEventHandlerBinding().to(CarrierAgentTracker.class);
+
+ // this switches on certain qsim components:
+ QSimComponentsConfigGroup qsimComponents =
+ ConfigUtils.addOrGetModule(getConfig(), QSimComponentsConfigGroup.class);
+ List abc = qsimComponents.getActiveComponents();
+ abc.add(FreightAgentSource.COMPONENT_NAME);
+ switch (freightConfig.getTimeWindowHandling()) {
+ case ignore:
+ break;
+ case enforceBeginnings:
+ //// abc.add( WithinDayActivityReScheduling.COMPONENT_NAME );
+ log.warn(
+ "LSP has never hedged against time window openings; this is probably wrong; but I don't know what to do ...");
+ // break;
+ default:
+ throw new IllegalStateException(
+ "Unexpected value: " + freightConfig.getTimeWindowHandling());
+ }
+ qsimComponents.setActiveComponents(abc);
+
+ // this installs qsim components, which are switched on (or not) via the above syntax:
+ this.installQSimModule(
+ new AbstractQSimModule() {
+ @Override
+ protected void configureQSim() {
+ this.bind(FreightAgentSource.class).in(Singleton.class);
+ this.addQSimComponentBinding(FreightAgentSource.COMPONENT_NAME)
+ .to(FreightAgentSource.class);
+ switch (freightConfig.getTimeWindowHandling()) {
+ case ignore:
+ break;
+ case enforceBeginnings:
+ ////
+ // this.addQSimComponentBinding(WithinDayActivityReScheduling.COMPONENT_NAME).to(
+ // WithinDayActivityReScheduling.class );
+ log.warn(
+ "LSP has never hedged against time window openings; this is probably wrong; but I don't know what to do ...");
+ // break;
+ default:
+ throw new IllegalStateException(
+ "Unexpected value: " + freightConfig.getTimeWindowHandling());
+ }
+ }
+ });
+
+ // the scorers are necessary to run a zeroth iteration to the end:
+ bind(CarrierScoringFunctionFactory.class).to(CarrierScoringFactoryDummyImpl.class);
+ bind(LSPScorerFactory.class).to(LSPScoringFunctionFactoryDummyImpl.class);
+
+ // for iterations, one needs to replace the following with something meaningful. If nothing
+ // else, there are "empty implementations" that do nothing. kai, jul'22
+ bind(CarrierStrategyManager.class).toProvider(() -> null);
+ bind(LSPStrategyManager.class).toProvider(() -> null);
+
+ this.addControlerListenerBinding().to(DumpLSPPlans.class);
+ }
+
+ @Provides
+ Carriers provideCarriers(LSPControlerListener lspControlerListener) {
+ return lspControlerListener.getCarriersFromLSP();
+ }
+
+ private static class LSPScoringFunctionFactoryDummyImpl implements LSPScorerFactory {
+ @Override
+ public LSPScorer createScoringFunction() {
+ return new LSPScorer() {
+ @Override
+ public double getScoreForCurrentPlan() {
+ return Double.NEGATIVE_INFINITY;
+ }
+
+ @Override
+ public void setEmbeddingContainer(LSP pointer) {}
+ };
+ }
+ }
+
+ private static class CarrierScoringFactoryDummyImpl implements CarrierScoringFunctionFactory {
+ @Override
+ public ScoringFunction createScoringFunction(Carrier carrier) {
+ return new ScoringFunction() {
+ @Override
+ public void handleActivity(Activity activity) {}
+
+ @Override
+ public void handleLeg(Leg leg) {}
+
+ @Override
+ public void agentStuck(double time) {}
+
+ @Override
+ public void addMoney(double amount) {}
+
+ @Override
+ public void addScore(double amount) {}
+
+ @Override
+ public void finish() {}
+
+ @Override
+ public double getScore() {
+ return Double.NEGATIVE_INFINITY;
+ }
+
+ @Override
+ public void handleEvent(Event event) {}
+ };
+ }
+ }
+
+ public static final class LSPStrategyManagerEmptyImpl implements LSPStrategyManager {
+
+ @Override
+ public void addStrategy(
+ GenericPlanStrategy strategy, String subpopulation, double weight) {
+ throw new RuntimeException("not implemented");
+ }
+
+ @Override
+ public void run(
+ Iterable extends HasPlansAndId> persons,
+ int iteration,
+ ReplanningContext replanningContext) {
+ log.warn("Running iterations without a strategy may lead to unclear results."); // "run" is
+ // possible, but
+ // will not do
+ // anything. kai,
+ // jul'22
+ }
+
+ @Override
+ public void setMaxPlansPerAgent(int maxPlansPerAgent) {
+ throw new RuntimeException("not implemented");
+ }
+
+ @Override
+ public void addChangeRequest(
+ int iteration,
+ GenericPlanStrategy strategy,
+ String subpopulation,
+ double newWeight) {
+ throw new RuntimeException("not implemented");
+ }
+
+ @Override
+ public void setPlanSelectorForRemoval(PlanSelector planSelector) {
+ throw new RuntimeException("not implemented");
+ }
+
+ @Override
+ public List> getStrategies(String subpopulation) {
+ throw new RuntimeException("not implemented");
+ }
+
+ @Override
+ public List getWeights(String subpopulation) {
+ throw new RuntimeException("not implemented");
+ }
+ }
+
+ public static final class DumpLSPPlans implements BeforeMobsimListener {
+ @Inject Scenario scenario;
+
+ @Override
+ public void notifyBeforeMobsim(BeforeMobsimEvent event) {
+ LSPs lsps = LSPUtils.getLSPs(scenario);
+ for (LSP lsp : lsps.getLSPs().values()) {
+ log.warn(
+ "Dumping plan(s) of [LSP="
+ + lsp.getId()
+ + "] ; [No of plans="
+ + lsp.getPlans().size()
+ + "]");
+ for (LSPPlan plan : lsp.getPlans()) {
+ log.warn("[LSPPlan: " + plan.toString() + "]");
+ }
+ log.warn("Plan(s) of [LSP=" + lsp.getId() + "] dumped.");
+ }
+ }
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPPlan.java b/src/main/java/org/matsim/freight/logistics/LSPPlan.java
index 2acdbc0d..4f1f6fd5 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPPlan.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPPlan.java
@@ -20,36 +20,40 @@
package org.matsim.freight.logistics;
+import java.util.Collection;
+import org.matsim.api.core.v01.population.BasicPlan;
import org.matsim.freight.logistics.shipment.LSPShipment;
import org.matsim.freight.logistics.shipment.ShipmentPlan;
-import org.matsim.api.core.v01.population.BasicPlan;
-
-import java.util.Collection;
/**
- * This interface has the following properties:
- *
As a {@link BasicPlan} it has a score, so it can be used for evolutionary learning. kai, may'22
- *
An {@link LSPShipment} is added via lspPlan#getAssigner().assignToSolution(shipment). The {@link ShipmentAssigner} assigns it deterministically to a {@link LogisticChain}.
+ * This interface has the following properties:
+ *
+ *
+ *
As a {@link BasicPlan} it has a score, so it can be used for evolutionary learning. kai,
+ * may'22
+ *
An {@link LSPShipment} is added via lspPlan#getAssigner().assignToSolution(shipment). The
+ * {@link ShipmentAssigner} assigns it deterministically to a {@link LogisticChain}.
*
*/
public interface LSPPlan extends BasicPlan, KnowsLSP {
- LSPPlan addLogisticChain(LogisticChain solution);
+ LSPPlan addLogisticChain(LogisticChain solution);
- Collection getLogisticChains();
+ Collection getLogisticChains();
- /**
- * yy My intuition would be to replace lspPlan#getAssigner().assignToSolution( shipment ) by lspPlan.addShipment( shipment ). kai, may'22
- */
- ShipmentAssigner getAssigner();
+ /**
+ * yy My intuition would be to replace lspPlan#getAssigner().assignToSolution( shipment ) by
+ * lspPlan.addShipment( shipment ). kai, may'22
+ */
+ ShipmentAssigner getAssigner();
- LSPPlan setAssigner(ShipmentAssigner assigner);
+ LSPPlan setAssigner(ShipmentAssigner assigner);
- Collection getShipmentPlans();
- LSPPlan addShipmentPlan(ShipmentPlan shipmentPlan);
+ Collection getShipmentPlans();
- String getType();
+ LSPPlan addShipmentPlan(ShipmentPlan shipmentPlan);
- void setType(final String type);
+ String getType();
+ void setType(final String type);
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPPlanImpl.java b/src/main/java/org/matsim/freight/logistics/LSPPlanImpl.java
index 9af9ae38..590607e4 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPPlanImpl.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPPlanImpl.java
@@ -1,4 +1,3 @@
-
/*
* *********************************************************************** *
* * project: org.matsim.*
@@ -21,109 +20,116 @@
package org.matsim.freight.logistics;
-import org.matsim.freight.logistics.shipment.ShipmentPlan;
-
import java.util.ArrayList;
import java.util.Collection;
+import org.matsim.freight.logistics.shipment.ShipmentPlan;
public class LSPPlanImpl implements LSPPlan {
- private final Collection logisticChains;
- private final Collection shipmentPlans;
- private LSP lsp;
- private Double score = null;
- private ShipmentAssigner assigner;
- private String type = null;
-
- public LSPPlanImpl() {
- this.logisticChains = new ArrayList<>();
- this.shipmentPlans = new ArrayList<>();
- }
-
- @Override
- public LSPPlan addLogisticChain(LogisticChain solution) {
- this.logisticChains.add(solution);
- solution.setLSP(this.lsp);
- return this;
- }
-
- @Override
- public Collection getLogisticChains() {
- return logisticChains;
- }
-
- @Override
- public ShipmentAssigner getAssigner() {
- return assigner;
- }
-
- @Override
- public LSPPlan setAssigner(ShipmentAssigner assigner) {
- this.assigner = assigner;
- this.assigner.setLSP(this.lsp);
- return this;
- }
-
- @Override public Collection getShipmentPlans() {
- return this.shipmentPlans;
- }
-
- @Override public LSPPlan addShipmentPlan(ShipmentPlan shipmentPlan) {
- this.shipmentPlans.add(shipmentPlan);
- return null;
- }
-
- @Override
- public Double getScore() {
- return score;
- }
-
- @Override
- public void setScore(Double score) {
- this.score = score;
- }
-
- @Override
- public String getType() {
- return this.type;
- }
-
- @Override
- public void setType(final String type) {
- this.type = type;
- }
-
- @Override
- public LSP getLSP() {
- return lsp;
- }
-
- @Override
- public void setLSP(LSP lsp) {
- this.lsp = lsp;
- if (assigner != null) {
- this.assigner.setLSP(lsp);
- // yy vom Design her wäre es vlt. einfacher und logischer, wenn der assigner einen backpointer auf den LSPPlan hätte. Dann
- // müsste man nicht (wie hier) hedgen gegen unterschiedliche Initialisierungssequenzen. kai, may'22
- }
- for (LogisticChain solution : logisticChains) {
- solution.setLSP(lsp);
- }
- }
-
- @Override public String toString() {
- StringBuilder strb = new StringBuilder();
- strb.append("[score=").append(this.score).append("]");
- strb.append(", [type=").append(this.type).append("]");
- for (LogisticChain logisticChain : this.logisticChains) {
- strb.append(", [LogisticChainId=").append(logisticChain.getId()).append("], [No of LogisticChainElements=").append(logisticChain.getLogisticChainElements().size()).append("] \n");
- if (!logisticChain.getLogisticChainElements().isEmpty()){
- for (LogisticChainElement solutionElement : logisticChain.getLogisticChainElements()) {
- strb.append("\t \t").append(solutionElement.toString()).append("\n");
- }
- }
- }
- return strb.toString();
- }
-
+ private final Collection logisticChains;
+ private final Collection shipmentPlans;
+ private LSP lsp;
+ private Double score = null;
+ private ShipmentAssigner assigner;
+ private String type = null;
+
+ public LSPPlanImpl() {
+ this.logisticChains = new ArrayList<>();
+ this.shipmentPlans = new ArrayList<>();
+ }
+
+ @Override
+ public LSPPlan addLogisticChain(LogisticChain solution) {
+ this.logisticChains.add(solution);
+ solution.setLSP(this.lsp);
+ return this;
+ }
+
+ @Override
+ public Collection getLogisticChains() {
+ return logisticChains;
+ }
+
+ @Override
+ public ShipmentAssigner getAssigner() {
+ return assigner;
+ }
+
+ @Override
+ public LSPPlan setAssigner(ShipmentAssigner assigner) {
+ this.assigner = assigner;
+ this.assigner.setLSP(this.lsp);
+ return this;
+ }
+
+ @Override
+ public Collection getShipmentPlans() {
+ return this.shipmentPlans;
+ }
+
+ @Override
+ public LSPPlan addShipmentPlan(ShipmentPlan shipmentPlan) {
+ this.shipmentPlans.add(shipmentPlan);
+ return null;
+ }
+
+ @Override
+ public Double getScore() {
+ return score;
+ }
+
+ @Override
+ public void setScore(Double score) {
+ this.score = score;
+ }
+
+ @Override
+ public String getType() {
+ return this.type;
+ }
+
+ @Override
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ @Override
+ public LSP getLSP() {
+ return lsp;
+ }
+
+ @Override
+ public void setLSP(LSP lsp) {
+ this.lsp = lsp;
+ if (assigner != null) {
+ this.assigner.setLSP(lsp);
+ // yy vom Design her wäre es vlt. einfacher und logischer, wenn der assigner einen backpointer
+ // auf den LSPPlan hätte. Dann
+ // müsste man nicht (wie hier) hedgen gegen unterschiedliche Initialisierungssequenzen. kai,
+ // may'22
+ }
+ for (LogisticChain solution : logisticChains) {
+ solution.setLSP(lsp);
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder strb = new StringBuilder();
+ strb.append("[score=").append(this.score).append("]");
+ strb.append(", [type=").append(this.type).append("]");
+ for (LogisticChain logisticChain : this.logisticChains) {
+ strb.append(", [LogisticChainId=")
+ .append(logisticChain.getId())
+ .append("], [No of LogisticChainElements=")
+ .append(logisticChain.getLogisticChainElements().size())
+ .append("] \n");
+ if (!logisticChain.getLogisticChainElements().isEmpty()) {
+ for (LogisticChainElement solutionElement : logisticChain.getLogisticChainElements()) {
+ strb.append("\t \t").append(solutionElement.toString()).append("\n");
+ }
+ }
+ }
+ return strb.toString();
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPRescheduler.java b/src/main/java/org/matsim/freight/logistics/LSPRescheduler.java
index e69de29b..8b137891 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPRescheduler.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPRescheduler.java
@@ -0,0 +1 @@
+
diff --git a/src/main/java/org/matsim/freight/logistics/LSPResource.java b/src/main/java/org/matsim/freight/logistics/LSPResource.java
index 9997d5e0..4f1e595e 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPResource.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPResource.java
@@ -20,24 +20,21 @@
package org.matsim.freight.logistics;
+import java.util.Collection;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Identifiable;
import org.matsim.api.core.v01.network.Link;
import org.matsim.utils.objectattributes.attributable.Attributable;
-import java.util.Collection;
-
-/**
- *
- */
-public interface LSPResource extends Identifiable, HasSimulationTrackers, Attributable {
-
- Id getStartLinkId();
+/** */
+public interface LSPResource
+ extends Identifiable, HasSimulationTrackers, Attributable {
- Id getEndLinkId();
+ Id getStartLinkId();
- Collection getClientElements();
+ Id getEndLinkId();
- void schedule(int bufferTime, LSPPlan lspPlan);
+ Collection getClientElements();
+ void schedule(int bufferTime, LSPPlan lspPlan);
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPResourceScheduler.java b/src/main/java/org/matsim/freight/logistics/LSPResourceScheduler.java
index 27252990..6b489e23 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPResourceScheduler.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPResourceScheduler.java
@@ -20,97 +20,89 @@
package org.matsim.freight.logistics;
-import org.matsim.freight.logistics.shipment.LSPShipment;
-import org.matsim.freight.logistics.shipment.ShipmentUtils;
-
import java.util.ArrayList;
import java.util.Comparator;
+import org.matsim.freight.logistics.shipment.LSPShipment;
+import org.matsim.freight.logistics.shipment.ShipmentUtils;
/**
* Resources are scheduled separately by calling their individual scheduling algorithm.
- *
- * Within this algorithm, some methods are abstract, whereas others
- * have a default implementation for forward scheduling.
- * The former ones are specified in a suitable way by the corresponding Resource whereas the latter are only specified in
- * the abstract parent class in order to coordinate the way in which the LSPShipments are
- * handed over between subsequent Resources.
- * The abstract methods deal with aspects that are specific to the Resource which
- * contains the implementation of the ResourceScheduler.
- *
- * Forwarding of LSPShipments is done by the two methods
- * presortIncomingShipments() and switchHandledShipments(int bufferTime).
+ *
+ *
Within this algorithm, some methods are abstract, whereas others have a default implementation
+ * for forward scheduling. The former ones are specified in a suitable way by the corresponding
+ * Resource whereas the latter are only specified in the abstract parent class in order to
+ * coordinate the way in which the LSPShipments are handed over between subsequent Resources. The
+ * abstract methods deal with aspects that are specific to the Resource which contains the
+ * implementation of the ResourceScheduler.
+ *
+ *
Forwarding of LSPShipments is done by the two methods presortIncomingShipments() and
+ * switchHandledShipments(int bufferTime).
*/
public abstract class LSPResourceScheduler {
- protected LSPResource resource;
- protected ArrayList lspShipmentsWithTime;
-
- protected LSPPlan lspPlan;
-
-
- public final void scheduleShipments(LSPPlan lspPlan, LSPResource resource, int bufferTime) {
- this.lspPlan = lspPlan;
- this.resource = resource;
- this.lspShipmentsWithTime = new ArrayList<>();
- initializeValues(resource);
- presortIncomingShipments();
- scheduleResource();
- updateShipments();
- switchHandeledShipments(bufferTime);
- lspShipmentsWithTime.clear();
- }
-
- /**
- * Is in charge of the initialization of the actual
- * scheduling process for the concerned Resource. Depending on the concrete shape
- * of this process, there are mainly values to be deleted that are still stored from the
- * previous iteration or the infrastructure for the used algorithm has to be set up.
- *
- * @param resource
- */
- protected abstract void initializeValues(LSPResource resource);
-
- /**
- * Controls the actual scheduling process that depends on the shape
- * and task of the Resource.
- */
- protected abstract void scheduleResource();
-
- /**
- * Endows the involved {@link LSPShipment}s with information that resulted
- * from the scheduling in a narrow sense in scheduleResource(). The information
- * can be divided into two main components.
- * 1.) the schedule of the {@link LSPShipment}s is updated if necessary
- * 2.) the information for a later logging of the is added.
- */
- protected abstract void updateShipments();
-
- private final void presortIncomingShipments() {
- this.lspShipmentsWithTime = new ArrayList<>();
- for (LogisticChainElement element : resource.getClientElements()) {
- lspShipmentsWithTime.addAll(element.getIncomingShipments().getShipments());
- }
- lspShipmentsWithTime.sort(Comparator.comparingDouble(LspShipmentWithTime::getTime));
- }
-
-
- private final void switchHandeledShipments(int bufferTime) {
- for (LspShipmentWithTime lspShipmentWithTime : lspShipmentsWithTime) {
- var shipmentPlan = ShipmentUtils.getOrCreateShipmentPlan(lspPlan, lspShipmentWithTime.getShipment().getId());
- double endOfTransportTime = shipmentPlan.getMostRecentEntry().getEndTime() + bufferTime;
- LspShipmentWithTime outgoingTuple = new LspShipmentWithTime(endOfTransportTime, lspShipmentWithTime.getShipment());
- for (LogisticChainElement element : resource.getClientElements()) {
- if (element.getIncomingShipments().getShipments().contains(lspShipmentWithTime)) {
- element.getOutgoingShipments().getShipments().add(outgoingTuple);
- element.getIncomingShipments().getShipments().remove(lspShipmentWithTime);
- if (element.getNextElement() != null) {
- element.getNextElement().getIncomingShipments().getShipments().add(outgoingTuple);
- element.getOutgoingShipments().getShipments().remove(outgoingTuple);
- }
- }
- }
- }
- }
-
-
+ protected LSPResource resource;
+ protected ArrayList lspShipmentsWithTime;
+
+ protected LSPPlan lspPlan;
+
+ public final void scheduleShipments(LSPPlan lspPlan, LSPResource resource, int bufferTime) {
+ this.lspPlan = lspPlan;
+ this.resource = resource;
+ this.lspShipmentsWithTime = new ArrayList<>();
+ initializeValues(resource);
+ presortIncomingShipments();
+ scheduleResource();
+ updateShipments();
+ switchHandeledShipments(bufferTime);
+ lspShipmentsWithTime.clear();
+ }
+
+ /**
+ * Is in charge of the initialization of the actual scheduling process for the concerned Resource.
+ * Depending on the concrete shape of this process, there are mainly values to be deleted that are
+ * still stored from the previous iteration or the infrastructure for the used algorithm has to be
+ * set up.
+ *
+ * @param resource
+ */
+ protected abstract void initializeValues(LSPResource resource);
+
+ /** Controls the actual scheduling process that depends on the shape and task of the Resource. */
+ protected abstract void scheduleResource();
+
+ /**
+ * Endows the involved {@link LSPShipment}s with information that resulted from the scheduling in
+ * a narrow sense in scheduleResource(). The information can be divided into two main components.
+ * 1.) the schedule of the {@link LSPShipment}s is updated if necessary 2.) the information for a
+ * later logging of the is added.
+ */
+ protected abstract void updateShipments();
+
+ private final void presortIncomingShipments() {
+ this.lspShipmentsWithTime = new ArrayList<>();
+ for (LogisticChainElement element : resource.getClientElements()) {
+ lspShipmentsWithTime.addAll(element.getIncomingShipments().getShipments());
+ }
+ lspShipmentsWithTime.sort(Comparator.comparingDouble(LspShipmentWithTime::getTime));
+ }
+
+ private final void switchHandeledShipments(int bufferTime) {
+ for (LspShipmentWithTime lspShipmentWithTime : lspShipmentsWithTime) {
+ var shipmentPlan =
+ ShipmentUtils.getOrCreateShipmentPlan(lspPlan, lspShipmentWithTime.getShipment().getId());
+ double endOfTransportTime = shipmentPlan.getMostRecentEntry().getEndTime() + bufferTime;
+ LspShipmentWithTime outgoingTuple =
+ new LspShipmentWithTime(endOfTransportTime, lspShipmentWithTime.getShipment());
+ for (LogisticChainElement element : resource.getClientElements()) {
+ if (element.getIncomingShipments().getShipments().contains(lspShipmentWithTime)) {
+ element.getOutgoingShipments().getShipments().add(outgoingTuple);
+ element.getIncomingShipments().getShipments().remove(lspShipmentWithTime);
+ if (element.getNextElement() != null) {
+ element.getNextElement().getIncomingShipments().getShipments().add(outgoingTuple);
+ element.getOutgoingShipments().getShipments().remove(outgoingTuple);
+ }
+ }
+ }
+ }
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPScorer.java b/src/main/java/org/matsim/freight/logistics/LSPScorer.java
index 65c0b4ea..4f4916c0 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPScorer.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPScorer.java
@@ -27,14 +27,17 @@
import org.matsim.freight.carriers.Carrier;
/**
- * This is somewhat similar to the MATSim core {@link ScoringFunction}, which is also used for {@link Carrier}s. A difference, however, is that it
- * does not implement the separate methods {@link ScoringFunction#handleActivity(Activity)} etc., but is just an {@link EventHandler} and a {@link
- * ControlerListener}. (This is, in some sense, the old design for {@link ScoringFunction}, and one, where I am still not sure if the new design is
- * truly better.) In any case, here there is not a question: LSP scoring is not so much about activities and legs, since those are handled through
- * the carrier scoring, and need to be pulled in by the lsp scoring if the company is vertically integrated (i.e. if the LSP owns its carriers).
+ * This is somewhat similar to the MATSim core {@link ScoringFunction}, which is also used for
+ * {@link Carrier}s. A difference, however, is that it does not implement the separate methods
+ * {@link ScoringFunction#handleActivity(Activity)} etc., but is just an {@link EventHandler} and a
+ * {@link ControlerListener}. (This is, in some sense, the old design for {@link ScoringFunction},
+ * and one, where I am still not sure if the new design is truly better.) In any case, here there is
+ * not a question: LSP scoring is not so much about activities and legs, since those are handled
+ * through the carrier scoring, and need to be pulled in by the lsp scoring if the company is
+ * vertically integrated (i.e. if the LSP owns its carriers).
*
- * also @see {@link LSPScorerFactory}
+ *
also @see {@link LSPScorerFactory}
*/
public interface LSPScorer extends LSPSimulationTracker {
- double getScoreForCurrentPlan();
+ double getScoreForCurrentPlan();
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPScorerFactory.java b/src/main/java/org/matsim/freight/logistics/LSPScorerFactory.java
index f6dbf8ea..e5a5d7ea 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPScorerFactory.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPScorerFactory.java
@@ -3,5 +3,5 @@
import org.matsim.core.api.internal.MatsimFactory;
public interface LSPScorerFactory extends MatsimFactory {
- LSPScorer createScoringFunction( );
+ LSPScorer createScoringFunction();
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPSimulationTracker.java b/src/main/java/org/matsim/freight/logistics/LSPSimulationTracker.java
index ef3bf863..55d967c2 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPSimulationTracker.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPSimulationTracker.java
@@ -24,7 +24,9 @@
import org.matsim.core.controler.listener.ControlerListener;
import org.matsim.core.events.handler.EventHandler;
-public interface LSPSimulationTracker extends ControlerListener, EventHandler, HasBackpointer {
- // 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 ){};
+public interface LSPSimulationTracker
+ extends ControlerListener, EventHandler, HasBackpointer {
+ // 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) {}
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPStrategyManager.java b/src/main/java/org/matsim/freight/logistics/LSPStrategyManager.java
index e8690296..79d7c5a6 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPStrategyManager.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPStrategyManager.java
@@ -25,16 +25,20 @@
import org.matsim.core.replanning.GenericStrategyManager;
/**
- * The current (jul'22) logic of this is:
- *
There is a null binding of this interface in {@link LSPModule}. If one wants to use strategies, this needs to be overwritten.
- *
Normally, the strategy manager is fixed infrastructure, and should just be configured. However, since it is not yet there before
- * injection, it also cannot be configured before injection. Core matsim solves that by writing the corresponding configuration into the
- * config. We could, in principle, do the same here. Don't want to do this yet.
- *
So way to configure this "in code" is to bind {@link LSPStrategyManager} to a {@link Provider } and then
- * configure it in the provider.
+ * The current (jul'22) logic of this is:
+ *
+ *
+ *
There is a null binding of this interface in {@link LSPModule}. If one wants to use
+ * strategies, this needs to be overwritten.
+ *
Normally, the strategy manager is fixed infrastructure, and should just be configured.
+ * However, since it is not yet there before injection, it also cannot be configured before
+ * injection. Core matsim solves that by writing the corresponding configuration into the
+ * config. We could, in principle, do the same here. Don't want to do this yet.
+ *
So way to configure this "in code" is to bind {@link LSPStrategyManager} to a {@link
+ * Provider } and then configure it in the provider.
*
*/
public interface LSPStrategyManager extends GenericStrategyManager {
- // (this is mostly there so that it can be guice-bound. kai, jul'22)
+ // (this is mostly there so that it can be guice-bound. kai, jul'22)
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPStrategyManagerImpl.java b/src/main/java/org/matsim/freight/logistics/LSPStrategyManagerImpl.java
index 450e25e9..f628d4f2 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPStrategyManagerImpl.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPStrategyManagerImpl.java
@@ -1,5 +1,6 @@
package org.matsim.freight.logistics;
+import java.util.List;
import org.matsim.api.core.v01.population.HasPlansAndId;
import org.matsim.core.replanning.GenericPlanStrategy;
import org.matsim.core.replanning.GenericStrategyManager;
@@ -7,10 +8,10 @@
import org.matsim.core.replanning.ReplanningContext;
import org.matsim.core.replanning.selectors.PlanSelector;
-import java.util.List;
-
/**
- * Normally, this would be infrastructure that is configurable via the config. Since we ain't there yet, the way to configure this is something like:
+ * Normally, this would be infrastructure that is configurable via the config. Since we ain't there
+ * yet, the way to configure this is something like:
+ *
*
* bind( LSPStrategyManager.class ).to( new Provider() {
* public LSPStrategyManager.get() {
@@ -22,27 +23,49 @@
* }
*
*/
-public class LSPStrategyManagerImpl implements LSPStrategyManager{
- final GenericStrategyManager delegate = new GenericStrategyManagerImpl<>();
- @Override public void addStrategy( GenericPlanStrategy strategy, String subpopulation, double weight ){
- delegate.addStrategy( strategy, subpopulation, weight );
- }
- @Override public void run( Iterable extends HasPlansAndId> persons, int iteration, ReplanningContext replanningContext ){
- delegate.run( persons, iteration, replanningContext );
- }
- @Override public void setMaxPlansPerAgent( int maxPlansPerAgent ){
- delegate.setMaxPlansPerAgent( maxPlansPerAgent );
- }
- @Override public void addChangeRequest( int iteration, GenericPlanStrategy strategy, String subpopulation, double newWeight ){
- delegate.addChangeRequest( iteration, strategy, subpopulation, newWeight );
- }
- @Override public void setPlanSelectorForRemoval( PlanSelector planSelector ){
- delegate.setPlanSelectorForRemoval( planSelector );
- }
- @Override public List> getStrategies( String subpopulation ){
- return delegate.getStrategies( subpopulation );
- }
- @Override public List getWeights( String subpopulation ){
- return delegate.getWeights( subpopulation );
- }
+public class LSPStrategyManagerImpl implements LSPStrategyManager {
+ final GenericStrategyManager delegate = new GenericStrategyManagerImpl<>();
+
+ @Override
+ public void addStrategy(
+ GenericPlanStrategy strategy, String subpopulation, double weight) {
+ delegate.addStrategy(strategy, subpopulation, weight);
+ }
+
+ @Override
+ public void run(
+ Iterable extends HasPlansAndId> persons,
+ int iteration,
+ ReplanningContext replanningContext) {
+ delegate.run(persons, iteration, replanningContext);
+ }
+
+ @Override
+ public void setMaxPlansPerAgent(int maxPlansPerAgent) {
+ delegate.setMaxPlansPerAgent(maxPlansPerAgent);
+ }
+
+ @Override
+ public void addChangeRequest(
+ int iteration,
+ GenericPlanStrategy strategy,
+ String subpopulation,
+ double newWeight) {
+ delegate.addChangeRequest(iteration, strategy, subpopulation, newWeight);
+ }
+
+ @Override
+ public void setPlanSelectorForRemoval(PlanSelector planSelector) {
+ delegate.setPlanSelectorForRemoval(planSelector);
+ }
+
+ @Override
+ public List> getStrategies(String subpopulation) {
+ return delegate.getStrategies(subpopulation);
+ }
+
+ @Override
+ public List getWeights(String subpopulation) {
+ return delegate.getWeights(subpopulation);
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPUtils.java b/src/main/java/org/matsim/freight/logistics/LSPUtils.java
index 77ac0f5f..9424cefb 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPUtils.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPUtils.java
@@ -20,231 +20,237 @@
package org.matsim.freight.logistics;
-import org.matsim.freight.logistics.shipment.LSPShipment;
-import org.matsim.freight.logistics.shipment.ShipmentPlan;
+import java.util.ArrayList;
+import java.util.Collection;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
-import org.matsim.freight.carriers.CarriersUtils;
import org.matsim.freight.carriers.Carriers;
+import org.matsim.freight.carriers.CarriersUtils;
+import org.matsim.freight.logistics.shipment.LSPShipment;
+import org.matsim.freight.logistics.shipment.ShipmentPlan;
import org.matsim.utils.objectattributes.attributable.Attributable;
-import java.util.ArrayList;
-import java.util.Collection;
-
public final class LSPUtils {
- private static final String lspsString = "lsps";
-
- private LSPUtils() {
- } // do not instantiate
-
- public static LSPPlan createLSPPlan() {
- return new LSPPlanImpl();
- }
-
- public static LogisticChainScheduler createForwardLogisiticChainScheduler() {
- return new ForwardLogisticChainSchedulerImpl();
- }
-
- public static WaitingShipments createWaitingShipments() {
- return new WaitingShipmentsImpl();
- }
-
- public static void addLSPs(Scenario scenario, LSPs lsps) {
- Carriers carriers = CarriersUtils.addOrGetCarriers( scenario );
- //Register carriers from all lsps
- for (LSP lsp : lsps.getLSPs().values()){
- for (LSPResource lspResource : lsp.getResources()) {
- if (lspResource instanceof LSPCarrierResource lspCarrierResource) {
- carriers.addCarrier(lspCarrierResource.getCarrier());
- }
- }
- }
- scenario.addScenarioElement(lspsString, lsps);
- }
-
- public static LSPs getLSPs(Scenario scenario) {
- Object result = scenario.getScenarioElement(lspsString);
- if (result == null) {
- throw new RuntimeException("there is no scenario element of type " + lspsString +
- ". You will need something like LSPUtils.addLSPs( scenario, lsps) somewhere.");
- }
- return (LSPs) result;
- }
-
- public static Double getVariableCost(Attributable attributable) {
- return (Double) attributable.getAttributes().getAttribute("variableCost");
- }
-
- public static void setVariableCost(Attributable attributable, Double variableCost) {
- attributable.getAttributes().putAttribute("variableCost", variableCost);
- }
-
- public static Double getFixedCost(Attributable attributable) {
- return (Double) attributable.getAttributes().getAttribute("fixedCost");
- }
- // The following would be closer to how we have done it elsewhere (scenario containers are mutable). kai, may'22'
-// public static LSPs createOrGetLPSs( Scenario scenario ){
-// Object result = scenario.getScenarioElement( lspsString );
-// LSPs lsps;
-// if ( result != null ) {
-// lsps = (LSPs) result;
-// } else {
-// lsps = new LSPs( );
-// scenario.addScenarioElement( lspsString, lsps );
-// }
-// return lsps;
-// }
-
- public static void setFixedCost(Attributable attributable, Double fixedCost) {
- attributable.getAttributes().putAttribute("fixedCost", fixedCost);
- }
-
- public static final class LSPBuilder {
- final Collection resources;
- final Id id;
- LogisticChainScheduler logisticChainScheduler;
- LSPPlan initialPlan;
-
- private LSPBuilder(Id id) {
- this.id = id; // this line was not there until today. kai, may'22
- this.resources = new ArrayList<>();
- }
-
- public static LSPBuilder getInstance(Id id) {
- return new LSPBuilder(id);
- }
-
- public LSPBuilder setLogisticChainScheduler(LogisticChainScheduler logisticChainScheduler) {
- this.logisticChainScheduler = logisticChainScheduler;
- return this;
- }
-
-// /**
-// * @deprecated -- It feels attractive to attach this to the "agent". A big disadvantage with this approach, however, is that
-// * we cannot use injection ... since we cannot inject as many scorers as we have agents. (At least this is what I think.) Which means
-// * that the approach in matsim core and in carriers to have XxxScoringFunctionFactory is better for what we are doing here. yyyyyy So
-// * this needs to be changed. kai, jul'22
-// */
-// public LSPBuilder setSolutionScorer(LSPScorer scorer) {
-// this.scorer = scorer;
-// return this;
-// }
-
-// /**
-// * @deprecated -- It feels attractive to attach this to the "agent". A big disadvantage with this approach, however, is that
-// * we cannot use injection ... since we cannot inject as many replanners as we have agents. (At least this is what I think.) yyyyyy So
-// * this needs to be changed. kai, jul'22
-// */
-// public LSPBuilder setReplanner(LSPReplanner replanner) {
-// this.replanner = replanner;
-// return this;
-// }
- // never used. Thus disabling it. kai, jul'22
-
-
- public LSPBuilder setInitialPlan(LSPPlan plan) {
- this.initialPlan = plan;
- for (LogisticChain solution : plan.getLogisticChains()) {
- for (LogisticChainElement element : solution.getLogisticChainElements()) {
- if (!resources.contains(element.getResource())) {
- resources.add(element.getResource());
- }
- }
- }
- return this;
- }
-
-
- public LSP build() {
- return new LSPImpl(this);
- }
- }
-
- public static final class LogisticChainBuilder {
- final Id id;
- final Collection elements;
- // final Collection eventHandlers;
- final Collection> trackers;
-
- private LogisticChainBuilder(Id id) {
- this.elements = new ArrayList<>();
- this.trackers = new ArrayList>();
- this.id = id;
- }
-
- public static LogisticChainBuilder newInstance(Id id) {
- return new LogisticChainBuilder(id);
- }
-
- public LogisticChainBuilder addLogisticChainElement(LogisticChainElement element) {
- elements.add(element);
- return this;
- }
-
- public LogisticChainBuilder addTracker(LSPSimulationTracker tracker) {
- trackers.add(tracker);
- return this;
- }
-
- public LogisticChain build() {
- return new LogisticChainImpl(this);
- }
- }
-
- public static final class LogisticChainElementBuilder {
- final Id id;
- final WaitingShipments incomingShipments;
- final WaitingShipments outgoingShipments;
- LSPResource resource;
-
- private LogisticChainElementBuilder(Id id) {
- this.id = id;
- this.incomingShipments = createWaitingShipments();
- this.outgoingShipments = createWaitingShipments();
- }
-
- public static LogisticChainElementBuilder newInstance(Id id) {
- return new LogisticChainElementBuilder(id);
- }
-
- public LogisticChainElementBuilder setResource(LSPResource resource) {
- this.resource = resource;
- return this;
- }
-
- public LogisticChainElement build() {
- return new LogisticChainElementImpl(this);
- }
- }
-
- /**
- * Gives back the {@link LSPShipment} object of the {@link LSP}, which matches to the shipmentId
- * @param lsp In this LSP this method tries to find the shipment.
- * @param shipmentId Id of the shipment that should be found.
- * @return the lspShipment object or null, if it is not found.
- */
- public static LSPShipment findLspShipment(LSP lsp, Id shipmentId){
- for (LSPShipment lspShipment : lsp.getShipments()) {
- if (lspShipment.getId().equals(shipmentId)) {
- return lspShipment;
- }
- }
- return null;
- }
-
- /**
- * Returns the {@link ShipmentPlan} of an {@link LSPShipment}.
- * @param lspPlan the lspPlan: It contains the information of its shipmentPlans
- * @param shipmentId Id of the shipment that should be found.
- * @return the shipmentPlan object or null, if it is not found.
- */
- public static ShipmentPlan findLspShipmentPlan(LSPPlan lspPlan, Id shipmentId){
- for (ShipmentPlan shipmentPlan : lspPlan.getShipmentPlans()) {
- if (shipmentPlan.getLspShipmentId().equals(shipmentId)) {
- return shipmentPlan;
- }
- }
- return null;
- }
-
+ private static final String lspsString = "lsps";
+
+ private LSPUtils() {} // do not instantiate
+
+ public static LSPPlan createLSPPlan() {
+ return new LSPPlanImpl();
+ }
+
+ public static LogisticChainScheduler createForwardLogisiticChainScheduler() {
+ return new ForwardLogisticChainSchedulerImpl();
+ }
+
+ public static WaitingShipments createWaitingShipments() {
+ return new WaitingShipmentsImpl();
+ }
+
+ public static void addLSPs(Scenario scenario, LSPs lsps) {
+ Carriers carriers = CarriersUtils.addOrGetCarriers(scenario);
+ // Register carriers from all lsps
+ for (LSP lsp : lsps.getLSPs().values()) {
+ for (LSPResource lspResource : lsp.getResources()) {
+ if (lspResource instanceof LSPCarrierResource lspCarrierResource) {
+ carriers.addCarrier(lspCarrierResource.getCarrier());
+ }
+ }
+ }
+ scenario.addScenarioElement(lspsString, lsps);
+ }
+
+ public static LSPs getLSPs(Scenario scenario) {
+ Object result = scenario.getScenarioElement(lspsString);
+ if (result == null) {
+ throw new RuntimeException(
+ "there is no scenario element of type "
+ + lspsString
+ + ". You will need something like LSPUtils.addLSPs( scenario, lsps) somewhere.");
+ }
+ return (LSPs) result;
+ }
+
+ public static Double getVariableCost(Attributable attributable) {
+ return (Double) attributable.getAttributes().getAttribute("variableCost");
+ }
+
+ public static void setVariableCost(Attributable attributable, Double variableCost) {
+ attributable.getAttributes().putAttribute("variableCost", variableCost);
+ }
+
+ public static Double getFixedCost(Attributable attributable) {
+ return (Double) attributable.getAttributes().getAttribute("fixedCost");
+ }
+
+ // The following would be closer to how we have done it elsewhere (scenario containers are
+ // mutable). kai, may'22'
+ // public static LSPs createOrGetLPSs( Scenario scenario ){
+ // Object result = scenario.getScenarioElement( lspsString );
+ // LSPs lsps;
+ // if ( result != null ) {
+ // lsps = (LSPs) result;
+ // } else {
+ // lsps = new LSPs( );
+ // scenario.addScenarioElement( lspsString, lsps );
+ // }
+ // return lsps;
+ // }
+
+ public static void setFixedCost(Attributable attributable, Double fixedCost) {
+ attributable.getAttributes().putAttribute("fixedCost", fixedCost);
+ }
+
+ /**
+ * Gives back the {@link LSPShipment} object of the {@link LSP}, which matches to the shipmentId
+ *
+ * @param lsp In this LSP this method tries to find the shipment.
+ * @param shipmentId Id of the shipment that should be found.
+ * @return the lspShipment object or null, if it is not found.
+ */
+ public static LSPShipment findLspShipment(LSP lsp, Id shipmentId) {
+ for (LSPShipment lspShipment : lsp.getShipments()) {
+ if (lspShipment.getId().equals(shipmentId)) {
+ return lspShipment;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the {@link ShipmentPlan} of an {@link LSPShipment}.
+ *
+ * @param lspPlan the lspPlan: It contains the information of its shipmentPlans
+ * @param shipmentId Id of the shipment that should be found.
+ * @return the shipmentPlan object or null, if it is not found.
+ */
+ public static ShipmentPlan findLspShipmentPlan(LSPPlan lspPlan, Id shipmentId) {
+ for (ShipmentPlan shipmentPlan : lspPlan.getShipmentPlans()) {
+ if (shipmentPlan.getLspShipmentId().equals(shipmentId)) {
+ return shipmentPlan;
+ }
+ }
+ return null;
+ }
+
+ public static final class LSPBuilder {
+ final Collection resources;
+ final Id id;
+ LogisticChainScheduler logisticChainScheduler;
+ LSPPlan initialPlan;
+
+ private LSPBuilder(Id id) {
+ this.id = id; // this line was not there until today. kai, may'22
+ this.resources = new ArrayList<>();
+ }
+
+ public static LSPBuilder getInstance(Id id) {
+ return new LSPBuilder(id);
+ }
+
+ public LSPBuilder setLogisticChainScheduler(LogisticChainScheduler logisticChainScheduler) {
+ this.logisticChainScheduler = logisticChainScheduler;
+ return this;
+ }
+
+ // /**
+ // * @deprecated -- It feels attractive to attach this to the "agent". A big disadvantage
+ // with this approach, however, is that
+ // * we cannot use injection ... since we cannot inject as many scorers as we have agents.
+ // (At least this is what I think.) Which means
+ // * that the approach in matsim core and in carriers to have XxxScoringFunctionFactory is
+ // better for what we are doing here. yyyyyy So
+ // * this needs to be changed. kai, jul'22
+ // */
+ // public LSPBuilder setSolutionScorer(LSPScorer scorer) {
+ // this.scorer = scorer;
+ // return this;
+ // }
+
+ // /**
+ // * @deprecated -- It feels attractive to attach this to the "agent". A big disadvantage
+ // with this approach, however, is that
+ // * we cannot use injection ... since we cannot inject as many replanners as we have
+ // agents. (At least this is what I think.) yyyyyy So
+ // * this needs to be changed. kai, jul'22
+ // */
+ // public LSPBuilder setReplanner(LSPReplanner replanner) {
+ // this.replanner = replanner;
+ // return this;
+ // }
+ // never used. Thus disabling it. kai, jul'22
+
+ public LSPBuilder setInitialPlan(LSPPlan plan) {
+ this.initialPlan = plan;
+ for (LogisticChain solution : plan.getLogisticChains()) {
+ for (LogisticChainElement element : solution.getLogisticChainElements()) {
+ if (!resources.contains(element.getResource())) {
+ resources.add(element.getResource());
+ }
+ }
+ }
+ return this;
+ }
+
+ public LSP build() {
+ return new LSPImpl(this);
+ }
+ }
+
+ public static final class LogisticChainBuilder {
+ final Id id;
+ final Collection elements;
+ // final Collection eventHandlers;
+ final Collection> trackers;
+
+ private LogisticChainBuilder(Id id) {
+ this.elements = new ArrayList<>();
+ this.trackers = new ArrayList>();
+ this.id = id;
+ }
+
+ public static LogisticChainBuilder newInstance(Id id) {
+ return new LogisticChainBuilder(id);
+ }
+
+ public LogisticChainBuilder addLogisticChainElement(LogisticChainElement element) {
+ elements.add(element);
+ return this;
+ }
+
+ public LogisticChainBuilder addTracker(LSPSimulationTracker tracker) {
+ trackers.add(tracker);
+ return this;
+ }
+
+ public LogisticChain build() {
+ return new LogisticChainImpl(this);
+ }
+ }
+
+ public static final class LogisticChainElementBuilder {
+ final Id id;
+ final WaitingShipments incomingShipments;
+ final WaitingShipments outgoingShipments;
+ LSPResource resource;
+
+ private LogisticChainElementBuilder(Id id) {
+ this.id = id;
+ this.incomingShipments = createWaitingShipments();
+ this.outgoingShipments = createWaitingShipments();
+ }
+
+ public static LogisticChainElementBuilder newInstance(Id id) {
+ return new LogisticChainElementBuilder(id);
+ }
+
+ public LogisticChainElementBuilder setResource(LSPResource resource) {
+ this.resource = resource;
+ return this;
+ }
+
+ public LogisticChainElement build() {
+ return new LogisticChainElementImpl(this);
+ }
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/LSPs.java b/src/main/java/org/matsim/freight/logistics/LSPs.java
index 8cf58692..7adfc6d4 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPs.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPs.java
@@ -20,29 +20,26 @@
package org.matsim.freight.logistics;
-import org.matsim.api.core.v01.Id;
-
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
+import org.matsim.api.core.v01.Id;
public class LSPs {
- private final Map, LSP> lsps = new LinkedHashMap<>();
-
- public LSPs(Collection lsps) {
- makeMap(lsps);
- }
-
- private void makeMap(Collection lsps) {
- for (LSP c : lsps) {
- this.lsps.put(c.getId(), c);
- }
- }
+ private final Map, LSP> lsps = new LinkedHashMap<>();
+ public LSPs(Collection lsps) {
+ makeMap(lsps);
+ }
- public Map, LSP> getLSPs() {
- return lsps;
- }
+ private void makeMap(Collection lsps) {
+ for (LSP c : lsps) {
+ this.lsps.put(c.getId(), c);
+ }
+ }
+ public Map, LSP> getLSPs() {
+ return lsps;
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/LogisticChain.java b/src/main/java/org/matsim/freight/logistics/LogisticChain.java
index 1f76f1d3..ba5f5cf9 100644
--- a/src/main/java/org/matsim/freight/logistics/LogisticChain.java
+++ b/src/main/java/org/matsim/freight/logistics/LogisticChain.java
@@ -20,28 +20,28 @@
package org.matsim.freight.logistics;
-import org.matsim.freight.logistics.shipment.LSPShipment;
+import java.util.Collection;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Identifiable;
+import org.matsim.freight.logistics.shipment.LSPShipment;
import org.matsim.utils.objectattributes.attributable.Attributable;
-import java.util.Collection;
-
-
/**
- * A LogisticsSolution can be seen as a representative of a
- * transport chain. It consists of several chain links that implement the interface
- * {@link LogisticChainElement}. The latter is more a logical than a physical entity.
- * Physical entities, in turn, are housed inside classes that implement the interface
- * {@link LSPResource}. This introduction of an intermediate layer allows physical Resources
- * to be used by several {@link LogisticChain}s and thus transport chains.
+ * A LogisticsSolution can be seen as a representative of a transport chain. It consists of several
+ * chain links that implement the interface {@link LogisticChainElement}. The latter is more a
+ * logical than a physical entity. Physical entities, in turn, are housed inside classes that
+ * implement the interface {@link LSPResource}. This introduction of an intermediate layer allows
+ * physical Resources to be used by several {@link LogisticChain}s and thus transport chains.
*/
-public interface LogisticChain extends Identifiable, KnowsLSP, HasSimulationTrackers, Attributable {
-
- Collection getLogisticChainElements();
+public interface LogisticChain
+ extends Identifiable,
+ KnowsLSP,
+ HasSimulationTrackers,
+ Attributable {
- Collection> getShipmentIds();
+ Collection getLogisticChainElements();
- void addShipmentToChain(LSPShipment shipment);
+ Collection> getShipmentIds();
+ void addShipmentToChain(LSPShipment shipment);
}
diff --git a/src/main/java/org/matsim/freight/logistics/LogisticChainElement.java b/src/main/java/org/matsim/freight/logistics/LogisticChainElement.java
index b59ad6a6..67a16b43 100644
--- a/src/main/java/org/matsim/freight/logistics/LogisticChainElement.java
+++ b/src/main/java/org/matsim/freight/logistics/LogisticChainElement.java
@@ -23,33 +23,33 @@
import org.matsim.api.core.v01.Identifiable;
import org.matsim.utils.objectattributes.attributable.Attributable;
-
-public interface LogisticChainElement extends Identifiable, HasBackpointer, HasSimulationTrackers, Attributable {
-
- void connectWithNextElement(LogisticChainElement element);
-
- /**
- * The logistics solution element wraps around a resource. Don't know why we need this wrapping.
- *
- * @return the resource
- */
- LSPResource getResource();
-
- LogisticChainElement getPreviousElement();
-
- LogisticChainElement getNextElement();
-
- /**
- * This collection stores LSPShipments that are waiting for their treatment in this element or more precisely the Resource that is in
- * charge of the actual physical handling.
- *
- * @return WaitingShipments
- */
- WaitingShipments getIncomingShipments();
-
- /**
- * Shipments that have already been treated.
- */
- WaitingShipments getOutgoingShipments();
-
+public interface LogisticChainElement
+ extends Identifiable,
+ HasBackpointer,
+ HasSimulationTrackers,
+ Attributable {
+
+ void connectWithNextElement(LogisticChainElement element);
+
+ /**
+ * The logistics solution element wraps around a resource. Don't know why we need this wrapping.
+ *
+ * @return the resource
+ */
+ LSPResource getResource();
+
+ LogisticChainElement getPreviousElement();
+
+ LogisticChainElement getNextElement();
+
+ /**
+ * This collection stores LSPShipments that are waiting for their treatment in this element or
+ * more precisely the Resource that is in charge of the actual physical handling.
+ *
+ * @return WaitingShipments
+ */
+ WaitingShipments getIncomingShipments();
+
+ /** Shipments that have already been treated. */
+ WaitingShipments getOutgoingShipments();
}
diff --git a/src/main/java/org/matsim/freight/logistics/LogisticChainElementImpl.java b/src/main/java/org/matsim/freight/logistics/LogisticChainElementImpl.java
index 01ef8041..757c7714 100644
--- a/src/main/java/org/matsim/freight/logistics/LogisticChainElementImpl.java
+++ b/src/main/java/org/matsim/freight/logistics/LogisticChainElementImpl.java
@@ -20,81 +20,84 @@
package org.matsim.freight.logistics;
-
-/* package-private */ class LogisticChainElementImpl extends LSPDataObject implements LogisticChainElement {
-
- private final LSPResource resource;
- private final WaitingShipments incomingShipments;
- private final WaitingShipments outgoingShipments;
- //die beiden nicht im Builder. Die können erst in der Solution als ganzes gesetzt werden
- private LogisticChainElement previousElement;
- private LogisticChainElement nextElement;
-
- LogisticChainElementImpl(LSPUtils.LogisticChainElementBuilder builder) {
- super(builder.id);
- this.resource = builder.resource;
- this.incomingShipments = builder.incomingShipments;
- this.outgoingShipments = builder.outgoingShipments;
- resource.getClientElements().add(this);
- }
-
- @Override
- public void connectWithNextElement(LogisticChainElement element) {
- this.nextElement = element;
- ((LogisticChainElementImpl) element).previousElement = this;
- }
-
- @Override
- public LSPResource getResource() {
- return resource;
- }
-
- @Override
- public WaitingShipments getIncomingShipments() {
- return incomingShipments;
- }
-
- @Override
- public WaitingShipments getOutgoingShipments() {
- return outgoingShipments;
- }
-
-
- @Override
- public void setEmbeddingContainer(LogisticChain logisticChain) {
- /* not */
- }
-
- @Override
- public LogisticChainElement getPreviousElement() {
- return previousElement;
- }
-
- @Override
- public LogisticChainElement getNextElement() {
- return nextElement;
- }
-
- @Override public String toString() {
- StringBuilder strb = new StringBuilder();
- strb.append("LogisticsSolutionElementImpl{")
- .append("resourceId=").append(resource.getId())
- .append(", incomingShipments=").append(incomingShipments)
- .append(", outgoingShipments=").append(outgoingShipments);
-
- if (previousElement != null) {
- strb.append(", previousElementId=").append(previousElement.getId());
- } else {
- strb.append(", previousElementId=").append("null");
- }
-
- if (nextElement != null) {
- strb.append(", nextElementId=").append(nextElement.getId());
- } else {
- strb.append(", nextElementId=").append("null");
- }
-
- strb.append('}');
- return strb.toString();
- }
+/* package-private */ class LogisticChainElementImpl extends LSPDataObject
+ implements LogisticChainElement {
+
+ private final LSPResource resource;
+ private final WaitingShipments incomingShipments;
+ private final WaitingShipments outgoingShipments;
+ // die beiden nicht im Builder. Die können erst in der Solution als ganzes gesetzt werden
+ private LogisticChainElement previousElement;
+ private LogisticChainElement nextElement;
+
+ LogisticChainElementImpl(LSPUtils.LogisticChainElementBuilder builder) {
+ super(builder.id);
+ this.resource = builder.resource;
+ this.incomingShipments = builder.incomingShipments;
+ this.outgoingShipments = builder.outgoingShipments;
+ resource.getClientElements().add(this);
+ }
+
+ @Override
+ public void connectWithNextElement(LogisticChainElement element) {
+ this.nextElement = element;
+ ((LogisticChainElementImpl) element).previousElement = this;
+ }
+
+ @Override
+ public LSPResource getResource() {
+ return resource;
+ }
+
+ @Override
+ public WaitingShipments getIncomingShipments() {
+ return incomingShipments;
+ }
+
+ @Override
+ public WaitingShipments getOutgoingShipments() {
+ return outgoingShipments;
+ }
+
+ @Override
+ public void setEmbeddingContainer(LogisticChain logisticChain) {
+ /* not */
+ }
+
+ @Override
+ public LogisticChainElement getPreviousElement() {
+ return previousElement;
+ }
+
+ @Override
+ public LogisticChainElement getNextElement() {
+ return nextElement;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder strb = new StringBuilder();
+ strb.append("LogisticsSolutionElementImpl{")
+ .append("resourceId=")
+ .append(resource.getId())
+ .append(", incomingShipments=")
+ .append(incomingShipments)
+ .append(", outgoingShipments=")
+ .append(outgoingShipments);
+
+ if (previousElement != null) {
+ strb.append(", previousElementId=").append(previousElement.getId());
+ } else {
+ strb.append(", previousElementId=").append("null");
+ }
+
+ if (nextElement != null) {
+ strb.append(", nextElementId=").append(nextElement.getId());
+ } else {
+ strb.append(", nextElementId=").append("null");
+ }
+
+ strb.append('}');
+ return strb.toString();
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/LogisticChainImpl.java b/src/main/java/org/matsim/freight/logistics/LogisticChainImpl.java
index 626392a8..8a7f9003 100644
--- a/src/main/java/org/matsim/freight/logistics/LogisticChainImpl.java
+++ b/src/main/java/org/matsim/freight/logistics/LogisticChainImpl.java
@@ -20,76 +20,78 @@
package org.matsim.freight.logistics;
-import org.matsim.freight.logistics.shipment.LSPShipment;
+import java.util.ArrayList;
+import java.util.Collection;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Id;
+import org.matsim.freight.logistics.shipment.LSPShipment;
-import java.util.ArrayList;
-import java.util.Collection;
-
-/* package-private */ class LogisticChainImpl extends LSPDataObject implements LogisticChain {
- private static final Logger log = LogManager.getLogger(LogisticChainImpl.class);
-
- private final Collection logisticChainElements;
- private final Collection> shipmentIds;
- private LSP lsp;
+/* package-private */ class LogisticChainImpl extends LSPDataObject
+ implements LogisticChain {
+ private static final Logger log = LogManager.getLogger(LogisticChainImpl.class);
- LogisticChainImpl(LSPUtils.LogisticChainBuilder builder) {
- super(builder.id);
- this.logisticChainElements = builder.elements;
- for (LogisticChainElement element : this.logisticChainElements) {
- element.setEmbeddingContainer(this);
- }
- this.shipmentIds = new ArrayList<>();
- }
+ private final Collection logisticChainElements;
+ private final Collection> shipmentIds;
+ private LSP lsp;
- @Override
- public void setLSP( LSP lsp ) {
- this.lsp = lsp;
- }
+ LogisticChainImpl(LSPUtils.LogisticChainBuilder builder) {
+ super(builder.id);
+ this.logisticChainElements = builder.elements;
+ for (LogisticChainElement element : this.logisticChainElements) {
+ element.setEmbeddingContainer(this);
+ }
+ this.shipmentIds = new ArrayList<>();
+ }
- @Override
- public LSP getLSP() {
- return lsp;
- }
+ @Override
+ public LSP getLSP() {
+ return lsp;
+ }
- @Override
- public Collection getLogisticChainElements() {
- return logisticChainElements;
- }
+ @Override
+ public void setLSP(LSP lsp) {
+ this.lsp = lsp;
+ }
- @Override
- public Collection> getShipmentIds() {
- return shipmentIds;
- }
+ @Override
+ public Collection getLogisticChainElements() {
+ return logisticChainElements;
+ }
- @Override
- public void addShipmentToChain(LSPShipment shipment) {
- shipmentIds.add(shipment.getId());
- }
+ @Override
+ public Collection> getShipmentIds() {
+ return shipmentIds;
+ }
- @Override public String toString() {
- StringBuilder strb = new StringBuilder();
- strb.append("LogisticsSolutionImpl{")
- .append("[No of SolutionsElements=").append(logisticChainElements.size()).append("] \n");
- if (!logisticChainElements.isEmpty()){
- strb.append("{SolutionElements=");
- for (LogisticChainElement solutionElement : logisticChainElements) {
- strb.append("\n [" + solutionElement.toString() + "]");
- }
- strb.append("}");
- }
- strb.append("[No of Shipments=").append(shipmentIds.size()).append("] \n");
- if (!shipmentIds.isEmpty()){
- strb.append("{ShipmentIds=");
- for (Id lspShipmentId : shipmentIds) {
- strb.append("[" + lspShipmentId.toString() + "]");
- }
- strb.append("}");
- }
- strb.append('}');
- return strb.toString();
- }
+ @Override
+ public void addShipmentToChain(LSPShipment shipment) {
+ shipmentIds.add(shipment.getId());
+ }
+ @Override
+ public String toString() {
+ StringBuilder strb = new StringBuilder();
+ strb.append("LogisticsSolutionImpl{")
+ .append("[No of SolutionsElements=")
+ .append(logisticChainElements.size())
+ .append("] \n");
+ if (!logisticChainElements.isEmpty()) {
+ strb.append("{SolutionElements=");
+ for (LogisticChainElement solutionElement : logisticChainElements) {
+ strb.append("\n [" + solutionElement.toString() + "]");
+ }
+ strb.append("}");
+ }
+ strb.append("[No of Shipments=").append(shipmentIds.size()).append("] \n");
+ if (!shipmentIds.isEmpty()) {
+ strb.append("{ShipmentIds=");
+ for (Id lspShipmentId : shipmentIds) {
+ strb.append("[" + lspShipmentId.toString() + "]");
+ }
+ strb.append("}");
+ }
+ strb.append('}');
+ return strb.toString();
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/LogisticChainScheduler.java b/src/main/java/org/matsim/freight/logistics/LogisticChainScheduler.java
index 95a11589..ab407a39 100644
--- a/src/main/java/org/matsim/freight/logistics/LogisticChainScheduler.java
+++ b/src/main/java/org/matsim/freight/logistics/LogisticChainScheduler.java
@@ -20,24 +20,26 @@
package org.matsim.freight.logistics;
-
/**
- * Serve the purpose of routing a set of {@link org.matsim.freight.logistics.shipment.LSPShipment}s through a set of
- * {@link LogisticChain}s, which, in turn, consist of several {@link LogisticChainElement}s
- * and the corresponding {@link LSPResource}s.
+ * Serve the purpose of routing a set of {@link org.matsim.freight.logistics.shipment.LSPShipment}s
+ * through a set of {@link LogisticChain}s, which, in turn, consist of several {@link
+ * LogisticChainElement}s and the corresponding {@link LSPResource}s.
*/
public interface LogisticChainScheduler extends HasBackpointer {
- void scheduleLogisticChain();
+ void scheduleLogisticChain();
- /**
- * The buffer time is only taken into account in planning / scheduling.
- * The idea is to ensure that the goods are available for the next ressource "in time", because the scheduling does not take into account
- * any congestion during the simulation. E.g. if multiple vehicle are leaving the depot at the same time and thus influence each other.
- * It is not intended to be available as buffer in the simulation itself -> It does not influence the events and shipmentLogs.
- * As a consequence, the transportation (in simulation, events, ...) is in many cases earlier than scheduled.
- * (Information from TM after asking; KMT 17.11.23)
- * @param bufferTime for scheduling [in sec]
- */
- void setBufferTime(int bufferTime);
+ /**
+ * The buffer time is only taken into account in planning / scheduling. The idea is to
+ * ensure that the goods are available for the next ressource "in time", because the scheduling
+ * does not take into account any congestion during the simulation. E.g. if multiple vehicle are
+ * leaving the depot at the same time and thus influence each other.
+ * It is not intended to be available as buffer in the simulation itself -> It does not
+ * influence the events and shipmentLogs. As a consequence, the transportation (in simulation,
+ * events, ...) is in many cases earlier than scheduled. (Information from TM after asking; KMT
+ * 17.11.23)
+ *
+ * @param bufferTime for scheduling [in sec]
+ */
+ void setBufferTime(int bufferTime);
}
diff --git a/src/main/java/org/matsim/freight/logistics/LspShipmentWithTime.java b/src/main/java/org/matsim/freight/logistics/LspShipmentWithTime.java
index 488799d1..0b531ad5 100644
--- a/src/main/java/org/matsim/freight/logistics/LspShipmentWithTime.java
+++ b/src/main/java/org/matsim/freight/logistics/LspShipmentWithTime.java
@@ -20,28 +20,28 @@
package org.matsim.freight.logistics;
-
import org.matsim.freight.logistics.shipment.LSPShipment;
public class LspShipmentWithTime {
- // yyyyyy find better solution for this. It is not so good to define an interface, and then immediately define a class that goes beyond it.
- // Maybe the time should be added to the interface? However, I don't even know what that time means (delivery time? current time?). kai,
- // jun'22
-
- private final LSPShipment shipment;
- private final double time;
-
- public LspShipmentWithTime(double time, LSPShipment shipment) {
- this.shipment = shipment;
- this.time = time;
- }
-
- public LSPShipment getShipment() {
- return shipment;
- }
-
- public double getTime() {
- return time;
- }
-
+ // yyyyyy find better solution for this. It is not so good to define an interface, and then
+ // immediately define a class that goes beyond it.
+ // Maybe the time should be added to the interface? However, I don't even know what that time
+ // means (delivery time? current time?). kai,
+ // jun'22
+
+ private final LSPShipment shipment;
+ private final double time;
+
+ public LspShipmentWithTime(double time, LSPShipment shipment) {
+ this.shipment = shipment;
+ this.time = time;
+ }
+
+ public LSPShipment getShipment() {
+ return shipment;
+ }
+
+ public double getTime() {
+ return time;
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/ShipmentAssigner.java b/src/main/java/org/matsim/freight/logistics/ShipmentAssigner.java
index 11879d90..8adcf835 100644
--- a/src/main/java/org/matsim/freight/logistics/ShipmentAssigner.java
+++ b/src/main/java/org/matsim/freight/logistics/ShipmentAssigner.java
@@ -24,18 +24,20 @@
/**
* Takes an {@link LSPShipment} and normally assigns it to something that belongs to an {@link LSP}.
- *
- * If there are several {@link LogisticChain}s, the {@link LSP} has to assign each {@link LSPShipment} to
- * the suitable one. For this purpose, each LSPPlan contains a pluggable strategy that
- * is contained in classes implementing the interface {@link ShipmentAssigner}.
- *
- * Discussion points:
- *
yyyy Shipments are normally assigned to the selected plan only. I am not sure if this is what I would
- * expect from the outside. kai, may'22
+ *
+ *
+ * If there are several {@link LogisticChain}s, the {@link LSP} has to assign each {@link
+ * LSPShipment} to the suitable one. For this purpose, each LSPPlan contains a pluggable strategy
+ * that is contained in classes implementing the interface {@link ShipmentAssigner}.
+ *
+ * Discussion points:
+ *
+ *
+ *
yyyy Shipments are normally assigned to the selected plan only. I am not sure if this is
+ * what I would expect from the outside. kai, may'22
*
*/
public interface ShipmentAssigner extends KnowsLSP {
- void assignToPlan(LSPPlan lspPlan, LSPShipment shipment);
-
+ void assignToPlan(LSPPlan lspPlan, LSPShipment shipment);
}
diff --git a/src/main/java/org/matsim/freight/logistics/WaitingShipments.java b/src/main/java/org/matsim/freight/logistics/WaitingShipments.java
index f49689d4..ff7b7bb9 100644
--- a/src/main/java/org/matsim/freight/logistics/WaitingShipments.java
+++ b/src/main/java/org/matsim/freight/logistics/WaitingShipments.java
@@ -20,34 +20,32 @@
package org.matsim.freight.logistics;
-import org.matsim.freight.logistics.shipment.LSPShipment;
-
import java.util.Collection;
+import org.matsim.freight.logistics.shipment.LSPShipment;
/**
- * Each LogisticsSolutionElement maintains two collections of WaitingShipments.
- * Instances of the latter class contain tuples of LSPShipments and time stamps.
- *
- * The first of these collections stores LSPShipments that are waiting for their treatment in this element or more precisely the Resource that is in
- * charge of the actual physical handling.
- *
- * The second one stores shipments that have already been treated.
- *
- * At the beginning of the scheduling process, all LSPShipments are added
- * to the collection of incoming shipments of the first LogisticsSolutionElement of the
- * LogisticsSolution to which they were assigned before. The tuples in the collection of
- * WaitingShipments thus consist of the shipments themselves and a time stamp that states
- * when they arrived there (see 3.9). In the case of the first LogisticsSolutionElement,
- * this time stamp corresponds to the start time window of the LSPShipment
+ * Each LogisticsSolutionElement maintains two collections of WaitingShipments. Instances of the
+ * latter class contain tuples of LSPShipments and time stamps.
+ *
+ *
The first of these collections stores LSPShipments that are waiting for their treatment in
+ * this element or more precisely the Resource that is in charge of the actual physical handling.
+ *
+ *
The second one stores shipments that have already been treated.
+ *
+ *
At the beginning of the scheduling process, all LSPShipments are added to the collection of
+ * incoming shipments of the first LogisticsSolutionElement of the LogisticsSolution to which they
+ * were assigned before. The tuples in the collection of WaitingShipments thus consist of the
+ * shipments themselves and a time stamp that states when they arrived there (see 3.9). In the case
+ * of the first LogisticsSolutionElement, this time stamp corresponds to the start time window of
+ * the LSPShipment
*/
public interface WaitingShipments {
- void addShipment(double time, LSPShipment shipment);
-
- Collection getSortedShipments();
+ void addShipment(double time, LSPShipment shipment);
- Collection getShipments();
+ Collection getSortedShipments();
- void clear();
+ Collection getShipments();
+ void clear();
}
diff --git a/src/main/java/org/matsim/freight/logistics/WaitingShipmentsImpl.java b/src/main/java/org/matsim/freight/logistics/WaitingShipmentsImpl.java
index 7f137040..36a40f06 100644
--- a/src/main/java/org/matsim/freight/logistics/WaitingShipmentsImpl.java
+++ b/src/main/java/org/matsim/freight/logistics/WaitingShipmentsImpl.java
@@ -20,57 +20,53 @@
package org.matsim.freight.logistics;
-import org.matsim.freight.logistics.shipment.LSPShipment;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
+import org.matsim.freight.logistics.shipment.LSPShipment;
/* package-private */ class WaitingShipmentsImpl implements WaitingShipments {
- private final List shipments;
-
- WaitingShipmentsImpl() {
- this.shipments = new ArrayList<>();
- }
+ private final List shipments;
+ WaitingShipmentsImpl() {
+ this.shipments = new ArrayList<>();
+ }
- @Override
- public void addShipment(double time, LSPShipment shipment) {
- LspShipmentWithTime tuple = new LspShipmentWithTime(time, shipment);
- this.shipments.add(tuple);
- shipments.sort(Comparator.comparingDouble(LspShipmentWithTime::getTime));
- }
+ @Override
+ public void addShipment(double time, LSPShipment shipment) {
+ LspShipmentWithTime tuple = new LspShipmentWithTime(time, shipment);
+ this.shipments.add(tuple);
+ shipments.sort(Comparator.comparingDouble(LspShipmentWithTime::getTime));
+ }
- @Override
- public Collection getSortedShipments() {
- shipments.sort(Comparator.comparingDouble(LspShipmentWithTime::getTime));
- return shipments;
- }
+ @Override
+ public Collection getSortedShipments() {
+ shipments.sort(Comparator.comparingDouble(LspShipmentWithTime::getTime));
+ return shipments;
+ }
- public void clear() {
- shipments.clear();
- }
+ public void clear() {
+ shipments.clear();
+ }
- @Override
- public Collection getShipments() {
- return shipments;
- }
+ @Override
+ public Collection getShipments() {
+ return shipments;
+ }
- @Override public String toString() {
- StringBuilder strb = new StringBuilder();
- strb.append("WaitingShipmentsImpl{")
- .append("No of Shipments= ").append(shipments.size());
- if (shipments.size() >0 ){
- strb.append("; ShipmentIds=");
- for (LspShipmentWithTime shipment : getSortedShipments()) {
- strb.append("[")
- .append(shipment.getShipment().getId())
- .append("]");
- }
- }
- strb.append('}');
- return strb.toString();
- }
+ @Override
+ public String toString() {
+ StringBuilder strb = new StringBuilder();
+ strb.append("WaitingShipmentsImpl{").append("No of Shipments= ").append(shipments.size());
+ if (shipments.size() > 0) {
+ strb.append("; ShipmentIds=");
+ for (LspShipmentWithTime shipment : getSortedShipments()) {
+ strb.append("[").append(shipment.getShipment().getId()).append("]");
+ }
+ }
+ strb.append('}');
+ return strb.toString();
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/events/AbstractLspEvent.java b/src/main/java/org/matsim/freight/logistics/events/AbstractLspEvent.java
index 0487ce45..d8e13f02 100644
--- a/src/main/java/org/matsim/freight/logistics/events/AbstractLspEvent.java
+++ b/src/main/java/org/matsim/freight/logistics/events/AbstractLspEvent.java
@@ -1,5 +1,8 @@
package org.matsim.freight.logistics.events;
+import static org.matsim.freight.logistics.HasLspShipmentId.ATTRIBUTE_LSP_SHIPMENT_ID;
+
+import java.util.Map;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.events.Event;
import org.matsim.api.core.v01.events.HasLinkId;
@@ -7,52 +10,48 @@
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.
- *
- * Please note, that general _freight_ events can be found in the freight contrib.
+ * A general logistic event contains the information (= {@link Id}) of the - the location (= {@link
+ * Link}) - the lspShipment (= {@link LSPShipment}) belonging to it.
+ *
+ *
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 linkId;
- private final Id lspShipmentId;
-
- public AbstractLspEvent(double time, Id linkId, Id lspShipmentId) {
- super(time);
- this.linkId = linkId;
- this.lspShipmentId = lspShipmentId;
- }
-
- /**
- * @return id of the {@link LSPShipment}
- */
- @Override public final Id getLspShipmentId() {
- return lspShipmentId;
- }
-
- @Override public final Id getLinkId() {
- return linkId;
- }
-
- /**
- * Adds the {@link Id} to the list of attributes.
- * {@link Id} is handled by superclass {@link Event}
- *
- * @return The map of attributes
- */
- @Override
- public Map getAttributes() {
- Map attr = super.getAttributes();
- attr.put(ATTRIBUTE_LSP_SHIPMENT_ID, lspShipmentId.toString());
- return attr;
- }
+ private final Id linkId;
+ private final Id lspShipmentId;
+
+ public AbstractLspEvent(double time, Id linkId, Id lspShipmentId) {
+ super(time);
+ this.linkId = linkId;
+ this.lspShipmentId = lspShipmentId;
+ }
+
+ /**
+ * @return id of the {@link LSPShipment}
+ */
+ @Override
+ public final Id getLspShipmentId() {
+ return lspShipmentId;
+ }
+
+ @Override
+ public final Id getLinkId() {
+ return linkId;
+ }
+
+ /**
+ * Adds the {@link Id} to the list of attributes. {@link Id} is handled by
+ * superclass {@link Event}
+ *
+ * @return The map of attributes
+ */
+ @Override
+ public Map getAttributes() {
+ Map attr = super.getAttributes();
+ attr.put(ATTRIBUTE_LSP_SHIPMENT_ID, lspShipmentId.toString());
+ return attr;
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/events/HandlingInHubStartedEventHandler.java b/src/main/java/org/matsim/freight/logistics/events/HandlingInHubStartedEventHandler.java
index 22f7b148..b8b9c6e9 100644
--- a/src/main/java/org/matsim/freight/logistics/events/HandlingInHubStartedEventHandler.java
+++ b/src/main/java/org/matsim/freight/logistics/events/HandlingInHubStartedEventHandler.java
@@ -7,5 +7,5 @@
*/
public interface HandlingInHubStartedEventHandler extends EventHandler {
- void handleEvent (HandlingInHubStartsEvent event);
+ void handleEvent(HandlingInHubStartsEvent event);
}
diff --git a/src/main/java/org/matsim/freight/logistics/events/HandlingInHubStartsEvent.java b/src/main/java/org/matsim/freight/logistics/events/HandlingInHubStartsEvent.java
index 9da8ebac..221ba491 100644
--- a/src/main/java/org/matsim/freight/logistics/events/HandlingInHubStartsEvent.java
+++ b/src/main/java/org/matsim/freight/logistics/events/HandlingInHubStartsEvent.java
@@ -21,62 +21,68 @@
package org.matsim.freight.logistics.events;
+import static org.matsim.freight.logistics.events.LspEventAttributes.ATTRIBUTE_EXP_HANDLING_DURATION;
+import static org.matsim.freight.logistics.events.LspEventAttributes.ATTRIBUTE_HUB_ID;
+import java.util.Map;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.events.GenericEvent;
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.
+ * 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 hubId;
- private final double expHandlingDuration;
+ public static final String EVENT_TYPE = "Handling_started";
+ private final Id hubId;
+ private final double expHandlingDuration;
- public HandlingInHubStartsEvent(double time, Id linkId, Id lspShipmentId, Id hubId, double expHandlingDuration) {
- super(time, linkId, lspShipmentId);
- this.hubId = hubId;
- this.expHandlingDuration = expHandlingDuration;
- }
+ public HandlingInHubStartsEvent(
+ double time,
+ Id linkId,
+ Id lspShipmentId,
+ Id hubId,
+ double expHandlingDuration) {
+ super(time, linkId, lspShipmentId);
+ this.hubId = hubId;
+ this.expHandlingDuration = expHandlingDuration;
+ }
- @Override public String getEventType() {
- return EVENT_TYPE;
- }
+ public static HandlingInHubStartsEvent convert(GenericEvent event) {
+ Map attributes = event.getAttributes();
+ double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME));
+ Id linkId = Id.createLinkId(attributes.get(ATTRIBUTE_LINK));
+ Id lspSipmentId =
+ Id.create(attributes.get(ATTRIBUTE_LSP_SHIPMENT_ID), LSPShipment.class);
+ var hubId = Id.create(attributes.get(ATTRIBUTE_HUB_ID), LSPResource.class);
+ double expHandlingDuration =
+ Double.parseDouble(attributes.get(ATTRIBUTE_EXP_HANDLING_DURATION));
+ return new HandlingInHubStartsEvent(time, linkId, lspSipmentId, hubId, expHandlingDuration);
+ }
- public Id getHubId() {
- return hubId;
- }
+ @Override
+ public String getEventType() {
+ return EVENT_TYPE;
+ }
- public double getExpHandlingDuration(){
- return expHandlingDuration;
- }
+ public Id getHubId() {
+ return hubId;
+ }
- @Override
- public Map getAttributes() {
- Map attr = super.getAttributes();
- attr.put(ATTRIBUTE_HUB_ID, hubId.toString());
- attr.put(ATTRIBUTE_EXP_HANDLING_DURATION, String.valueOf(expHandlingDuration));
- return attr;
- }
+ public double getExpHandlingDuration() {
+ return expHandlingDuration;
+ }
- public static HandlingInHubStartsEvent convert (GenericEvent event) {
- Map attributes = event.getAttributes();
- double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME));
- Id linkId = Id.createLinkId(attributes.get(ATTRIBUTE_LINK));
- Id lspSipmentId = Id.create(attributes.get(ATTRIBUTE_LSP_SHIPMENT_ID), LSPShipment.class);
- var hubId = Id.create(attributes.get(ATTRIBUTE_HUB_ID), LSPResource.class);
- double expHandlingDuration = Double.parseDouble(attributes.get(ATTRIBUTE_EXP_HANDLING_DURATION));
- return new HandlingInHubStartsEvent(time, linkId, lspSipmentId, hubId, expHandlingDuration);
- }
+ @Override
+ public Map getAttributes() {
+ Map attr = super.getAttributes();
+ attr.put(ATTRIBUTE_HUB_ID, hubId.toString());
+ attr.put(ATTRIBUTE_EXP_HANDLING_DURATION, String.valueOf(expHandlingDuration));
+ return attr;
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/events/LspEventAttributes.java b/src/main/java/org/matsim/freight/logistics/events/LspEventAttributes.java
index ca6c0330..830862b6 100644
--- a/src/main/java/org/matsim/freight/logistics/events/LspEventAttributes.java
+++ b/src/main/java/org/matsim/freight/logistics/events/LspEventAttributes.java
@@ -22,12 +22,11 @@
package org.matsim.freight.logistics.events;
/**
- * Some constants, that are used for the Attributes of different logistic events.
+ * Some constants, that are used for the Attributes of different logistic events.
*
- * @author Kai Martins-Turner (kturner)
+ * @author Kai Martins-Turner (kturner)
*/
public class LspEventAttributes {
- public static final String ATTRIBUTE_HUB_ID = "hubId";
- public static final String ATTRIBUTE_EXP_HANDLING_DURATION = "expHandlingDuration";
-
-}
\ No newline at end of file
+ public static final String ATTRIBUTE_HUB_ID = "hubId";
+ public static final String ATTRIBUTE_EXP_HANDLING_DURATION = "expHandlingDuration";
+}
diff --git a/src/main/java/org/matsim/freight/logistics/events/LspEventCreator.java b/src/main/java/org/matsim/freight/logistics/events/LspEventCreator.java
index 1752ec25..034592ca 100644
--- a/src/main/java/org/matsim/freight/logistics/events/LspEventCreator.java
+++ b/src/main/java/org/matsim/freight/logistics/events/LspEventCreator.java
@@ -21,19 +21,16 @@
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.shipment.LSPShipment;
/**
- *
* @author Kai Martins-Turner (kturner)
*/
-
public interface LspEventCreator {
- // I am unsure, if I need the activity or not. kmt 'dec22
- Event createEvent(Event event, Id lspShipmentId, Activity activity);
+ // I am unsure, if I need the activity or not. kmt 'dec22
+ Event createEvent(Event event, Id lspShipmentId, Activity activity);
}
diff --git a/src/main/java/org/matsim/freight/logistics/events/LspEventsReader.java b/src/main/java/org/matsim/freight/logistics/events/LspEventsReader.java
index 93df8197..196e89ee 100644
--- a/src/main/java/org/matsim/freight/logistics/events/LspEventsReader.java
+++ b/src/main/java/org/matsim/freight/logistics/events/LspEventsReader.java
@@ -21,30 +21,32 @@
package org.matsim.freight.logistics.events;
+import java.util.Map;
+import java.util.TreeMap;
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.events.MatsimEventsReader;
import org.matsim.freight.carriers.events.CarrierEventsReaders;
-import java.util.Map;
-import java.util.TreeMap;
-
/**
- * Creates an {@link MatsimEventsReader} that also handles the {@link org.matsim.freight.logistics.LSP} specific events.
-
+ * Creates an {@link MatsimEventsReader} that also handles the {@link
+ * org.matsim.freight.logistics.LSP} specific events.
+ *
* @author kturner (Kai Martins-Turner)
*/
public class LspEventsReader {
- public static Map createCustomEventMappers() {
- Map map = new TreeMap<>(CarrierEventsReaders.createCustomEventMappers());// also get all the Carrier-related EventMapper
- map.put(HandlingInHubStartsEvent.EVENT_TYPE, HandlingInHubStartsEvent::convert);
- return map;
- }
-
- public static MatsimEventsReader createEventsReader(EventsManager eventsManager) {
- MatsimEventsReader reader = new MatsimEventsReader(eventsManager);
- createCustomEventMappers().forEach(reader::addCustomEventMapper);
- return reader;
- }
-
+ public static Map createCustomEventMappers() {
+ Map map =
+ new TreeMap<>(
+ CarrierEventsReaders
+ .createCustomEventMappers()); // also get all the Carrier-related EventMapper
+ map.put(HandlingInHubStartsEvent.EVENT_TYPE, HandlingInHubStartsEvent::convert);
+ return map;
+ }
+
+ public static MatsimEventsReader createEventsReader(EventsManager eventsManager) {
+ MatsimEventsReader reader = new MatsimEventsReader(eventsManager);
+ createCustomEventMappers().forEach(reader::addCustomEventMapper);
+ return reader;
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/example/lsp/initialPlans/ExampleSchedulingOfInitialPlan.java b/src/main/java/org/matsim/freight/logistics/example/lsp/initialPlans/ExampleSchedulingOfInitialPlan.java
index 3c194896..b35e9a11 100644
--- a/src/main/java/org/matsim/freight/logistics/example/lsp/initialPlans/ExampleSchedulingOfInitialPlan.java
+++ b/src/main/java/org/matsim/freight/logistics/example/lsp/initialPlans/ExampleSchedulingOfInitialPlan.java
@@ -20,12 +20,10 @@
package org.matsim.freight.logistics.example.lsp.initialPlans;
-import org.matsim.freight.logistics.*;
-import org.matsim.freight.logistics.resourceImplementations.ResourceImplementationUtils;
-import org.matsim.freight.logistics.resourceImplementations.collectionCarrier.CollectionCarrierUtils;
-import org.matsim.freight.logistics.shipment.LSPShipment;
-import org.matsim.freight.logistics.shipment.ShipmentPlanElement;
-import org.matsim.freight.logistics.shipment.ShipmentUtils;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Random;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
@@ -35,152 +33,177 @@
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.freight.carriers.*;
import org.matsim.freight.carriers.CarrierCapabilities.FleetSize;
+import org.matsim.freight.logistics.*;
+import org.matsim.freight.logistics.resourceImplementations.ResourceImplementationUtils;
+import org.matsim.freight.logistics.resourceImplementations.collectionCarrier.CollectionCarrierUtils;
+import org.matsim.freight.logistics.shipment.LSPShipment;
+import org.matsim.freight.logistics.shipment.ShipmentPlanElement;
+import org.matsim.freight.logistics.shipment.ShipmentUtils;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Random;
-
/*package-private*/ class ExampleSchedulingOfInitialPlan {
- private static LSP createInitialLSP(Network network) {
-
- //The Carrier for the resource of the sole LogisticsSolutionElement of the LSP is created
- Id carrierId = Id.create("CollectionCarrier", Carrier.class);
- Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class);
- CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId);
- vehicleTypeBuilder.setCapacity(10);
- vehicleTypeBuilder.setCostPerDistanceUnit(0.0004);
- vehicleTypeBuilder.setCostPerTimeUnit(0.38);
- vehicleTypeBuilder.setFixCost(49);
- vehicleTypeBuilder.setMaxVelocity(50 / 3.6);
- org.matsim.vehicles.VehicleType collectionType = vehicleTypeBuilder.build();
-
- Id collectionLinkId = Id.createLinkId("(4 2) (4 3)");
- Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle");
- CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId, collectionType);
-
- CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance();
- capabilitiesBuilder.addType(collectionType);
- capabilitiesBuilder.addVehicle(carrierVehicle);
- capabilitiesBuilder.setFleetSize(FleetSize.INFINITE);
- CarrierCapabilities capabilities = capabilitiesBuilder.build();
-
- Carrier carrier = CarriersUtils.createCarrier(carrierId);
- carrier.setCarrierCapabilities(capabilities);
-
- //The Resource i.e. the Resource is created
- LSPResource collectionResource = CollectionCarrierUtils.CollectionCarrierResourceBuilder.newInstance(carrier, network)
- .setCollectionScheduler(CollectionCarrierUtils.createDefaultCollectionCarrierScheduler())
- .setLocationLinkId(collectionLinkId)
- .build();
-
- //The adapter is now inserted into the only LogisticsSolutionElement of the only LogisticsSolution of the LSP
- LogisticChainElement collectionElement = LSPUtils.LogisticChainElementBuilder.newInstance(Id.create("CollectionElement", LogisticChainElement.class))
- .setResource(collectionResource)
- .build();
-
- //The LogisticsSolutionElement is now inserted into the only LogisticsSolution of the LSP
- LogisticChain collectionSolution = LSPUtils.LogisticChainBuilder.newInstance(Id.create("CollectionSolution", LogisticChain.class))
- .addLogisticChainElement(collectionElement)
- .build();
-
- //The initial plan of the lsp is generated and the assigner and the solution from above are added
- LSPPlan collectionPlan = LSPUtils.createLSPPlan();
- ShipmentAssigner assigner = ResourceImplementationUtils.createSingleLogisticChainShipmentAssigner();
- collectionPlan.setAssigner(assigner);
- collectionPlan.addLogisticChain(collectionSolution);
-
- //The exogenous list of Resoruces for the SolutuionScheduler is compiled and the Scheduler is added to the LSPBuilder
- ArrayList resourcesList = new ArrayList<>();
- resourcesList.add(collectionResource);
- LogisticChainScheduler simpleScheduler = ResourceImplementationUtils.createDefaultSimpleForwardLogisticChainScheduler(resourcesList);
-
- return LSPUtils.LSPBuilder.getInstance(Id.create("CollectionLSP", LSP.class))
- .setInitialPlan(collectionPlan)
- .setLogisticChainScheduler(simpleScheduler)
- .build();
- }
-
- private static Collection createInitialLSPShipments(Network network) {
- ArrayList shipmentList = new ArrayList<>();
- ArrayList linkList = new ArrayList<>(network.getLinks().values());
-
- //Create five LSPShipments that are located in the left half of the network.
- for (int i = 1; i < 6; i++) {
- Id id = Id.create(i, LSPShipment.class);
- ShipmentUtils.LSPShipmentBuilder builder = ShipmentUtils.LSPShipmentBuilder.newInstance(id);
- Random random = new Random(1);
- int capacityDemand = random.nextInt(4);
- builder.setCapacityDemand(capacityDemand);
-
- while (true) {
- Collections.shuffle(linkList, random);
- Link pendingFromLink = linkList.get(0);
- if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 &&
- pendingFromLink.getFromNode().getCoord().getY() <= 4000 &&
- pendingFromLink.getToNode().getCoord().getX() <= 4000 &&
- pendingFromLink.getToNode().getCoord().getY() <= 4000) {
- builder.setFromLinkId(pendingFromLink.getId());
- break;
- }
- }
-
- builder.setToLinkId(Id.createLinkId("(4 2) (4 3)"));
- TimeWindow endTimeWindow = TimeWindow.newInstance(0, (24 * 3600));
- builder.setEndTimeWindow(endTimeWindow);
- TimeWindow startTimeWindow = TimeWindow.newInstance(0, (24 * 3600));
- builder.setStartTimeWindow(startTimeWindow);
- builder.setDeliveryServiceTime(capacityDemand * 60);
- shipmentList.add(builder.build());
- }
- return shipmentList;
- }
-
-
- public static void main(String[] args) {
-
- //Set up required MATSim classes
- Config config = new Config();
- config.addCoreModules();
- Scenario scenario = ScenarioUtils.createScenario(config);
- new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml");
- Network network = scenario.getNetwork();
-
- //Create LSP and shipments
- LSP lsp = createInitialLSP(network);
- Collection shipments = createInitialLSPShipments(network);
-
- //assign the shipments to the LSP
- for (LSPShipment shipment : shipments) {
- lsp.assignShipmentToLSP(shipment);
- }
-
- //schedule the LSP with the shipments and according to the scheduler of the Resource
- lsp.scheduleLogisticChains();
-
- //print the schedules for the assigned LSPShipments
- for (LSPShipment shipment : shipments) {
- System.out.println("Shipment: " + shipment.getId());
- ArrayList scheduleElements = new ArrayList<>(ShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId())
- .getPlanElements().values());
- scheduleElements.sort(ShipmentUtils.createShipmentPlanElementComparator());
- ArrayList logElements = new ArrayList<>(shipment.getShipmentLog().getPlanElements().values());
- logElements.sort(ShipmentUtils.createShipmentPlanElementComparator());
-
- for (ShipmentPlanElement element : ShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId())
- .getPlanElements().values()) {
- System.out.println(
-// "Solution Id: " + element.getSolutionElement().getEmbeddingContainer().getId() +
- " SolutionElement Id: " + element.getLogisticChainElement().getId()
- + " Resource Id: " + element.getResourceId()
- + " Type: " + element.getElementType()
- + " Start Time: " + element.getStartTime()
- + " End Time: " + element.getEndTime());
- }
- System.out.println();
- }
- }
+ private static LSP createInitialLSP(Network network) {
+
+ // The Carrier for the resource of the sole LogisticsSolutionElement of the LSP is created
+ Id carrierId = Id.create("CollectionCarrier", Carrier.class);
+ Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class);
+ CarrierVehicleType.Builder vehicleTypeBuilder =
+ CarrierVehicleType.Builder.newInstance(vehicleTypeId);
+ vehicleTypeBuilder.setCapacity(10);
+ vehicleTypeBuilder.setCostPerDistanceUnit(0.0004);
+ vehicleTypeBuilder.setCostPerTimeUnit(0.38);
+ vehicleTypeBuilder.setFixCost(49);
+ vehicleTypeBuilder.setMaxVelocity(50 / 3.6);
+ org.matsim.vehicles.VehicleType collectionType = vehicleTypeBuilder.build();
+
+ Id collectionLinkId = Id.createLinkId("(4 2) (4 3)");
+ Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle");
+ CarrierVehicle carrierVehicle =
+ CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId, collectionType);
+
+ CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance();
+ capabilitiesBuilder.addType(collectionType);
+ capabilitiesBuilder.addVehicle(carrierVehicle);
+ capabilitiesBuilder.setFleetSize(FleetSize.INFINITE);
+ CarrierCapabilities capabilities = capabilitiesBuilder.build();
+
+ Carrier carrier = CarriersUtils.createCarrier(carrierId);
+ carrier.setCarrierCapabilities(capabilities);
+
+ // The Resource i.e. the Resource is created
+ LSPResource collectionResource =
+ CollectionCarrierUtils.CollectionCarrierResourceBuilder.newInstance(carrier, network)
+ .setCollectionScheduler(
+ CollectionCarrierUtils.createDefaultCollectionCarrierScheduler())
+ .setLocationLinkId(collectionLinkId)
+ .build();
+
+ // The adapter is now inserted into the only LogisticsSolutionElement of the only
+ // LogisticsSolution of the LSP
+ LogisticChainElement collectionElement =
+ LSPUtils.LogisticChainElementBuilder.newInstance(
+ Id.create("CollectionElement", LogisticChainElement.class))
+ .setResource(collectionResource)
+ .build();
+
+ // The LogisticsSolutionElement is now inserted into the only LogisticsSolution of the LSP
+ LogisticChain collectionSolution =
+ LSPUtils.LogisticChainBuilder.newInstance(
+ Id.create("CollectionSolution", LogisticChain.class))
+ .addLogisticChainElement(collectionElement)
+ .build();
+
+ // The initial plan of the lsp is generated and the assigner and the solution from above are
+ // added
+ LSPPlan collectionPlan = LSPUtils.createLSPPlan();
+ ShipmentAssigner assigner =
+ ResourceImplementationUtils.createSingleLogisticChainShipmentAssigner();
+ collectionPlan.setAssigner(assigner);
+ collectionPlan.addLogisticChain(collectionSolution);
+
+ // The exogenous list of Resoruces for the SolutuionScheduler is compiled and the Scheduler is
+ // added to the LSPBuilder
+ ArrayList resourcesList = new ArrayList<>();
+ resourcesList.add(collectionResource);
+ LogisticChainScheduler simpleScheduler =
+ ResourceImplementationUtils.createDefaultSimpleForwardLogisticChainScheduler(resourcesList);
+
+ return LSPUtils.LSPBuilder.getInstance(Id.create("CollectionLSP", LSP.class))
+ .setInitialPlan(collectionPlan)
+ .setLogisticChainScheduler(simpleScheduler)
+ .build();
+ }
+
+ private static Collection createInitialLSPShipments(Network network) {
+ ArrayList shipmentList = new ArrayList<>();
+ ArrayList linkList = new ArrayList<>(network.getLinks().values());
+
+ // Create five LSPShipments that are located in the left half of the network.
+ for (int i = 1; i < 6; i++) {
+ Id id = Id.create(i, LSPShipment.class);
+ ShipmentUtils.LSPShipmentBuilder builder = ShipmentUtils.LSPShipmentBuilder.newInstance(id);
+ Random random = new Random(1);
+ int capacityDemand = random.nextInt(4);
+ builder.setCapacityDemand(capacityDemand);
+
+ while (true) {
+ Collections.shuffle(linkList, random);
+ Link pendingFromLink = linkList.get(0);
+ if (pendingFromLink.getFromNode().getCoord().getX() <= 4000
+ && pendingFromLink.getFromNode().getCoord().getY() <= 4000
+ && pendingFromLink.getToNode().getCoord().getX() <= 4000
+ && pendingFromLink.getToNode().getCoord().getY() <= 4000) {
+ builder.setFromLinkId(pendingFromLink.getId());
+ break;
+ }
+ }
+
+ builder.setToLinkId(Id.createLinkId("(4 2) (4 3)"));
+ TimeWindow endTimeWindow = TimeWindow.newInstance(0, (24 * 3600));
+ builder.setEndTimeWindow(endTimeWindow);
+ TimeWindow startTimeWindow = TimeWindow.newInstance(0, (24 * 3600));
+ builder.setStartTimeWindow(startTimeWindow);
+ builder.setDeliveryServiceTime(capacityDemand * 60);
+ shipmentList.add(builder.build());
+ }
+ return shipmentList;
+ }
+
+ public static void main(String[] args) {
+
+ // Set up required MATSim classes
+ Config config = new Config();
+ config.addCoreModules();
+ Scenario scenario = ScenarioUtils.createScenario(config);
+ new MatsimNetworkReader(scenario.getNetwork())
+ .readFile("scenarios/2regions/2regions-network.xml");
+ Network network = scenario.getNetwork();
+
+ // Create LSP and shipments
+ LSP lsp = createInitialLSP(network);
+ Collection shipments = createInitialLSPShipments(network);
+
+ // assign the shipments to the LSP
+ for (LSPShipment shipment : shipments) {
+ lsp.assignShipmentToLSP(shipment);
+ }
+
+ // schedule the LSP with the shipments and according to the scheduler of the Resource
+ lsp.scheduleLogisticChains();
+
+ // print the schedules for the assigned LSPShipments
+ for (LSPShipment shipment : shipments) {
+ System.out.println("Shipment: " + shipment.getId());
+ ArrayList scheduleElements =
+ new ArrayList<>(
+ ShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId())
+ .getPlanElements()
+ .values());
+ scheduleElements.sort(ShipmentUtils.createShipmentPlanElementComparator());
+ ArrayList logElements =
+ new ArrayList<>(shipment.getShipmentLog().getPlanElements().values());
+ logElements.sort(ShipmentUtils.createShipmentPlanElementComparator());
+
+ for (ShipmentPlanElement element :
+ ShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId())
+ .getPlanElements()
+ .values()) {
+ System.out.println(
+ // "Solution Id: " + element.getSolutionElement().getEmbeddingContainer().getId() +
+ " SolutionElement Id: "
+ + element.getLogisticChainElement().getId()
+ + " Resource Id: "
+ + element.getResourceId()
+ + " Type: "
+ + element.getElementType()
+ + " Start Time: "
+ + element.getStartTime()
+ + " End Time: "
+ + element.getEndTime());
+ }
+ System.out.println();
+ }
+ }
}
diff --git a/src/main/java/org/matsim/freight/logistics/example/lsp/initialPlans/ExampleSchedulingOfTransportChain.java b/src/main/java/org/matsim/freight/logistics/example/lsp/initialPlans/ExampleSchedulingOfTransportChain.java
index a29cf450..64ec11ad 100644
--- a/src/main/java/org/matsim/freight/logistics/example/lsp/initialPlans/ExampleSchedulingOfTransportChain.java
+++ b/src/main/java/org/matsim/freight/logistics/example/lsp/initialPlans/ExampleSchedulingOfTransportChain.java
@@ -20,15 +20,10 @@
package org.matsim.freight.logistics.example.lsp.initialPlans;
-import org.matsim.freight.logistics.*;
-import org.matsim.freight.logistics.resourceImplementations.ResourceImplementationUtils;
-import org.matsim.freight.logistics.resourceImplementations.collectionCarrier.CollectionCarrierUtils;
-import org.matsim.freight.logistics.resourceImplementations.distributionCarrier.DistributionCarrierUtils;
-import org.matsim.freight.logistics.resourceImplementations.mainRunCarrier.MainRunCarrierUtils;
-import org.matsim.freight.logistics.resourceImplementations.transshipmentHub.TranshipmentHubUtils;
-import org.matsim.freight.logistics.shipment.LSPShipment;
-import org.matsim.freight.logistics.shipment.ShipmentPlanElement;
-import org.matsim.freight.logistics.shipment.ShipmentUtils;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Random;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
@@ -38,311 +33,361 @@
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.freight.carriers.*;
import org.matsim.freight.carriers.CarrierCapabilities.FleetSize;
+import org.matsim.freight.logistics.*;
+import org.matsim.freight.logistics.resourceImplementations.ResourceImplementationUtils;
+import org.matsim.freight.logistics.resourceImplementations.collectionCarrier.CollectionCarrierUtils;
+import org.matsim.freight.logistics.resourceImplementations.distributionCarrier.DistributionCarrierUtils;
+import org.matsim.freight.logistics.resourceImplementations.mainRunCarrier.MainRunCarrierUtils;
+import org.matsim.freight.logistics.resourceImplementations.transshipmentHub.TranshipmentHubUtils;
+import org.matsim.freight.logistics.shipment.LSPShipment;
+import org.matsim.freight.logistics.shipment.ShipmentPlanElement;
+import org.matsim.freight.logistics.shipment.ShipmentUtils;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Random;
-
/*A transport chain with five elements (collection-> reloading -> main run -> reloading -> delivery) is created and scheduled
*
*/
/*package-private*/ class ExampleSchedulingOfTransportChain {
- private static LSP createInitialLSP(Scenario scenario) {
-
- Network network = scenario.getNetwork();
-
- //The Carrier for collection is created
- Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class);
- Id