Java Code Examples for org.matsim.core.config.ConfigUtils#createConfig()

The following examples show how to use org.matsim.core.config.ConfigUtils#createConfig() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WaitingTimeTest.java    From amodeus with GNU General Public License v2.0 6 votes vote down vote up
static Controler createController(AmodeusConfigGroup avConfigGroup) {
    Config config = ConfigUtils.createConfig(avConfigGroup, new DvrpConfigGroup());
    Scenario scenario = TestScenarioGenerator.generateWithAVLegs(config);

    PlanCalcScoreConfigGroup.ModeParams modeParams = config.planCalcScore().getOrCreateModeParams(AmodeusModeConfig.DEFAULT_MODE);
    modeParams.setMonetaryDistanceRate(0.0);
    modeParams.setMarginalUtilityOfTraveling(8.86);
    modeParams.setConstant(0.0);

    Controler controler = new Controler(scenario);
    controler.addOverridingModule(new DvrpModule());
    controler.addOverridingModule(new AmodeusModule());
    controler.addOverridingQSimModule(new AmodeusQSimModule());

    controler.configureQSimComponents(AmodeusQSimModule.activateModes(avConfigGroup));

    return controler;
}
 
Example 2
Source File: RunTest.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testStuckScoring() {
    AmodeusConfigGroup avConfigGroup = new AmodeusConfigGroup();

    AmodeusModeConfig operatorConfig = new AmodeusModeConfig(AmodeusModeConfig.DEFAULT_MODE);
    operatorConfig.getGeneratorConfig().setNumberOfVehicles(0);
    avConfigGroup.addMode(operatorConfig);

    AmodeusScoringConfig scoringParams = operatorConfig.getScoringParameters(null);
    scoringParams.setMarginalUtilityOfWaitingTime(-0.84);

    Config config = ConfigUtils.createConfig(avConfigGroup, new DvrpConfigGroup());
    Scenario scenario = TestScenarioGenerator.generateWithAVLegs(config);
    config.planCalcScore().getOrCreateModeParams(AmodeusModeConfig.DEFAULT_MODE); // Refactor av

    Controler controler = new Controler(scenario);
    controler.addOverridingModule(new DvrpModule());
    controler.addOverridingModule(new AmodeusModule());
    controler.addOverridingQSimModule(new AmodeusQSimModule());

    controler.configureQSimComponents(AmodeusQSimModule.activateModes(avConfigGroup));

    controler.run();

    for (Person person : scenario.getPopulation().getPersons().values()) {
        Assert.assertEquals(-1000.0, person.getSelectedPlan().getScore(), 1e-6);
    }
}
 
Example 3
Source File: RunTest.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testMultiOD() {
    AmodeusConfigGroup avConfigGroup = new AmodeusConfigGroup();

    AmodeusModeConfig operatorConfig = new AmodeusModeConfig(AmodeusModeConfig.DEFAULT_MODE);
    operatorConfig.getDispatcherConfig().setType(MultiODHeuristic.TYPE);
    operatorConfig.getGeneratorConfig().setNumberOfVehicles(100);
    operatorConfig.getPricingConfig().setPricePerKm(0.48);
    operatorConfig.getPricingConfig().setSpatialBillingInterval(1000.0);
    avConfigGroup.addMode(operatorConfig);

    AmodeusScoringConfig scoringParams = operatorConfig.getScoringParameters(null);
    scoringParams.setMarginalUtilityOfWaitingTime(-0.84);

    Config config = ConfigUtils.createConfig(avConfigGroup, new DvrpConfigGroup());
    Scenario scenario = TestScenarioGenerator.generateWithAVLegs(config);

    PlanCalcScoreConfigGroup.ModeParams modeParams = config.planCalcScore().getOrCreateModeParams(AmodeusModeConfig.DEFAULT_MODE); // Refactor av
    modeParams.setMonetaryDistanceRate(0.0);
    modeParams.setMarginalUtilityOfTraveling(8.86);
    modeParams.setConstant(0.0);

    Controler controler = new Controler(scenario);
    controler.addOverridingModule(new DvrpModule());
    controler.addOverridingModule(new AmodeusModule());
    controler.addOverridingQSimModule(new AmodeusQSimModule());

    controler.configureQSimComponents(AmodeusQSimModule.activateModes(avConfigGroup));

    TestScenarioAnalyzer analyzer = new TestScenarioAnalyzer();
    controler.addOverridingModule(analyzer);

    controler.run();

    Assert.assertEquals(0, analyzer.numberOfDepartures - analyzer.numberOfArrivals);
}
 
