Hi Geoffrey.<br><br>Thank you very much for your replies. I was just testing the Drools Planner, and the way it was implemented (with a search approach), I thought it would work with the 8Puzzle problem. I already worked with this problem executing an A* search (<a href="http://en.wikipedia.org/wiki/A*_search_algorithm">http://en.wikipedia.org/wiki/A*_search_algorithm</a>). This search is also usefull to calculate the shortest distance between 2 locations (there is an example in the wikipedia page). So, for now on, I will be carefull with the problems I work with, to be sure they can be solved with Drools Planner =)<br>
<br>Regards,<br>Anderson<br><br><div class="gmail_quote">2010/11/15 Geoffrey De Smet <span dir="ltr">&lt;<a href="mailto:ge0ffrey.spam@gmail.com">ge0ffrey.spam@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I &#39;ve been thinking about this: 8puzzle isn&#39;t really a planning problem<br>
as you model it, here&#39;s the main problem:<br>
  a planner move != an 8puzzle move<br>
I &#39;ll call a 8puzzle move &quot;a sliding of a number&quot; from now on, to avoid<br>
confusion.<br>
<br>
A perfectly valid planner move would basically move 1 to place and 2 to<br>
place 2 and 3 to place 3.<br>
But the whole point of 8puzzle is to find the sequence of valid 8puzzle<br>
&quot;slidings of a number&quot; to come for a certain problem instance to the<br>
final state.<br>
<br>
So if you really want to make 8puzzle work in planner, model it differently:<br>
  a possible solution = a sequence of &quot;slidings of a number&quot;<br>
  a move = add or remove &quot;slidings&quot;, change a &quot;sliding&quot;s direction or<br>
change the order of &quot;slidings&quot;<br>
  hard score: if after all the slidings, it&#39;s not the perfect endstate:<br>
sum of distance each number still have to slide<br>
  soft score: count number of slidings<br>
<div class="im"><br>
With kind regards / Met vriendelijke groeten,<br>
Geoffrey De Smet<br>
<br>
</div>Op 14-11-10 21:01, Geoffrey De Smet schreef:<br>
<div><div></div><div class="h5">&gt; See below.<br>
&gt;<br>
&gt; With kind regards / Met vriendelijke groeten,<br>
&gt; Geoffrey De Smet<br>
&gt;<br>
&gt; Op 13-11-10 19:33, Anderson Rocha schreef:<br>
&gt;&gt; Hi Geoffrey, thanks for your reply.<br>
&gt;<br>
&gt; Overall, 8 puzzle isn&#39;t a natural planning problem fit, like bin<br>
&gt; packing, employee rostering, freight routing or even n queens.<br>
&gt; But it should be possible to solve this with planner.<br>
&gt;&gt;<br>
&gt;&gt; When I try the tabu search like you suggested, if I use 7 or 5 in the<br>
&gt;&gt; move tabu, it ends up with a wrong solution, and if I use 3 or 1, it<br>
&gt;&gt; gets into loop. Here is my Drools Planner configuration:<br>
&gt;&gt;<br>
&gt;&gt; &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>
&gt;&gt;<br>
&gt;&gt; &lt;localSearchSolver&gt;<br>
&gt;&gt;      &lt;environmentMode&gt;DEBUG&lt;/environmentMode&gt;<br>
&gt;&gt;      &lt;scoreDrl&gt;/rules/eightPuzzleScoreRules.drl&lt;/scoreDrl&gt;<br>
&gt;&gt;              &lt;scoreDefinition&gt;<br>
&gt;&gt;           &lt;scoreDefinitionType&gt;SIMPLE&lt;/scoreDefinitionType&gt;<br>
&gt;&gt;       &lt;/scoreDefinition&gt;<br>
&gt;&gt;       &lt;selector&gt;<br>
&gt;&gt;           &lt;moveFactoryClass&gt;solver.move.factory.EightPuzzleMoveFactory&lt;/moveFactoryClass&gt;<br>
&gt;&gt;       &lt;/selector&gt;<br>
&gt;&gt;       &lt;acceptor&gt;<br>
&gt;&gt;           &lt;completeSolutionTabuSize&gt;1000&lt;/completeSolutionTabuSize&gt;<br>
&gt;&gt;           &lt;completeMoveTabuSize&gt;7&lt;/completeMoveTabuSize&gt;<br>
&gt;&gt;       &lt;/acceptor&gt;<br>
&gt;&gt;       &lt;forager&gt;<br>
&gt;&gt;           &lt;pickEarlyType&gt;NEVER&lt;/pickEarlyType&gt;<br>
&gt;&gt;       &lt;/forager&gt;<br>
&gt;&gt;       &lt;termination&gt;<br>
&gt;&gt;           &lt;scoreAttained&gt;0&lt;/scoreAttained&gt;<br>
&gt;&gt;       &lt;/termination&gt;<br>
&gt;&gt; &lt;/localSearchSolver&gt;<br>
&gt;&gt;<br>
&gt;&gt; I tried out 2 score calculations:<br>
&gt;&gt;<br>
&gt;&gt; 1- The number of 8Puzzle pieces that are out of place.<br>
&gt; that&#39;s bad, the score should favouritize solutions closers to the final<br>
&gt; solution<br>
&gt;&gt; 2- The sum of the number of moves that each 8Puzzle piece that is out<br>
&gt;&gt; of place need to do to go to its place. This is calculated with the<br>
&gt;&gt; Manhattan Distance (<a href="http://en.wikipedia.org/wiki/Taxicab_geometry" target="_blank">http://en.wikipedia.org/wiki/Taxicab_geometry</a>).<br>
&gt; that&#39;s better. But maybe it&#39;s even better to double or exponentialize<br>
&gt; that distance.<br>
&gt; So distance 1 = 1*1 = 1<br>
&gt; distance 2 = 2*2 = 4<br>
&gt; distance 3 = 3*3 = 9<br>
&gt; distance 4 = 4*4 = 16<br>
&gt;&gt;<br>
&gt;&gt; To simplify the Email, I will tell you how I defined the first score<br>
&gt;&gt; calculation. I defined a state as a String, like &quot;6751#2430&quot;, where<br>
&gt;&gt; the character &#39;#&#39; is the empty space, that I called white space. So,<br>
&gt;&gt; the final state should be &quot;01234567#&quot;. The moves are:<br>
&gt;&gt;<br>
&gt;&gt; 1- WhiteUpMove -&gt;   from &quot;6751#2430&quot; to &quot;6#5172430&quot;<br>
&gt;&gt; 2- WhiteDownMove -&gt;   from &quot;6751#2430&quot; to &quot;6751324#0&quot;<br>
&gt;&gt; 3- WhiteLeftMove -&gt;   from &quot;6751#2430&quot; to &quot;675#12430&quot;<br>
&gt;&gt; 4- WhiteRightMove -&gt;   from &quot;6751#2430&quot; to &quot;67512#430&quot;<br>
&gt;&gt;<br>
&gt;&gt; And here are the rules that calculate the score:<br>
&gt;&gt;<br>
&gt;&gt; rule &quot;0 out of place&quot;<br>
&gt;&gt;      when<br>
&gt;&gt;              $p : Puzzle(gameState not matches &quot;0........&quot;)<br>
&gt;&gt;      then<br>
&gt;&gt;              insertLogical(new UnweightedConstraintOccurrence(&quot;0 out of place&quot;, $p));<br>
&gt;&gt; end<br>
&gt;<br>
&gt; matches uses regex, that&#39;s very unoptimal<br>
&gt; Don&#39;t use a String to represent the gameState of the problem, use new<br>
&gt; int[3][3] or even better new NumberEnum[3][3]<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; rule &quot;1 out of place&quot;<br>
&gt;&gt;      when<br>
&gt;&gt;              $p : Puzzle(gameState not matches &quot;.1.......&quot;)<br>
&gt;&gt;      then<br>
&gt;&gt;              insertLogical(new UnweightedConstraintOccurrence(&quot;1 out of place&quot;, $p));<br>
&gt;&gt; end<br>
&gt;&gt;<br>
&gt;&gt; rule &quot;2 out of place&quot;<br>
&gt;&gt;      when<br>
&gt;&gt;              $p : Puzzle(gameState not matches &quot;..2......&quot;)<br>
&gt;&gt;      then<br>
&gt;&gt;              insertLogical(new UnweightedConstraintOccurrence(&quot;2 out of place&quot;, $p));<br>
&gt;&gt; end<br>
&gt;&gt;<br>
&gt;&gt; rule &quot;3 out of place&quot;<br>
&gt;&gt;      when<br>
&gt;&gt;              $p : Puzzle(gameState not matches &quot;...3.....&quot;)<br>
&gt;&gt;      then<br>
&gt;&gt;              insertLogical(new UnweightedConstraintOccurrence(&quot;3 out of place&quot;, $p));<br>
&gt;&gt; end<br>
&gt;&gt;<br>
&gt;&gt; rule &quot;4 out of place&quot;<br>
&gt;&gt;      when<br>
&gt;&gt;              $p : Puzzle(gameState not matches &quot;....4....&quot;)<br>
&gt;&gt;      then<br>
&gt;&gt;              insertLogical(new UnweightedConstraintOccurrence(&quot;4 out of place&quot;, $p));<br>
&gt;&gt; end<br>
&gt;&gt;<br>
&gt;&gt; rule &quot;5 out of place&quot;<br>
&gt;&gt;      when<br>
&gt;&gt;              $p : Puzzle(gameState not matches &quot;.....5...&quot;)<br>
&gt;&gt;      then<br>
&gt;&gt;              insertLogical(new UnweightedConstraintOccurrence(&quot;5 out of place&quot;, $p));<br>
&gt;&gt; end<br>
&gt;&gt;<br>
&gt;&gt; rule &quot;6 out of place&quot;<br>
&gt;&gt;      when<br>
&gt;&gt;              $p : Puzzle(gameState not matches &quot;......6..&quot;)<br>
&gt;&gt;      then<br>
&gt;&gt;              insertLogical(new UnweightedConstraintOccurrence(&quot;6 out of place&quot;, $p));<br>
&gt;&gt; end<br>
&gt;&gt;<br>
&gt;&gt; rule &quot;7 out of place&quot;<br>
&gt;&gt;      when<br>
&gt;&gt;              $p : Puzzle(gameState not matches &quot;.......7.&quot;)<br>
&gt;&gt;      then<br>
&gt;&gt;              insertLogical(new UnweightedConstraintOccurrence(&quot;7 out of place&quot;, $p));<br>
&gt;&gt; end<br>
&gt;&gt;<br>
&gt;&gt; rule &quot;# out of place&quot;<br>
&gt;&gt;      when<br>
&gt;&gt;              $p : Puzzle(gameState not matches &quot;........#&quot;)<br>
&gt;&gt;      then<br>
&gt;&gt;              insertLogical(new UnweightedConstraintOccurrence(&quot;# out of place&quot;, $p));<br>
&gt;&gt; end<br>
&gt;&gt;<br>
&gt;&gt; rule &quot;hardConstraintsBroken&quot;<br>
&gt;&gt;       when<br>
&gt;&gt;           $occurrenceCount : Number() from accumulate(<br>
&gt;&gt;               $unweightedConstraintOccurrence : UnweightedConstraintOccurrence(),<br>
&gt;&gt;               count($unweightedConstraintOccurrence)<br>
&gt;&gt;           );<br>
&gt;&gt;       then<br>
&gt;&gt;           scoreCalculator.setScore(- $occurrenceCount.intValue());<br>
&gt;&gt; end<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Thanks again,<br>
&gt;&gt; Anderson<br>
&gt;&gt;<br>
&gt;&gt; 2010/11/13, Geoffrey De Smet&lt;<a href="mailto:ge0ffrey.spam@gmail.com">ge0ffrey.spam@gmail.com</a>&gt;:<br>
&gt;&gt;&gt; Hi Anderson,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Try a solution tabu of 1000 and combine it a move tabu of 7 (or even a<br>
&gt;&gt;&gt; smaller prime number), tweak from there with the benchmarker.<br>
&gt;&gt;&gt; How did you define your score function?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Op 13-11-10 01:27, Anderson Rocha schreef:<br>
&gt;&gt;&gt;&gt; Hi all,<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I am wondering if Drools Planner can handle the 8Puzzle problem. I<br>
&gt;&gt;&gt;&gt; once resolved it with the A* search. But I do not know these simulated<br>
&gt;&gt;&gt;&gt; annealing and tabu search that Drools Planner implements. So I am<br>
&gt;&gt;&gt;&gt; having a &quot;Getting stuck in local optima&quot; problem, and depending on the<br>
&gt;&gt;&gt;&gt; start sollution it gets into loop. But if you enter a really simple<br>
&gt;&gt;&gt;&gt; start solution it resolves, because it choose the best scores until<br>
&gt;&gt;&gt;&gt; finish with few steps. If some one can help, let me know what I can<br>
&gt;&gt;&gt;&gt; send (source code, configuration files) to get some help.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Thanks,<br>
&gt;&gt;&gt;&gt; Anderson<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt;&gt; rules-users mailing list<br>
&gt;&gt;&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; --<br>
&gt;&gt;&gt; With kind regards,<br>
&gt;&gt;&gt; Geoffrey De Smet<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; rules-users mailing list<br>
&gt;&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-users mailing list<br>
&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>