public void addMove(ConstructionHeuristicMoveScope moveScope) {
   checkPickEarly(moveScope);
   if (maxScoreMoveScope == null
       || scoreComparator.compare(moveScope.getScore(), maxScoreMoveScope.getScore()) > 0) {
     maxScoreMoveScope = moveScope;
   }
 }
Пример #2
0
  public ConstructionHeuristicMoveScope nominateMove(ConstructionHeuristicStepScope stepScope) {
    Object entity = stepScope.getEntity();
    if (!reinitializeVariableEntityFilter.accept(stepScope.getScoreDirector(), entity)) {
      return null;
    }
    // TODO extract to PlacerForager
    Score maxScore = null;
    ConstructionHeuristicMoveScope nominatedMoveScope = null;

    int moveIndex = 0;
    for (Iterator it = valueSelector.iterator(entity); it.hasNext(); ) {
      Object value = it.next();
      ConstructionHeuristicMoveScope moveScope = new ConstructionHeuristicMoveScope(stepScope);
      moveScope.setMoveIndex(moveIndex);
      Move move;
      if (variableDescriptor.isChained()) {
        move = new ChainedChangeMove(entity, variableDescriptor, value);
      } else {
        move = new ChangeMove(entity, variableDescriptor, value);
      }
      moveScope.setMove(move);
      if (!move.isMoveDoable(stepScope.getScoreDirector())) {
        logger.trace(
            "        Move index ({}) not doable, ignoring move ({}).",
            moveScope.getMoveIndex(),
            move);
      } else {
        doMove(moveScope);
        // TODO extract to PlacerForager
        if (maxScore == null || moveScope.getScore().compareTo(maxScore) > 0) {
          maxScore = moveScope.getScore();
          // TODO for non explicit Best Fit *, default to random picking from a maxMoveScopeList
          nominatedMoveScope = moveScope;
        }
        if (moveIndex >= selectedCountLimit) {
          break;
        }
      }
      moveIndex++;
      if (termination.isPhaseTerminated(stepScope.getPhaseScope())) {
        break;
      }
    }
    return nominatedMoveScope;
  }
 protected void checkPickEarly(ConstructionHeuristicMoveScope moveScope) {
   switch (pickEarlyType) {
     case NEVER:
       break;
     case FIRST_NON_DETERIORATING_SCORE:
       Score lastStepScore =
           moveScope.getStepScope().getPhaseScope().getLastCompletedStepScope().getScore();
       if (scoreComparator.compare(moveScope.getScore(), lastStepScore) >= 0) {
         earlyPickedMoveScope = moveScope;
       }
       break;
     default:
       throw new IllegalStateException(
           "The pickEarlyType (" + pickEarlyType + ") is not implemented.");
   }
 }
Пример #4
0
 private void doMove(ConstructionHeuristicMoveScope moveScope) {
   ScoreDirector scoreDirector = moveScope.getScoreDirector();
   Move move = moveScope.getMove();
   Move undoMove = move.createUndoMove(scoreDirector);
   moveScope.setUndoMove(undoMove);
   move.doMove(scoreDirector);
   processMove(moveScope);
   undoMove.doMove(scoreDirector);
   if (assertExpectedUndoMoveScore) {
     ConstructionHeuristicSolverPhaseScope phaseScope = moveScope.getStepScope().getPhaseScope();
     phaseScope.assertExpectedUndoMoveScore(move, undoMove);
   }
   logger.trace(
       "        Move index ({}), score ({}) for move ({}).",
       moveScope.getMoveIndex(),
       moveScope.getScore(),
       moveScope.getMove());
 }