Example 4
Source File: RunTest.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testBasicSetup() {
    // CONFIG PART

    Config config = ConfigUtils.createConfig(new DvrpConfigGroup(), new AmodeusConfigGroup());

    // Add Amodeus mode
    AmodeusModeConfig modeConfig = new AmodeusModeConfig("av");
    modeConfig.getDispatcherConfig().setType("GlobalBipartiteMatchingDispatcher");
    AmodeusConfigGroup.get(config).addMode(modeConfig);

    config.planCalcScore().getOrCreateModeParams("av");

    // DVRP adjustments
    config.qsim().setSimStarttimeInterpretation(StarttimeInterpretation.onlyUseStarttime);

    // SCENARIO PART

    // Generates a scenario with "av" legs
    Scenario scenario = TestScenarioGenerator.generateWithAVLegs(config);

    // CONTROLLER PART
    Controler controller = new Controler(scenario);

    controller.addOverridingModule(new DvrpModule());
    controller.addOverridingModule(new AmodeusModule());

    controller.addOverridingQSimModule(new AmodeusQSimModule());
    controller.configureQSimComponents(AmodeusQSimModule.activateModes(AmodeusConfigGroup.get(controller.getConfig())));

    // Some analysis listener for testing
    TestScenarioAnalyzer analyzer = new TestScenarioAnalyzer();
    controller.addOverridingModule(analyzer);

    controller.run();

    Assert.assertEquals(0, analyzer.numberOfDepartures - analyzer.numberOfArrivals);
    Assert.assertEquals(100, analyzer.numberOfDepartures);
}
 
Example 5
Source File: RunDrtTest.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testAmodeusDrt() {
    Config config = ConfigUtils.createConfig(new MultiModeDrtConfigGroup(), new DvrpConfigGroup(), new AmodeusConfigGroup());
    Scenario scenario = TestScenarioGenerator.generateWithAVLegs(config);
    run(config, scenario, true);

    // Currently, Amodeus does not know where to put the auto-generated ScenarioOptions file.
    // We can make this a config option for AmodeusConfigGroup.
    FileUtils.deleteQuietly(new File("AmodeusOptions.properties"));
}
 
Example 6
Source File: CreateDefaultPTMapperConfig.java    From pt2matsim with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a default publicTransitMapping config file.
 * @param args [0] default config filename
 */
public static void main(final String[] args) {
	if(args.length < 1) {
		throw new IllegalArgumentException("Config file name as argument needed");
	}

	Config config = ConfigUtils.createConfig();

	config.addModule(PublicTransitMappingConfigGroup.createDefaultConfig());

	Set<String> toRemove = config.getModules().keySet().stream().filter(module -> !module.equals(PublicTransitMappingConfigGroup.GROUP_NAME)).collect(Collectors.toSet());
	toRemove.forEach(config::removeModule);

	new ConfigWriter(config).write(args[0]);
}
 
