Examples of Move


Examples of org.drools.compiler.Move

         StatefulKnowledgeSession ksession = createKnowledgeSession( kbase );
         List<String> results = new ArrayList<String>();
         ksession.setGlobal( "results",
                             results );
         ksession.insert( new Move( 1,
                                    2 ) );
         ksession.insert( new Move( 2,
                                    3 ) );

         Win win2 = new Win( 2 );
         Win win3 = new Win( 3 );

         ksession.fireAllRules();
         assertEquals( 2,
                       results.size() );
         assertTrue( results.contains( win2 ) );
         assertTrue( results.contains( win3 ) );

         ksession.dispose();
         ksession = createKnowledgeSession( kbase );
         results = new ArrayList<String>();
         ksession.setGlobal( "results",
                             results );
         // reverse the order of the inserts
         ksession.insert( new Move( 2,
                                    3 ) );
         ksession.insert( new Move( 1,
                                    2 ) );

         ksession.fireAllRules();
         assertEquals( 2,
                       results.size() );
View Full Code Here

Examples of org.drools.compiler.Move

        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
        StatefulKnowledgeSession ksession = createKnowledgeSession( kbase );
        List<String> results = new ArrayList<String>();
        ksession.setGlobal( "results",
                            results );
        ksession.insert( new Move( 1,
                                   2 ) );
        ksession.insert( new Move( 2,
                                   3 ) );

        Win win2 = new Win( 2 );
        Win win3 = new Win( 3 );

        ksession.fireAllRules();
        assertEquals( 2,
                      results.size() );
        assertTrue( results.contains( win2 ) );
        assertTrue( results.contains( win3 ) );

        ksession.dispose();
        ksession = createKnowledgeSession( kbase );
        results = new ArrayList<String>();
        ksession.setGlobal( "results",
                            results );
        // reverse the order of the inserts
        ksession.insert( new Move( 2,
                                   3 ) );
        ksession.insert( new Move( 1,
                                   2 ) );

        ksession.fireAllRules();
        assertEquals( 2,
                      results.size() );
View Full Code Here

