Package rinde.sim.core

Examples of rinde.sim.core.Simulator


   */
  public static void main(String[] args) {
    final String string = "AgentWise";
    final List<Point> points = measureString(string, 30, 30, 0);
    final RandomGenerator rng = new MersenneTwister(123);
    final Simulator sim = new Simulator(rng, Measure.valueOf(1000L,
        SI.MILLI(SI.SECOND)));
    sim.register(new PlaneRoadModel(new Point(0, 0), new Point(4500, 1200),
        SI.METER, Measure.valueOf(1000d, NonSI.KILOMETERS_PER_HOUR)));
    sim.configure();
    for (final Point p : points) {
      sim.register(new Vehicle(p, rng));
    }
    View.create(sim)
        .with(new PlaneRoadModelRenderer(), new VehicleRenderer(),
            new DemoPanel(string, rng)).show();
  }
View Full Code Here


    // initialize a random generator which we use throughout this
    // 'experiment'
    final RandomGenerator rnd = new MersenneTwister(123);

    // initialize a new Simulator instance
    final Simulator sim = new Simulator(rnd, Measure.valueOf(1000L,
        SI.MILLI(SI.SECOND)));

    // register 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)
    sim.register(new PlaneRoadModel(new Point(0, 0), new Point(10, 10),
        SI.KILOMETER, Measure.valueOf(VEHICLE_SPEED, NonSI.KILOMETERS_PER_HOUR)));
    // configure the simulator, once configured we can no longer change the
    // configuration (i.e. add new models) but we can start adding objects
    sim.configure();

    // add a number of drivers on the road
    final int numDrivers = 200;
    for (int i = 0; i < numDrivers; 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(rnd));
    }
    // initialize the GUI. We use separate renderers for the road model and
    // for the drivers. By default the road model is rendererd as a square
    // (indicating its boundaries), and the drivers are rendererd as red
    // dots.
