예제 #1
0
파일: MovePair.java 프로젝트: rinde/RinLog
    static void apply(List<Visit> state, ScoreDirector scoreDirector) {
      for (int i = state.size() - 1; i > 0; i--) {
        final ParcelVisit subject = (ParcelVisit) state.get(i);
        scoreDirector.beforeVariableChanged(subject, PREV_VISIT);

        final Visit target = state.get(i - 1);
        if (target == NullVisit.INSTANCE) {
          subject.setPreviousVisit(null);
        } else {
          subject.setPreviousVisit(target);
        }
        scoreDirector.afterVariableChanged(subject, PREV_VISIT);
      }
    }
예제 #2
0
파일: MovePair.java 프로젝트: rinde/RinLog
  static MovePair create(ParcelVisit pick, ParcelVisit delv, Visit pickToPrev, Visit delvToPrev) {
    final ImmutableList.Builder<Changeset> changesets = ImmutableList.builder();

    if (delv.equals(pick.getNextVisit()) || pick.equals(delv.getNextVisit())) {
      // pickup and delivery are neighbors in originating vehicle
      if (pick.isBefore(delv)) {
        changesets.add(
            Changeset.create(
                nonNulls(pick.getPreviousVisit(), pick, delv, delv.getNextVisit()),
                nonNulls(pick.getPreviousVisit(), delv.getNextVisit())));
      } else {
        changesets.add(
            Changeset.create(
                nonNulls(delv.getPreviousVisit(), delv, pick, pick.getNextVisit()),
                nonNulls(delv.getPreviousVisit(), pick.getNextVisit())));
      }
    } else {
      // not neighbors in originating vehicle
      changesets.add(
          Changeset.create(
              nonNulls(pick.getPreviousVisit(), pick, pick.getNextVisit()),
              nonNulls(pick.getPreviousVisit(), pick.getNextVisit())));
      changesets.add(
          Changeset.create(
              nonNulls(delv.getPreviousVisit(), delv, delv.getNextVisit()),
              nonNulls(delv.getPreviousVisit(), delv.getNextVisit())));
    }

    if (pickToPrev.equals(delvToPrev) || delvToPrev.equals(pick)) {
      // targets are the same, meaning that they are neighbors
      changesets.add(
          Changeset.create(
              nonNulls(pickToPrev, pickToPrev.getNextVisit()),
              nonNulls(pickToPrev, pick, delv, pickToPrev.getNextVisit())));
    } else {
      changesets.add(
          Changeset.create(
              nonNulls(pickToPrev, pickToPrev.getNextVisit()),
              nonNulls(pickToPrev, pick, pickToPrev.getNextVisit())));
      changesets.add(
          Changeset.create(
              nonNulls(delvToPrev, delvToPrev.getNextVisit()),
              nonNulls(delvToPrev, delv, delvToPrev.getNextVisit())));
    }
    return new MovePair(changesets.build(), false);
  }