private void assignDistanceBinsPerPerson(DesiredDurationPerson desiredDurationPerson) {

    Id personId = desiredDurationPerson.getPersonId();
    PlanImpl plan = (PlanImpl) this.plans.getPersons().get(personId).getSelectedPlan();

    List<? extends PlanElement> actslegs = plan.getPlanElements();
    for (int j = 0; j < actslegs.size(); j = j + 2) {
      final Activity act = (Activity) actslegs.get(j);

      if (act.getType().startsWith("leisure")) {
        final LegImpl leg = (LegImpl) actslegs.get(j + 1);

        if (leg.getMode().equals(this.mode)) {
          int randomDistance =
              (int)
                  Math.round(
                      this.distanceBins.getRandomDistance(
                          desiredDurationPerson.planContainsLeisurePriorToWork()));
          String newActType = act.getType() + "_" + randomDistance;
          act.setType(newActType);

          // minimum duration is 30 min! -> else division by zero while scoring
          plan.getPerson()
              .getDesires()
              .putActivityDuration(
                  newActType, Math.max(30 * 60, desiredDurationPerson.getDuration()));

          // for plot
          this.durationDistanceBins.addVal(desiredDurationPerson.getDuration(), randomDistance);
        }
      }
    }
  }
  public void assignDistanceBins(ArrayList<DesiredDurationPerson> desiredDurationsPerson) {
    ArrayList<DesiredDurationPerson> linearBins = new ArrayList<DesiredDurationPerson>();
    ArrayList<DesiredDurationPerson> uniformBins = new ArrayList<DesiredDurationPerson>();

    Iterator<DesiredDurationPerson> desiredDurationPerson_it = desiredDurationsPerson.iterator();
    while (desiredDurationPerson_it.hasNext()) {
      DesiredDurationPerson desiredDurationPerson = desiredDurationPerson_it.next();

      if (desiredDurationPerson.getDuration() <= linearLimitDuration) {
        linearBins.add(desiredDurationPerson);
      } else {
        uniformBins.add(desiredDurationPerson);
      }
    }
    linearBins = this.movePlansWithLeisurePriorToWorkToHead(linearBins);
    this.assignDistanceBinsLinear(linearBins);
    this.assignDistanceBinsUniformly(uniformBins);
  }
  private ArrayList<DesiredDurationPerson> movePlansWithLeisurePriorToWorkToHead(
      ArrayList<DesiredDurationPerson> linearBins) {

    ArrayList<DesiredDurationPerson> linearBinsOrdered = new ArrayList<DesiredDurationPerson>();
    Collections.reverse(linearBins); // long duration -------- short duration

    int cnt = 0;

    Iterator<DesiredDurationPerson> bins_it = linearBins.iterator();
    while (bins_it.hasNext()) {
      DesiredDurationPerson desiredDurationPerson = bins_it.next();
      if (desiredDurationPerson.planContainsLeisurePriorToWork()) {
        linearBinsOrdered.add(0, desiredDurationPerson);
        cnt++;
      } else {
        linearBinsOrdered.add(cnt, desiredDurationPerson);
      }
    }
    return linearBinsOrdered;
  }