Package org.apache.commons.math3.random

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


  private PanelTest() {}

  public static void main(String[] args) {

    final Simulator sim = new Simulator(new MersenneTwister(123),
        Measure.valueOf(1000L, SI.MILLI(SI.SECOND)));
    sim.register(new PlaneRoadModel(new Point(0, 0), new Point(10, 10), 10));
    sim.configure();

    View.create(sim)
View Full Code Here


   * @param timeUnit The time unit to use for the underlying
   *          {@link RandomMVArraysSolver}.
   * @param seed The seed to use for the {@link RandomMVArraysSolver}.
   */
  public DebugSolverCreator(long seed, Unit<Duration> timeUnit) {
    this(new RandomMVArraysSolver(new MersenneTwister(seed)), timeUnit);
  }
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

        .useParcels(ImmutableSet.<DefaultParcel> of())
        .noCurrentRoutes());
    assertEquals(1, sc.state.availableParcels.size());
    assertEquals(0, sc.state.vehicles.get(0).contents.size());
    final Solver solver = SolverValidator.wrap(new MultiVehicleSolverAdapter(
        new RandomMVArraysSolver(new MersenneTwister(123)), NonSI.MINUTE));
    Solvers.solverBuilder(solver).with(mp).with(simAPI).build().solve(sc);

    // give enough time to reach destination
    rm.moveTo(v1, destination, TimeLapseFactory.create(0, 1000000000));
    assertEquals(rm.getPosition(destination), rm.getPosition(v1));
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

    final SupplierRng<Solver> s = new SupplierRng<Solver>() {
      @Override
      public Solver get(long seed) {
        return SolverValidator.wrap(new MultiVehicleSolverAdapter(
            ArraysSolverValidator.wrap(new RandomMVArraysSolver(
                new MersenneTwister(seed))), scenario.getTimeUnit()));
      }
    };
    final Experiment.Builder builder = Experiment
        .build(new Gendreau06ObjectiveFunction()) //
        .addScenario(scenario) //
View Full Code Here

  DefaultDepot depot;
  DefaultParcel p1, p2, p3;

  @Before
  public void setUp() {
    sim = new Simulator(new MersenneTwister(123), Measure.valueOf(1000L,
        SI.MILLI(SI.SECOND)));
    rm = new PDPRoadModel(new PlaneRoadModel(new Point(0, 0),
        new Point(10, 10), SI.KILOMETER, Measure.valueOf(300d,
            NonSI.KILOMETERS_PER_HOUR)), false);
    pm = new DefaultPDPModel(new TardyAllowedPolicy());
View Full Code Here

  static final String WORK_DIR = "files/generator/locations/";

  @Test
  public void test() {
    final List<Point> locations = lg.generate(1000, new MersenneTwister(123));

    final String fileName = new StringBuilder().append(lg.getEnvSize())
        .append("-").append(lg.getRelativeStd()).append("-")
        .append(lg.getBinSize()).toString();
View Full Code Here

TOP

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

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.