Example 7
Source File: MATSimVirtualNetworkTravelDataTest.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
private static Controler prepare() throws IOException {
    File scenarioDirectory = new File(Locate.repoFolder(StandardMATSimScenarioTest.class, "amodeus"), "resources/testScenario");
    File workingDirectory = MultiFileTools.getDefaultWorkingDirectory();
    GlobalAssert.that(workingDirectory.isDirectory());
    TestFileHandling.copyScnearioToMainDirectory(scenarioDirectory.getAbsolutePath(), workingDirectory.getAbsolutePath());

    StaticHelper.setup();
    MatsimRandom.reset();

    // Set up
    Config config = ConfigUtils.createConfig(new AmodeusConfigGroup(), new DvrpConfigGroup());
    Scenario scenario = TestScenarioGenerator.generateWithAVLegs(config);

    ScenarioOptions simOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault());
    LocationSpec locationSpec = simOptions.getLocationSpec();
    ReferenceFrame referenceFrame = locationSpec.referenceFrame();
    MatsimAmodeusDatabase db = MatsimAmodeusDatabase.initialize(scenario.getNetwork(), referenceFrame);

    PlanCalcScoreConfigGroup.ModeParams modeParams = config.planCalcScore().getOrCreateModeParams(AmodeusModeConfig.DEFAULT_MODE);
    modeParams.setMonetaryDistanceRate(0.0);
    modeParams.setMarginalUtilityOfTraveling(8.86);
    modeParams.setConstant(0.0);

    // Config

    AmodeusConfigGroup avConfig = AmodeusConfigGroup.get(config);

    AmodeusModeConfig operatorConfig = new AmodeusModeConfig(AmodeusModeConfig.DEFAULT_MODE);
    avConfig.addMode(operatorConfig);

    GeneratorConfig generatorConfig = operatorConfig.getGeneratorConfig();
    generatorConfig.setType("VehicleToVSGenerator");
    generatorConfig.setNumberOfVehicles(100);

    // Choose a dispatcher
    DispatcherConfig dispatcherConfig = operatorConfig.getDispatcherConfig();
    dispatcherConfig.addParam("infoLinePeriod", "3600");
    dispatcherConfig.setType("FeedforwardFluidicRebalancingPolicy");

    // Make sure that we do not need the SimulationObjectCompiler
    dispatcherConfig.addParam("publishPeriod", "-1");

    // Set up stuff for TravelData (but we'll generate it on the fly)
    LPOptions lpOptions = new LPOptions(simOptions.getWorkingDirectory(), LPOptionsBase.getDefault());
    lpOptions.setProperty(LPOptionsBase.LPSOLVER, "timeInvariant");
    lpOptions.saveAndOverwriteLPOptions();

    // Set up paths
    operatorConfig.getDispatcherConfig().setVirtualNetworkPath("generatedVirtualNetwork");
    operatorConfig.getDispatcherConfig().setTravelDataPath("generatedTravelData");

    // Controller
    Controler controller = new Controler(scenario);
    AmodeusConfigurator.configureController(controller, db, simOptions);

    // Run
    return controller;
}
 
Example 8
Source File: PreroutingTest.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testPreRouting() {
    AmodeusConfigGroup avConfigGroup = new AmodeusConfigGroup();

    AmodeusModeConfig operatorConfig = new AmodeusModeConfig(AmodeusModeConfig.DEFAULT_MODE);
    operatorConfig.setPredictRouteTravelTime(true);
    operatorConfig.getGeneratorConfig().setNumberOfVehicles(100);
    avConfigGroup.addMode(operatorConfig);

    AmodeusScoringConfig scoringParams = operatorConfig.getScoringParameters(null);
    scoringParams.setMarginalUtilityOfWaitingTime(-0.84);

    operatorConfig.getPricingConfig().setPricePerKm(1.0);

    Config config = ConfigUtils.createConfig(avConfigGroup, new DvrpConfigGroup());
    Scenario scenario = TestScenarioGenerator.generateWithAVLegs(config);

    config.plansCalcRoute().setRoutingRandomness(0.0);

    PlanCalcScoreConfigGroup.ModeParams modeParams = config.planCalcScore().getOrCreateModeParams(AmodeusModeConfig.DEFAULT_MODE);
    modeParams.setMonetaryDistanceRate(0.0);
    modeParams.setMarginalUtilityOfTraveling(8.86);
    modeParams.setConstant(0.0);

    StrategySettings strategySettings = new StrategySettings();
    strategySettings.setStrategyName("KeepLastSelected");
    strategySettings.setWeight(1.0);
    config.strategy().addStrategySettings(strategySettings);

    Controler controler = new Controler(scenario);
    controler.addOverridingModule(new DvrpModule());
    controler.addOverridingModule(new AmodeusModule());
    controler.addOverridingQSimModule(new AmodeusQSimModule());

    controler.configureQSimComponents(AmodeusQSimModule.activateModes(avConfigGroup));

    controler.run();

    for (Person person : scenario.getPopulation().getPersons().values()) {
        Plan plan = person.getSelectedPlan();

        for (PlanElement element : plan.getPlanElements()) {
            if (element instanceof Leg) {
                Leg leg = (Leg) element;
                AmodeusRoute route = (AmodeusRoute) leg.getRoute();

                Assert.assertTrue(route.getTravelTime().isDefined() && Double.isFinite(route.getTravelTime().seconds()));
                Assert.assertTrue(route.getExpectedDistance().isPresent());
                Assert.assertTrue(route.getWaitingTime().isDefined());
                Assert.assertTrue(route.getPrice().isPresent());
                Assert.assertTrue(route.getPrice().get() > 0.0);
            }
        }
    }
}
 
