Examples of MoveScope


Examples of org.drools.planner.core.localsearch.decider.MoveScope

    protected MoveScope pickMaxScoreMoveScopeFromAcceptedList(LocalSearchStepScope localSearchStepScope) {
        if (acceptedList.isEmpty()) {
            return null;
        }
        sortAcceptedList();
        MoveScope pickedMoveScope = null;
        double randomChance = localSearchStepScope.getWorkingRandom().nextDouble();
        double acceptMark = acceptChanceMaxScoreTotal * randomChance;
        for (ListIterator<MoveScope> it = acceptedList.listIterator(acceptedList.size()); it.hasPrevious();) {
            MoveScope moveScope = it.previous();
            acceptMark -= moveScope.getAcceptChance();
            // TODO That underflow warn is nonsense. randomChance can be 0.0 and the last acceptMark can end up 0.0
            // TODO so < is nonsense (do a testcase though)
            if (acceptMark < 0.0) {
                pickedMoveScope = moveScope;
                break;
View Full Code Here

Examples of org.drools.planner.core.localsearch.decider.MoveScope

        LocalSearchSolverPhaseScope localSearchSolverPhaseScope = createLocalSearchSolverPhaseScope();
        forager.phaseStarted(localSearchSolverPhaseScope);
        LocalSearchStepScope localSearchStepScope = createStepScope(localSearchSolverPhaseScope);
        forager.beforeDeciding(localSearchStepScope);
        // Pre conditions
        MoveScope a = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-20), true);
        MoveScope b = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-1), true);
        MoveScope c = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-20), false);
        MoveScope d = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-300), true);
        MoveScope e = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-2), true);
        // Do stuff
        forager.addMove(a);
        assertFalse(forager.isQuitEarly());
        forager.addMove(b);
        assertFalse(forager.isQuitEarly());
        forager.addMove(c);
        assertFalse(forager.isQuitEarly());
        forager.addMove(d);
        assertFalse(forager.isQuitEarly());
        forager.addMove(e);
        assertFalse(forager.isQuitEarly());
        MoveScope pickedScope = forager.pickMove(localSearchStepScope);
        // Post conditions
        assertSame(b, pickedScope);
        List<Move> topList = forager.getTopList(3);
        assertTrue(topList.contains(a.getMove())); // Because c is not accepted
        assertTrue(topList.contains(b.getMove()));
View Full Code Here

Examples of org.drools.planner.core.localsearch.decider.MoveScope

        LocalSearchSolverPhaseScope localSearchSolverPhaseScope = createLocalSearchSolverPhaseScope();
        forager.phaseStarted(localSearchSolverPhaseScope);
        LocalSearchStepScope localSearchStepScope = createStepScope(localSearchSolverPhaseScope);
        forager.beforeDeciding(localSearchStepScope);
        // Pre conditions
        MoveScope a = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-1), false);
        MoveScope b = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-20), true);
        MoveScope c = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-300), true);
        MoveScope d = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-1), true);
        // Do stuff
        forager.addMove(a);
        assertFalse(forager.isQuitEarly());
        forager.addMove(b);
        assertFalse(forager.isQuitEarly());
        forager.addMove(c);
        assertFalse(forager.isQuitEarly());
        forager.addMove(d);
        assertTrue(forager.isQuitEarly());
        // Post conditions
        MoveScope pickedScope = forager.pickMove(localSearchStepScope);
        assertSame(d, pickedScope);
        List<Move> topList = forager.getTopList(2);
        assertTrue(topList.contains(b.getMove()));
        assertTrue(topList.contains(d.getMove()));
        forager.phaseEnded(localSearchSolverPhaseScope);
View Full Code Here

