@Override
  public void handleAgentLeg(AgentWithParking aem) {
    Id personId = aem.getPerson().getId();

    boolean endOfLegReached = aem.endOfLegReached();

    if (endOfLegReached) {
      if (!parkingFound.contains(personId)) {
        parkingFound.add(personId);

        DebugLib.traceAgent(personId);

        Activity nextAct =
            (Activity)
                aem.getPerson()
                    .getSelectedPlan()
                    .getPlanElements()
                    .get(aem.getPlanElementIndex() + 3);

        Id parkingId =
            AgentWithParking.parkingManager.getFreePrivateParking(
                nextAct.getFacilityId(), nextAct.getType());

        if (isInvalidParking(aem, parkingId)) {
          parkingId =
              AgentWithParking.parkingManager.getClosestParkingFacilityNotOnLink(
                  nextAct.getCoord(), aem.getInvalidLinkForParking());
        }

        parkVehicleAndLogSearchTime(aem, personId, parkingId);
      }
    } else {
      super.handleAgentLeg(aem);
    }
  }
  @Override
  public void handleAgentLeg(AgentWithParking aem) {
    Activity nextAct =
        (Activity)
            aem.getPerson().getSelectedPlan().getPlanElements().get(aem.getPlanElementIndex() + 3);

    if (GeneralLib.getDistance(
            getCurrentLink(aem).getCoord(), network.getLinks().get(nextAct.getLinkId()).getCoord())
        < distanceToDestinationForStartingRandomSearch) {
      throughAwayRestOfRoute(aem);
    }
    super.handleAgentLeg(aem);
  }
  public static double getSearchTime(AgentWithParking aem, Id parkingId) {
    Link currentLink = aem.getCurrentLink();
    double travelTime =
        ZHScenarioGlobal.ttMatrix.getTravelTime(aem.getMessageArrivalTime(), currentLink.getId());
    double speed = currentLink.getLength() / travelTime;

    Id linkOfParking = AgentWithParking.parkingManager.getLinkOfParking(parkingId);
    double distance =
        GeneralLib.getDistance(
            ZHScenarioGlobal.scenario.getNetwork().getLinks().get(linkOfParking).getCoord(),
            currentLink.getCoord());

    double searchTime =
        distance / speed * ZHScenarioGlobal.loadDoubleParam("Dummy_SearchTimeFactor");
    return searchTime;
  }
  public void parkVehicleAndLogSearchTime(AgentWithParking aem, Id personId, Id parkingId) {
    double searchTime = getSearchTime(aem, parkingId);
    triggerSeachTimeStart(personId, aem.getMessageArrivalTime() - searchTime);

    parkVehicle(aem, parkingId);
  }
 @Override
 public void handleParkingDepartureActivity(AgentWithParking aem) {
   super.handleParkingDepartureActivity(aem);
   parkingFound.remove(aem.getPerson().getId());
 }