Example 9
Source File: RunTest.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testAVExampleWithAccessEgress() {
    AmodeusConfigGroup avConfigGroup = new AmodeusConfigGroup();

    AmodeusModeConfig operatorConfig = new AmodeusModeConfig(AmodeusModeConfig.DEFAULT_MODE);
    operatorConfig.getGeneratorConfig().setNumberOfVehicles(100);
    operatorConfig.getPricingConfig().setPricePerKm(0.48);
    operatorConfig.getPricingConfig().setSpatialBillingInterval(1000.0);
    avConfigGroup.addMode(operatorConfig);

    AmodeusScoringConfig scoringParams = operatorConfig.getScoringParameters(null);
    scoringParams.setMarginalUtilityOfWaitingTime(-0.84);

    operatorConfig.setUseAccessAgress(true);

    Config config = ConfigUtils.createConfig(avConfigGroup, new DvrpConfigGroup());
    Scenario scenario = TestScenarioGenerator.generateWithAVLegs(config);

    Iterator<? extends Person> iterator = scenario.getPopulation().getPersons().values().iterator();
    for (int i = 0; i < 3; i++) {
        Person person = iterator.next();

        for (PlanElement element : person.getSelectedPlan().getPlanElements()) {
            if (element instanceof Activity) {
                Activity activity = (Activity) element;
                activity.setCoord(CoordUtils.plus(activity.getCoord(), new Coord(5.0, 5.0)));
            }
        }
    }

    ActivityParams activityParams = new ActivityParams("amodeus interaction");
    activityParams.setTypicalDuration(1.0);
    config.planCalcScore().addActivityParams(activityParams);

    PlanCalcScoreConfigGroup.ModeParams modeParams = config.planCalcScore().getOrCreateModeParams(AmodeusModeConfig.DEFAULT_MODE); // Refactor av
    modeParams.setMonetaryDistanceRate(0.0);
    modeParams.setMarginalUtilityOfTraveling(8.86);
    modeParams.setConstant(0.0);

    Controler controler = new Controler(scenario);
    controler.addOverridingModule(new DvrpModule());
    controler.addOverridingModule(new AmodeusModule());
    controler.addOverridingQSimModule(new AmodeusQSimModule());

    controler.configureQSimComponents(AmodeusQSimModule.activateModes(avConfigGroup));

    TestScenarioAnalyzer analyzer = new TestScenarioAnalyzer();
    controler.addOverridingModule(analyzer);

    controler.run();

    Assert.assertEquals(0, analyzer.numberOfDepartures - analyzer.numberOfArrivals);
    Assert.assertEquals(6, analyzer.numberOfInteractionActivities);
}
 
