コード例 #1
0
    public void init() {
      System.out.println("Initializing simulation (null hypothesis).");

      // Create road
      road = new Road(2, 3);

      // Add lights
      road.addLight(0, 29, 15, 15);
      road.addLight(1, 29, 15, 15);
      // road.addLight(2, 29, 15, 15);

      road.addLight(0, 59, 15, 15);
      road.addLight(1, 59, 15, 15);
      // road.addLight(2, 59, 15, 15);

      // Add left turns
      road.addExit(0, 30, 'n');
      road.addExit(0, 60, 'n');

      // Add right turns
      road.addExit(road.getNumLanes() - 1, 30, 's');
      road.addExit(road.getNumLanes() - 1, 60, 's');

      // Add obstacles?
      for (int i = 1; i < 15; i++) {
        int rightLaneNumber = road.getNumLanes() - 1;
        road.addParkedCar(rightLaneNumber, random.nextInt(road.getLane(rightLaneNumber).length()));
      }

      System.out.println("Exits: " + road.getExits().length);
      System.out.println("Inital road...");
      road.print();
    }
コード例 #2
0
    public void init2() {
      System.out.println("Initializing simulation (alternative hypothesis.");

      // Create road
      road = new Road(3, 3);

      // Add lights
      road.addLight(0, 29, 15, 15);
      road.addLight(1, 29, 15, 15);
      road.addLight(2, 29, 15, 15);

      road.addLight(0, 59, 15, 15);
      road.addLight(1, 59, 15, 15);
      road.addLight(2, 59, 15, 15);

      // NO left turns

      // Add right turns
      road.addExit(road.getNumLanes() - 1, 30, 's');
      road.addExit(road.getNumLanes() - 1, 60, 's');

      // NO parked cars

      System.out.println("Exits: " + road.getExits().length);
      System.out.println("Inital road...");
      road.print();
    }
コード例 #3
0
    public void step() {
      rest();

      road.updateLights();
      road.pushCars();

      if (random.nextInt(10) < 9) {
        road.addCar();
      } else {
        int exitNum = randomRange(1, road.getExits().length - 1);
        road.addCar(road.getExits()[exitNum]);
      }

      // road.addCar();
      road.print();
    }
コード例 #4
0
 public void results() {
   System.out.println("SIMULATION RESULTS");
   System.out.println("Number of iterations: " + this.steps);
   System.out.println("Successful trips:" + road.getExits()[0].getCount());
 }