Package org.optaplanner.core.impl.constructionheuristic.scope

Examples of org.optaplanner.core.impl.constructionheuristic.scope.ConstructionHeuristicStepScope


    public void solve(DefaultSolverScope solverScope) {
        ConstructionHeuristicPhaseScope phaseScope = new ConstructionHeuristicPhaseScope(solverScope);
        phaseStarted(phaseScope);

        for (Placement placement : entityPlacer) {
            ConstructionHeuristicStepScope stepScope = new ConstructionHeuristicStepScope(phaseScope);
            stepStarted(stepScope);
            decider.decideNextStep(stepScope, placement);
            if (stepScope.getStep() == null) {
                if (termination.isPhaseTerminated(phaseScope)) {
                    logger.trace("    Step index ({}), time spent ({}) terminated without picking a nextStep.",
                            stepScope.getStepIndex(),
                            stepScope.getPhaseScope().calculateSolverTimeMillisSpent());
                } else if (stepScope.getSelectedMoveCount() == 0L) {
                    logger.warn("    No doable selected move at step index ({}), time spent ({})."
                            + " Terminating phase early.",
                            stepScope.getStepIndex(),
                            stepScope.getPhaseScope().calculateSolverTimeMillisSpent());
                } else {
                    throw new IllegalStateException("The step index (" + stepScope.getStepIndex()
                            + ") has selected move count (" + stepScope.getSelectedMoveCount()
                            + ") but failed to pick a nextStep (" + stepScope.getStep() + ").");
                }
                // Although stepStarted has been called, stepEnded is not called for this step
                break;
            }
            doStep(stepScope);
View Full Code Here


    @Test
    public void checkPickEarlyNever() {
        DefaultConstructionHeuristicForager forager = new DefaultConstructionHeuristicForager(
                ConstructionHeuristicPickEarlyType.NEVER);
        ConstructionHeuristicStepScope stepScope = buildStepScope(SimpleScore.valueOf(-100));
        forager.checkPickEarly(buildMoveScope(stepScope, SimpleScore.valueOf(-110)));
        assertEquals(false, forager.isQuitEarly());
        forager.checkPickEarly(buildMoveScope(stepScope, SimpleScore.valueOf(-100)));
        assertEquals(false, forager.isQuitEarly());
        forager.checkPickEarly(buildMoveScope(stepScope, SimpleScore.valueOf(-90)));
View Full Code Here

    @Test
    public void checkPickEarlyFirstNonDeterioratingScore() {
        DefaultConstructionHeuristicForager forager = new DefaultConstructionHeuristicForager(
                ConstructionHeuristicPickEarlyType.FIRST_NON_DETERIORATING_SCORE);
        ConstructionHeuristicStepScope stepScope = buildStepScope(SimpleScore.valueOf(-100));
        forager.checkPickEarly(buildMoveScope(stepScope, SimpleScore.valueOf(-110)));
        assertEquals(false, forager.isQuitEarly());
        forager.checkPickEarly(buildMoveScope(stepScope, SimpleScore.valueOf(-100)));
        assertEquals(true, forager.isQuitEarly());
    }
View Full Code Here

    @Test
    public void checkPickEarlyFirstFeasibleScore() {
        DefaultConstructionHeuristicForager forager = new DefaultConstructionHeuristicForager(
                ConstructionHeuristicPickEarlyType.FIRST_FEASIBLE_SCORE);
        ConstructionHeuristicStepScope stepScope = buildStepScope(HardSoftScore.valueOf(0, -100));
        forager.checkPickEarly(buildMoveScope(stepScope, HardSoftScore.valueOf(-1, -110)));
        assertEquals(false, forager.isQuitEarly());
        forager.checkPickEarly(buildMoveScope(stepScope, HardSoftScore.valueOf(-1, -90)));
        assertEquals(false, forager.isQuitEarly());
        forager.checkPickEarly(buildMoveScope(stepScope, HardSoftScore.valueOf(0, -110)));
View Full Code Here

    @Test
    public void checkPickEarlyFirstFeasibleScoreOrNonDeterioratingHard() {
        DefaultConstructionHeuristicForager forager = new DefaultConstructionHeuristicForager(
                ConstructionHeuristicPickEarlyType.FIRST_FEASIBLE_SCORE_OR_NON_DETERIORATING_HARD);
        ConstructionHeuristicStepScope stepScope = buildStepScope(HardSoftScore.valueOf(-10, -100));
        forager.checkPickEarly(buildMoveScope(stepScope, HardSoftScore.valueOf(-11, -110)));
        assertEquals(false, forager.isQuitEarly());
        forager.checkPickEarly(buildMoveScope(stepScope, HardSoftScore.valueOf(-11, -90)));
        assertEquals(false, forager.isQuitEarly());
        forager.checkPickEarly(buildMoveScope(stepScope, HardSoftScore.valueOf(-10, -110)));
View Full Code Here

    }


    protected ConstructionHeuristicStepScope buildStepScope(Score lastStepScore) {
        ConstructionHeuristicPhaseScope phaseScope = mock(ConstructionHeuristicPhaseScope.class);
        ConstructionHeuristicStepScope lastCompletedStepScope = mock(ConstructionHeuristicStepScope.class);
        when(lastCompletedStepScope.getPhaseScope()).thenReturn(phaseScope);
        when(lastCompletedStepScope.getScore()).thenReturn(lastStepScore);
        when(phaseScope.getLastCompletedStepScope()).thenReturn(lastCompletedStepScope);

        ConstructionHeuristicStepScope stepScope = mock(ConstructionHeuristicStepScope.class);
        when(stepScope.getPhaseScope()).thenReturn(phaseScope);
        return stepScope;
    }
View Full Code Here

TOP

Related Classes of org.optaplanner.core.impl.constructionheuristic.scope.ConstructionHeuristicStepScope

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.