private static Trip getTripWithLeg(
     final Plan plan, final Leg leg, final StageActivityTypes stages) {
   for (Trip t : TripStructureUtils.getTrips(plan, stages)) {
     if (t.getTripElements().contains(leg)) return t;
   }
   throw new RuntimeException(plan.getPlanElements() + " doesn't contain " + leg);
 }
  private List<TripStructureUtils.Trip> getDriverTrip(
      final JointTrip toRemove, final Plan driverPlan) {
    final TripStructureUtils.Trip driverTrip =
        getTripWithLeg(driverPlan, toRemove.getDriverLegs().get(0), stagesWithJointTypes);
    assert driverTrip.getTripElements().containsAll(toRemove.getDriverLegs());

    final List<PlanElement> elements = new ArrayList<PlanElement>();
    elements.add(driverTrip.getOriginActivity());
    elements.addAll(driverTrip.getTripElements());
    elements.add(driverTrip.getDestinationActivity());
    return TripStructureUtils.getTrips(elements, stages);
  }
  @Override
  public void run(Plan plan) {

    List<Trip> t = TripStructureUtils.getTrips(plan, stageActivityTypes);
    boolean ffcard = false;
    boolean owcard = false;
    int cnt = t.size();
    Person p = plan.getPerson();
    if (cnt == 0) {
      return;
    }
    int rndIdx = this.rng.nextInt(cnt);

    for (Leg l : t.get(rndIdx).getLegsOnly())
      if (l.getMode().equals("car")
          || l.getMode().equals("bike")
          || l.getMode().equals("twowaycarsharing")) return;

    if (Boolean.parseBoolean(
        ((String)
            this.scenario
                .getPopulation()
                .getPersonAttributes()
                .getAttribute(plan.getPerson().getId().toString(), "FF_CARD")))) ffcard = true;
    if (Boolean.parseBoolean(
        ((String)
            this.scenario
                .getPopulation()
                .getPersonAttributes()
                .getAttribute(plan.getPerson().getId().toString(), "OW_CARD")))) owcard = true;
    double centerX = 683217.0;
    double centerY = 247300.0;
    Coord coord = new Coord(centerX, centerY);
    if (CoordUtils.calcDistance(t.get(rndIdx).getOriginActivity().getCoord(), coord) < 10500
        && CoordUtils.calcDistance(t.get(rndIdx).getDestinationActivity().getCoord(), coord)
            < 10500) {
      // don't change the trips between the same links
      if (!t.get(rndIdx)
          .getOriginActivity()
          .getLinkId()
          .toString()
          .equals(t.get(rndIdx).getDestinationActivity().getLinkId().toString()))
        setRandomTripMode(t.get(rndIdx), plan, ffcard, owcard);
      else return;
    } else return;
  }
  @Override
  public void run(Plan plan) {

    if (!Boolean.parseBoolean(
        this.scenario
            .getConfig()
            .getModule("ActivityStrategies")
            .getValue("useSwapActivitiesStrategy"))) return;
    List<Activity> t = TripStructureUtils.getActivities(plan, this.stageActivityTypes);
    int countActivities = t.size();
    if (countActivities > 3) {

      int index1 = 1 + this.rng.nextInt(countActivities - 2);

      int index2 = 1 + this.rng.nextInt(countActivities - 2);

      while (index1 == index2) index2 = 1 + this.rng.nextInt(countActivities - 2);

      swap(plan, t.get(index1), t.get(index2));
    }
  }