Package org.optaplanner.core.impl.heuristic.move

Examples of org.optaplanner.core.impl.heuristic.move.Move


        phaseEnded(phaseScope);
    }

    private void doStep(ConstructionHeuristicStepScope stepScope) {
        ConstructionHeuristicPhaseScope phaseScope = stepScope.getPhaseScope();
        Move nextStep = stepScope.getStep();
        nextStep.doMove(stepScope.getScoreDirector());
        // there is no need to recalculate the score, but we still need to set it
        phaseScope.getWorkingSolution().setScore(stepScope.getScore());
        if (assertStepScoreFromScratch) {
            phaseScope.assertWorkingScoreFromScratch(stepScope.getScore(), nextStep);
        }
View Full Code Here


            }
        }
        stepScope.setSelectedMoveCount((long) moveIndex);
        ConstructionHeuristicMoveScope pickedMoveScope = forager.pickMove(stepScope);
        if (pickedMoveScope != null) {
            Move step = pickedMoveScope.getMove();
            stepScope.setStep(step);
            if (logger.isDebugEnabled()) {
                stepScope.setStepString(step.toString());
            }
            stepScope.setUndoStep(pickedMoveScope.getUndoMove());
            stepScope.setScore(pickedMoveScope.getScore());
        }
    }
View Full Code Here

        }
    }

    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) {
            ConstructionHeuristicPhaseScope phaseScope = moveScope.getStepScope().getPhaseScope();
            phaseScope.assertExpectedUndoMoveScore(move, undoMove);
        }
        logger.trace("        Move index ({}), score ({}), move ({}).",
View Full Code Here

        // do not change bestScore
    }

    protected LocalSearchMoveScope buildMoveScope(LocalSearchStepScope stepScope, int hardScore, int softScore) {
        LocalSearchMoveScope moveScope = new LocalSearchMoveScope(stepScope);
        Move move = mock(Move.class);
        moveScope.setAccepted(true);
        moveScope.setMove(move);
        moveScope.setScore(HardSoftScore.valueOf(hardScore, softScore));
        return moveScope;
    }
View Full Code Here

    }

    protected LocalSearchMoveScope buildMoveScope(LocalSearchStepScope stepScope,
            int hardScore, int mediumScore, int softScore) {
        LocalSearchMoveScope moveScope = new LocalSearchMoveScope(stepScope);
        Move move = mock(Move.class);
        moveScope.setAccepted(true);
        moveScope.setMove(move);
        moveScope.setScore(HardMediumSoftScore.valueOf(hardScore, mediumScore, softScore));
        return moveScope;
    }
View Full Code Here

        phaseEnded(phaseScope);
    }

    private void doStep(LocalSearchStepScope stepScope) {
        LocalSearchPhaseScope phaseScope = stepScope.getPhaseScope();
        Move nextStep = stepScope.getStep();
        nextStep.doMove(stepScope.getScoreDirector());
        // there is no need to recalculate the score, but we still need to set it
        phaseScope.getWorkingSolution().setScore(stepScope.getScore());
        if (assertStepScoreFromScratch) {
            phaseScope.assertWorkingScoreFromScratch(stepScope.getScore(), nextStep);
        }
View Full Code Here

        SelectorTestUtils.mockMethodGetTrailingEntity(scoreDirector, variableDescriptor,
                new TestdataChainedEntity[]{a1, a2, a3, a4, a5, b1, b2, b3});

        SubChainSwapMove move = new SubChainSwapMove(variableDescriptor, new SubChain(Arrays.<Object>asList(a3, a4, a5)),
                new SubChain(Arrays.<Object>asList(b2, b3)));
        Move undoMove = move.createUndoMove(scoreDirector);
        move.doMove(scoreDirector);

        SelectorTestUtils.assertChain(a0, a1, a2, b2, b3);
        SelectorTestUtils.assertChain(b0, b1, a3, a4, a5);

        verify(scoreDirector).beforeVariableChanged(variableDescriptor, a3);
        verify(scoreDirector).afterVariableChanged(variableDescriptor, a3);
        verify(scoreDirector, never()).beforeVariableChanged(variableDescriptor, a4);
        verify(scoreDirector, never()).afterVariableChanged(variableDescriptor, a4);
        verify(scoreDirector, never()).beforeVariableChanged(variableDescriptor, a5);
        verify(scoreDirector, never()).afterVariableChanged(variableDescriptor, a5);
        verify(scoreDirector, atLeastOnce()).beforeVariableChanged(variableDescriptor, b2);
        verify(scoreDirector, atLeastOnce()).afterVariableChanged(variableDescriptor, b2);
        verify(scoreDirector, never()).beforeVariableChanged(variableDescriptor, b3);
        verify(scoreDirector, never()).afterVariableChanged(variableDescriptor, b3);

        undoMove.doMove(scoreDirector);
        SelectorTestUtils.assertChain(a0, a1, a2, a3, a4, a5);
        SelectorTestUtils.assertChain(b0, b1, b2, b3);
    }
