private void doRandomChoice(double now) { // When do I want to stop the current activity? endTime = now + MatsimRandom.getRandom().nextInt(100);// 1% chance that endTime == now } }
public LexicographicForCompositionExtraPlanRemover( final int maxPlansPerComposition, final int maxPlansPerAgent) { this.maxPlansPerComposition = maxPlansPerComposition; this.maxPlansPerAgent = maxPlansPerAgent; this.random = MatsimRandom.getLocalInstance(); }
private QNodeImpl(final Node n, NetsimEngineContext context, NetsimInternalInterface netsimEngine2, TurnAcceptanceLogic turnAcceptanceLogic) { this.node = n; this.netsimEngine = netsimEngine2 ; this.context = context ; this.turnAcceptanceLogic = turnAcceptanceLogic; int nofInLinks = this.node.getInLinks().size(); this.inLinksArrayCache = new QLinkI[nofInLinks]; this.tempLinks = new QLinkI[nofInLinks]; if (this.context.qsimConfig.getNumberOfThreads() > 1) { // This could just as well be the "normal" case. The second alternative // is just there so some scenarios / test cases stay // "event-file-compatible". Consider removing the second alternative. this.random = MatsimRandom.getLocalInstance(); } else { this.random = MatsimRandom.getRandom(); } }
/** * 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); }
/** Resets the random number generator with a default random seed. */ public static void reset() { reset(DEFAULT_RANDOM_SEED); }
/** Returns an instance of a random number generator, which can be used * locally, e.g. in threads. * * @return pseudo random number generator */ public static Random getLocalInstance() { internalCounter++; Random r = new Random(lastUsedSeed + internalCounter*23l); prepareRNG(r); return r; }
public MatsimTestUtils() { MatsimRandom.reset(); }
/** * 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); }
/** Resets the random number generator with the given seed. * * @param seed The seed used to draw random numbers. */ public static void reset(final long seed) { lastUsedSeed = seed; internalCounter = 0; getRandom().setSeed(seed); // prepareRNG(random); } public static Random getRandom() {
public GroupStrategyManager( final IterationStopWatch stopWatch, final GroupIdentifier groupIdentifier, final GroupStrategyRegistry registry ) { this.stopWatch = stopWatch; this.groupIdentifier = groupIdentifier; this.registry = registry; this.random = MatsimRandom.getLocalInstance(); }
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); }
static <E> E chooseRandomElement(Set<E> set) { int randomIndex = MatsimRandom.getRandom().nextInt(set.size()); return Iterators.get(set.iterator(), randomIndex); } }
RandomizingTimeDistanceTravelDisutility( final TravelTime timeCalculator, final double marginalCostOfTime_s, final double marginalCostOfDistance_m, final double normalization, final double sigma) { this.timeCalculator = timeCalculator; this.marginalCostOfTime = marginalCostOfTime_s; this.marginalCostOfDistance = marginalCostOfDistance_m; this.normalization = normalization; this.sigma = sigma; this.random = sigma != 0 ? MatsimRandom.getLocalInstance() : null; }
/** * 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); }
@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(); }
public StrategySettings() { this( Id.create( MatsimRandom.getRandom().nextLong(), StrategySettings.class) ); }
public BoardingModelStochasticLinear() { random = MatsimRandom.getLocalInstance(); }
Scenario scenario; this.config = ConfigUtils.loadConfig(this.configfile); MatsimRandom.reset(this.config.global().getRandomSeed()); scenario = ScenarioUtils.createScenario(this.config);