

Solving Sudoku with genetic algorithms - daivd
http://fakeguido.blogspot.com/2010/05/solving-sudoku-with-genetic-algorithms.html

======
merraksh
While genetic algorithms are useful for solving certain problems, Sudoku
puzzles exhibit a strong combinatorial structure that can be exploited by
other approaches (Constraint Programming above all, I think).

When modeled as feasibility problems, for instance, their solution can be
found very quickly -- it took 0.2 seconds to solve that instance on my laptop.

~~~
daivd
It is the refusal to exploit any specific properties that makes it fun :).
Real Sudoku solvers have been around for ages.

~~~
merraksh
Genetic algorithms usually do exploit the structure of the problem in order to
make crossover/mutation more efficient. This is indeed what the OP says:

 _For more difficult Sudoku puzzles, I would definitely go with the
permutation genome_

------
jerf
"I think a Sudoku puzzle that is harder for humans would not be that much
harder for optopus to solve, but I have not tested it."

Try it. You may be surprised. Here's a good one:
zonkedyak.blogspot.com/2006/11/worlds-hardest-sudoku-puzzle-al.html

Also try a 5-based instance of the same problem (against the standard 3-base
of sudoku, that is, a 5x5 matrix of 5x5 matrices containing the numbers 1-25),
and compare performance of that problem to a normal solver.

I'm not going to tell you what will happen, because you won't believe me.
Somebody seems to have cast a glamor on GP.

~~~
daivd
OK, I will try it. And if you had said that it would be almost impossible,
because there are too many local minima, I would have believed you.

A serious try with GA would require abandoning Python for a faster fitness
function in C, that does not copy dozens of lists back and forth. I estimate
that just about anyone could make it more than 100 times as fast. The slow
implementation will have to suffice for now.

The interesting part is of course not the absolute times, but if the
complexity scales differently. If a real Sudoku solver takes about 50 times as
long to solve that problem, I will consider it a victory if the GA does the
same.

~~~
bryanh
As a quick fix, check out Psyco. I've had success running algorithms in Python
up to 6-8x faster.

------
dman
Plus one for posts about Genetic Algorithms. My masters research was on
Genetic Algorithms. Btw for those interested in learning more about the field
my professor has a free book out on Metaheuristics (Which includes genetic
algorithms) at <http://cs.gmu.edu/~sean/book/metaheuristics/>

~~~
jacquesm
While we're at it: <http://www.gp-field-guide.org.uk/>

~~~
barmstrong
Cool! PDF version is free.

------
zokier
Isn't sudoku bit problematic problem for GA as there is just one correct
solution and the rest are just wrong, compared to a problem that has solutions
that are better or worse, but potentially no solution is absolutely correct?

~~~
swernli
A fair point (though technically sudoku can have multiple solutions, they are
all equally correct; there is no range of correctness, it's just binary).
However, I think something like this is useful as a proof of concept for a GA
system, because it's easy to judge its solutions. Many textbook examples of GA
I've seen involve evolving a best fit line for a given line, and the simple
examples use functions like y = x^2+1 because its easy to judge completion.