View Full Code Here

        SelectorTestUtils.mockMethodGetTrailingEntity(scoreDirector, variableDescriptor,
                new TestdataChainedEntity[]{a1, a2, a3, a4, a5, b1, b2, b3});

        SubChainSwapMove move = new SubChainSwapMove(variableDescriptor, new SubChain(Arrays.<Object>asList(a2, a3, a4)),
                new SubChain(Arrays.<Object>asList(b1, b2)));
        Move undoMove = move.createUndoMove(scoreDirector);
        move.doMove(scoreDirector);

        SelectorTestUtils.assertChain(a0, a1, b1, b2, a5);
        SelectorTestUtils.assertChain(b0, a2, a3, a4, b3);

        verify(scoreDirector).beforeVariableChanged(variableDescriptor, a2);
        verify(scoreDirector).afterVariableChanged(variableDescriptor, a2);
        verify(scoreDirector, never()).beforeVariableChanged(variableDescriptor, a3);
        verify(scoreDirector, never()).afterVariableChanged(variableDescriptor, a3);
        verify(scoreDirector, never()).beforeVariableChanged(variableDescriptor, a4);
        verify(scoreDirector, never()).afterVariableChanged(variableDescriptor, a4);
        verify(scoreDirector, atLeastOnce()).beforeVariableChanged(variableDescriptor, a5);
        verify(scoreDirector, atLeastOnce()).afterVariableChanged(variableDescriptor, a5);
        verify(scoreDirector, atLeastOnce()).beforeVariableChanged(variableDescriptor, b1);
        verify(scoreDirector, atLeastOnce()).afterVariableChanged(variableDescriptor, b1);
        verify(scoreDirector, never()).beforeVariableChanged(variableDescriptor, b2);
        verify(scoreDirector, never()).afterVariableChanged(variableDescriptor, b2);
        verify(scoreDirector).beforeVariableChanged(variableDescriptor, b3);
        verify(scoreDirector).afterVariableChanged(variableDescriptor, b3);

        undoMove.doMove(scoreDirector);
        SelectorTestUtils.assertChain(a0, a1, a2, a3, a4, a5);
        SelectorTestUtils.assertChain(b0, b1, b2, b3);
    }
View Full Code Here

        return Collections.singletonList(moveScope.getMove());
    }

    @Override
    protected Collection<? extends Object> findNewTabu(LocalSearchStepScope stepScope) {
        Move tabuMove;
        if (useUndoMoveAsTabuMove) {
            tabuMove = stepScope.getUndoStep();
        } else {
            tabuMove = stepScope.getStep();
        }
View Full Code Here

            }
            double randomOffset = RandomUtils.nextDouble(workingRandom, probabilityWeightTotal);
            Map.Entry<Double, Iterator<Move>> entry = moveIteratorMap.floorEntry(randomOffset);
            // entry is never null because randomOffset < probabilityWeightTotal
            Iterator<Move> moveIterator = entry.getValue();
            Move next = moveIterator.next();
            if (!moveIterator.hasNext()) {
                stale = true;
            }
            return next;
        }
View Full Code Here

TOP

Related Classes of org.optaplanner.core.impl.heuristic.move.Move

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.