예제 #1
0
 @SuppressWarnings({"boxing"})
 public void show(Point point, Vehicle vehicle) {
   final String exitString;
   if (vehicle.exitRoadSegmentId() == Vehicle.ROAD_SEGMENT_ID_NOT_SET) {
     exitString = this.trafficCanvas.popupStringExitEndRoad;
   } else {
     exitString = this.trafficCanvas.roadNetwork.findById(vehicle.exitRoadSegmentId()).userId();
   }
   final PhysicalQuantities vehiclePhysical = vehicle.physicalQuantities();
   final String string =
       String.format(
           this.trafficCanvas.popupString,
           vehicle.getId(),
           vehicle.getLabel(),
           vehicle.lane(),
           vehiclePhysical.getFrontPosition(),
           vehiclePhysical.getSpeed() * Units.MS_TO_KMH,
           vehiclePhysical.getAcc(),
           vehicle.totalTravelDistance(),
           exitString);
   final Label label = new Label(string, Label.LEFT);
   label.setBackground(new Color(200, 220, 240));
   removeAll();
   add(label);
   pack();
   final Point screenLocation = owner.getLocationOnScreen();
   setLocation(point.x + screenLocation.x + 15, point.y + screenLocation.y + 90);
   currentPopupId = vehicle.getId();
   setVisible(true);
   final PopupTimer popupTimer = new PopupTimer();
   popupTimer.start(currentPopupId);
 }
예제 #2
0
  /**
   * Calculates the acceleration of vehicle me, under European lane changing rules (no
   * "undertaking").
   *
   * @param vCritEur critical speed under which European rules no longer apply
   * @param me
   * @param laneSegment
   * @param leftLaneSegment
   * @param alphaT
   * @param alphaV0
   * @param alphaA
   * @return the acceleration of vehicle me
   */
  public double calcAccEur(
      double vCritEur,
      Vehicle me,
      LaneSegment laneSegment,
      LaneSegment leftLaneSegment,
      double alphaT,
      double alphaV0,
      double alphaA) {

    // calculate normal acceleration in own lane
    final double accInOwnLane = calcAcc(me, laneSegment, alphaT, alphaV0, alphaA);

    // no lane on left-hand side
    if (leftLaneSegment == null) {
      return accInOwnLane;
    }

    // check left-vehicle's speed
    final Vehicle newFrontLeft = leftLaneSegment.frontVehicle(me);
    if (newFrontLeft == null) {
      return accInOwnLane;
    }
    final double speedFront = newFrontLeft.getSpeed();
    if (speedFront <= vCritEur) {
      return accInOwnLane;
    }

    // condition me.getSpeed() > speedFront will be evaluated by softer tanh
    // condition below
    final double accLeft = calcAcc(me, leftLaneSegment, alphaT, alphaV0, alphaA);

    // avoid hard switching by condition vMe>vLeft needed in European
    // acceleration rule
    final double frac = calcSmoothFraction(me.getSpeed(), speedFront);
    final double accResult = frac * Math.min(accInOwnLane, accLeft) + (1 - frac) * accInOwnLane;

    // if (speedFront != -1) {
    // LOG.debug(String
    // .format("pos=%.4f, accLeft: frac=%.4f, acc=%.4f, accLeft=%.4f, accResult=%.4f, meSpeed=%.2f,
    // frontLeftSpeed=%.2f\n",
    // me.getPosition(), frac, accInOwnLane, accLeft, accResult, me.getSpeed(), speedFront));
    // }
    return accResult;
  }
예제 #3
0
 private PrintWriter checkFloatingCar(Vehicle vehicle) {
   PrintWriter printWriter = printWriters.get(vehicle);
   if (printWriter != null) {
     return printWriter;
   }
   final int vehNumber = vehicle.getVehNumber();
   if (floatingCarVehicleNumbers.contains(vehNumber) || selectRandomPercentage(vehicle)) {
     floatingCarVehicleNumbers.remove(vehNumber);
     final PrintWriter writer = fileFloatingCars.createWriter(vehicle, route);
     FileFloatingCars.writeHeader(writer, vehicle, route);
     writer.flush();
     printWriters.put(vehicle, writer);
     return writer;
   }
   return null;
 }
예제 #4
0
 private boolean selectRandomPercentage(Vehicle vehicle) {
   return (vehicle.getRandomFix() < randomFraction)
       && (vehicle.roadSegmentId() == route.getOrigin().id());
 }