public static Set<Integer> validateInsertableCusts(Iterator<Integer> custsIter, int custBefore, int custAfter, double minDepartTime, 
      double maxVisitTime, VrpProblem problem, boolean remove) {
    
    int[] serviceTimes = problem.getServiceTimes();
    int[] windowStartTimes = problem.getWindowStartTimes();
    int[] windowEndTimes = problem.getWindowEndTimes();
    double[][] distances = problem.getDistances();
    double[] distsFromBefore = (custBefore == -1) ? problem.getDistancesFromDepot() : distances[custBefore];
    double[] distsFromAfter = (custAfter == -1) ? problem.getDistancesFromDepot() : distances[custAfter];
    Set<Integer> list = new HashSet<Integer>();
    
    while (custsIter.hasNext()) {
      int custId = custsIter.next();
      boolean insertable = true;
      double custMinArriveTime = minDepartTime + distsFromBefore[custId];
      if (custMinArriveTime > windowEndTimes[custId]) {
        insertable = false;
      } else {
        double custMinDepartTime = Math.max(windowStartTimes[custId], custMinArriveTime) + serviceTimes[custId];
        if (custMinDepartTime + distsFromAfter[custId] > maxVisitTime) {
          insertable = false;
        }
      }
      if (!insertable && remove) {
        custsIter.remove();
        list.add(custId);
      } else if (insertable && !remove) {
        list.add(custId);
      }
    }
    
    return list;
  }