private List<Activity> findBestInsertion(List<Activity> partialRoute,boolean allowAsMajor){
  int startIndex=1;
  int endIndex=partialRoute.size() - 1;
  if (allowAsMajor) {
    startIndex=0;
    endIndex=partialRoute.size();
  }
  List<Activity> newList=partialRoute;
  double best=Double.POSITIVE_INFINITY;
  List<Activity> bestList=null;
  for (int i=startIndex; i <= endIndex; i++) {
    List<Activity> tmpList=new ArrayList<>(newList);
    Activity tmpActivity=getRelocationActivity();
    tmpList.add(i,tmpActivity);
    double tmp=evaluateList(tmpList);
    if (tmp < best) {
      if (i == 0) {
        tmpActivity.setType("major");
        tmpActivity.setEndTime(Time.parseTime("08:00:00"));
      }
 else       if (i == partialRoute.size()) {
        tmpActivity.setType("major");
      }
 else {
        tmpActivity.setType("minor");
        tmpActivity.setMaximumDuration(Time.parseTime("00:20:00"));
      }
      best=tmp;
      bestList=tmpList;
    }
  }
  return bestList;
}

private List < Activity > findBestInsertion ( List < Activity > partialRoute , boolean allowAsMajor ) { int startIndex = 1 ; int endIndex = partialRoute . size ( ) - 1 ; if ( allowAsMajor ) { startIndex = 0 ; endIndex = partialRoute . size ( ) ; } List < Activity > newList = partialRoute ; double best = Double . POSITIVE_INFINITY ; List < Activity > bestList = null ; for ( int i = startIndex ; i <= endIndex ; i ++ ) { List < Activity > tmpList = new ArrayList < > ( newList ) ; Activity tmpActivity = getRelocationActivity ( ) ; tmpList . add ( i , tmpActivity ) ; double tmp = evaluateList ( tmpList ) ; if ( tmp < best ) { if ( i == 0 ) { tmpActivity . setType ( "major" ) ; tmpActivity . setEndTime ( Time . parseTime ( "08:00:00" ) ) ; } else if ( i == partialRoute . size ( ) ) { tmpActivity . setType ( "major" ) ; } else { tmpActivity . setType ( "minor" ) ; tmpActivity . setMaximumDuration ( Time . parseTime ( "00:20:00" ) ) ; } best = tmp ; bestList = tmpList ; } } return bestList ; }
find the best insertion position for a relocated activity in a given list of current activities .
