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

Commit

Permalink
rename shipment(s) to lspShipments, to avoid confusions with (Carrier…
Browse files Browse the repository at this point in the history
…) Shipments
  • Loading branch information
kt86 committed Aug 12, 2024
1 parent 624417c commit 818f69d
Show file tree
Hide file tree
Showing 94 changed files with 483 additions and 483 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void insertShipmentsAtBeginning() {
for (LogisticChain solution : lsp.getSelectedPlan().getLogisticChains()) {
LogisticChainElement firstElement = getFirstElement(solution);
assert firstElement != null;
for (Id<LSPShipment> lspShipmentId : solution.getShipmentIds()) {
for (Id<LSPShipment> lspShipmentId : solution.getLspShipmentIds()) {
var shipment = LSPUtils.findLspShipment(lsp, lspShipmentId);
assert shipment != null;
firstElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
*/
public interface InitialShipmentAssigner {

void assignToPlan(LSPPlan lspPlan, LSPShipment shipment);
void assignToPlan(LSPPlan lspPlan, LSPShipment lspShipment);
}
6 changes: 3 additions & 3 deletions src/main/java/org/matsim/freight/logistics/LSP.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public interface LSP extends HasPlansAndId<LSPPlan, LSP>, HasSimulationTrackers<LSP> {

/** yyyy does this have to be exposed? */
Collection<LSPShipment> getShipments();
Collection<LSPShipment> getLspShipments();

/** ok (behavioral method) */
void scheduleLogisticChains();
Expand All @@ -46,8 +46,8 @@ public interface LSP extends HasPlansAndId<LSPPlan, LSP>, HasSimulationTrackers<
void scoreSelectedPlan();

/**
* @param shipment ok (LSP needs to be told that it is responsible for shipment)
* @param lspShipment ok (LSP needs to be told that it is responsible for lspShipment)
*/
void assignShipmentToLSP(LSPShipment shipment);
void assignShipmentToLSP(LSPShipment lspShipment);

}
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public void notifyBeforeMobsim(BeforeMobsimEvent event) {
}

// simulation trackers of shipments:
for (LSPShipment shipment : lsp.getShipments()) {
registerSimulationTrackers(shipment);
for (LSPShipment lspShipment : lsp.getLspShipments()) {
registerSimulationTrackers(lspShipment);
}

// simulation trackers of solutions:
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/org/matsim/freight/logistics/LSPImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
/* package-private */ class LSPImpl extends LSPDataObject<LSP> implements LSP {
private static final Logger log = LogManager.getLogger(LSPImpl.class);

private final Collection<LSPShipment> shipments;
private final ArrayList<LSPPlan> plans;
private final Collection<LSPShipment> lspShipments;
private final ArrayList<LSPPlan> lspPlans;
private final LogisticChainScheduler logisticChainScheduler;
private final Collection<LSPResource> resources;
private LSPPlan selectedPlan;
Expand All @@ -41,13 +41,13 @@

LSPImpl(LSPUtils.LSPBuilder builder) {
super(builder.id);
this.shipments = new ArrayList<>();
this.plans = new ArrayList<>();
this.lspShipments = new ArrayList<>();
this.lspPlans = new ArrayList<>();
this.logisticChainScheduler = builder.logisticChainScheduler;
this.logisticChainScheduler.setEmbeddingContainer(this);
this.selectedPlan = builder.initialPlan;
this.selectedPlan.setLSP(this);
this.plans.add(builder.initialPlan);
this.lspPlans.add(builder.initialPlan);
this.resources = builder.resources;
}

Expand All @@ -57,7 +57,7 @@ public static LSPPlan copyPlan(LSPPlan plan2copy) {
LogisticChain newPlanChain =
LSPUtils.LogisticChainBuilder.newInstance(initialPlanChain.getId()).build();
newPlanChain.getLogisticChainElements().addAll(initialPlanChain.getLogisticChainElements());
newPlanChain.getShipmentIds().addAll(initialPlanChain.getShipmentIds());
newPlanChain.getLspShipmentIds().addAll(initialPlanChain.getLspShipmentIds());
newPlanChains.add(newPlanChain);
}

Expand Down Expand Up @@ -95,7 +95,7 @@ public boolean addPlan(LSPPlan plan) {
}
}
plan.setLSP(this);
return plans.add(plan);
return lspPlans.add(plan);
}

@Override
Expand All @@ -107,7 +107,7 @@ public LSPPlan createCopyOfSelectedPlanAndMakeSelected() {

@Override
public ArrayList<LSPPlan> getPlans() {
return plans;
return lspPlans;
}

@Override
Expand All @@ -117,16 +117,16 @@ public LSPPlan getSelectedPlan() {

@Override
public void setSelectedPlan(LSPPlan selectedPlan) {
if (!plans.contains(selectedPlan)) {
plans.add(selectedPlan);
if (!lspPlans.contains(selectedPlan)) {
lspPlans.add(selectedPlan);
}
this.selectedPlan = selectedPlan;
}

@Override
public boolean removePlan(LSPPlan plan) {
if (plans.contains(plan)) {
plans.remove(plan);
public boolean removePlan(LSPPlan lspPlan) {
if (lspPlans.contains(lspPlan)) {
lspPlans.remove(lspPlan);
return true;
} else {
return false;
Expand All @@ -147,17 +147,17 @@ public void scoreSelectedPlan() {
}

@Override
public void assignShipmentToLSP(LSPShipment shipment) {
public void assignShipmentToLSP(LSPShipment lspShipment) {
// shipment.setLspId(this.getId()); // und rückweg dann auch darüber und dann
// lsp.getselectedPlan.getShipment...
shipments.add(shipment);
for (LSPPlan lspPlan : plans) {
lspPlan.getInitialShipmentAssigner().assignToPlan(lspPlan, shipment);
lspShipments.add(lspShipment);
for (LSPPlan lspPlan : lspPlans) {
lspPlan.getInitialShipmentAssigner().assignToPlan(lspPlan, lspShipment);
}
}

@Override
public Collection<LSPShipment> getShipments() {
return this.shipments;
public Collection<LSPShipment> getLspShipments() {
return this.lspShipments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,25 @@ public final void scheduleShipments(LSPPlan lspPlan, LSPResource resource, int b
private void presortIncomingShipments() {
this.lspShipmentsWithTime = new ArrayList<>();
for (LogisticChainElement element : resource.getClientElements()) {
lspShipmentsWithTime.addAll(element.getIncomingShipments().getShipments());
lspShipmentsWithTime.addAll(element.getIncomingShipments().getLspShipmentsWTime());
}
lspShipmentsWithTime.sort(Comparator.comparingDouble(LspShipmentWithTime::getTime));
}

private void switchHandledShipments(int bufferTime) {
for (LspShipmentWithTime lspShipmentWithTime : lspShipmentsWithTime) {
var shipmentPlan =
ShipmentUtils.getOrCreateShipmentPlan(lspPlan, lspShipmentWithTime.getShipment().getId());
ShipmentUtils.getOrCreateShipmentPlan(lspPlan, lspShipmentWithTime.getLspShipment().getId());
double endOfTransportTime = shipmentPlan.getMostRecentEntry().getEndTime() + bufferTime;
LspShipmentWithTime outgoingTuple =
new LspShipmentWithTime(endOfTransportTime, lspShipmentWithTime.getShipment());
new LspShipmentWithTime(endOfTransportTime, lspShipmentWithTime.getLspShipment());
for (LogisticChainElement element : resource.getClientElements()) {
if (element.getIncomingShipments().getShipments().contains(lspShipmentWithTime)) {
element.getOutgoingShipments().getShipments().add(outgoingTuple);
element.getIncomingShipments().getShipments().remove(lspShipmentWithTime);
if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipmentWithTime)) {
element.getOutgoingShipments().getLspShipmentsWTime().add(outgoingTuple);
element.getIncomingShipments().getLspShipmentsWTime().remove(lspShipmentWithTime);
if (element.getNextElement() != null) {
element.getNextElement().getIncomingShipments().getShipments().add(outgoingTuple);
element.getOutgoingShipments().getShipments().remove(outgoingTuple);
element.getNextElement().getIncomingShipments().getLspShipmentsWTime().add(outgoingTuple);
element.getOutgoingShipments().getLspShipmentsWTime().remove(outgoingTuple);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/matsim/freight/logistics/LSPUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static void setFixedCost(Attributable attributable, Double fixedCost) {
* @return the lspShipment object or null, if it is not found.
*/
public static LSPShipment findLspShipment(LSP lsp, Id<LSPShipment> shipmentId) {
for (LSPShipment lspShipment : lsp.getShipments()) {
for (LSPShipment lspShipment : lsp.getLspShipments()) {
if (lspShipment.getId().equals(shipmentId)) {
return lspShipment;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/matsim/freight/logistics/LogisticChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface LogisticChain

Collection<LogisticChainElement> getLogisticChainElements();

Collection<Id<LSPShipment>> getShipmentIds();
Collection<Id<LSPShipment>> getLspShipmentIds();

void addShipmentToChain(LSPShipment shipment);
void addShipmentToChain(LSPShipment lspShipment);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
private static final Logger log = LogManager.getLogger(LogisticChainImpl.class);

private final Collection<LogisticChainElement> logisticChainElements;
private final Collection<Id<LSPShipment>> shipmentIds;
private final Collection<Id<LSPShipment>> lspShipmentIds;
private LSP lsp;

LogisticChainImpl(LSPUtils.LogisticChainBuilder builder) {
Expand All @@ -41,7 +41,7 @@
for (LogisticChainElement element : this.logisticChainElements) {
element.setEmbeddingContainer(this);
}
this.shipmentIds = new ArrayList<>();
this.lspShipmentIds = new ArrayList<>();
}

@Override
Expand All @@ -60,13 +60,13 @@ public Collection<LogisticChainElement> getLogisticChainElements() {
}

@Override
public Collection<Id<LSPShipment>> getShipmentIds() {
return shipmentIds;
public Collection<Id<LSPShipment>> getLspShipmentIds() {
return lspShipmentIds;
}

@Override
public void addShipmentToChain(LSPShipment shipment) {
shipmentIds.add(shipment.getId());
public void addShipmentToChain(LSPShipment lspShipment) {
lspShipmentIds.add(lspShipment.getId());
}

@Override
Expand All @@ -83,10 +83,10 @@ public String toString() {
}
strb.append("}");
}
strb.append("[No of Shipments=").append(shipmentIds.size()).append("] \n");
if (!shipmentIds.isEmpty()) {
strb.append("[No of Shipments=").append(lspShipmentIds.size()).append("] \n");
if (!lspShipmentIds.isEmpty()) {
strb.append("{ShipmentIds=");
for (Id<LSPShipment> lspShipmentId : shipmentIds) {
for (Id<LSPShipment> lspShipmentId : lspShipmentIds) {
strb.append("[").append(lspShipmentId.toString()).append("]");
}
strb.append("}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ public class LspShipmentWithTime {
// means (delivery time? current time?). kai,
// jun'22

private final LSPShipment shipment;
private final LSPShipment lspShipment;
private final double time;

public LspShipmentWithTime(double time, LSPShipment shipment) {
this.shipment = shipment;
public LspShipmentWithTime(double time, LSPShipment lspShipment) {
this.lspShipment = lspShipment;
this.time = time;
}

public LSPShipment getShipment() {
return shipment;
public LSPShipment getLspShipment() {
return lspShipment;
}

public double getTime() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
*/
public interface WaitingShipments {

void addShipment(double time, LSPShipment shipment);
void addShipment(double time, LSPShipment lspShipment);

Collection<LspShipmentWithTime> getSortedShipments();
Collection<LspShipmentWithTime> getSortedLspShipments();

Collection<LspShipmentWithTime> getShipments();
Collection<LspShipmentWithTime> getLspShipmentsWTime();

void clear();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
}

@Override
public void addShipment(double time, LSPShipment shipment) {
LspShipmentWithTime tuple = new LspShipmentWithTime(time, shipment);
public void addShipment(double time, LSPShipment lspShipment) {
LspShipmentWithTime tuple = new LspShipmentWithTime(time, lspShipment);
this.shipments.add(tuple);
shipments.sort(Comparator.comparingDouble(LspShipmentWithTime::getTime));
}

@Override
public Collection<LspShipmentWithTime> getSortedShipments() {
public Collection<LspShipmentWithTime> getSortedLspShipments() {
shipments.sort(Comparator.comparingDouble(LspShipmentWithTime::getTime));
return shipments;
}
Expand All @@ -52,7 +52,7 @@ public void clear() {
}

@Override
public Collection<LspShipmentWithTime> getShipments() {
public Collection<LspShipmentWithTime> getLspShipmentsWTime() {
return shipments;
}

Expand All @@ -62,8 +62,8 @@ public String toString() {
strb.append("WaitingShipmentsImpl{").append("No of Shipments= ").append(shipments.size());
if (!shipments.isEmpty()) {
strb.append("; ShipmentIds=");
for (LspShipmentWithTime shipment : getSortedShipments()) {
strb.append("[").append(shipment.getShipment().getId()).append("]");
for (LspShipmentWithTime shipment : getSortedLspShipments()) {
strb.append("[").append(shipment.getLspShipment().getId()).append("]");
}
}
strb.append('}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,33 @@ public static void main(String[] args) {
.readFile("scenarios/2regions/2regions-network.xml");
Network network = scenario.getNetwork();

// Create LSP and shipments
// Create LSP and lspShipments
LSP lsp = createInitialLSP(network);
Collection<LSPShipment> shipments = createInitialLSPShipments(network);
Collection<LSPShipment> lspShipments = createInitialLSPShipments(network);

// assign the shipments to the LSP
for (LSPShipment shipment : shipments) {
lsp.assignShipmentToLSP(shipment);
// assign the lspShipments to the LSP
for (LSPShipment lspShipment : lspShipments) {
lsp.assignShipmentToLSP(lspShipment);
}

// schedule the LSP with the shipments and according to the scheduler of the Resource
// schedule the LSP with the lspShipments 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());
for (LSPShipment lspShipment : lspShipments) {
System.out.println("Shipment: " + lspShipment.getId());
ArrayList<ShipmentPlanElement> scheduleElements =
new ArrayList<>(
ShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId())
ShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), lspShipment.getId())
.getPlanElements()
.values());
scheduleElements.sort(ShipmentUtils.createShipmentPlanElementComparator());
ArrayList<ShipmentPlanElement> logElements =
new ArrayList<>(shipment.getShipmentLog().getPlanElements().values());
new ArrayList<>(lspShipment.getShipmentLog().getPlanElements().values());
logElements.sort(ShipmentUtils.createShipmentPlanElementComparator());

for (ShipmentPlanElement element :
ShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId())
ShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), lspShipment.getId())
.getPlanElements()
.values()) {
System.out.println(
Expand Down
Loading

0 comments on commit 818f69d

Please sign in to comment.