/** Resets the random number generator with a default random seed. */ public static void reset() { reset(DEFAULT_RANDOM_SEED); }
private void resetRandomNumbers(long seed, int iteration) { MatsimRandom.reset(seed + iteration); MatsimRandom.getRandom().nextDouble(); // draw one because of strange // "not-randomness" is the first // draw... // Fixme [kn] this should really be ten thousand draws instead of just // one }
public MatsimTestUtils() { MatsimRandom.reset(); }
public static void playConfig(final String[] args) { Config config = ConfigUtils.loadConfig(args[0]); MatsimRandom.reset(config.global().getRandomSeed()); log.info("Complete config dump:"); StringWriter writer = new StringWriter(); new ConfigWriter(config).writeStream(new PrintWriter(writer)); log.info("\n\n" + writer.getBuffer().toString()); log.info("Complete config dump done."); Scenario scenario = ScenarioUtils.loadScenario(config); playScenario(scenario); }
@Override protected void setUp() throws Exception { super.setUp(); this.outputDirectory = "test/output/" + this.getClass().getCanonicalName().replace('.', '/') + "/" + getName() + "/"; this.classInputDirectory = "test/input/" + this.getClass().getCanonicalName().replace('.', '/'); this.packageInputDirectory = this.classInputDirectory.substring(0, this.classInputDirectory.lastIndexOf('/') + 1); this.classInputDirectory = this.classInputDirectory + "/"; this.inputDirectory = this.classInputDirectory + getName() + "/"; MatsimRandom.reset(); }
/** * Tests that the same number of random numbers is generated if a custom seed * is used, and that these numbers are different with different seeds. */ public void testSeedReset() { final long seed1 = 123L; final long seed2 = 234L; MatsimRandom.reset(seed1); double value1 = MatsimRandom.getRandom().nextDouble(); MatsimRandom.reset(seed1); double value2 = MatsimRandom.getRandom().nextDouble(); assertEquals(value1, value2, EPSILON); MatsimRandom.reset(seed2); double value3 = MatsimRandom.getRandom().nextInt(); assertTrue(Math.abs(value1 - value3) > EPSILON); }
/** * Tests that multiple local instance return different random numbers, * and that they are more or less evenly distributed. */ public void testLocalInstances_distribution() { MatsimRandom.reset(123L); Random local1a = MatsimRandom.getLocalInstance(); double value1 = local1a.nextDouble(); MatsimRandom.reset(234L); Random local2a = MatsimRandom.getLocalInstance(); double value2a = local2a.nextDouble(); Random local2b = MatsimRandom.getLocalInstance(); double value2b = local2b.nextDouble(); assertTrue(Math.abs(value1 - value2a) > EPSILON); assertTrue(Math.abs(value2a - value2b) > EPSILON); assertTrue(Math.abs(value1 - value2b) > EPSILON); }
/** * Tests that local instances can be recreated (=are deterministic) if the * same random seed is used to generate them. */ public void testLocalInstances_deterministic() { MatsimRandom.reset(); Random local1a = MatsimRandom.getLocalInstance(); Random local1b = MatsimRandom.getLocalInstance(); MatsimRandom.reset(); Random local2a = MatsimRandom.getLocalInstance(); Random local2b = MatsimRandom.getLocalInstance(); assertEqualRandomNumberGenerators(local1a, local2a); assertEqualRandomNumberGenerators(local1b, local2b); }
Scenario scenario; this.config = ConfigUtils.loadConfig(this.configfile); MatsimRandom.reset(this.config.global().getRandomSeed()); scenario = ScenarioUtils.createScenario(this.config);
@Test public void test_EmptyCarRoute() { Config config = utils.loadConfig(IOUtils.newUrl(utils.packageInputResourcePath(), "config2.xml")); MatsimRandom.reset(config.global().getRandomSeed()); Scenario scenario = ScenarioUtils.createScenario(config); ScenarioUtils.loadScenario(scenario); this.runJDEQSim(scenario); // at least one event assertTrue(eventsByPerson.size() > 0); // super.checkAscendingTimeStamps: intentionally not executed, because of -infinity time step checkEventsCorrespondToPlans(scenario.getPopulation()); // custom checks: // problem in that method (and not required). boolean wasInLoop=false; for (List<Event> list : super.eventsByPerson.values()) { wasInLoop=true; assertTrue(list.get(0) instanceof ActivityEndEvent); assertTrue(list.get(1) instanceof PersonDepartureEvent); assertTrue(list.get(2) instanceof PersonArrivalEvent); assertTrue(list.get(3) instanceof ActivityStartEvent); } assertTrue(wasInLoop); }
@Test public void testEquilOneAgent() { Map<Id<Vehicle>, Map<Id<Link>, Double>> agentTravelTimes = new HashMap<>(); Config config = ConfigUtils.loadConfig("test/scenarios/equil/config.xml"); MatsimRandom.reset(config.global().getRandomSeed()); Scenario scenario = ScenarioUtils.createScenario(config); String popFileName = "plans1.xml"; config.plans().setInputFile(popFileName); ScenarioUtils.loadScenario(scenario); EventsManager events = EventsUtils.createEventsManager(); events.addHandler(new EventTestHandler(agentTravelTimes)); PrepareForSimUtils.createDefaultPrepareForSim(scenario).run(); new QSimBuilder(scenario.getConfig()) // .useDefaults() // .build(scenario, events) // .run(); Map<Id<Link>, Double> travelTimes = agentTravelTimes.get(Id.create("1", Vehicle.class)); Assert.assertEquals(360.0, travelTimes.get(Id.create(6, Link.class)).intValue(), MatsimTestUtils.EPSILON); Assert.assertEquals(180.0, travelTimes.get(Id.create(15, Link.class)).intValue(), MatsimTestUtils.EPSILON); // this one is NOT a travel time (it includes two activities and a zero-length trip) Assert.assertEquals(13561.0, travelTimes.get(Id.create(20, Link.class)).intValue(), MatsimTestUtils.EPSILON); Assert.assertEquals(360.0, travelTimes.get(Id.create(21, Link.class)).intValue(), MatsimTestUtils.EPSILON); Assert.assertEquals(1260.0, travelTimes.get(Id.create(22, Link.class)).intValue(), MatsimTestUtils.EPSILON); Assert.assertEquals(360.0, travelTimes.get(Id.create(23, Link.class)).intValue(), MatsimTestUtils.EPSILON); }
@Test public void test_Berlin_TestHandlerDetailedEventChecker() { Config config = ConfigUtils.loadConfig("test/scenarios/berlin/config.xml"); MatsimRandom.reset(config.global().getRandomSeed()); Scenario scenario = ScenarioUtils.createScenario(config); ScenarioUtils.loadScenario(scenario); this.runJDEQSim(scenario); assertEquals(scenario.getPopulation().getPersons().size(), super.eventsByPerson.size()); super.checkAscendingTimeStamps(); super.checkEventsCorrespondToPlans(scenario.getPopulation()); }
@Test public void test_equilPlans100_TestHandlerDetailedEventChecker() { Config config = ConfigUtils.loadConfig("test/scenarios/equil/config.xml"); MatsimRandom.reset(config.global().getRandomSeed()); Scenario scenario = ScenarioUtils.createScenario(config); ScenarioUtils.loadScenario(scenario); this.runJDEQSim(scenario); assertEquals(scenario.getPopulation().getPersons().size(), super.eventsByPerson.size()); super.checkAscendingTimeStamps(); super.checkEventsCorrespondToPlans(scenario.getPopulation()); }
MatsimRandom.reset(config.global().getRandomSeed()); Scenario scenario = ScenarioUtils.createScenario(config); ScenarioUtils.loadScenario(scenario);
/** Starts the assignment of links to activities. * * @param args command-line arguments */ public void run(final String[] args) { parseArguments(args); this.config = ConfigUtils.loadConfig(this.configfile); MatsimRandom.reset(this.config.global().getRandomSeed()); MutableScenario scenario = ScenarioUtils.createMutableScenario(this.config); new MatsimNetworkReader(scenario.getNetwork()).readFile(this.config.network().getInputFile()); this.config = scenario.getConfig(); StreamingPopulationReader reader = new StreamingPopulationReader( scenario ) ; final StreamingPopulationWriter plansWriter = new StreamingPopulationWriter(); plansWriter.startStreaming(this.plansfile); reader.addAlgorithm(new org.matsim.core.population.algorithms.XY2Links(scenario)); reader.addAlgorithm(plansWriter); reader.readFile(this.config.plans().getInputFile()); PopulationUtils.printPlansCount(reader) ; plansWriter.closeStreaming(); System.out.println("done."); }
/** * Loads a configuration from file (or the default config if <code>configfile</code> is <code>null</code>). * * @param configfile The path/filename of a configuration file, or null to load the default configuration. * @return The loaded configuration. */ public Config loadConfig(final String configfile) { Config config; if (configfile != null) { config = ConfigUtils.loadConfig(configfile); MatsimRandom.reset(config.global().getRandomSeed()); } else { config = new Config(); config.addCoreModules(); } createOutputDirectory(); config.controler().setOutputDirectory(this.outputDirectory); return config; }
@Test public void test_EquilPopulationPlans1Modified1_TestHandlerDetailedEventChecker() { Config config = ConfigUtils.loadConfig("test/scenarios/equil/config.xml"); config.plans().setInputFile("plans1.xml"); MatsimRandom.reset(config.global().getRandomSeed()); Scenario scenario = ScenarioUtils.createScenario(config); ScenarioUtils.loadScenario(scenario); new EquilPopulationPlans1Modified1().modifyPopulation(scenario.getPopulation()); this.runJDEQSim(scenario); assertEquals(scenario.getPopulation().getPersons().size(), super.eventsByPerson.size()); super.checkAscendingTimeStamps(); super.checkEventsCorrespondToPlans(scenario.getPopulation()); super.compareToDEQSimTravelTimes(utils.getPackageInputDirectory() + "deq_events.txt", 1.0); }
public void setUp() { String configFile = "test/input/org/matsim/pt/counts/config.xml"; this.config = ConfigUtils.loadConfig(configFile); MatsimRandom.reset(config.global().getRandomSeed()); this.scenario = ScenarioUtils.createScenario(config); config = scenario.getConfig(); new MatsimCountsReader(this.counts).readFile(config.findParam(MODULE_NAME, countFileParamName)); this.network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(config.network().getInputFile()); }
public void setUp() { String configFile = "test/input/org/matsim/counts/config.xml"; Config config = ConfigUtils.loadConfig(configFile); MatsimRandom.reset(config.global().getRandomSeed()); this.scenario = ScenarioUtils.createScenario(config); MatsimCountsReader counts_parser = new MatsimCountsReader(this.counts); counts_parser.readFile(config.counts().getCountsFileName()); this.network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(config.network().getInputFile()); }