Package org.drools.planner.core.localsearch

Examples of org.drools.planner.core.localsearch.LocalSearchSolverScope


    @Test @Ignore
    public void testPickMoveRandomly() {
        // Setup
        Forager forager = new AcceptedForager(PickEarlyType.NEVER, 1);
        LocalSearchSolverScope localSearchSolverScope = createLocalSearchSolverScope();
        forager.solvingStarted(localSearchSolverScope);
        LocalSearchStepScope localSearchStepScope = createStepScope(localSearchSolverScope);
        forager.beforeDeciding(localSearchStepScope);
        // Pre conditions
        MoveScope a = createMoveScope(localSearchStepScope, DefaultSimpleScore.valueOf(-20), 0.0);
View Full Code Here


        assertTrue(topList.contains(d.getMove()));
        forager.solvingEnded(localSearchSolverScope);
    }

    private LocalSearchSolverScope createLocalSearchSolverScope() {
        LocalSearchSolverScope localSearchSolverScope = new LocalSearchSolverScope();
        localSearchSolverScope.setScoreDefinition(new SimpleScoreDefinition());
        localSearchSolverScope.setWorkingRandom(new Random() {
            public double nextDouble() {
                return 0.2;
            }
        });
        localSearchSolverScope.setBestScore(DefaultSimpleScore.valueOf(-10));
        LocalSearchStepScope lastLocalSearchStepScope = new LocalSearchStepScope(localSearchSolverScope);
        lastLocalSearchStepScope.setScore(DefaultSimpleScore.valueOf(-100));
        localSearchSolverScope.setLastCompletedLocalSearchStepScope(lastLocalSearchStepScope);
        return localSearchSolverScope;
    }
View Full Code Here

    @Test
    public void testCalculateAcceptChance() {
        // Setup
        Acceptor acceptor = new GreatDelugeAcceptor(1.20, 0.01);
        LocalSearchSolverScope localSearchSolverScope = createLocalSearchSolverScope();
        acceptor.solvingStarted(localSearchSolverScope);
        LocalSearchStepScope localSearchStepScope = new LocalSearchStepScope(localSearchSolverScope);
        localSearchStepScope.setStepIndex(0);
        acceptor.beforeDeciding(localSearchStepScope);
        // Pre conditions
View Full Code Here

//        // Post conditions
//        acceptor.solvingEnded(localSearchSolverScope);
    }

    private LocalSearchSolverScope createLocalSearchSolverScope() {
        LocalSearchSolverScope localSearchSolverScope = new LocalSearchSolverScope();
        localSearchSolverScope.setScoreDefinition(new SimpleScoreDefinition());
        localSearchSolverScope.setWorkingRandom(new Random() {
            public double nextDouble() {
                return 0.2;
            }
        });
        localSearchSolverScope.setBestScore(DefaultSimpleScore.valueOf(-1000));
        LocalSearchStepScope lastLocalSearchStepScope = new LocalSearchStepScope(localSearchSolverScope);
        lastLocalSearchStepScope.setScore(DefaultSimpleScore.valueOf(-1000));
        localSearchSolverScope.setLastCompletedLocalSearchStepScope(lastLocalSearchStepScope);
        return localSearchSolverScope;
    }
View Full Code Here

        deciderScoreComparatorFactory.setSuccessiveNoHardChangeMinimum(1);
        deciderScoreComparatorFactory.setSuccessiveNoHardChangeMaximum(3);
        deciderScoreComparatorFactory.setSuccessiveNoHardChangeRepetitionMultiplicand(5.0);
        deciderScoreComparatorFactory.setHardWeightSurvivalRatio(0.9);

        LocalSearchSolverScope localSearchSolverScope = createLocalSearchSolverScope();
        deciderScoreComparatorFactory.solvingStarted(localSearchSolverScope);
        LocalSearchStepScope localSearchStepScope = localSearchSolverScope.getLastCompletedLocalSearchStepScope();
        // Under hardScoreActivationThreshold 1
        localSearchStepScope = nextStepScope(localSearchStepScope);
        deciderScoreComparatorFactory.beforeDeciding(localSearchStepScope);
        assertTrue(deciderScoreComparatorFactory.createDeciderScoreComparator() instanceof NaturalScoreComparator);
        deciderScoreComparatorFactory.stepDecided(localSearchStepScope);
        localSearchStepScope.setScore(DefaultHardAndSoftScore.valueOf(-11, -200));
        deciderScoreComparatorFactory.stepTaken(localSearchStepScope);
        // Under hardScoreActivationThreshold 2
        localSearchStepScope = nextStepScope(localSearchStepScope);
        deciderScoreComparatorFactory.beforeDeciding(localSearchStepScope);
        assertTrue(deciderScoreComparatorFactory.createDeciderScoreComparator() instanceof NaturalScoreComparator);
        deciderScoreComparatorFactory.stepDecided(localSearchStepScope);
        localSearchStepScope.setScore(DefaultHardAndSoftScore.valueOf(-10, -200));
        localSearchSolverScope.setBestSolutionStepIndex(localSearchStepScope.getStepIndex());
        deciderScoreComparatorFactory.stepTaken(localSearchStepScope);
        // Above hardScoreActivationThreshold 0
        localSearchStepScope = nextStepScope(localSearchStepScope);
        deciderScoreComparatorFactory.beforeDeciding(localSearchStepScope);
        assertTrue(deciderScoreComparatorFactory.createDeciderScoreComparator() instanceof NaturalScoreComparator);
