Skip to content

Commit

Permalink
Merge pull request #3348 from matsim-org/mode-restriction
Browse files Browse the repository at this point in the history
Handle mode restriction correctly
  • Loading branch information
paulheinr authored Aug 1, 2024
2 parents ec12c86 + 43287db commit ad2da0c
Show file tree
Hide file tree
Showing 110 changed files with 1,613 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.QSimConfigGroup;
import org.matsim.core.config.groups.QSimConfigGroup.StarttimeInterpretation;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting;
import org.matsim.core.mobsim.framework.MobsimTimer;
Expand Down Expand Up @@ -124,7 +125,7 @@ void testRepeatedSameDestinationDiversions() {

{
/* Create some necessary configuration for the test */

config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists);
config.controller().setLastIteration(0);

Expand Down Expand Up @@ -454,6 +455,7 @@ void testRepeatedDiversionToDifferentDestinationRightBeforeLastLink() {

config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists);
config.controller().setLastIteration(0);
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);

config.qsim().setStartTime(0.0);
config.qsim().setSimStarttimeInterpretation(StarttimeInterpretation.onlyUseStarttime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
import org.matsim.contrib.emissions.utils.EmissionsConfigGroup;
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.ControllerConfigGroup;
import org.matsim.core.config.groups.NetworkConfigGroup;
import org.matsim.core.config.groups.ReplanningConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.core.config.groups.QSimConfigGroup;
import org.matsim.core.config.groups.*;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
Expand Down Expand Up @@ -91,6 +87,7 @@ void compareToOtherModule_singleVehicleSingleLink() {
var config = ConfigUtils.loadConfig(configFile, emissionConfig);
config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);
config.controller().setOutputDirectory(testUtils.getOutputDirectory());
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);

