GithubHelp home page GithubHelp logo

ctjacobs / sudoku-genetic-algorithm Goto Github PK

View Code? Open in Web Editor NEW
20.0 20.0 30.0 19 KB

Solves a Sudoku puzzle using a genetic algorithm.

Python 100.00%
evolutionary-computation genetic-algorithm sudoku sudoku-solver

sudoku-genetic-algorithm's People

Contributors

ctjacobs avatar fabricecoulon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sudoku-genetic-algorithm's Issues

'range' object has no attribute 'remove'

File "C:\Users\M\Downloads\sudoku-genetic-algorithm-master\sudoku.py", line 499, in
solution = s.solve()
File "C:\Users\M\Downloads\sudoku-genetic-algorithm-master\sudoku.py", line 430, in solve
child1, child2 = cc.crossover(parent1, parent2, crossover_rate=1.0)
File "C:\Users\M\Downloads\sudoku-genetic-algorithm-master\sudoku.py", line 294, in crossover
child1.values[i], child2.values[i] = self.crossover_rows(child1.values[i], child2.values[i])
File "C:\Users\M\Downloads\sudoku-genetic-algorithm-master\sudoku.py", line 310, in crossover_rows
remaining.remove(row1[index])
AttributeError: 'range' object has no attribute 'remove'

Error in running the code

The following error occur when running the code with python 2 and 3.

Traceback (most recent call last):
File "/Desktop/sudoku.py", line 487, in
solution = s.solve()
File "/Desktop/sudoku.py", line 377, in solve
self.population.seed(Nc, self.given)
File "/Desktop/sudoku.py", line 64, in seed
self.update_fitness()
File "/Desktop/sudoku.py", line 73, in update_fitness
candidate.update_fitness()
File "/Desktop/sudoku.py", line 108, in update_fitness
column_count[self.values[i][j]-1] += 1 # ...Update list with occurrence of a particular number.
IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

sort() takes no positional arguments

using python3 and the same puzzle_mild.txt file. Any suggestions?

Seeding complete.
Generation 0
Best fitness: 0.303155
sort() takes no positional arguments
Stack trace:

File "C:\Users\R\source\repos\SGA\SGA\SGA.py", line 78, in sort
self.candidates.sort(self.sort_fitness)
File "C:\Users\R\source\repos\SGA\SGA\SGA.py", line 414, in solve
self.population.sort()
File "C:\Users\R\source\repos\SGA\SGA\SGA.py", line 499, in (Current frame)
solution = s.solve()

broken code avoid at all cost

do not use this, you will pull your hair out trying to get one single line of code to cooperate, the line "self.candidates.sort(self.sort_fitness)"
DOES NOT WORK and you can not make it work first it throws the error "sort() takes no positional arguments" should be an easy fix just add key= before self.sort_fitness but nope gives you the error sort_fitness() missing 1 required positional argument: 'y'
so you add () after the sort_fitness function it gives you sort_fitness() missing 2 required positional arguments: 'x' and 'y' so then you add x and y then it tells you they are both undefined so then you set x and y equal to something in the method and it does not matter what you set x and y equal too it always returns the error object has no attribute 'fitness'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.