Example 10
Source File: RunTest.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testAVExampleWithAccessEgressAttribute() {
    AmodeusConfigGroup avConfigGroup = new AmodeusConfigGroup();

    AmodeusModeConfig operatorConfig = new AmodeusModeConfig(AmodeusModeConfig.DEFAULT_MODE);
    operatorConfig.getGeneratorConfig().setNumberOfVehicles(100);
    operatorConfig.getPricingConfig().setPricePerKm(0.48);
    operatorConfig.getPricingConfig().setSpatialBillingInterval(1000.0);
    operatorConfig.getInteractionFinderConfig().setType(LinkAttributeInteractionFinder.TYPE);
    operatorConfig.getInteractionFinderConfig().getParams().put("allowedLinkAttribute", "avflag");
    avConfigGroup.addMode(operatorConfig);

    AmodeusScoringConfig scoringParams = operatorConfig.getScoringParameters(null);
    scoringParams.setMarginalUtilityOfWaitingTime(-0.84);

    operatorConfig.setUseAccessAgress(true);

    Config config = ConfigUtils.createConfig(avConfigGroup, new DvrpConfigGroup());
    Scenario scenario = TestScenarioGenerator.generateWithAVLegs(config);

    for (Link link : scenario.getNetwork().getLinks().values()) {
        if (link.getFromNode().getCoord().getX() == 5000.0) {
            link.getAttributes().putAttribute("avflag", true);
        }
    }

    ActivityParams activityParams = new ActivityParams("amodeus interaction");
    activityParams.setTypicalDuration(1.0);
    config.planCalcScore().addActivityParams(activityParams);

    PlanCalcScoreConfigGroup.ModeParams modeParams = config.planCalcScore().getOrCreateModeParams(AmodeusModeConfig.DEFAULT_MODE); // Refactor av
    modeParams.setMonetaryDistanceRate(0.0);
    modeParams.setMarginalUtilityOfTraveling(8.86);
    modeParams.setConstant(0.0);

    config.qsim().setEndTime(40.0 * 3600.0);
    config.qsim().setSimStarttimeInterpretation(StarttimeInterpretation.onlyUseStarttime);

    Controler controler = new Controler(scenario);
    controler.addOverridingModule(new DvrpModule());
    controler.addOverridingModule(new AmodeusModule());
    controler.addOverridingQSimModule(new AmodeusQSimModule());

    controler.configureQSimComponents(AmodeusQSimModule.activateModes(avConfigGroup));

    TestScenarioAnalyzer analyzer = new TestScenarioAnalyzer();
    controler.addOverridingModule(analyzer);

    controler.run();

    Assert.assertEquals(0, analyzer.numberOfDepartures - analyzer.numberOfArrivals);
    Assert.assertEquals(163, analyzer.numberOfInteractionActivities);
}
 
Example 11
Source File: ConfigTest.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testDuplication() throws IOException {
    // The way the config was set up previously loading and saving the config file
    // would duplicate operators etc. This test makes sure this does not happen
    // anymore.

    AmodeusConfigGroup configGroup = new AmodeusConfigGroup();
    Config config = ConfigUtils.createConfig(configGroup);

    AmodeusModeConfig operator1 = new AmodeusModeConfig("id_abc");
    operator1.getDispatcherConfig().setType("disp_abc");
    operator1.getGeneratorConfig().setType("gen_abc");
    operator1.getGeneratorConfig().setNumberOfVehicles(5);
    operator1.getTimingConfig().setPickupDurationPerPassenger(123.0);
    configGroup.addMode(operator1);

    new ConfigWriter(config).write("test_output/test_config1.xml");

    Config config2 = ConfigUtils.loadConfig("test_output/test_config1.xml", new AmodeusConfigGroup());
    new ConfigWriter(config2).write("test_output/test_config2.xml");

    Config config3 = ConfigUtils.loadConfig("test_output/test_config2.xml", new AmodeusConfigGroup());
    new ConfigWriter(config3).write("test_output/test_config3.xml");

    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File("test_output/test_config3.xml"))));

    String line = null;

    int numberOfOperators = 0;
    int numberOfDispatchers = 0;
    boolean inAmodeus = false;

    while ((line = reader.readLine()) != null) {
        if (line.contains("<module") && line.contains("amodeus")) {
            inAmodeus = true;
        }

        if (inAmodeus) {
            if (line.contains("</module>")) {
                inAmodeus = false;
            }

            if (line.contains("parameterset") && line.contains("mode")) {
                numberOfOperators++;
            }

            if (line.contains("parameterset") && line.contains("dispatcher")) {
                numberOfDispatchers++;
            }
        }
    }

    reader.close();

    Assert.assertEquals(1, numberOfOperators);
    Assert.assertEquals(1, numberOfDispatchers);
}
 
Example 12
Source File: RunDrtTest.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testDefaultDrt() {
    Config config = ConfigUtils.createConfig(new MultiModeDrtConfigGroup(), new DvrpConfigGroup());
    Scenario scenario = TestScenarioGenerator.generateWithAVLegs(config);
    run(config, scenario, false);
}