[rules-users] Simple Drools Planner Example with NQueens
Geoffrey De Smet
ge0ffrey.spam at gmail.com
Sat Nov 20 05:58:28 EST 2010
A ClassCastException?
Theory 1) Did you copy the examples code or add the
drools-planner-examples jar to your classpath?
If you did both, don't do that.
Theory 2) After this line:
Solution startingSolution = generator.createNQueens(4);
Can you add this line:
if (startingSolution == null) throw new IllegalStateException("The startingSolution is null");
Let me know if that exception is thrown, then I 'll add a cleared
exception when this occurs.
Op 17-11-10 11:24, morge schreef:
> Hi all,
>
> I am currently looking at Drools planner. I try to solve a simple 4 queens
> problem with the following
> code:
>
> XmlSolverConfigurer configurer = new XmlSolverConfigurer();
> configurer.configure("/org/drools/planner/myexamples/nqueens/app/nqueensSolverConfig.xml");
> Solver solver = configurer.buildSolver();
> NQueensGenerator generator=new NQueensGenerator();
> Solution startingSolution = generator.createNQueens(4);
> solver.setStartingSolution(startingSolution);
> solver.solve();
> Solution bestSolution = solver.getBestSolution();
> System.out.println((NQueens) bestSolution);
>
> The config file is the usual one:
> <?xml version="1.0" encoding="UTF-8"?>
> <localSearchSolver>
> <environmentMode>DEBUG</environmentMode>
>
> <scoreDrl>/org/drools/planner/examples/nqueens/solver/nQueensScoreRules.drl</scoreDrl>
> <scoreDefinition>
> <scoreDefinitionType>SIMPLE</scoreDefinitionType>
> </scoreDefinition>
> <!-- Real world problems require to use of
> <startingSolutionInitializerClass>. -->
> <termination>
> <terminationCompositionStyle>OR</terminationCompositionStyle>
> <maximumStepCount>100</maximumStepCount>
> <scoreAttained>0</scoreAttained>
> </termination>
> <selector>
>
> <moveFactoryClass>org.drools.planner.examples.nqueens.solver.move.factory.NQueensMoveFactory</moveFactoryClass>
> </selector>
> <acceptor>
> <completeSolutionTabuSize>1000</completeSolutionTabuSize>
> </acceptor>
> <forager>
> <pickEarlyType>NEVER</pickEarlyType>
> <!-- Real world problems require to use of
> <minimalAcceptedSelection> -->
> </forager>
> </localSearchSolver>
>
>
> I do not understand why but it does not work:
>
> 2010-11-17 11:15:13,791 [main] INFO Solving with random seed (0).
> 2010-11-17 11:15:13,793 [main] INFO Initialization time spend (4) for score
> (0). Updating best solution and best score.
> Exception in thread "main" java.lang.ClassCastException:
> org.drools.planner.myexamples.nqueens.domain.NQueens
> at
> org.drools.planner.examples.nqueens.solver.move.factory.NQueensMoveFactory.createCachedMoveList(NQueensMoveFactory.java:35)
> at
> org.drools.planner.core.move.factory.CachedMoveFactory.solvingStarted(CachedMoveFactory.java:39)
> at
> org.drools.planner.core.localsearch.decider.selector.MoveFactorySelector.solvingStarted(MoveFactorySelector.java:58)
> at
> org.drools.planner.core.localsearch.decider.DefaultDecider.solvingStarted(DefaultDecider.java:91)
> at
> org.drools.planner.core.localsearch.DefaultLocalSearchSolver.solvingStarted(DefaultLocalSearchSolver.java:188)
> at
> org.drools.planner.core.localsearch.DefaultLocalSearchSolver.solveImplementation(DefaultLocalSearchSolver.java:125)
> at org.drools.planner.core.AbstractSolver.solve(AbstractSolver.java:57)
> at org.drools.planner.myexamples.nqueens.app.Main.main(Main.java:32)
>
>
> Any idea ?
>
> Thanks in advance,
>
>
> MM.
--
With kind regards,
Geoffrey De Smet
More information about the rules-users
mailing list