Examples of org.drools.planner.core.localsearch.decider.MoveScope

        LocalSearchSolverPhaseScope localSearchSolverPhaseScope = createLocalSearchSolverPhaseScope();
        forager.phaseStarted(localSearchSolverPhaseScope);
        LocalSearchStepScope localSearchStepScope = createStepScope(localSearchSolverPhaseScope);
        forager.beforeDeciding(localSearchStepScope);
        // Pre conditions
        MoveScope a = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-1), false);
        MoveScope b = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-300), true);
        MoveScope c = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-4000), true);
        MoveScope d = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-20), true);
        // Do stuff
        forager.addMove(a);
        assertFalse(forager.isQuitEarly());
        forager.addMove(b);
        assertFalse(forager.isQuitEarly());
        forager.addMove(c);
        assertFalse(forager.isQuitEarly());
        forager.addMove(d);
        assertTrue(forager.isQuitEarly());
        // Post conditions
        MoveScope pickedScope = forager.pickMove(localSearchStepScope);
        assertSame(d, pickedScope);
        List<Move> topList = forager.getTopList(2);
        assertTrue(topList.contains(b.getMove()));
        assertTrue(topList.contains(d.getMove()));
        forager.phaseEnded(localSearchSolverPhaseScope);
View Full Code Here

Examples of org.drools.planner.core.localsearch.decider.MoveScope

        LocalSearchSolverPhaseScope localSearchSolverPhaseScope = createLocalSearchSolverPhaseScope();
        forager.phaseStarted(localSearchSolverPhaseScope);
        LocalSearchStepScope localSearchStepScope = createStepScope(localSearchSolverPhaseScope);
        forager.beforeDeciding(localSearchStepScope);
        // Pre conditions
        MoveScope a = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-20), false);
        MoveScope b = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-1), true);
        MoveScope c = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-1), false);
        MoveScope d = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-20), true);
        // Do stuff
        forager.addMove(a);
        assertFalse(forager.isQuitEarly());
        forager.addMove(b);
        assertFalse(forager.isQuitEarly());
        forager.addMove(c);
        assertFalse(forager.isQuitEarly());
        forager.addMove(d);
        assertTrue(forager.isQuitEarly());
        // Post conditions
        MoveScope pickedScope = forager.pickMove(localSearchStepScope);
        assertSame(d, pickedScope);
        List<Move> topList = forager.getTopList(2);
        assertTrue(topList.contains(b.getMove()));
        assertTrue(topList.contains(d.getMove()));
        forager.phaseEnded(localSearchSolverPhaseScope);
View Full Code Here

Examples of org.drools.planner.core.localsearch.decider.MoveScope

        LocalSearchStepScope localSearchStepScope = new LocalSearchStepScope(localSearchSolverPhaseScope);
        return localSearchStepScope;
    }

    public MoveScope createMoveScope(LocalSearchStepScope localSearchStepScope, Score score, boolean accepted) {
        MoveScope moveScope = new MoveScope(localSearchStepScope);
        moveScope.setMove(new DummyMove());
        moveScope.setScore(score);
        moveScope.setAccepted(accepted);
        return moveScope;
    }
View Full Code Here

