[rules-users] CustomSolverPhaseCommand throws The entity ... was never added to this ScoreDirector.

Michiel Vermandel mvermand at yahoo.com
Wed Jan 23 08:31:46 EST 2013


works like a charm :-)


thanks

 
-----------------
http://www.codessentials.com - Your essential software, for free!
Follow us at http://twitter.com/#!/Codessentials


________________________________
 From: Geoffrey De Smet <ge0ffrey.spam at gmail.com>
To: Michiel Vermandel <mvermand at yahoo.com>; Rules Users List <rules-users at lists.jboss.org> 
Sent: Wednesday, January 23, 2013 2:26 PM
Subject: Re: CustomSolverPhaseCommand throws The entity ... was never added to this ScoreDirector.
 

Basically, this is fixed for 6.0.0.Beta1 (unreleased).

Read further if you want to understand why this was a problem before
    6.0.0.Beta1

Op 23-01-13 14:13, Michiel Vermandel schreef:

Hi,
>
>
>I am trying to use a CustomSolverPhaseCommand (SolutionInitializer) to analyze what happens if I start with a given configuration.
>
>
>I get java.lang.IllegalArgumentException: The entity ({T= Inspect B747-XA2.I#0 [1->3] null null}) was never added to this ScoreDirector.
>
>
>If I keep the constructionHeuristic phase before the SolutionInitializer then it works, but if I remove the constructionHeuristic phase and thus start with my SolutionInitializerthen I get the exception.
>
>
>
>I reduced my SolutionInitializer to a minmal but the issue remains.
>What am I doing wrong?
>
>
>This is my SolutionInitializer:
>
>
>
>package planner.solution;
>
>import
            org.drools.planner.core.phase.custom.CustomSolverPhaseCommand;
>import org.drools.planner.core.score.Score;
>import org.drools.planner.core.score.director.ScoreDirector;
>import org.slf4j.Logger;
>import org.slf4j.LoggerFactory;
>
>import planner.app.InspectionSchedule;
>import planner.domain.Task;
>
>public class SolutionInitializer implements
            CustomSolverPhaseCommand {
>
>    private Logger logger =
            LoggerFactory.getLogger(this.getClass());
>
>    public void changeWorkingSolution(ScoreDirector
            scoreDirector) {
>
>        InspectionSchedule schedule = (InspectionSchedule)
            scoreDirector.getWorkingSolution();
>        Task task = schedule.getTasks().get(0);
>
if task.getPeriod() returns null, then 5.5 has not inserted that Task into the working memory yet (while 6.0 will),
so you need to do something like
if (task.getPeriod() == null) {
   scoreDirector.beforeEntityAdded(task);
   scoreDirector.afterEntityAdded(task);
}
// and continue with beforeVariableChanged (although you can optimize this if-else stuff)
 
        scoreDirector.beforeVariableChanged(task, "period");
>
        task.setPeriod(schedule.getPeriods().get(0));
>        scoreDirector.afterVariableChanged(task, "period");
>
>        score = scoreDirector.calculateScore();
>        logger.debug("Score after custom: " + score);
>
>    }
>
>}
>
>
>planning configuration:
>
>
><?xml version="1.0" encoding="UTF-8"?>
><solver>
>    <environmentMode>DEBUG</environmentMode>
>
>    <!-- Domain model configuration -->
>   
<solutionClass>be.axi.planner.app.InspectionSchedule</solutionClass>
>   
<planningEntityClass>be.axi.planner.domain.Task</planningEntityClass>
>
>    <!-- Score configuration -->
>    <scoreDirectorFactory>
>       
          <scoreDefinitionType>HARD_AND_SOFT</scoreDefinitionType>
>        <scoreDrl>/inspectionRules.drl</scoreDrl>
>    </scoreDirectorFactory>
>    
>    <customSolverPhase>
>       
<customSolverPhaseCommandClass>be.axi.planner.solution.SolutionInitializer</customSolverPhaseCommandClass>
>    </customSolverPhase>
>     
>    <localSearch>
>        <termination>
>           
<terminationCompositionStyle>OR</terminationCompositionStyle>
>           
          <maximumSecondsSpend>3600</maximumSecondsSpend>
>           
          <scoreAttained>0hard/0soft</scoreAttained>
>        </termination>
>        <unionMoveSelector>
>            <changeMoveSelector>
>                <valueSelector>
>                   
          <planningVariableName>type</planningVariableName>
>                </valueSelector>
>            </changeMoveSelector>
>            <changeMoveSelector>
>                <valueSelector>
>                   
          <planningVariableName>spector</planningVariableName>
>                </valueSelector>
>            </changeMoveSelector>
>            <changeMoveSelector>
>                <valueSelector>
>                   
          <planningVariableName>period</planningVariableName>
>                </valueSelector>
>            </changeMoveSelector>
>        </unionMoveSelector>
>
>        <acceptor>
>         
          <planningEntityTabuSize>7</planningEntityTabuSize>
>        </acceptor>
>        <forager>
>           
          <minimalAcceptedSelection>1000</minimalAcceptedSelection>
>        </forager>
>    </localSearch>
></solver>
>
>
>
>Stack trace:
>
>
>
>java.lang.IllegalArgumentException: The entity ({T= Inspect B747-XA2.I#0 [1->3] null null}) was never added to this ScoreDirector.
>    at
org.drools.planner.core.score.director.drools.DroolsScoreDirector.afterVariableChanged(DroolsScoreDirector.java:125)
>    at
planner.solution.SolutionInitializer.changeWorkingSolution(SolutionInitializer2.java:24)
>    at
org.drools.planner.core.phase.custom.DefaultCustomSolverPhase.solve(DefaultCustomSolverPhase.java:58)
>    at
org.drools.planner.core.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:190)
>    at
org.drools.planner.core.solver.DefaultSolver.solve(DefaultSolver.java:155)
>    at
            planner.app.InspectionSchedule.solve(InspectionSchedule.java:192)
>    at
planner.testcore.AbstractPlanningTestClass.solve(AbstractPlanningTestClass.java:288)
>    at
planner.testcore.AbstractPlanningTestClass.solve(AbstractPlanningTestClass.java:298)
>    at
planner.testcore.AbstractPlanningTestClass.solve(AbstractPlanningTestClass.java:315)
>    at
            planner.TaskGroupingTest.communitySuccess02(TaskGroupingTest.java:289)
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
            Method)
>    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown
            Source)
>    at
            sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
            Source)
>    at java.lang.reflect.Method.invoke(Unknown Source)
>    at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>    at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>    at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>    at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>    at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>    at
org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>    at
            org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>    at
            org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>    at
            org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>    at
            org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>    at
            org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>    at
            org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>    at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>
>Thanks,
>
>
>Michiel
> 
>-----------------
>http://www.codessentials.com - Your essential software, for free!
>Follow us at http://twitter.com/#!/Codessentials
>
>
>_______________________________________________
rules-users mailing list rules-users at lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20130123/f7566f45/attachment-0001.html 


More information about the rules-users mailing list