View Full Code Here

      String graphFile,
      @Nullable Display display, @Nullable Monitor m, @Nullable Listener list) {

    // create a new simulator
    final RandomGenerator rng = new MersenneTwister(123);
    final Simulator simulator = new Simulator(rng, Measure.valueOf(1000L,
        SI.MILLI(SI.SECOND)));

    // use map of leuven
    final RoadModel roadModel = new GraphRoadModel(loadGraph(graphFile));
    final DefaultPDPModel pdpModel = new DefaultPDPModel();

    // configure simulator with models
    simulator.register(roadModel);
    simulator.register(pdpModel);
    simulator.configure();

    // add depots, taxis and parcels to simulator
    for (int i = 0; i < NUM_DEPOTS; i++) {
      simulator.register(new TaxiBase(roadModel.getRandomPosition(rng),
          DEPOT_CAPACITY));
    }
    for (int i = 0; i < NUM_TAXIS; i++) {
      simulator.register(new Taxi(roadModel.getRandomPosition(rng),
          TAXI_CAPACITY));
    }
    for (int i = 0; i < NUM_CUSTOMERS; i++) {
      simulator.register(new Customer(roadModel.getRandomPosition(rng),
          roadModel.getRandomPosition(rng), SERVICE_DURATION, SERVICE_DURATION,
          1 + rng.nextInt(3)));
    }

    simulator.addTickListener(new TickListener() {
      @Override
      public void tick(TimeLapse time) {
        if (time.getStartTime() > endTime) {
          simulator.stop();
        } else if (rng.nextDouble() < .007) {
          simulator.register(new Customer(
              roadModel.getRandomPosition(rng), roadModel
                  .getRandomPosition(rng), SERVICE_DURATION, SERVICE_DURATION,
              1 + rng.nextInt(3)));
        }
      }
View Full Code Here

    run(false);
  }

  public static void run(boolean testing) throws IOException {
    final MersenneTwister rand = new MersenneTwister(123);
    final Simulator simulator = new Simulator(rand, Measure.valueOf(1000L,
        SI.MILLI(SI.SECOND)));
    final Graph<LengthData> graph = DotGraphSerializer
        .getLengthGraphSerializer(new SelfCycleFilter()).read(
            AgentCommunicationExample.class.getResourceAsStream(MAP_DIR));

    // create models
    final RoadModel roadModel = new GraphRoadModel(graph);
    final CommunicationModel communicationModel = new CommunicationModel(rand,
        false);
    simulator.register(roadModel);
    simulator.register(communicationModel);
    simulator.configure();

    // add agents
    for (int i = 0; i < NUM_AGENTS; i++) {
      final int radius = MIN_RADIUS + rand.nextInt(MAX_RADIUS - MIN_RADIUS);
      final double speed = MIN_SPEED + (MAX_SPEED - MIN_SPEED)
          * rand.nextDouble();
      final double reliability = MIN_RELIABILITY
          + (rand.nextDouble() * (MAX_RELIABILITY - MIN_RELIABILITY));

      final RandomWalkAgent agent = new RandomWalkAgent(speed, radius,
          reliability);
      simulator.register(agent);
    }

    // create GUI
    final UiSchema schema = new UiSchema(false);
    schema
View Full Code Here

        .addEvent(new TimedEvent(EVENT_C, 5))
        .addEvent(new TimedEvent(EVENT_C, 100));
    scenario = sb.build();
    assertNotNull(scenario);
    ScenarioController.EventType.valueOf("SCENARIO_STARTED");
    simulator = new Simulator(new MersenneTwister(123),
        Measure.valueOf(1L, SI.SECOND));
  }
View Full Code Here

    }
    // projector
    else {}

    final RandomGenerator rng = new MersenneTwister(123);
    final Simulator simulator = new Simulator(rng, Measure.valueOf(1000L,
        SI.MILLI(SI.SECOND)));

    final ImmutableList.Builder<ImmutableList<Point>> pointBuilder = ImmutableList
        .builder();

    for (final String word : WORDS) {
      pointBuilder.add(SwarmDemo.measureString(word, FONT_SIZE, SPACING, 2));
    }

    final ImmutableList<ImmutableList<Point>> points = pointBuilder.build();
    int max = 0;
    double xMax = 0;
    double yMax = 0;
    for (final List<Point> ps : points) {
      max = Math.max(max, ps.size());
      for (final Point p : ps) {
        xMax = Math.max(p.x, xMax);
        yMax = Math.max(p.y, yMax);
      }
    }

    int width = DoubleMath.roundToInt(xMax / SPACING, RoundingMode.CEILING);
    width += VERTICAL_LINE_SPACING - width % VERTICAL_LINE_SPACING;
    width += ((width / VERTICAL_LINE_SPACING) % 2) == 0 ? VERTICAL_LINE_SPACING
        : 0;

    int height = DoubleMath.roundToInt(yMax / SPACING, RoundingMode.CEILING) + 2;
    height += height % 2;
    final Graph<?> g = createGrid(width, height, 1, VERTICAL_LINE_SPACING,
        SPACING);

    final RoadModel roadModel = new BlockingGraphRoadModel(g, SI.METER,
        NonSI.KILOMETERS_PER_HOUR);
    final PDPModel pdpModel = new DefaultPDPModel();
    simulator.register(roadModel);
    simulator.register(pdpModel);

    final List<Point> borderNodes = newArrayList(getBorderNodes(g));
    Collections.shuffle(borderNodes, new Random(123));

    simulator.register(new AgvModel(rng, ImmutableList
        .<ImmutableList<Point>> builder().addAll(points)
        .add(ImmutableList.copyOf(borderNodes))
        .build(), getBorderNodes(g)));
    simulator.configure();

    for (int i = 0; i < NUM_VECHICLES; i++) {
      simulator.register(new AGV(rng));
    }

    simulator.addTickListener(new TickListener() {
      @Override
      public void tick(TimeLapse time) {
        if (time.getStartTime() > endTime) {
          simulator.stop();
        }
      }

      @Override
      public void afterTick(TimeLapse timeLapse) {}
View Full Code Here

  /**
   * Simple GUI test.
   */
  @Test
  public void testRenderer() {
    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), 50));
    sim.configure();
    sim.addTickListener(new TickListener() {
      @Override
      public void tick(TimeLapse timeLapse) {
        if (timeLapse.getTime() >= 10000) {
          sim.stop();
        }
      }

      @Override
      public void afterTick(TimeLapse timeLapse) {}
View Full Code Here

   * Closes the window while the simulator is running. This emulates what
   * happens when a user closes the window.
   */
  @Test
  public void closeWindowWhilePlaying() {
    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), 50));
    sim.register(new DefaultPDPModel());
    sim.configure();
    sim.addTickListener(new TickListener() {
      @Override
      public void tick(TimeLapse timeLapse) {
        if (timeLapse.getTime() >= 10000) {
          final Display disp = UITestTools.findDisplay();
          disp.syncExec(
              new Runnable() {
                @Override
                public void run() {
                  disp.getActiveShell().close();
                }
              });
        }
      }

      @Override
      public void afterTick(TimeLapse timeLapse) {}
    });

    UITestTools.startAndClose(-1);

    sim.register(new TestDepot());
    final UiSchema uis = new UiSchema();
    uis.add(TestDepot.class, "/graphics/perspective/tall-building-64.png");
    View.create(sim)
        .setTitleAppendix("ViewTest")
        .with(new PlaneRoadModelRenderer())
View Full Code Here

  /**
   * Tests a view with a simulator that is not configured.
   */
  @Test(expected = IllegalStateException.class)
  public void failNotConfiguredSim() {
    final Simulator sim = new Simulator(new MersenneTwister(123),
        Measure.valueOf(1000L, SI.MILLI(SI.SECOND)));
    View.create(sim).show();
  }
View Full Code Here

  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)
        .with(new RoadUserRenderer(), new PlaneRoadModelRenderer(),
            new TestPanelRenderer("LEFT", SWT.LEFT, 200),
            new TestPanelRenderer("RIHGT BOEEE YEAH", SWT.RIGHT, 300),
View Full Code Here

TOP

Related Classes of rinde.sim.core.Simulator

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.