emissionConfig.setAverageColdEmissionFactorsFile("../sample_41_EFA_ColdStart_vehcat_2020average.csv");
emissionConfig.setAverageWarmEmissionFactorsFile( "../sample_41_EFA_HOT_vehcat_2020average.csv" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.matsim.api.core.v01.Scenario;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
Expand All @@ -53,6 +54,7 @@ public class CarrierModuleTest {
@BeforeEach
public void setUp(){
Config config = ConfigUtils.createConfig() ;
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
ScoringConfigGroup.ActivityParams workParams = new ScoringConfigGroup.ActivityParams("w");
workParams.setTypicalDuration(60 * 60 * 8);
config.scoring().addActivityParams(workParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
Expand Down Expand Up @@ -57,6 +58,8 @@ static Config commonConfig( MatsimTestUtils testUtils ) {
config.controller().setOutputDirectory(testUtils.getOutputDirectory());
config.network().setInputFile( testUtils.getClassInputDirectory() + "network.xml" );

config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);

return config;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.matsim.api.core.v01.Scenario;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
import org.matsim.freight.carriers.FreightCarriersConfigGroup;
Expand All @@ -50,6 +51,7 @@ public class EquilWithCarrierWithoutPersonsIT {

public void setUp() {
Config config = EquilWithCarrierWithPersonsIT.commonConfig( testUtils );
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
Scenario scenario = EquilWithCarrierWithPersonsIT.commonScenario( config, testUtils );
controler = new Controler(scenario);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class LocationChoiceIT {
void testLocationChoice() {

final Config config = localCreateConfig( utils.getPackageInputDirectory() + "config2.xml");
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);

final MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void testSimpleScenario() {
static void runSimpleScenario(int numberOfThreads) {

Config config = ConfigUtils.createConfig();

config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
config.qsim().setEndTime(24 * 3600);

config.controller().setLastIteration(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Injector;
Expand Down Expand Up @@ -73,6 +74,7 @@ void testRouteLeg() {
config.routing().addParam("teleportedModeSpeed_ride", "15.0");
config.routing().addParam("teleportedModeSpeed_undefined", "13.88888888888889");
config.routing().addParam("teleportedModeSpeed_walk", "1.34");
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);

config.scoring().addModeParams( new ScoringConfigGroup.ModeParams( TransportMode.ride ) );
final Scenario scenario = ScenarioUtils.createScenario(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ void main(){
URL url = IOUtils.extendUrl( ExamplesUtils.getTestScenarioURL( "berlin" ), "config_multimodal.xml" );;

String [] args = { url.toString(),
"--config:controler.outputDirectory" , utils.getOutputDirectory()
} ;
"--config:controler.outputDirectory" , utils.getOutputDirectory(),
"--config:routing.networkRouteConsistencyCheck", "disable"
} ;;

try{
RunMultimodalExample.main( args );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void testMultiModalPtCombination() {
Scenario scenario = f.scenario;
Config config = scenario.getConfig();
config.controller().setOutputDirectory(utils.getOutputDirectory());
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);

MultiModalConfigGroup mmcg = new MultiModalConfigGroup();
mmcg.setMultiModalSimulationEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.matsim.contrib.multimodal.config.MultiModalConfigGroup;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams;
import org.matsim.core.controler.Controler;
import org.matsim.core.events.handler.BasicEventHandler;
Expand All @@ -69,7 +70,7 @@ public class StuckAgentTest {
void testStuckEvents() {
Config config = ConfigUtils.createConfig();
config.controller().setOutputDirectory(utils.getOutputDirectory());

config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
config.qsim().setEndTime(24*3600);

config.controller().setLastIteration(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
*/
package org.matsim.contrib.noise;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.matsim.api.core.v01.Scenario;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.testcases.MatsimTestUtils;

import org.matsim.testcases.MatsimTestUtils;

/**
* @author ikaddoura
*
Expand All @@ -41,9 +42,9 @@
public class NoiseConfigGroupIT {

@RegisterExtension
private MatsimTestUtils testUtils = new MatsimTestUtils();

@Test
private MatsimTestUtils testUtils = new MatsimTestUtils();

@Test
final void test0(){

String configFile = testUtils.getPackageInputDirectory() + "NoiseConfigGroupTest/config0.xml";
Expand All @@ -69,14 +70,15 @@ final void test0(){

String tunnelLinkIds = noiseParameters.getTunnelLinkIDsSet().toArray()[0] + "," + noiseParameters.getTunnelLinkIDsSet().toArray()[1];
Assertions.assertEquals("link1,link2", tunnelLinkIds, "wrong config parameter");
}

@Test
}

@Test
final void test1(){

String configFile = testUtils.getPackageInputDirectory() + "NoiseConfigGroupTest/config1.xml";
Config config = ConfigUtils.loadConfig(configFile, new NoiseConfigGroup());
config.controller().setOutputDirectory(testUtils.getOutputDirectory());
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);

NoiseConfigGroup noiseParameters = (NoiseConfigGroup) config.getModule("noise");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.controler.PrepareForSimUtils;
import org.matsim.core.events.EventsUtils;
import org.matsim.core.mobsim.qsim.QSimBuilder;
Expand All @@ -58,6 +59,7 @@ public class CalcPaidTollTest {
@Test
void testDistanceToll() {
Config config = ConfigUtils.loadConfig(utils.getClassInputDirectory() + "config.xml");
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
final String tollFile = utils.getClassInputDirectory() + "/roadpricing1.xml";

Id<Person> id1 = Id.create("1", Person.class);
Expand Down Expand Up @@ -94,6 +96,7 @@ void testDistanceToll() {
@Test
void testAreaToll() {
Config config = ConfigUtils.loadConfig(utils.getClassInputDirectory() + "config.xml");
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
final String tollFile = utils.getClassInputDirectory() + "/roadpricing2.xml";

Id<Person> id1 = Id.create("1", Person.class);
Expand Down Expand Up @@ -145,6 +148,7 @@ void testAreaToll() {
@Test
void testCordonToll() {
Config config = ConfigUtils.loadConfig(utils.getClassInputDirectory() + "config.xml");
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
final String tollFile = utils.getClassInputDirectory() + "/roadpricing3.xml";

Id<Person> id1 = Id.create("1", Person.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.matsim.api.core.v01.population.PlanElement;
import org.matsim.api.core.v01.population.Population;
import org.matsim.core.config.Config;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.config.groups.RoutingConfigGroup.AccessEgressType;
import org.matsim.core.controler.Injector;
import org.matsim.core.controler.NewControlerModule;
Expand Down Expand Up @@ -74,6 +75,7 @@ public class PlansCalcRouteWithTollOrNotTest {
@Test
void testBestAlternatives() {
Config config = matsimTestUtils.createConfig();
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles);
MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
RoadPricingTestUtils.createNetwork2(scenario);
Expand Down Expand Up @@ -180,6 +182,7 @@ private PlansCalcRouteWithTollOrNot testee(final Scenario scenario, final RoadPr
@Test
void testTolledActLink() {
Config config = matsimTestUtils.createConfig();
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
RoadPricingTestUtils.createNetwork2(scenario);

Expand All @@ -206,6 +209,7 @@ void testTolledActLink() {
@Test
void testAllAlternativesTolled() {
Config config = matsimTestUtils.createConfig();
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
RoadPricingTestUtils.createNetwork2(scenario);

Expand Down Expand Up @@ -245,6 +249,7 @@ private static Leg getLeg3(Config config, Population population, Id<Person> id1)
@Test
void testOutsideTollTime() {
Config config = matsimTestUtils.createConfig();
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
RoadPricingTestUtils.createNetwork2(scenario);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.List;
import java.util.Map;

import jakarta.inject.Provider;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -74,6 +75,7 @@ public class TollTravelCostCalculatorTest {
@Test
void testDisutilityResults() {
Config config = ConfigUtils.createConfig() ;
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);

Scenario scenario = ScenarioUtils.createScenario(config) ;
RoadPricingTestUtils.createNetwork2((MutableScenario)scenario);
Expand Down Expand Up @@ -124,11 +126,12 @@ void testDisutilityResults() {
@Test
void testDistanceTollRouter() {
Config config = utils.createConfig();
MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
RoadPricingTestUtils.createNetwork2(scenario);
Network network = scenario.getNetwork();
// a basic toll where only the morning hours are tolled
RoadPricingSchemeImpl toll = RoadPricingUtils.addOrGetMutableRoadPricingScheme(ScenarioUtils.createScenario( ConfigUtils.createConfig() ) );
RoadPricingSchemeImpl toll = RoadPricingUtils.addOrGetMutableRoadPricingScheme(ScenarioUtils.createScenario( config ) );
toll.setType(RoadPricingScheme.TOLL_TYPE_DISTANCE);
toll.addLink(Id.create("5", Link.class));
toll.addLink(Id.create("11", Link.class));
Expand Down Expand Up @@ -209,11 +212,12 @@ void testDistanceTollRouter() {
@Test
void testLinkTollRouter() {
Config config = utils.createConfig();
MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
RoadPricingTestUtils.createNetwork2(scenario);
Network network = scenario.getNetwork();
// a basic toll where only the morning hours are tolled
RoadPricingSchemeImpl toll = RoadPricingUtils.addOrGetMutableRoadPricingScheme(ScenarioUtils.createScenario( ConfigUtils.createConfig() ) );
RoadPricingSchemeImpl toll = RoadPricingUtils.addOrGetMutableRoadPricingScheme(ScenarioUtils.createScenario( config ) );
toll.setType(RoadPricingScheme.TOLL_TYPE_LINK);
toll.addLink(Id.create("5", Link.class));
toll.addLink(Id.create("11", Link.class));
Expand Down Expand Up @@ -304,11 +308,11 @@ void testLinkTollRouter() {
@Test
void testCordonTollRouter() {
Config config = utils.createConfig();
MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
RoadPricingTestUtils.createNetwork2(scenario);
Network network = scenario.getNetwork();
// a basic toll where only the morning hours are tolled
RoadPricingSchemeImpl toll = RoadPricingUtils.addOrGetMutableRoadPricingScheme(ScenarioUtils.createScenario( ConfigUtils.createConfig() ) );
RoadPricingSchemeImpl toll = RoadPricingUtils.addOrGetMutableRoadPricingScheme(ScenarioUtils.createScenario( config ) );
// toll.setType(RoadPricingScheme.TOLL_TYPE_CORDON);
toll.setType(RoadPricingScheme.TOLL_TYPE_LINK);
toll.addLink(Id.create("5", Link.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.controler.PrepareForSimUtils;
import org.matsim.core.events.EventsUtils;
import org.matsim.core.events.algorithms.EventWriterXML;
Expand Down Expand Up @@ -140,6 +141,7 @@ private void generateOutput(Scenario scenario, final List<Event> eventslist) {

private Scenario prepareTest(int numberOfPersons) {
Config config = ConfigUtils.createConfig();
config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
Scenario scenario = ScenarioUtils.createScenario(config);
createNetwork(scenario);
createPopulation(scenario, numberOfPersons);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.matsim.contrib.signals.model.SignalSystem;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams;
import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings;
import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting;
Expand Down Expand Up @@ -87,6 +88,7 @@ private Config createConfigOneSignal(Boolean useIntergreens) {
}
Config conf = ConfigUtils.createConfig(testUtils.classInputResourcePath());
conf.controller().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles);
conf.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable);
ActivityParams params = new ActivityParams("h");
params.setTypicalDuration(24.0 * 3600.0);
conf.scoring().addActivityParams(params);
Expand Down
Loading

0 comments on commit ad2da0c

Please sign in to comment.