reset password
Author Message
JPtheGmaer
Posts: 1
Posted 16:23 Nov 28, 2019 |

Hello

I'm having trouble with GA and how the deap code works. I'm using the code from magic_square.py for reference but it doesn't click with me. I also read the example he linked "Evolution of a salesman: A complete genetic algorithm tutorial for Python" he posted on csns. So i'm asking everyone on how they came to understand GA and deap to write their puzzles. Any information and links anyone can provide will be helpful. For example, did you read other articles, watch youtube videos. 

Thanks and Happy Thanksgiving

Ps. My thoughts and understands will be below if your interested. I've also tried to look up other references as well. Nothing so has clicked with me yet. I'm at a standstill. Also i'm not expecting a replay today since its thanksgiving and all. Thanks for your help.

Here is how I see magic squares solved using GA. I'm basing the framework from the same article he posted on csns. The "Evolution" one.

The Problem: Magic square uses 3x3 square to 1. have each square have one number (1-9)  and 2. row, columns, and diagonals add up to the same number.

The approach

Gene: inside one square can only be 1-9

Individual: one square of the grid

Population: all 9 squares

Parents: the squares next to other squares

Mating pool: each parent combines to make a chain of numbers

Fitness: check whether the children add up to the same number or all  different

Mutation: switch rows or columns

Elitism: not sure if this applies here

This is my framework to tackle magic square with GA, not sure if this is correct but I've not been able to find out on my own. I will keep trying. coding it is a different beast but I would like to know if i'm right about GA before writing code for it.

rabbott
Posts: 1649
Posted 20:46 Nov 28, 2019 |

There is a fundamental misunderstanding. Here are the key problems. I've copied and highlighted your definitions and then replied in regular font.

Gene: inside one square can only be 1-9. That's correct. (I don't like the biological term "gene," but when it is used, that's how it's used.)

Individual: one square of the grid. That's not correct. An individual is a collection of "genes." That is, an individual is 9 squares, each of which contains a number 1..9.

Population: all 9 squares. That an individual, not a population. A population is a collection of Individuals. So an individual is a sequence of 9 squares; a population is a collection of such sequences.

Parents: the squares next to other squares. When two individuals combine to create a new (child) individual, each individual is a "parent." So the term parent refers to a role an individual plays when generating the next generation.

Mating pool: each parent combines to make a chain of numbers. Mating pool and population are synonyms. The population is the pool from which individuals are selected. The selected individuals act as parents to generate new individuals to be included in the next generation. 

Let me know if you need additional explanations.