Skip to content
Snippets Groups Projects
Commit d8df0983 authored by Sepehr Madani's avatar Sepehr Madani
Browse files

Add a Butterfly-based implementation of genetic

parent 24f3ff78
No related branches found
No related tags found
No related merge requests found
from random import randrange, random, choice, sample
from cmath import exp, phase
from math import log10, pi, nan, cos, sin
from utils.pattern import compute_pattern, compute_single_pattern
from .genetic_algorithm import GeneticAlgorithm, Chromosome
from .butterfly_algorithm import ButterflyAlgorithm
class GeneticWithButterflyAlgorithm(GeneticAlgorithm):
""" Finds nulls by running a genetic algorithm on all possible
discrete values. Uses the Butterfly algorithm to create a base
chromosome, from which the entire population is created.
"""
def __init__(self, options):
super().__init__(options)
butterfly_alg = ButterflyAlgorithm(options)
weights, score = butterfly_alg.solve()
self.base_weights = [x for x in weights]
pass
def initialize_sample(self):
self.generations = 0
self.chromosomes.clear()
if self.overwrite_mutations:
self.chromosomes = [Chromosome(self.base_weights, shufflize=False)] + [
Chromosome(self.base_weights) for _ in range(self.sample_size - 1)
]
else:
self.chromosomes = [Chromosome(self.base_weights, shufflize=False)] + [
Chromosome(self.base_weights) for _ in range(self.sample_size * 2 - 2)
]
if self.buckets is not None:
self.initialize_buckets()
# TODO: Find what overloading I missed from Genetic. The min score for this alg cannot be worse than the base_weights
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment