Added small database functionality but its commented out of running.
This commit is contained in:
@ -19,6 +19,10 @@ from crossover import Crossover_Methods
|
||||
# Default Attributes for the GA
|
||||
from attributes import Attributes
|
||||
|
||||
# Database class
|
||||
from database import database
|
||||
from sqlite3 import Error
|
||||
|
||||
|
||||
class GA(Attributes):
|
||||
"""GA is the main class in EasyGA. Everything is run through the ga
|
||||
@ -40,8 +44,14 @@ class GA(Attributes):
|
||||
and (not consider_termination # and if consider_termination flag is set
|
||||
or self.active())): # then also check if termination conditions reached
|
||||
|
||||
# If its the first generation then initialize the population
|
||||
# If its the first generation
|
||||
if self.current_generation == 0:
|
||||
|
||||
# Create the database and tables
|
||||
# self.database = database.database()
|
||||
# self.database.create_data_table(self)
|
||||
|
||||
# Create the initial population
|
||||
self.initialize_population()
|
||||
self.set_all_fitness()
|
||||
self.population.sort_by_best_fitness(self)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import random
|
||||
import sqlite3
|
||||
|
||||
# Import all the data structure prebuilt modules
|
||||
from structure import Population as create_population
|
||||
@ -18,6 +19,10 @@ from survivor_selection import Survivor_Selection
|
||||
from mutation import Mutation_Methods
|
||||
from crossover import Crossover_Methods
|
||||
|
||||
# Database class
|
||||
from database import database
|
||||
from sqlite3 import Error
|
||||
|
||||
class Attributes:
|
||||
"""Default GA attributes can be found here. If any attributes have not
|
||||
been set then they will fall back onto the default attribute. All
|
||||
@ -55,7 +60,15 @@ class Attributes:
|
||||
'mutation_individual_impl' : Mutation_Methods.Individual.single_gene,
|
||||
'mutation_population_impl' : Mutation_Methods.Population.random_selection,
|
||||
'termination_impl' : Termination_Methods.fitness_and_generation_based,
|
||||
'database_name' : 'database.db'
|
||||
'database' : None,
|
||||
'database_name' : r"database.db",
|
||||
'sql_create_data_structure' : """ CREATE TABLE IF NOT EXISTS data (
|
||||
id integer PRIMARY KEY,
|
||||
generation integer NOT NULL,
|
||||
fitness DOUBLE,
|
||||
chromosome text
|
||||
); """
|
||||
|
||||
}
|
||||
|
||||
# Filling in the default settings
|
||||
@ -108,6 +121,12 @@ class Attributes:
|
||||
# Database varibles
|
||||
self.database_name = attributes['database_name']
|
||||
|
||||
# Database varibles
|
||||
self.database = attributes['database']
|
||||
self.database_name = attributes['database_name']
|
||||
self.sql_create_data_structure = attributes['sql_create_data_structure']
|
||||
|
||||
|
||||
# Getter and setters for all required varibles
|
||||
@property
|
||||
def chromosome_length(self):
|
||||
|
||||
Reference in New Issue
Block a user