Skip to content

Commit

Permalink
pseudosim no longer depends on eventsbasedPtRouter
Browse files Browse the repository at this point in the history
  • Loading branch information
mrieser committed Oct 12, 2023
1 parent e4dca00 commit 11c62de
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 371 deletions.
5 changes: 0 additions & 5 deletions contribs/pseudosimulation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
<artifactId>common</artifactId>
<version>16.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>events-based-pt-router</artifactId>
<version>16.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.Plan;
import org.matsim.contrib.eventsBasedPTRouter.TransitRouterEventsWSFactory;
import org.matsim.contrib.eventsBasedPTRouter.stopStopTimes.StopStopTimeCalculatorImpl;
import org.matsim.contrib.eventsBasedPTRouter.waitTimes.WaitTimeStuckCalculator;
//import org.matsim.contrib.eventsBasedPTRouter.TransitRouterEventsWSFactory;
//import org.matsim.contrib.eventsBasedPTRouter.stopStopTimes.StopStopTimeCalculatorImpl;
//import org.matsim.contrib.eventsBasedPTRouter.waitTimes.WaitTimeStuckCalculator;
import org.matsim.contrib.pseudosimulation.mobsim.PSimProvider;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
Expand All @@ -34,8 +34,8 @@
*/
public class ChoiceGenerationControler implements BeforeMobsimListener{

final WaitTimeStuckCalculator waitTimeCalculator;
final StopStopTimeCalculatorImpl stopStopTimeCalculator;
// final WaitTimeStuckCalculator waitTimeCalculator;
// final StopStopTimeCalculatorImpl stopStopTimeCalculator;
final TravelTimeCalculator travelTimeCalculator;
private PSimProvider pSimProvider;
Config config;
Expand All @@ -49,32 +49,32 @@ public ChoiceGenerationControler(String[] args) {
scenario = ScenarioUtils.loadScenario(config);
controler = new Controler(scenario);

waitTimeCalculator = new WaitTimeStuckCalculator(
controler.getScenario().getPopulation(),
controler.getScenario().getTransitSchedule(),
controler.getConfig().travelTimeCalculator().getTraveltimeBinSize(),
(int) (controler.getConfig().qsim().getEndTime().seconds() - controler.getConfig().qsim().getStartTime().seconds()));
stopStopTimeCalculator = new StopStopTimeCalculatorImpl(
controler.getScenario().getTransitSchedule(),
controler.getConfig().travelTimeCalculator().getTraveltimeBinSize(),
(int) (controler.getConfig().qsim().getEndTime().seconds() - controler.getConfig().qsim().getStartTime().seconds()));
controler.addOverridingModule(new AbstractModule() {
@Override
public void install() {
bind(TransitRouter.class).toProvider(new TransitRouterEventsWSFactory(controler.getScenario(),
waitTimeCalculator.get(),
stopStopTimeCalculator.get()));
}
});
// waitTimeCalculator = new WaitTimeStuckCalculator(
// controler.getScenario().getPopulation(),
// controler.getScenario().getTransitSchedule(),
// controler.getConfig().travelTimeCalculator().getTraveltimeBinSize(),
// (int) (controler.getConfig().qsim().getEndTime().seconds() - controler.getConfig().qsim().getStartTime().seconds()));
// stopStopTimeCalculator = new StopStopTimeCalculatorImpl(
// controler.getScenario().getTransitSchedule(),
// controler.getConfig().travelTimeCalculator().getTraveltimeBinSize(),
// (int) (controler.getConfig().qsim().getEndTime().seconds() - controler.getConfig().qsim().getStartTime().seconds()));
// controler.addOverridingModule(new AbstractModule() {
// @Override
// public void install() {
// bind(TransitRouter.class).toProvider(new TransitRouterEventsWSFactory(controler.getScenario(),
// waitTimeCalculator.get(),
// stopStopTimeCalculator.get()));
// }
// });
// controler.setScoringFunctionFactory(
// new CharyparNagelOpenTimesScoringFunctionFactory(controler.getConfig().planCalcScore(),
// controler.getScenario()));
travelTimeCalculator = TravelTimeCalculator.create(scenario.getNetwork(), config.travelTimeCalculator());

EventsManagerImpl eventsManager = new EventsManagerImpl();
EventsReaderXMLv1 reader = new EventsReaderXMLv1(eventsManager);
eventsManager.addHandler(waitTimeCalculator);
eventsManager.addHandler(stopStopTimeCalculator);
// eventsManager.addHandler(waitTimeCalculator);
// eventsManager.addHandler(stopStopTimeCalculator);
eventsManager.addHandler(travelTimeCalculator);
reader.readFile(args[1]);

Expand Down Expand Up @@ -106,8 +106,8 @@ public void notifyBeforeMobsim(BeforeMobsimEvent event) {
for(Person person:controler.getScenario().getPopulation().getPersons().values()){
plans.add(person.getSelectedPlan());
}
pSimProvider.setWaitTime(waitTimeCalculator.get());
// pSimProvider.setWaitTime(waitTimeCalculator.get());
pSimProvider.setTravelTime(travelTimeCalculator.getLinkTravelTimes());
pSimProvider.setStopStopTime(stopStopTimeCalculator.get());
// pSimProvider.setStopStopTime(stopStopTimeCalculator.get());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.matsim.contrib.pseudosimulation;

import org.matsim.contrib.eventsBasedPTRouter.stopStopTimes.StopStopTime;
import org.matsim.contrib.eventsBasedPTRouter.waitTimes.WaitTime;
//import org.matsim.contrib.eventsBasedPTRouter.stopStopTimes.StopStopTime;
//import org.matsim.contrib.eventsBasedPTRouter.waitTimes.WaitTime;
import org.matsim.contrib.pseudosimulation.distributed.listeners.events.transit.TransitPerformance;
import org.matsim.contrib.pseudosimulation.replanning.PlanCatcher;
import org.matsim.core.router.util.TravelTime;
Expand All @@ -10,8 +10,8 @@
* Created by fouriep on 4/21/15.
*/
public interface PSimDataProvider {
public StopStopTime getStopStopTime();
public WaitTime getWaitTime();
// public StopStopTime getStopStopTime();
// public WaitTime getWaitTime();
public TransitPerformance getTransitPerformance();
public PlanCatcher getPlanCatcher();
public TravelTime getTravelTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@

import com.google.inject.Singleton;
import org.matsim.api.core.v01.Scenario;
import org.matsim.contrib.eventsBasedPTRouter.TransitRouterEventsWSFactory;
import org.matsim.contrib.eventsBasedPTRouter.stopStopTimes.StopStopTime;
import org.matsim.contrib.eventsBasedPTRouter.stopStopTimes.StopStopTimeCalculator;
import org.matsim.contrib.eventsBasedPTRouter.waitTimes.WaitTime;
import org.matsim.contrib.eventsBasedPTRouter.waitTimes.WaitTimeCalculator;
//import org.matsim.contrib.eventsBasedPTRouter.TransitRouterEventsWSFactory;
//import org.matsim.contrib.eventsBasedPTRouter.stopStopTimes.StopStopTime;
//import org.matsim.contrib.eventsBasedPTRouter.stopStopTimes.StopStopTimeCalculator;
//import org.matsim.contrib.eventsBasedPTRouter.waitTimes.WaitTime;
//import org.matsim.contrib.eventsBasedPTRouter.waitTimes.WaitTimeCalculator;
//import org.matsim.contrib.pseudosimulation.distributed.listeners.events.transit.TransitPerformanceRecorder;
import org.matsim.contrib.pseudosimulation.mobsim.PSimProvider;
import org.matsim.contrib.pseudosimulation.mobsim.SwitchingMobsimProvider;
import org.matsim.contrib.pseudosimulation.replanning.PlanCatcher;
import org.matsim.contrib.pseudosimulation.trafficinfo.PSimStopStopTimeCalculator;
import org.matsim.contrib.pseudosimulation.trafficinfo.PSimTravelTimeCalculator;
import org.matsim.contrib.pseudosimulation.trafficinfo.PSimWaitTimeCalculator;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.AbstractModule;
Expand All @@ -43,7 +41,6 @@
import org.matsim.core.mobsim.qsim.QSimProvider;
import org.matsim.core.router.util.TravelTime;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.pt.router.TransitRouter;

/**
* @author pieterfourie
Expand Down Expand Up @@ -74,18 +71,18 @@ public RunPSim(Config config, PSimConfigGroup pSimConfigGroup) {
public void install() {
bind(MobSimSwitcher.class).toInstance(mobSimSwitcher);
bindMobsim().toProvider(SwitchingMobsimProvider.class);
bind(WaitTimeCalculator.class).to(PSimWaitTimeCalculator.class);
bind(WaitTime.class).toProvider(PSimWaitTimeCalculator.class);
bind(StopStopTimeCalculator.class).to(PSimStopStopTimeCalculator.class);
bind(StopStopTime.class).toProvider(PSimStopStopTimeCalculator.class);
// bind(WaitTimeCalculator.class).to(PSimWaitTimeCalculator.class);
// bind(WaitTime.class).toProvider(PSimWaitTimeCalculator.class);
// bind(StopStopTimeCalculator.class).to(PSimStopStopTimeCalculator.class);
// bind(StopStopTime.class).toProvider(PSimStopStopTimeCalculator.class);

// bind(TravelTimeCalculator.class).to(PSimTravelTimeCalculator.class);
// I made TravelTimeCalculator final, so PSimTravelTimeCalculator can no longer inherit from it. The following statement binds PSimTravelTimeCalculator
// directly. I am not even sure if that is necessary. Pls let me know if you get stuck and I will try to help. kai, feb'19

bind(PSimTravelTimeCalculator.class).in( Singleton.class ) ;
bind(TravelTime.class).toProvider(PSimTravelTimeCalculator.class);
bind(TransitRouter.class).toProvider(TransitRouterEventsWSFactory.class);
// bind(TransitRouter.class).toProvider(TransitRouterEventsWSFactory.class);
bind(PlanCatcher.class).toInstance(new PlanCatcher());
bind(PSimProvider.class).toInstance(new PSimProvider(scenario,matsimControler.getEvents()));
bind(QSimProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.Plan;
import org.matsim.contrib.eventsBasedPTRouter.stopStopTimes.StopStopTimeCalculatorSerializable;
import org.matsim.contrib.eventsBasedPTRouter.waitTimes.WaitTimeCalculatorSerializable;
import org.matsim.contrib.pseudosimulation.distributed.instrumentation.scorestats.SlaveScoreStats;
import org.matsim.contrib.pseudosimulation.distributed.listeners.controler.GenomeAnalysis;
import org.matsim.contrib.pseudosimulation.distributed.listeners.controler.SlaveScoreWriter;
Expand Down Expand Up @@ -73,8 +71,8 @@ public class MasterControler implements AfterMobsimListener, ShutdownListener, S
private Config config;
private Controler matsimControler;
private TreeMap<Integer, SlaveHandler> slaveHandlerTreeMap;
private WaitTimeCalculatorSerializable waitTimeCalculator;
private StopStopTimeCalculatorSerializable stopStopTimeCalculator;
// private WaitTimeCalculatorSerializable waitTimeCalculator;
// private StopStopTimeCalculatorSerializable stopStopTimeCalculator;
private TransitPerformanceRecorder transitPerformanceRecorder;
private SerializableLinkTravelTimes linkTravelTimes;
private AtomicInteger numThreads = new AtomicInteger(0);
Expand Down Expand Up @@ -180,13 +178,13 @@ public MasterControler(String configFile) throws NumberFormatException, IOExcept


if (this.config.transit().isUseTransit()) {
waitTimeCalculator = new WaitTimeCalculatorSerializable(matsimControler.getScenario().getTransitSchedule(), this.config.travelTimeCalculator().getTraveltimeBinSize(),
(int) (this.config.qsim().getEndTime().seconds() - this.config.qsim().getStartTime().seconds()));
matsimControler.getEvents().addHandler(waitTimeCalculator);
stopStopTimeCalculator = new StopStopTimeCalculatorSerializable(matsimControler.getScenario().getTransitSchedule(),
this.config.travelTimeCalculator().getTraveltimeBinSize(), (int) (this.config.qsim()
.getEndTime().seconds() - this.config.qsim().getStartTime().seconds()));
matsimControler.getEvents().addHandler(stopStopTimeCalculator);
// waitTimeCalculator = new WaitTimeCalculatorSerializable(matsimControler.getScenario().getTransitSchedule(), this.config.travelTimeCalculator().getTraveltimeBinSize(),
// (int) (this.config.qsim().getEndTime().seconds() - this.config.qsim().getStartTime().seconds()));
// matsimControler.getEvents().addHandler(waitTimeCalculator);
// stopStopTimeCalculator = new StopStopTimeCalculatorSerializable(matsimControler.getScenario().getTransitSchedule(),
// this.config.travelTimeCalculator().getTraveltimeBinSize(), (int) (this.config.qsim()
// .getEndTime().seconds() - this.config.qsim().getStartTime().seconds()));
// matsimControler.getEvents().addHandler(stopStopTimeCalculator);
//tell PlanSerializable to record transit routes
PlanSerializable.isUseTransit = true;
if (fullTransitPerformanceTransmission) {
Expand Down Expand Up @@ -778,8 +776,8 @@ public void transmitTravelTimes() throws IOException {
writer.writeInt(currentIteration);
writer.writeObject(linkTravelTimes);
if (config.transit().isUseTransit()) {
writer.writeObject(stopStopTimeCalculator.getStopStopTimes());
writer.writeObject(waitTimeCalculator.getWaitTimes());
// writer.writeObject(stopStopTimeCalculator.getStopStopTimes());
// writer.writeObject(waitTimeCalculator.getWaitTimes());
if (fullTransitPerformanceTransmission)
writer.writeObject(transitPerformanceRecorder.getTransitPerformance());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.Plan;
import org.matsim.contrib.common.diversitygeneration.planselectors.DiversityGeneratingPlansRemover;
import org.matsim.contrib.eventsBasedPTRouter.TransitRouterEventsWSFactory;
import org.matsim.contrib.eventsBasedPTRouter.stopStopTimes.StopStopTime;
import org.matsim.contrib.eventsBasedPTRouter.stopStopTimes.StopStopTimeCalculatorSerializable;
import org.matsim.contrib.eventsBasedPTRouter.waitTimes.WaitTime;
import org.matsim.contrib.eventsBasedPTRouter.waitTimes.WaitTimeCalculatorSerializable;
import org.matsim.contrib.pseudosimulation.distributed.instrumentation.scorestats.SlaveScoreStatsCalculator;
import org.matsim.contrib.pseudosimulation.distributed.listeners.events.transit.TransitPerformance;
import org.matsim.contrib.pseudosimulation.mobsim.PSimProvider;
Expand Down Expand Up @@ -86,8 +81,6 @@ public class SlaveControler implements IterationStartsListener, StartupListener,
private double totalIterationTime;
private Controler matsimControler;
private TravelTime linkTravelTimes;
private WaitTime waitTimes;
private StopStopTime stopStopTimes;
private ObjectInputStream reader;
private ObjectOutputStream writer;
private PSimProvider pSimProvider;
Expand All @@ -97,7 +90,6 @@ public class SlaveControler implements IterationStartsListener, StartupListener,
private boolean isOkForNextIter = true;
private Map<Id<Person>, Double> selectedPlanScoreMemory;
private TransitPerformance transitPerformance;
private TransitRouterEventsWSFactory transitRouterEventsWSFactory;

private void printHelp(Options options) {
String header = "The MasterControler takes the following options:\n\n";
Expand Down Expand Up @@ -268,15 +260,6 @@ public void install() {
});

if (config.transit().isUseTransit()) {

stopStopTimes = new StopStopTimeCalculatorSerializable(scenario.getTransitSchedule(),
config.travelTimeCalculator().getTraveltimeBinSize(), (int) (config
.qsim().getEndTime().seconds() - config.qsim().getStartTime().seconds())).getStopStopTimes();

waitTimes = new WaitTimeCalculatorSerializable(scenario.getTransitSchedule(),
config.travelTimeCalculator().getTraveltimeBinSize(), (int) (config
.qsim().getEndTime().seconds() - config.qsim().getStartTime().seconds())).getWaitTimes();

// tell PlanSerializable to record transit routes
PlanSerializable.isUseTransit = true;

Expand All @@ -285,11 +268,11 @@ public void install() {
matsimControler.addOverridingModule(new AbstractModule() {
@Override
public void install() {
System.out.println("init routers");
// System.out.println("init routers");
// transitRouterEventsWSFactory = new TransitRouterEventsWSFactory(scenario,
// waitTimes,
// stopStopTimes);
bind(TransitRouter.class).toProvider(transitRouterEventsWSFactory);
// bind(TransitRouter.class).toProvider(transitRouterEventsWSFactory);
}
});

Expand Down Expand Up @@ -387,13 +370,13 @@ public void notifyIterationStarts(IterationStartsEvent event) {
travelTime.setTravelTime(linkTravelTimes);
pSimProvider.setTravelTime(linkTravelTimes);
if (config.transit().isUseTransit()) {
pSimProvider.setStopStopTime(stopStopTimes);
pSimProvider.setWaitTime(waitTimes);
pSimProvider.setTransitPerformance(transitPerformance);
if (transitRouterEventsWSFactory != null) {
// pSimProvider.setStopStopTime(stopStopTimes);
// pSimProvider.setWaitTime(waitTimes);
// pSimProvider.setTransitPerformance(transitPerformance);
// if (transitRouterEventsWSFactory != null) {
// transitRouterEventsWSFactory.setStopStopTimeCalculator(stopStopTimes);
// transitRouterEventsWSFactory.setWaitTimeCalculator(waitTimes);
}
// }
}
plancatcher.init();
numberOfIterations++;
Expand Down Expand Up @@ -449,8 +432,8 @@ public void transmitTravelTimes() throws IOException, ClassNotFoundException {
masterCurrentIteration = reader.readInt();
linkTravelTimes = (SerializableLinkTravelTimes) reader.readObject();
if (config.transit().isUseTransit()) {
stopStopTimes = (StopStopTime) reader.readObject();
waitTimes = (WaitTime) reader.readObject();
// stopStopTimes = (StopStopTime) reader.readObject();
// waitTimes = (WaitTime) reader.readObject();
if (fullTransitPerformanceTransmission) {
Object o = reader.readObject();
transitPerformance = (TransitPerformance) o;
Expand Down Expand Up @@ -619,8 +602,8 @@ public void notifyBeforeMobsim(BeforeMobsimEvent event) {
@Override
public void notifyIterationEnds(IterationEndsEvent event) {
Iterator<Map.Entry<Id<Person>, Double>> iterator = selectedPlanScoreMemory.entrySet().iterator();
StopStopTimeCalculatorSerializable.printCallStatisticsAndReset();
WaitTimeCalculatorSerializable.printCallStatisticsAndReset();
// StopStopTimeCalculatorSerializable.printCallStatisticsAndReset();
// WaitTimeCalculatorSerializable.printCallStatisticsAndReset();
while (iterator.hasNext()) {
Map.Entry<Id<Person>, Double> entry = iterator.next();
scenario.getPopulation().getPersons().get(entry.getKey()).getSelectedPlan().setScore(entry.getValue());
Expand Down
Loading

0 comments on commit 11c62de

Please sign in to comment.