Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mostly comments; some refactoring #3225

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@
import org.matsim.contrib.dvrp.run.DvrpModule;
import org.matsim.contrib.dvrp.run.DvrpQSimComponents;
import org.matsim.api.core.v01.events.HasPersonId;
import org.matsim.contrib.otfvis.OTFVisLiveModule;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
import org.matsim.core.events.handler.BasicEventHandler;
import org.matsim.core.mobsim.qsim.AbstractQSimModule;
import org.matsim.core.mobsim.qsim.ActivityEngineModule;
import org.matsim.core.mobsim.qsim.ActivityEngineWithWakeup;
import org.matsim.core.mobsim.qsim.PreplanningEngine;
import org.matsim.core.mobsim.qsim.*;
import org.matsim.core.mobsim.qsim.components.QSimComponentsConfigGroup;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.io.IOUtils;
Expand Down Expand Up @@ -96,9 +94,7 @@ void testRun() {
Scenario scenario = ScenarioUtils.loadScenario(config);

for (Person person : scenario.getPopulation().getPersons().values()) {
person.getSelectedPlan()
.getAttributes()
.putAttribute(PreplanningEngine.PREBOOKING_OFFSET_ATTRIBUTE_NAME, 900.);
PreplanningUtils.setPrebookingOffset_s( person.getSelectedPlan(), 900. );
}

//PopulationUtils.writePopulation(scenario.getPopulation(), utils.getOutputDirectory() + "/../pop.xml");
Expand Down Expand Up @@ -158,6 +154,12 @@ public void install() {
}
});

if ("true".equals(System.getProperty("runOTFVis"))) {
// This will start otfvis
controler.addOverridingModule(new OTFVisLiveModule() );
// !! does not work together with parameterized tests :-( !!
}

// run simulation
controler.run();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.matsim.core.mobsim.qsim;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.population.Person;
import org.matsim.contrib.otfvis.OTFVisLiveModule;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.Controler;
import org.matsim.core.mobsim.qsim.components.QSimComponentsConfigGroup;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.examples.ExamplesUtils;
import org.matsim.testcases.MatsimTestUtils;

import javax.inject.Singleton;

class PreplanningEngineTest{
// Cannot use otfvis if in core matsim. --> In vsp contrib for time being. kai, apr'24
private static final Logger log = LogManager.getLogger(PreplanningEngineTest.class );

@RegisterExtension private MatsimTestUtils utils = new MatsimTestUtils();

@Disabled
@Test public void test() {
// I am interested here in testing this NOT with DRT but with other modes. kai, apr'24
// In the somewhat longer run, should work together with fleetpy (of TUM). kai, apr'24

Config config = ConfigUtils.loadConfig( IOUtils.extendUrl( ExamplesUtils.getTestScenarioURL( "equil" ), "config.xml" ) );

config.controller().setOutputDirectory( utils.getOutputDirectory() );
config.controller().setLastIteration( 0 );

QSimComponentsConfigGroup componentsConfig = ConfigUtils.addOrGetModule( config, QSimComponentsConfigGroup.class );

componentsConfig.removeActiveComponent( ActivityEngineModule.COMPONENT_NAME );
componentsConfig.addActiveComponent( ActivityEngineWithWakeup.COMPONENT_NAME );

componentsConfig.addActiveComponent( PreplanningEngineQSimModule.COMPONENT_NAME );

Scenario scenario = ScenarioUtils.loadScenario( config );
for( Person person : scenario.getPopulation().getPersons().values() ){
PreplanningUtils.setPrebookingOffset_s( person.getSelectedPlan(), 900. );
}

Controler controler = new Controler( scenario );

controler.addOverridingQSimModule( new AbstractQSimModule(){
@Override protected void configureQSim(){
bind(PreplanningEngine.class).asEagerSingleton();
addQSimComponentBinding(PreplanningEngineQSimModule.COMPONENT_NAME).to(PreplanningEngine.class).in( Singleton.class );
// Does the following:
// * on prepare sim: register all departure handlers that implement the TripInfo.Provider interface
// *

// the above just installs the functionality; it also needs to be requested (from config).

// needs to go along with ActivityEngineWithWakeup. complains if not bound.
// yy is, however, ok if bound but not activated. --?? --> should end up in same module!

addQSimComponentBinding( ActivityEngineWithWakeup.COMPONENT_NAME ).to( ActivityEngineWithWakeup.class ).in( Singleton.class );

}
} );

if ("true".equals(System.getProperty("runOTFVis"))) {
// This will start otfvis if property is set
controler.addOverridingModule(new OTFVisLiveModule() );
// !! does not work together with parameterized tests :-( !!
}

controler.run();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.events.IterationEndsEvent;
import org.matsim.core.controler.listener.IterationEndsListener;
import org.matsim.core.mobsim.qsim.AbstractQSimModule;
import org.matsim.core.mobsim.qsim.ActivityEngineModule;
import org.matsim.core.mobsim.qsim.ActivityEngineWithWakeup;
import org.matsim.core.mobsim.qsim.PreplanningEngine;
import org.matsim.core.mobsim.qsim.*;
import org.matsim.core.mobsim.qsim.components.QSimComponentsConfigGroup;
import org.matsim.core.router.AnalysisMainModeIdentifier;
import org.matsim.core.router.TripStructureUtils;
Expand Down Expand Up @@ -321,9 +318,7 @@ void testPtAlongALineWithRaptorAndDrtServiceArea() {
}
if (drtMode == DrtMode.withPrebooking) {
for (Person person : scenario.getPopulation().getPersons().values()) {
person.getSelectedPlan()
.getAttributes()
.putAttribute(PreplanningEngine.PREBOOKING_OFFSET_ATTRIBUTE_NAME, 7200.);
PreplanningUtils.setPrebookingOffset_s( person.getSelectedPlan(), 7200. );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import jakarta.inject.Inject;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.events.Event;
import org.matsim.api.core.v01.population.Activity;
Expand All @@ -37,7 +39,7 @@

public final class ActivityEngineWithWakeup implements ActivityEngine {
public static final String COMPONENT_NAME = "ActivityEngineWithWakeup";

private static final Logger log = LogManager.getLogger(ActivityEngineWithWakeup.class );
private final EventsManager eventsManager;
private final PreplanningEngine preplanningEngine;
private final ActivityEngine delegate;
Expand All @@ -55,6 +57,7 @@ public final class ActivityEngineWithWakeup implements ActivityEngine {

@Override
public void onPrepareSim() {
log.warn( "running onPrepareSim");
delegate.onPrepareSim();
}

Expand Down
Loading
Loading