View Full Code Here

        localSearchStepScope.setStepIndex(lastLocalSearchStepScope.getStepIndex() + 1);
        return localSearchStepScope;
    }

    private LocalSearchSolverScope createLocalSearchSolverScope() {
        LocalSearchSolverScope localSearchSolverScope = new LocalSearchSolverScope();
        localSearchSolverScope.setScoreDefinition(new HardAndSoftScoreDefinition());
        localSearchSolverScope.setBestScore(DefaultHardAndSoftScore.valueOf(-11, -200));
        localSearchSolverScope.setBestSolutionStepIndex(1000);
        LocalSearchStepScope lastLocalSearchStepScope = new LocalSearchStepScope(localSearchSolverScope);
        lastLocalSearchStepScope.setStepIndex(1000);
        lastLocalSearchStepScope.setScore(DefaultHardAndSoftScore.valueOf(-11, -200));
        localSearchSolverScope.setLastCompletedLocalSearchStepScope(lastLocalSearchStepScope);
        return localSearchSolverScope;
    }
View Full Code Here

public class ExaminationScoreRulesTest extends LoggingTest {

    @Test
    public void moveRoom() {
        LocalSearchSolverScope localSearchSolverScope = new LocalSearchSolverScope();
        localSearchSolverScope.setRuleBase(buildRuleBase());
        localSearchSolverScope.setWorkingScoreCalculator(new DefaultHardAndSoftConstraintScoreCalculator());
        Examination examination = (Examination) new ExaminationDaoImpl().readSolution(getClass().getResourceAsStream(
                "/org/drools/planner/examples/examination/data/testExaminationScoreRules.xml"));
        localSearchSolverScope.setWorkingSolution(examination);
        WorkingMemory workingMemory = localSearchSolverScope.getWorkingMemory();

        localSearchSolverScope.calculateScoreFromWorkingMemory();
        // do RoomChangeMove
        Exam exam = findExamById(examination, 123L);
        Room room = findRoomById(examination, 0L);
        ExaminationMoveHelper.moveRoom(workingMemory, exam, room);
        Score score = localSearchSolverScope.calculateScoreFromWorkingMemory();
        localSearchSolverScope.assertWorkingScore(score);
    }
View Full Code Here

public class NurseRosteringScoreRulesTest extends LoggingTest {

    @Test
    public void switchEmployeeAndUndo() {
        LocalSearchSolverScope localSearchSolverScope = new LocalSearchSolverScope();
        localSearchSolverScope.setRuleBase(buildRuleBase());
        localSearchSolverScope.setWorkingScoreCalculator(new DefaultHardAndSoftConstraintScoreCalculator());
        NurseRoster nurseRoster = (NurseRoster) new NurseRosteringDaoImpl().readSolution(getClass().getResourceAsStream(
                "/org/drools/planner/examples/nurserostering/data/testNurseRosteringScoreRules.xml"));
        localSearchSolverScope.setWorkingSolution(nurseRoster);
        WorkingMemory workingMemory = localSearchSolverScope.getWorkingMemory();

        Score firstScore = localSearchSolverScope.calculateScoreFromWorkingMemory();
        // do AssignmentSwitchMove
        Employee leftEmployee = findEmployeeById(nurseRoster, 0L);
        Assignment leftAssignment = findAssignmentById(nurseRoster, 200204001L);
        assertEquals(leftEmployee, leftAssignment.getEmployee());
        Employee rightEmployee = findEmployeeById(nurseRoster, 12L);
        Assignment rightAssignment = findAssignmentById(nurseRoster, 200204002L);
        assertEquals(rightEmployee, rightAssignment.getEmployee());
        NurseRosteringMoveHelper.moveEmployee(workingMemory, leftAssignment, rightEmployee);
        NurseRosteringMoveHelper.moveEmployee(workingMemory, rightAssignment, leftEmployee);
        localSearchSolverScope.calculateScoreFromWorkingMemory();
        // undo AssignmentSwitchMove;
        NurseRosteringMoveHelper.moveEmployee(workingMemory, rightAssignment, rightEmployee);
        NurseRosteringMoveHelper.moveEmployee(workingMemory, leftAssignment, leftEmployee);
        Score secondScore = localSearchSolverScope.calculateScoreFromWorkingMemory();
        assertEquals(firstScore, secondScore);
    }
View Full Code Here

    @Test
    public void testCalculateAcceptChance() {
        // Setup
        Acceptor acceptor = new GreatDelugeAcceptor(1.20, 0.01);
        LocalSearchSolverScope localSearchSolverScope = createLocalSearchSolverScope();
        acceptor.solvingStarted(localSearchSolverScope);
        LocalSearchStepScope localSearchStepScope = new LocalSearchStepScope(localSearchSolverScope);
        localSearchStepScope.setStepIndex(0);
        acceptor.beforeDeciding(localSearchStepScope);
        // Pre conditions
View Full Code Here

//        // Post conditions
//        acceptor.solvingEnded(localSearchSolverScope);
    }

    private LocalSearchSolverScope createLocalSearchSolverScope() {
        LocalSearchSolverScope localSearchSolverScope = new LocalSearchSolverScope();
        localSearchSolverScope.setScoreDefinition(new SimpleScoreDefinition());
        localSearchSolverScope.setWorkingRandom(new Random() {
            public double nextDouble() {
                return 0.2;
            }
        });
        localSearchSolverScope.setBestScore(DefaultSimpleScore.valueOf(-1000));
        LocalSearchStepScope lastLocalSearchStepScope = new LocalSearchStepScope(localSearchSolverScope);
        lastLocalSearchStepScope.setScore(DefaultSimpleScore.valueOf(-1000));
        localSearchSolverScope.setLastCompletedLocalSearchStepScope(lastLocalSearchStepScope);
        return localSearchSolverScope;
    }
View Full Code Here

TOP

Related Classes of org.drools.planner.core.localsearch.LocalSearchSolverScope

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.