Skip to content

Commit

Permalink
Revert "more maintenance"
Browse files Browse the repository at this point in the history
This reverts commit 5f600b2.
  • Loading branch information
kt86 committed Jun 1, 2022
1 parent 2be961c commit b4e931d
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 70 deletions.
4 changes: 2 additions & 2 deletions src/main/java/example/lsp/lspScoring/ExampleLSPScoring.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ private static LSP createLSPWithScorer(Network network) {

//Create SimulationTracker for the information that the Scorer needs
TipSimulationTracker tracker = new TipSimulationTracker(handler,info);

//add SimulationTracker to the Resource
collectionAdapter.addSimulationTracker(tracker);

//Create the Scorer and add it to the lsp
lsp.setScorer( new TipScorer(lsp, tracker) );
TipScorer scorer = new TipScorer(lsp, tracker);
lsp.setScorer(scorer);

// yyyyyy there is almost surely something wrong with the design if you cannot set the
// scorer in the builder. kai, sep'18
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/lsp/HasBackpointer.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package lsp;

public interface HasBackpointer<T> {

// yy maybe also have interface HasSettableBackpointer?
default void setEmbeddingContainer(T pointer) {};

T getEmbeddingContainer();

void setEmbeddingContainer(T pointer);
T getEmbeddingContainer() ;
}
1 change: 0 additions & 1 deletion src/main/java/lsp/HasEventHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@
public interface HasEventHandlers {

Collection<EventHandler>getEventHandlers();

}
3 changes: 0 additions & 3 deletions src/main/java/lsp/HasSimulationTrackers.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import java.util.Collection;

public interface HasSimulationTrackers{

void addSimulationTracker( LSPSimulationTracker tracker );

Collection<LSPSimulationTracker> getSimulationTrackers();

}
10 changes: 5 additions & 5 deletions src/main/java/lsp/LSPUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.ArrayList;
import java.util.Collection;

public final class LSPUtils{
public class LSPUtils{
public static LSPPlan createLSPPlan(){
return new LSPPlanImpl();
}
Expand All @@ -41,7 +41,7 @@ public static WaitingShipments createWaitingShipments(){
return new WaitingShipmentsImpl();
}
private LSPUtils(){} // do not instantiate
public static final class LSPBuilder{
public static class LSPBuilder{
Id<LSP> id;
SolutionScheduler solutionScheduler;
LSPPlan initialPlan;
Expand All @@ -55,8 +55,8 @@ public static LSPBuilder getInstance(Id<LSP> id){
}

private LSPBuilder(Id<LSP> id){
this.id = id; // this line was not there until today. kai, may'22
this.resources = new ArrayList<>();

}

public LSPBuilder setSolutionScheduler( SolutionScheduler solutionScheduler ){
Expand Down Expand Up @@ -93,7 +93,7 @@ public LSP build(){
}
}

public static final class LogisticsSolutionBuilder{
public static class LogisticsSolutionBuilder{
final Id<LogisticsSolution> id;
final Collection<LogisticsSolutionElement> elements;
final Collection<LSPInfo> solutionInfos;
Expand Down Expand Up @@ -137,7 +137,7 @@ public LogisticsSolution build(){
}
}

public static final class LogisticsSolutionElementBuilder{
public static class LogisticsSolutionElementBuilder{
final Id<LogisticsSolutionElement>id;
LSPResource resource;
final WaitingShipments incomingShipments;
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/lsp/controler/LSPControlerListenerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;


class LSPControlerListenerImpl implements BeforeMobsimListener, AfterMobsimListener, ScoringListener,
Expand All @@ -54,12 +53,11 @@ class LSPControlerListenerImpl implements BeforeMobsimListener, AfterMobsimListe
private final LSPScoringModule scoringModule;
private final Collection<LSPEventCreator> creators;

private List<EventHandler> registeredHandlers;
private ArrayList <EventHandler> registeredHandlers;

@Inject private EventsManager eventsManager;
@Inject EventsManager eventsManager;

@Inject LSPControlerListenerImpl( Scenario scenario, LSPReplanningModule replanningModule, LSPScoringModule scoringModule,
Collection<LSPEventCreator> creators ) {
@Inject LSPControlerListenerImpl( Scenario scenario, LSPReplanningModule replanningModule, LSPScoringModule scoringModule, Collection<LSPEventCreator> creators ) {
this.scenario = scenario;
this.replanningModule = replanningModule;
this.scoringModule = scoringModule;
Expand All @@ -71,7 +69,8 @@ class LSPControlerListenerImpl implements BeforeMobsimListener, AfterMobsimListe
public void notifyBeforeMobsim(BeforeMobsimEvent event) {
LSPs lsps = LSPUtils.getLSPs( scenario );

LSPRescheduler.notifyBeforeMobsim(lsps, event);
LSPRescheduler rescheduler = new LSPRescheduler(lsps);
rescheduler.notifyBeforeMobsim(event);

carrierResourceTracker = new CarrierAgentTracker(carriers, creators, eventsManager );
eventsManager.addHandler(carrierResourceTracker);
Expand Down Expand Up @@ -122,7 +121,7 @@ public void notifyAfterMobsim(AfterMobsimEvent event) {

eventsManager.removeHandler(carrierResourceTracker);

Collection<LSPSimulationTracker> alreadyUpdatedTrackers = new ArrayList<>();
ArrayList<LSPSimulationTracker> alreadyUpdatedTrackers = new ArrayList<>();
for(LSP lsp : lsps.getLSPs().values()) {
for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) {
for(LogisticsSolutionElement element : solution.getSolutionElements()) {
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/lsp/controler/LSPModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public void install() {
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;
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() );
}
Expand All @@ -79,10 +79,10 @@ public void install() {
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;
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() );
}
Expand All @@ -96,8 +96,9 @@ public void install() {
// (if you do not like them, you will have to override the binding. kai, may'22)
}

@Provides CarrierAgentTracker provideCarrierResourceTracker( LSPControlerListenerImpl lspControlerListener ) {
return lspControlerListener.getCarrierResourceTracker();
@Provides
CarrierAgentTracker provideCarrierResourceTracker( LSPControlerListenerImpl lSPControlerListener ) {
return lSPControlerListener.getCarrierResourceTracker();
}

}
17 changes: 8 additions & 9 deletions src/main/java/lsp/controler/LSPRescheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,16 @@
* network, for example passenger traffic, and the network conditions change between
* subsequent iterations of the simulation due to congestion.
*/
final class LSPRescheduler {
private LSPRescheduler(){ }
class LSPRescheduler implements BeforeMobsimListener{


// private final LSPs lsps;
//
// public LSPRescheduler(LSPs lsps) {
// this.lsps = lsps;
// }

static void notifyBeforeMobsim( LSPs lsps, BeforeMobsimEvent arg0) {
private final LSPs lsps;

public LSPRescheduler(LSPs lsps) {
this.lsps = lsps;
}

public void notifyBeforeMobsim(BeforeMobsimEvent arg0) {
if(arg0.getIteration() != 0) {
for(LSP lsp : lsps.getLSPs().values()){
for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/lsp/controler/LSPSimulationTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@

package lsp.controler;

import java.util.Collection;

import lsp.HasEventHandlers;
import lsp.HasInfos;
import org.matsim.core.controler.listener.AfterMobsimListener;
import org.matsim.core.events.handler.EventHandler;

public interface LSPSimulationTracker extends AfterMobsimListener, HasEventHandlers, HasInfos {
import lsp.LSPInfo;

public interface LSPSimulationTracker extends AfterMobsimListener, HasEventHandlers, HasInfos {
void reset();

}
7 changes: 0 additions & 7 deletions src/main/java/lsp/shipment/LSPShipment.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@
import lsp.LogisticsSolution;
import lsp.LSPInfo;

/**
* This is, for example, a shipment that DHL moves from A to B. It may use multiple carriers to achieve that.
*
* Questions/comments:<ul>
* <li>Within more modern MATSim, we would probably prefer to have from and to in coordinates, not link IDs.</li>
* </ul>
*/
public interface LSPShipment extends Identifiable<LSPShipment>, HasInfos, HasEventHandlers {

Id<Link> getFrom(); // same as in CarrierShipment
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/lsp/shipment/LSPShipmentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
Expand All @@ -44,9 +43,9 @@ class LSPShipmentImpl implements LSPShipment {
private final double pickupServiceTime;
private final ShipmentPlan schedule;
private final ShipmentPlan log;
private final Collection<EventHandler> eventHandlers;
private final List<Requirement> requirements;
private final List<LSPInfo> infos;
private final ArrayList<EventHandler> eventHandlers;
private final ArrayList<Requirement> requirements;
private final ArrayList<LSPInfo> infos;
private Id<LogisticsSolution> solutionId;

LSPShipmentImpl( ShipmentUtils.LSPShipmentBuilder builder ){
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/lsp/shipment/ShipmentPlan.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@

import java.util.Map;

import lsp.HasBackpointer;
import org.matsim.api.core.v01.Id;

public interface ShipmentPlan extends HasBackpointer<LSPShipment> {
public interface ShipmentPlan {

LSPShipment getEmbeddingContainer();
LSPShipment getShipment();

Map<Id<ShipmentPlanElement>, ShipmentPlanElement> getPlanElements();

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/lsp/shipment/ShipmentPlanElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ public interface ShipmentPlanElement {
LogisticsSolutionElement getSolutionElement();

Id<LSPResource> getResourceId();

// yyyy "type" feels like this makes it a tagged class. These should be avoided (Effective Java 2018, Item 23). It is, however, probably not
// used as a type, but rather as a description. Rename?

String getElementType();

double getStartTime();

double getEndTime();

}
2 changes: 1 addition & 1 deletion src/main/java/lsp/shipment/ShipmentPlanImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public int compare(ShipmentPlanElement o1, ShipmentPlanElement o2) {
}

@Override
public LSPShipment getEmbeddingContainer() {
public LSPShipment getShipment() {
return shipment;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ public void testShipments() {
assertNotNull(shipment.getEventHandlers());

assertTrue(shipment.getEventHandlers().isEmpty());
assertEquals(shipment.getLog().getEmbeddingContainer(), shipment );
assertEquals(shipment.getLog().getShipment(), shipment);
assertTrue(shipment.getLog().getPlanElements().isEmpty());

assertEquals(shipment.getShipmentPlan().getEmbeddingContainer(), shipment );
assertEquals(shipment.getShipmentPlan().getShipment(), shipment);
assertTrue(shipment.getShipmentPlan().getPlanElements().isEmpty());

Link link = network.getLinks().get(shipment.getFrom() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public void testShipments() {
assertNotNull(shipment.getEventHandlers());

assertTrue(shipment.getEventHandlers().isEmpty());
assertEquals(shipment.getLog().getEmbeddingContainer(), shipment );
assertEquals(shipment.getLog().getShipment(), shipment);
assertTrue(shipment.getLog().getPlanElements().isEmpty());

assertEquals(shipment.getShipmentPlan().getEmbeddingContainer(), shipment );
assertEquals(shipment.getShipmentPlan().getShipment(), shipment);
assertTrue(shipment.getShipmentPlan().getPlanElements().isEmpty());
Link link = network.getLinks().get(shipment.getTo() );
assertTrue(link.getFromNode().getCoord().getX() <= 18000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ public void testShipments() {
assertNotNull(shipment.getEventHandlers());

assertTrue(shipment.getEventHandlers().isEmpty());
assertEquals(shipment.getLog().getEmbeddingContainer(), shipment );
assertEquals(shipment.getLog().getShipment(), shipment);
assertTrue(shipment.getLog().getPlanElements().isEmpty());

assertEquals(shipment.getShipmentPlan().getEmbeddingContainer(), shipment );
assertEquals(shipment.getShipmentPlan().getShipment(), shipment);
assertTrue(shipment.getShipmentPlan().getPlanElements().isEmpty());
Link link = network.getLinks().get(shipment.getTo() );
assertTrue(link.getFromNode().getCoord().getX() <= 18000);
Expand Down

0 comments on commit b4e931d

Please sign in to comment.