Пример #1
0
  /** Test for {@link PDPModelRenderer} in combination with a realtime clock. */
  @Test
  public void test() {
    final Simulator sim =
        Simulator.builder()
            .addModel(TimeModel.builder().withRealTime())
            .addModel(RoadModelBuilders.plane())
            .addModel(DefaultPDPModel.builder())
            .addModel(
                View.builder()
                    .with(PlaneRoadModelRenderer.builder())
                    .with(
                        RoadUserRenderer.builder()
                            .withColorAssociation(Depot.class, new RGB(255, 200, 0))
                            .withCircleAroundObjects())
                    .with(PDPModelRenderer.builder().withDestinationLines())
                    .withAutoPlay()
                    .withAutoClose()
                    .withSimulatorEndTime(5000))
            .build();

    for (int i = 0; i < 10; i++) {
      if (i != 5) {
        sim.register(Parcel.builder(new Point(i, i + 1), new Point(5, 5)).build());
        sim.register(new TestVehicle(new Point(i, 10 - i), new Point(i, i + 1)));
      }
    }
    sim.register(new Depot(new Point(5, 5)));

    sim.start();
  }
Пример #2
0
  /**
   * Run the example.
   *
   * @param testing if <code>true</code> turns on testing mode.
   */
  public static void run(boolean testing) {
    // configure the GUI. We use separate renderers for the road model and
    // for the drivers. By default the road model is rendered as a square
    // (indicating its boundaries), and the drivers are rendered as red
    // dots.
    View.Builder viewBuilder =
        View.builder().with(PlaneRoadModelRenderer.builder()).with(RoadUserRenderer.builder());

    if (testing) {
      viewBuilder =
          viewBuilder
              .withSpeedUp(TEST_SPEEDUP)
              .withAutoClose()
              .withAutoPlay()
              .withSimulatorEndTime(TEST_STOP_TIME);
    }

    // initialize a new Simulator instance
    final Simulator sim =
        Simulator.builder()
            // set the length of a simulation 'tick'
            .setTickLength(TICK_LENGTH)
            // set the random seed we use in this 'experiment'
            .setRandomSeed(RANDOM_SEED)
            // add a PlaneRoadModel, a model which facilitates the moving of
            // RoadUsers on a plane. The plane is bounded by two corner points:
            // (0,0) and (10,10)
            .addModel(
                RoadModelBuilders.plane()
                    .withMinPoint(MIN_POINT)
                    .withMaxPoint(MAX_POINT)
                    .withMaxSpeed(VEHICLE_SPEED_KMH))
            // in case a GUI is not desired simply don't add it.
            .addModel(viewBuilder)
            .build();

    // add a number of drivers on the road
    for (int i = 0; i < NUM_VEHICLES; i++) {
      // when an object is registered in the simulator it gets
      // automatically 'hooked up' with models that it's interested in. An
      // object declares to be interested in an model by implementing an
      // interface.
      sim.register(new Driver(sim.getRandomGenerator()));
    }

    // if a GUI is added, it starts it, if no GUI is specified it will
    // run the simulation without visualization.
    sim.start();
  }