Package org.apache.commons.math3.random

Examples of org.apache.commons.math3.random.RandomGenerator


    assertFalse(model.isPointInBoundary(new Point(-5, -0.0001)));
    assertFalse(model.isPointInBoundary(new Point(14, -0.0009)));
    assertFalse(model.isPointInBoundary(new Point(100, 100)));
    assertFalse(model.isPointInBoundary(new Point(-100, 100)));

    final RandomGenerator rnd = new MersenneTwister(123);
    for (int i = 0; i < 100; i++) {
      final Point p = model.getRandomPosition(rnd);
      assertTrue(model.isPointInBoundary(p));
    }
  }
View Full Code Here


    graph.getConnection(new Point(1, 2), new Point(2, 3));
  }

  @Test
  public void testRandomNode() {
    final RandomGenerator rnd = new MersenneTwister(456);
    for (int i = 0; i < 500; i++) {
      Graphs.addBiPath(graph, new Point(rnd.nextInt(), rnd.nextInt()),
          new Point(rnd.nextInt(), rnd.nextInt()));
    }
    final Graph<LengthData> unmod = Graphs.unmodifiableGraph(graph);
    final Point p1 = graph.getRandomNode(new MersenneTwister(123));
    final Point p2 = unmod.getRandomNode(new MersenneTwister(123));
    assertEquals(p1, p2);
View Full Code Here

    Graphs.addBiPath(graph, N, E);
  }

  @Test
  public void testMultimapGraphConstructor() {
    final RandomGenerator rnd = new MersenneTwister(123);
    final List<Point> path = new ArrayList<Point>();
    for (int i = 0; i < 20; i++) {
      path.add(new Point(rnd.nextInt(50), rnd.nextInt(50)));
    }
    Graphs.addBiPath(graph, path.toArray(new Point[path.size()]));

    final MultimapGraph<LengthData> testGraph = new MultimapGraph<LengthData>();
    testGraph.merge(graph);
View Full Code Here

    B = new Point(0, 10);
    C = new Point(10, 10);
    D = new Point(10, 0);
    Graphs.addBiPath(graph, A, B, C, D, A);

    final RandomGenerator rg = new RandomGenerator() {

      @Override
      public void setSeed(long arg0) {

      }
View Full Code Here

        .addFile("files/test/gendreau06/req_rapide_1_240_24")
        .offline()
        .parse()
        .get(0);

    final RandomGenerator rng = new MersenneTwister(123);
    for (int i = 0; i < 5; i++) {
      final long seed = rng.nextLong();
      final DebugSolverCreator dsc = new DebugSolverCreator(seed,
          scenario.getTimeUnit());
      final Gendreau06ObjectiveFunction obj = new Gendreau06ObjectiveFunction();
      final ExperimentResults results = Experiment.build(obj)
          .addConfiguration(Central.solverConfiguration(dsc))
View Full Code Here

    final double[] ordersPerHour = { 15d };// , 20d, 50d, 100d, 1000d };

    final StandardDeviation sd = new StandardDeviation();

    final RandomGenerator rng = new MersenneTwister(123L);

    final List<Times> times = newArrayList();
    // for (int i = 0; i < 10; i++) {
    // times.add(generateTimes(rng));
    // }
    times.add(asTimes(1000, 250L, 500L, 750L));
    times.add(asTimes(1000, 100L, 500L, 750L));
    times.add(asTimes(1000, 100L, 200L, 300L, 400L, 500L, 600L, 700L, 800L,
        900L));
    times.add(asTimes(1000, 100L, 200L, 300L, 399L, 500L, 600L, 700L, 800L,
        900L));
    times
        .add(asTimes(1000, 10L, 150L, 250L, 350L, 450L, 550L, 650L, 750L, 850L,
            950L));
    times
        .add(asTimes(1000, 50L, 150L, 250L, 350L, 450L, 551L, 650L, 750L, 850L,
            950L));
    times.add(asTimes(1000, 250L, 500L, 750L));
    times.add(asTimes(1000, 0L, 50L, 55L, 57L, 59L, 60L, 100L, 150L, 750L));
    times.add(asTimes(1000, 5L, 5L, 5L, 5L));
    times.add(asTimes(1000, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
        5L,
        5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L));
    times.add(asTimes(1000, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
        5L,
        5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L));
    times.add(asTimes(1000, 0L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
        5L,
        5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
        999L));
    times.add(asTimes(1000, 500L, 500L, 500L, 500L));
    times.add(asTimes(1000, 5L, 5L, 5L, 5L, 400L, 410L, 430L, 440L, 800L, 810L,
        820L,
        830L));
    times.add(asTimes(1000, 0L, 0L, 0L));
    times.add(asTimes(1000, 1L, 1L, 1L));
    times.add(asTimes(1000, 999L, 999L, 999L));
    times.add(asTimes(1000, 0L, 0L, 500L, 500L, 999L, 999L));
    times.add(asTimes(1000, 250L, 250L, 500L, 500L, 750L, 750L));
    times.add(asTimes(1000, 250L, 250L, 250L, 500L, 500L, 500L, 750L, 750L,
        750L));

    for (int i = 0; i < 10; i++) {
      times.add(generateTimes(rng, 10d));
    }

    for (int i = 0; i < 10; i++) {
      times.add(generateTimes(rng, 30d));
    }
    for (int i = 0; i < 5; i++) {

      final List<Double> ts = generateTimes(rng, 50d).list;

      final List<Double> newTs = newArrayList();
      for (final double l : ts) {
        newTs.add(l);
        newTs.add(Math.min(999, Math.max(0, l
            + DoubleMath.roundToLong((rng.nextDouble() * 6d) - 3d,
                RoundingMode.HALF_EVEN))));
      }
      times.add(asTimesDouble(1000, newTs));
    }

    for (int i = 0; i < 5; i++) {

      final List<Double> ts = generateTimes(rng, 100d).list;

      final List<Double> newTs = newArrayList();
      System.out.println("num events: " + ts.size());
      for (final double l : ts) {
        newTs.add(l);
        newTs.add(Math.min(999, Math.max(0, l
            + DoubleMath.roundToLong((rng.nextDouble() * 2d) - 1d,
                RoundingMode.HALF_EVEN))));
        newTs.add(Math.min(999, Math.max(0, l
            + DoubleMath.roundToLong((rng.nextDouble() * 2d) - 1d,
                RoundingMode.HALF_EVEN))));
      }
      times.add(asTimesDouble(1000, newTs));
    }

    final List<Long> t2 = asList(10L, 30L, 50L, 70L, 90L);
    for (int i = 0; i < 5; i++) {
      final List<Long> c = newArrayList();
      for (int j = 0; j < i + 1; j++) {
        c.addAll(t2);
      }
      Collections.sort(c);
      times.add(asTimes(100, c));
    }

    final List<Long> t = asList(100L, 300L, 500L, 700L, 900L);

    for (int i = 0; i < 15; i++) {
      final List<Long> c = newArrayList();
      for (int j = 0; j < i + 1; j++) {
        c.addAll(t);
      }
      Collections.sort(c);
      times.add(asTimes(1000, c));
    }

    final List<Long> variant = newArrayList();
    variant.addAll(t);
    for (int i = 0; i < 70; i++) {
      variant.add(100L);
    }
    Collections.sort(variant);
    times.add(asTimes(1000, variant));
    checkState(variant.size() == 75);
    checkState(times.get(times.size() - 2).list.size() == 75, "",
        times.get(times.size() - 2).list.size());

    for (int i = 0; i < 10; i++) {
      times.add(generateTimes(rng, (i + 1) * 100d));
    }

    final ImmutableList<Long> all = ContiguousSet.create(
        Range.closedOpen(0L, 1000L),
        DiscreteDomain.longs()).asList();

    times.add(asTimes(1000, all));

    final List<Long> more = newArrayList(all);
    for (final long l : all) {
      if (l % 2 == 0) {
        more.add(l);
      }
    }
    Collections.sort(more);
    times.add(asTimes(1000, more));

    final List<Long> more2 = newArrayList(all);
    for (int i = 0; i < 200; i++) {
      more2.add(100L);
    }
    for (int i = 0; i < 100; i++) {
      more2.add(200L);
    }

    Collections.sort(more2);
    final List<Long> newMore = newArrayList();
    for (int i = 0; i < more2.size(); i++) {
      newMore.add(more2.get(i) * 10L);
    }
    times.add(asTimes(1000, more2));
    times.add(asTimes(10000, newMore));

    for (int k = 0; k < 5; k++) {
      final List<Double> ts = newArrayList(generateTimes(rng, 20).list);
      final List<Double> additions = newArrayList();
      for (int i = 0; i < ts.size(); i++) {

        if (i % 3 == 0) {
          for (int j = 0; j < k; j++) {
            additions.add(ts.get(i) + (rng.nextDouble() * 10));
          }
        }
      }
      ts.addAll(additions);
      Collections.sort(ts);
View Full Code Here

   * <br/>
   * should give the same values.
   */
  @Test
  public void timeScaleInvariant() {
    final RandomGenerator rng = new MersenneTwister(123);
    final double startLengthOfDay = 1000;
    final int repetitions = 3;
    final List<Integer> numEvents = asList(200, 300, 400, 500, 600, 700, 800);
    final List<Double> lengthsOfDay = asList(startLengthOfDay, 1300d, 2000d,
        4500d, 7600d, 15000d, 60000d, 10000d, 100000d);
    for (final int events : numEvents) {
      // repetitions
      for (int j = 0; j < repetitions; j++) {
        final List<Double> scenario = newArrayList();
        for (int i = 0; i < events; i++) {
          scenario.add(rng.nextDouble() * startLengthOfDay);
        }
        Collections.sort(scenario);
        double dod = -1;
        for (final double dayLength : lengthsOfDay) {
          final List<Double> cur = newArrayList();
View Full Code Here

  /**
   * The metric should be insensitive to shifting all events left or right.
   */
  @Test
  public void shiftInvariant() {
    final RandomGenerator rng = new MersenneTwister(123);
    final double lengthOfDay = 1000;
    final int repetitions = 10;
    final List<Integer> numEvents = asList(20, 50, 120, 200, 300, 500, 670,
        800);

    for (final int num : numEvents) {
      for (int j = 0; j < repetitions; j++) {
        final List<Double> scenario = newArrayList();
        for (int i = 0; i < num; i++) {
          scenario.add(rng.nextDouble() * lengthOfDay);
        }
        Collections.sort(scenario);

        final double curDod = measureDynamism(scenario, lengthOfDay);

View Full Code Here

        .setAnnouncementIntensityPerKm2(1.3d)
        .setOrdersPerAnnouncement(1.3)
        .setScale(.1, 5)
        .setScenarioLength(240)
        .build();
    final RandomGenerator rng = new MersenneTwister(123);

    for (int i = 0; i < 10; i++) {
      final Scenario s = sg.generate(rng);

      Metrics.checkTimeWindowStrictness(s);
View Full Code Here

    final ScenarioGenerator.Builder sg = ScenarioGenerator.builder()
        .setAnnouncementIntensityPerKm2(0.3d).setOrdersPerAnnouncement(1.3) //
        .setScale(.1, 5) //
        .setScenarioLength(480);

    final RandomGenerator rng = new MersenneTwister(123);

    final List<List<Double>> allLoads = newArrayList();
    for (int i = 0; i < 10; i++) {
      final Scenario s = sg.build().generate(rng);
      Metrics.checkTimeWindowStrictness(s);
View Full Code Here

TOP

Related Classes of org.apache.commons.math3.random.RandomGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.