Examples of org.drools.planner.core.move.Move

        LocalSearchStepScope localSearchStepScope = createNextStepScope(localSearchSolverScope, null);
        while (!terminatedEarly.get() && !termination.isTerminated(localSearchStepScope)) {
            localSearchStepScope.setTimeGradient(termination.calculateTimeGradient(localSearchStepScope));
            beforeDeciding(localSearchStepScope);
            decider.decideNextStep(localSearchStepScope);
            Move nextStep = localSearchStepScope.getStep();
            if (nextStep == null) {
                // TODO JBRULES-2213 do not terminate, but warn and try again
                logger.warn("No move accepted for step index ({}) out of {} accepted moves. Terminating by exception.",
                        localSearchStepScope.getStepIndex(), decider.getForager().getAcceptedMovesSize());
                break;
            }
            String nextStepString = null;
            if (logger.isInfoEnabled()) {
                nextStepString = nextStep.toString();
            }
            stepDecided(localSearchStepScope);
            nextStep.doMove(localSearchStepScope.getWorkingMemory());
            // there is no need to recalculate the score, but we still need to set it
            localSearchSolverScope.getWorkingSolution().setScore(localSearchStepScope.getScore());
            if (assertStepScoreIsUncorrupted) {
                localSearchSolverScope.assertWorkingScore(localSearchStepScope.getScore());
            }
View Full Code Here

Examples of org.drools.planner.core.move.Move

    public void decideNextStep(LocalSearchStepScope localSearchStepScope) {
        WorkingMemory workingMemory = localSearchStepScope.getWorkingMemory();
        Iterator<Move> moveIterator = selector.moveIterator(localSearchStepScope);
        while (moveIterator.hasNext()) {
            Move move = moveIterator.next();
            MoveScope moveScope = new MoveScope(localSearchStepScope);
            moveScope.setMove(move);
            // Filter out not doable moves
            if (move.isMoveDoable(workingMemory)) {
                doMove(moveScope);
                if (forager.isQuitEarly()) {
                    break;
                }
            } else {
                logger.debug("    Ignoring not doable move ({}).", move);
            }
        }
        MoveScope pickedMoveScope = forager.pickMove(localSearchStepScope);
        if (pickedMoveScope != null) {
            Move step = pickedMoveScope.getMove();
            localSearchStepScope.setStep(step);
            localSearchStepScope.setUndoStep(step.createUndoMove(workingMemory));
            localSearchStepScope.setScore(pickedMoveScope.getScore());
        }
    }
View Full Code Here

Examples of org.drools.planner.core.move.Move

        }
    }

    private void doMove(MoveScope moveScope) {
        WorkingMemory workingMemory = moveScope.getWorkingMemory();
        Move move = moveScope.getMove();
        Move undoMove = move.createUndoMove(workingMemory);
        moveScope.setUndoMove(undoMove);
        move.doMove(workingMemory);
        processMove(moveScope);
        undoMove.doMove(workingMemory);
        if (assertUndoMoveIsUncorrupted) {
            Score undoScore = moveScope.getLocalSearchStepScope().getLocalSearchSolverScope().calculateScoreFromWorkingMemory();
            Score lastCompletedStepScore = moveScope.getLocalSearchStepScope().getLocalSearchSolverScope()
                    .getLastCompletedLocalSearchStepScope().getScore();
            if (!undoScore.equals(lastCompletedStepScore)) {
View Full Code Here

Examples of org.drools.planner.core.move.Move

        }

        public Move next() {
            int moveIteratorIndex = workingRandom.nextInt(moveIteratorList.size());
            Iterator<Move> moveIterator = moveIteratorList.get(moveIteratorIndex);
            Move next = moveIterator.next();
            if (!moveIterator.hasNext()) {
                moveIteratorList.remove(moveIteratorIndex);
            }
            return next;
        }
View Full Code Here

Examples of org.drools.planner.core.move.Move

        ConstructionHeuristicStepScope stepScope = createNextStepScope(phaseScope, null);
        while (!termination.isPhaseTerminated(phaseScope) && hackEntityPlacer.hasPlacement()) {
            stepStarted(stepScope);
            hackEntityPlacer.doPlacement(stepScope);
            Move nextStep = stepScope.getStep();
            if (nextStep == null) {
                logger.warn("    Cancelled step index ({}), time spend ({}): there is no doable move. Terminating phase early.",
                        stepScope.getStepIndex(),
                        phaseScope.calculateSolverTimeMillisSpend());
                break;
            }
            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 (assertStepScoreIsUncorrupted) {
                phaseScope.assertWorkingScore(stepScope.getScore());
            }
View Full Code Here

Examples of org.drools.planner.core.move.Move

        while (!termination.isPhaseTerminated(phaseScope) && it.hasNext()) {
            Object planningEntity = it.next();
            stepScope.setPlanningEntity(planningEntity);
            stepStarted(stepScope);
            greedyDecider.decideNextStep(stepScope);
            Move nextStep = stepScope.getStep();
            if (nextStep == null) {
                logger.warn("    Cancelled step index ({}), time spend ({}): there is no doable move. Terminating phase early.",
                        stepScope.getStepIndex(),
                        phaseScope.calculateSolverTimeMillisSpend());
                break;
            }
            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 (assertStepScoreIsUncorrupted) {
                phaseScope.assertWorkingScore(stepScope.getScore());
            }
View Full Code Here

Examples of org.drools.planner.core.move.Move

        LocalSearchStepScope stepScope = createNextStepScope(phaseScope, null);
        while (!termination.isPhaseTerminated(phaseScope)) {
            stepScope.setTimeGradient(termination.calculatePhaseTimeGradient(phaseScope));
            stepStarted(stepScope);
            decider.decideNextStep(stepScope);
            Move nextStep = stepScope.getStep();
            if (nextStep == null) {
                if (termination.isPhaseTerminated(phaseScope)) {
                    logger.trace("    Step index ({}), time spend ({}) terminated without picking a nextStep.",
                            stepScope.getStepIndex(),
                            stepScope.getPhaseScope().calculateSolverTimeMillisSpend());
                } else if (stepScope.getSelectedMoveCount() == 0L) {
                    logger.warn("    No doable selected move at step index ({}), time spend ({})."
                            + " Terminating phase early.",
                            stepScope.getStepIndex(),
                            stepScope.getPhaseScope().calculateSolverTimeMillisSpend());
                } else {
                    throw new IllegalStateException("The step index (" + stepScope.getStepIndex()
                            + ") has accepted/selected move count (" + stepScope.getAcceptedMoveCount() + "/"
                            + stepScope.getSelectedMoveCount() + ") but failed to pick a nextStep (" + nextStep + ").");
                }
                // Although stepStarted has been called, stepEnded is not called for this step
                break;
            }
            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 (assertStepScoreIsUncorrupted) {
                phaseScope.assertWorkingScore(stepScope.getScore());
            }
View Full Code Here

Examples of org.drools.planner.core.move.Move

            if (termination.isPhaseTerminated(stepScope.getPhaseScope())) {
                break;
            }
        }
        if (maxMoveScope != null) {
            Move step = maxMoveScope.getMove();
            stepScope.setStep(step);
            if (logger.isDebugEnabled()) {
                stepScope.setStepString(step.toString());
            }
            stepScope.setUndoStep(maxMoveScope.getUndoMove());
            stepScope.setScore(maxMoveScope.getScore());
        }
    }
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.