Examples of org.drools.planner.core.localsearch.decider.MoveScope

        LocalSearchSolverPhaseScope solverPhaseScope = new LocalSearchSolverPhaseScope(solverScope);
        tabuAcceptor.phaseStarted(solverPhaseScope);

        LocalSearchStepScope stepScope0 = new LocalSearchStepScope(solverPhaseScope);
        stepScope0.setStepIndex(0);
        MoveScope moveScope1 = buildMoveScope(stepScope0, e1);
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope0, e0)));
        assertEquals(true, tabuAcceptor.isAccepted(moveScope1));
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope0, e2)));
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope0, e3)));
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope0, e4)));
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope0, e2))); // repeated call
        stepScope0.setStep(moveScope1.getMove());
        tabuAcceptor.stepTaken(stepScope0);
       
        LocalSearchStepScope stepScope1 = new LocalSearchStepScope(solverPhaseScope);
        stepScope1.setStepIndex(1);
        MoveScope moveScope2 = buildMoveScope(stepScope1, e2);
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope1, e0)));
        assertEquals(false, tabuAcceptor.isAccepted(buildMoveScope(stepScope1, e1)));
        assertEquals(true, tabuAcceptor.isAccepted(moveScope2));
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope1, e3)));
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope1, e4)));
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope1, e2))); // repeated call
        stepScope1.setStep(moveScope2.getMove());
        tabuAcceptor.stepTaken(stepScope1);

        LocalSearchStepScope stepScope2 = new LocalSearchStepScope(solverPhaseScope);
        stepScope2.setStepIndex(2);
        MoveScope moveScope4 = buildMoveScope(stepScope1, e4);
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope2, e0)));
        assertEquals(false, tabuAcceptor.isAccepted(buildMoveScope(stepScope2, e1)));
        assertEquals(false, tabuAcceptor.isAccepted(buildMoveScope(stepScope2, e2)));
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope2, e3)));
        assertEquals(true, tabuAcceptor.isAccepted(moveScope4));
        assertEquals(false, tabuAcceptor.isAccepted(buildMoveScope(stepScope2, e2))); // repeated call
        stepScope2.setStep(moveScope4.getMove());
        tabuAcceptor.stepTaken(stepScope2);

        LocalSearchStepScope stepScope3 = new LocalSearchStepScope(solverPhaseScope);
        stepScope3.setStepIndex(3);
        MoveScope moveScope3 = buildMoveScope(stepScope1, e3);
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope3, e0)));
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope3, e1)));
        assertEquals(false, tabuAcceptor.isAccepted(buildMoveScope(stepScope3, e2)));
        assertEquals(true, tabuAcceptor.isAccepted(moveScope3));
        assertEquals(false, tabuAcceptor.isAccepted(buildMoveScope(stepScope3, e4)));
        assertEquals(false, tabuAcceptor.isAccepted(buildMoveScope(stepScope3, e2))); // repeated call
        stepScope3.setStep(moveScope3.getMove());
        tabuAcceptor.stepTaken(stepScope3);

        LocalSearchStepScope stepScope4 = new LocalSearchStepScope(solverPhaseScope);
        stepScope4.setStepIndex(4);
        MoveScope moveScope1Again = buildMoveScope(stepScope1, e1);
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope4, e0)));
        assertEquals(true, tabuAcceptor.isAccepted(moveScope1Again));
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope4, e2)));
        assertEquals(false, tabuAcceptor.isAccepted(buildMoveScope(stepScope4, e3)));
        assertEquals(false, tabuAcceptor.isAccepted(buildMoveScope(stepScope4, e4)));
        assertEquals(true, tabuAcceptor.isAccepted(buildMoveScope(stepScope4, e2))); // repeated call
        stepScope4.setStep(moveScope1Again.getMove());
        tabuAcceptor.stepTaken(stepScope4);
       
        tabuAcceptor.phaseEnded(solverPhaseScope);
    }
View Full Code Here

Examples of org.drools.planner.core.localsearch.decider.MoveScope

    private MoveScope buildMoveScope(LocalSearchStepScope stepScope, TestdataEntity... entities) {
        return buildMoveScope(stepScope, 0, entities);
    }

    private MoveScope buildMoveScope(LocalSearchStepScope stepScope, int score, TestdataEntity... entities) {
        MoveScope moveScope = new MoveScope(stepScope);
        Move move = mock(Move.class);
        when(move.getPlanningEntities()).thenReturn((Collection) Arrays.asList(entities));
        moveScope.setMove(move);
        moveScope.setScore(new DefaultSimpleScore(score));
        return moveScope;
    }
View Full Code Here

Examples of org.drools.planner.core.localsearch.decider.MoveScope

        acceptor.phaseStarted(localSearchSolverPhaseScope);
        LocalSearchStepScope localSearchStepScope = new LocalSearchStepScope(localSearchSolverPhaseScope);
        localSearchStepScope.setStepIndex(0);
        acceptor.beforeDeciding(localSearchStepScope);
        // Pre conditions
        MoveScope a1 = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-2000));
        MoveScope a2 = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-1300));
        MoveScope a3 = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-1200));
        MoveScope b1 = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-1200));
        MoveScope b2 = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-100));
        MoveScope c1 = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-1100));
        MoveScope c2 = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-120));
        // Do stuff
        assertEquals(false, acceptor.isAccepted(a1));
        assertEquals(false, acceptor.isAccepted(a2));
        assertEquals(true, acceptor.isAccepted(a3));
        // TODO reable a thorough test of great deluge
View Full Code Here

Examples of org.drools.planner.core.localsearch.decider.MoveScope

        phaseScope.setLastCompletedLocalSearchStepScope(lastLocalSearchStepScope);
        return phaseScope;
    }

    public MoveScope createMoveScope(LocalSearchStepScope localSearchStepScope, Score score) {
        MoveScope moveScope = new MoveScope(localSearchStepScope);
        moveScope.setMove(new DummyMove());
        moveScope.setScore(score);
        return moveScope;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.