[rules-users] [Planner]Sudoku solver
Qchevalier
quentin.chevalier.altran at gmail.com
Mon May 21 11:36:40 EDT 2012
Hi everybody,
In order to understand better Planner, I did a sudoku solver. I was inspired
by Queens example.
I need 3 minutes to solve a sudoku with localSearch .
*I have 2 issues :*
1- Construction Heuristic doesn't work at all : I don't understand why.
2- I use FROM_PLANNING_ENTITY_PROPERTY for my @PlanningVariable. The
@ValueRange is a collection of Value : [value1, value2, value3, value4,
value5, value6, value7, value8, value9]. => But this range isn't used in the
localSearch. Instead I think localSearch uses the value list
FROM_SOLUTION_PROPERTY.
I share my code on GitHub : git at github.com:qchevalier/Sudoku-solver.git
*[To understand my code]*
Firstly I use the API configuration : you will have to change the path of
the drl file in App.java(line 36), and put away the xml configuration file.
A sudoku is composed by 81 digits : each digit has 1 value, 1 column, 1 row
and 1 block.
1 value has a value between [1-9] (Value can be initialized; in this case
they can't be changed during solving. 0 is undefined value and has to be
changed).
1 column has an index with a value between [0-8].
1 row has an index with a value between [0-8].
1 block has an index with a value between [0-8].
http://drools.46999.n3.nabble.com/file/n4005002/sudoku_how_to.png
In order to initialize the sudoku I use methods initTab* from
NDigitsGenerator.java .
After get it on github (git at github.com:qchevalier/Sudoku-solver.git ):
In order to run the application : import it in eclipse, modify the path of
the DRL file, and then run as java application "App.java".
*A sample of the execution can be as this : *
2012-05-21 11:19:08,332 [main] INFO Solving started: time spend (218),
score (-508), new best score (-508), random seed (0).
/2012-05-21 11:19:08,332 [main] INFO Phase constructionHeuristic ended:
step total (0), time spend (234), best score (-508)./
2012-05-21 11:19:10,910 [main] DEBUG Step index (0), time spend (2812),
score (-485), new best score (-485), accepted move size (1948) for picked
step (col8 at row2@block6 at value0 => value1)
...
2012-05-21 11:21:55,909 [main] DEBUG Step index (88), time spend
(167811), score (-3), best score (-2), accepted move size (1797) for
picked step (col0 at row7@block2 at value3 => value6).
2012-05-21 11:21:57,643 [main] DEBUG Step index (89), time spend
(169545), score (-2), best score (-2), accepted move size (1795) for
picked step (col0 at row7@block2 at value3 => value6).
2012-05-21 11:22:09,815 [main] DEBUG Step index (96), time spend
(181717), score (-3), best score (-2), accepted move size (1797) for
picked step (col0 at row3@block1 at value6 => value3).
2012-05-21 11:22:11,534 [main] DEBUG Step index (97), time spend
(183436), score (0), new best score (0), accepted move size (1796) for
picked step (col2 at row3@block1 at value3 => value6).
2012-05-21 11:22:11,534 [main] INFO Phase localSearch ended: step total
(98), time spend (183436), best score (0).
2012-05-21 11:22:11,534 [main] INFO Solving ended: time spend (183436),
best score (0), average calculate count per second (984).
Solved sudoku:
I-------------I-------------I-------------I
I | 9 | 4 | 2 | I | 3 | 1 | 5 | I | 6 | 8 | 7 |I
I | 8 | 3 | 1 | I | 2 | 7 | 6 | I | 4 | 5 | 9 |I
I | 7 | 6 | 5 | I | 8 | 4 | 9 | I | 2 | 3 | 1 |I
I-------------I-------------I-------------I
I | 3 | 5 | 6 | I | 9 | 2 | 7 | I | 8 | 1 | 4 |I
I | 4 | 7 | 9 | I | 1 | 5 | 8 | I | 3 | 2 | 6 |I
I | 2 | 1 | 8 | I | 4 | 6 | 3 | I | 9 | 7 | 5 |I
I-------------I-------------I-------------I
I | 1 | 9 | 7 | I | 6 | 8 | 2 | I | 5 | 4 | 3 |I
I | 6 | 2 | 4 | I | 5 | 3 | 1 | I | 7 | 9 | 8 |I
I | 5 | 8 | 3 | I | 7 | 9 | 4 | I | 1 | 6 | 2 |I
I-------------I-------------I-------------I
--
View this message in context: http://drools.46999.n3.nabble.com/rules-users-Planner-Sudoku-solver-tp4005002.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
More information about the rules-users
mailing list