示例#1
0
  @Override
  protected void createWays(CardinalPoint begin) {

    // Clear all the trajectories
    this.trajectories.row(begin).clear();

    // Set all flows as not available
    this.available_flows.put(begin, CardinalPoint.NORTH, false);
    this.available_flows.put(begin, CardinalPoint.EAST, false);
    this.available_flows.put(begin, CardinalPoint.SOUTH, false);
    this.available_flows.put(begin, CardinalPoint.WEST, false);

    // For each way beginning at the Cardinal Point
    for (int i = 0; i < this.nb_ways.get(Flow.IN, begin); i++) {

      // Create the future way
      Trajectory way = new Trajectory();
      way.setLane(Lane.MID);
      way.setBegin(begin);

      // Get the zone in the conflict zone, dx and dy
      CardinalPoint zone = getZone(begin, Flow.IN);
      int zone_size = this.conflict_zone_size.get(zone);
      int begin_zone_size = this.conflict_zone_size.get(begin);

      int dx = getDX(begin, Flow.IN);
      int dy = getDY(begin, Flow.IN);

      // For each cell of the way before the conflict zone
      // *
      for (int j = this.ways_size.get(Flow.IN, begin); j > 0; j--) {

        // Determine coordinate of the cell
        int cell_x;
        int cell_y;

        // If begin is West or East
        if (begin.isHorizontal()) {
          // X depends of begin zone size, dx and j
          cell_x = this.center_x + dx * (begin_zone_size + j);

          // Y depends of zone size, dy and i
          cell_y = this.center_y + dy * (zone_size - i);
        }
        // If begin is North or South
        else {
          // X depends of zone size, dx and i
          cell_x = this.center_x + dx * (zone_size - i);

          // Y depends of begin zone size, dy and j
          cell_y = this.center_y + dy * (begin_zone_size + j);
        }

        // Add cell to the future way
        way.addCell(new Cell(cell_x, cell_y));
      }
      // */

      /* ----- Casual Case : right lane ----- */
      // *
      if (i == 0) {
        way.setLane(Lane.RIGHT);
        if (this.nb_ways.get(Flow.OUT, begin.getRight()) >= 1) {
          // Create right way, copy of the beginning of way
          Trajectory right_way = new Trajectory(way);

          CardinalPoint right = begin.getRight();
          int right_zone_size = this.conflict_zone_size.get(right);
          int right_dx = getDX(right, Flow.OUT);
          int right_dy = getDY(right, Flow.OUT);

          // For each cell of the way in the conflict zone (j = 0, not 1)
          // For each cell of the way after the conflict zone
          for (int j = 0; j <= this.ways_size.get(Flow.OUT, begin.getRight()); j++) {

            // Determine coordinate of the cell
            int cell_x;
            int cell_y;

            // If begin is West or East
            if (right.isHorizontal()) {
              // X depends of front zone size, dx and j
              cell_x = this.center_x + right_dx * (right_zone_size + j);

              // Y depends of zone size, dy and i
              cell_y = this.center_y + right_dy * (right_zone_size - i);
            }
            // If begin is North or South
            else {
              // X depends of zone size, dx and i
              cell_x = this.center_x + right_dx * (right_zone_size - i);

              // Y depends of front zone size, dy and j
              cell_y = this.center_y + right_dy * (right_zone_size + j);
            }

            // Add cell to the future way
            right_way.addCell(new Cell(cell_x, cell_y));
          }

          // Add the way to the array of trajectories
          this.trajectories.put(begin, this.nb_ways.get(Flow.IN, begin) + i, right_way);

          // Set the flow begin -> right as available
          this.available_flows.put(begin, right, true);
        }
      }
      // */

      /* ----- Casual Case : left lane ----- */
      // *
      if (i == this.nb_ways.get(Flow.IN, begin) - 1) {
        way.setLane(Lane.LEFT);
        if (i < this.nb_ways.get(Flow.OUT, begin.getRight())) {

          // Create right way, copy of the beginning of way
          Trajectory left_way = new Trajectory(way);

          CardinalPoint left = begin.getLeft();
          int left_zone_size = this.conflict_zone_size.get(left);
          int left_dx = getDX(left, Flow.OUT);
          int left_dy = getDY(left, Flow.OUT);

          // If it an indonesian intersection or not
          int n_in;
          int n_out;
          ArrayList<Cell> tmp = new ArrayList<>();
          if (this.indonesian_cross) {
            n_in = begin_zone_size - 1;
            n_out = left_zone_size - 1;
            if (left.isHorizontal()) {
              tmp.add(new Cell(this.center_x, this.center_y + dy));
              tmp.add(new Cell(this.center_x + left_dx, this.center_y));
            } else {
              tmp.add(new Cell(this.center_x + dx, this.center_y));
              tmp.add(new Cell(this.center_x, this.center_y + left_dy));
            }
          } else {
            n_in = begin_zone_size;
            n_out = left_zone_size;
            if (left.isHorizontal()) {
              tmp.add(new Cell(this.center_x + dx, this.center_y));
              tmp.add(new Cell(this.center_x + dx, this.center_y + left_dy));
              tmp.add(new Cell(this.center_x, this.center_y + left_dy));
            } else {
              tmp.add(new Cell(this.center_x, this.center_y + dy));
              tmp.add(new Cell(this.center_x + left_dx, this.center_y + dy));
              tmp.add(new Cell(this.center_x + left_dx, this.center_y));
            }
          }

          for (int j = 0; j < n_in; j++) {
            // Determine coordinate of the cell
            int cell_x;
            int cell_y;

            if (begin.isHorizontal()) {
              // X depends of begin zone size, j and dx
              cell_x = this.center_x + dx * (begin_zone_size - j);

              // Y depends of zone size, i and dy
              cell_y = this.center_y + dy * (zone_size - i);
            } else {
              // X depends of zone size, i and dx
              cell_x = this.center_x + dx * (zone_size - i);

              // Y depends of begin zone size, j and dy
              cell_y = this.center_y + dy * (begin_zone_size - j);
            }

            // Add cell to the future way
            left_way.addCell(new Cell(cell_x, cell_y));
          }

          for (Cell cell : tmp) left_way.addCell(cell);

          for (int j = n_out - 1; j >= 0; j--) {
            // Determine coordinate of the cell
            int cell_x;
            int cell_y;

            if (left.isHorizontal()) {
              // X depends of begin zone size, j and dx
              cell_x = this.center_x + left_dx * (left_zone_size - j);

              // Y depends of zone size, i and dy
              cell_y = this.center_y + left_dy * (left_zone_size - i);
            } else {
              // X depends of zone size, i and dx
              cell_x = this.center_x + left_dx * (left_zone_size - i);

              // Y depends of begin zone size, j and dy
              cell_y = this.center_y + left_dy * (left_zone_size - j);
            }

            // Add cell to the future way
            left_way.addCell(new Cell(cell_x, cell_y));
          }

          // For each cell of the way after the conflict zone
          for (int j = 1; j <= this.ways_size.get(Flow.OUT, begin.getLeft()); j++) {

            // Determine coordinate of the cell
            int cell_x;
            int cell_y;

            // If begin is West or East
            if (left.isHorizontal()) {
              // X depends of front zone size, dx and j
              cell_x = this.center_x + left_dx * (left_zone_size + j);

              // Y depends of zone size, dy and i
              cell_y = this.center_y + left_dy * (left_zone_size - i);
            }
            // If begin is North or South
            else {
              // X depends of zone size, dx and i
              cell_x = this.center_x + left_dx * (left_zone_size - i);

              // Y depends of front zone size, dy and j
              cell_y = this.center_y + left_dy * (left_zone_size + j);
            }

            // Add cell to the future way
            left_way.addCell(new Cell(cell_x, cell_y));
          }

          // Add the way to the array of trajectories
          this.trajectories.put(begin, this.nb_ways.get(Flow.IN, begin) + i, left_way);

          // Set the flow begin -> left as available
          this.available_flows.put(begin, left, true);
        }
      }
      // */

      /* ----- General Case : front lane ----- */

      // If the front way can be create
      // *
      if (i < this.nb_ways.get(Flow.OUT, begin.getFront())
          && !(i == this.nb_ways.get(Flow.IN, begin) - 1
              && this.nb_ways.get(Flow.IN, begin) >= 3)) { // If nb_ways >= 3, left way only go left

        int front_zone_size = this.conflict_zone_size.get(begin.getFront());

        // For each cell of the way in the conflict zone
        for (int j = 0; j < begin_zone_size + front_zone_size + 1; j++) {
          // Determine coordinate of the cell
          int cell_x;
          int cell_y;

          if (begin.isHorizontal()) {
            // X depends of begin zone size, j and dx
            cell_x = this.center_x + dx * (begin_zone_size - j);

            // Y depends of zone size, i and dy
            cell_y = this.center_y + dy * (zone_size - i);
          } else {
            // X depends of zone size, i and dx
            cell_x = this.center_x + dx * (zone_size - i);

            // Y depends of begin zone size, j and dy
            cell_y = this.center_y + dy * (begin_zone_size - j);
          }

          // Add cell to the future way
          way.addCell(new Cell(cell_x, cell_y));
        }

        // For each cell of the way after the conflict zone
        for (int j = 1; j <= this.ways_size.get(Flow.OUT, begin.getFront()); j++) {

          // Determine coordinate of the cell
          int cell_x;
          int cell_y;

          // If begin is West or East
          if (begin.isHorizontal()) {
            // X depends of front zone size, dx and j
            cell_x = this.center_x - dx * (front_zone_size + j);

            // Y depends of zone size, dy and i
            cell_y = this.center_y + dy * (zone_size - i);
          }

          // If begin is North or South
          else {
            // X depends of zone size, dx and i
            cell_x = this.center_x + dx * (zone_size - i);

            // Y depends of front zone size, dy and j
            cell_y = this.center_y - dy * (front_zone_size + j);
          }

          // Add cell to the future way
          way.addCell(new Cell(cell_x, cell_y));
        }
      }
      // */

      // Add the way to the array of trajectories
      this.trajectories.put(begin, i, way);

      // Set the flow begin -> front as available
      this.available_flows.put(begin, begin.getFront(), true);
    }
  }