Minor import changes

This commit is contained in:
SimpleArt
2020-12-30 14:36:50 -05:00
parent 54a774abd2
commit 7dc9c17e74
2 changed files with 12 additions and 12 deletions

View File

@ -26,7 +26,7 @@ from structure import Population as make_population
from structure import Chromosome as make_chromosome from structure import Chromosome as make_chromosome
from structure import Gene as make_gene from structure import Gene as make_gene
# Structure Methods # Misc. Methods
from fitness_function import Fitness_Examples from fitness_function import Fitness_Examples
from termination_point import Termination_Methods from termination_point import Termination_Methods
@ -35,8 +35,8 @@ from parent_selection import Parent_Selection
from survivor_selection import Survivor_Selection from survivor_selection import Survivor_Selection
# Genetic Operator Methods # Genetic Operator Methods
from mutation import Mutation_Methods
from crossover import Crossover_Methods from crossover import Crossover_Methods
from mutation import Mutation_Methods
# Default Attributes for the GA # Default Attributes for the GA
from attributes import Attributes from attributes import Attributes

View File

@ -1,8 +1,8 @@
# Import signature tool to check if functions start with self or ga # Import signature tool to check if functions start with self or ga
from inspect import signature from inspect import signature
# Import square root function for ga.adapt() and ga.dist() # Import math for square root (ga.dist()) and ceil (crossover methods)
from math import sqrt import math
import random import random
import sqlite3 import sqlite3
@ -13,7 +13,7 @@ from structure import Population as make_population
from structure import Chromosome as make_chromosome from structure import Chromosome as make_chromosome
from structure import Gene as make_gene from structure import Gene as make_gene
# Structure Methods # Misc. Methods
from fitness_function import Fitness_Examples from fitness_function import Fitness_Examples
from termination_point import Termination_Methods from termination_point import Termination_Methods
@ -22,8 +22,8 @@ from parent_selection import Parent_Selection
from survivor_selection import Survivor_Selection from survivor_selection import Survivor_Selection
# Genetic Operator Methods # Genetic Operator Methods
from mutation import Mutation_Methods
from crossover import Crossover_Methods from crossover import Crossover_Methods
from mutation import Mutation_Methods
# Database class # Database class
from database import sql_database from database import sql_database
@ -217,7 +217,7 @@ class Attributes:
def dist(self, chromosome_1, chromosome_2): def dist(self, chromosome_1, chromosome_2):
"""Default distance lambda. Returns the square root of the difference in fitnesses.""" """Default distance lambda. Returns the square root of the difference in fitnesses."""
return sqrt(abs(chromosome_1.fitness - chromosome_2.fitness)) return math.sqrt(abs(chromosome_1.fitness - chromosome_2.fitness))
def gene_impl(self, *args, **kwargs): def gene_impl(self, *args, **kwargs):
@ -299,7 +299,7 @@ class Attributes:
# Euclidean norm # Euclidean norm
self.dist = lambda self, chromosome_1, chromosome_2:\ self.dist = lambda self, chromosome_1, chromosome_2:\
sqrt(sum( math.sqrt(sum(
(gene_1.value - gene_2.value) ** 2 (gene_1.value - gene_2.value) ** 2
for gene_1, gene_2 for gene_1, gene_2
in zip(chromosome_1, chromosome_2) in zip(chromosome_1, chromosome_2)