Data Table - danielwilczak101/EasyGA GitHub Wiki
Here you can see how the data table is structured and used when saving your genetic algorithm
Structure:
The data table is made up over 5 columns that store all the running data of the genetic algorithm
id
config_id
generation
fitness
chromosome
- id : Auto incremented key that is used to identify that specific row.
- config_id : The config id that was to setup that specific genetic algorithm.
- generation : The generation that the chromosome was ran on.
- fitness : The fitness of the chromosome.
- chromosome : The chromosome stored as a string. Ex : '1,1,1'.
How to change structure:
If you want to add or modify from the data table structure then you can just access it as one of the attributes.
Default Attribute
ga.sql_create_data_structure = """CREATE TABLE IF NOT EXISTS data (
id INTEGER PRIMARY KEY,
config_id INTEGER DEFAULT NULL,
generation INTEGER NOT NULL,
fitness REAL,
chromosome TEXT
); """
Examples of use:
Here are some examples of getting this data from the data table inside of the database.
Getting the first generation data
import EasyGA
# Create the genetic algorithm
ga = EasyGA.GA()
# Evolve the genetic algorithm
ga.evolve()
# Returns all the rows from generation 0
print(ga.database.query_all("""SELECT * FROM data WHERE generation = 0;"""))
Output
Here you can see the id, config_id, generation, fitness and chromosome.
[(1, 1, 0, 3.0, '5, 9, 8, 8, 8, 5, 5, 7, 4, 8'),
(2, 1, 0, 2.0, '5, 4, 10, 2, 3, 7, 1, 5, 6, 3'),
(3, 1, 0, 2.0, '4, 5, 8, 3, 6, 1, 3, 8, 5, 3'),
(4, 1, 0, 1.0, '5, 4, 2, 4, 10, 2, 7, 10, 1, 7'),
(5, 1, 0, 1.0, '5, 4, 4, 3, 10, 4, 10, 8, 2, 10'),
(6, 1, 0, 1.0, '5, 10, 4, 9, 9, 10, 10, 2, 1, 3'),
(7, 1, 0, 1.0, '3, 4, 9, 5, 6, 2, 3, 9, 1, 4'),
(8, 1, 0, 0.0, '8, 4, 8, 1, 3, 6, 6, 4, 8, 9'),
(9, 1, 0, 0.0, '3, 7, 1, 1, 7, 9, 9, 4, 8, 4'),
(10, 1, 0, 0.0, '7, 4, 2, 6, 1, 4, 8, 10, 1, 4')]