def __init__(self, genome, interactiveMode=True): """ Initializator of GSimpleGA """ #if seed is not None: random.seed(seed) # used to be like this if type(interactiveMode) != BooleanType: utils.raiseException( "Interactive Mode option must be True or False", TypeError) if not isinstance(genome, GenomeBase): utils.raiseException("The genome must be a GenomeBase subclass", TypeError) self.internalPop = GPopulation(genome) self.nGenerations = constants.CDefGAGenerations self.pMutation = constants.CDefGAMutationRate self.pCrossover = constants.CDefGACrossoverRate self.nElitismReplacement = constants.CDefGAElitismReplacement self.setPopulationSize(constants.CDefGAPopulationSize) self.minimax = constants.minimaxType["maximize"] self.elitism = True # NEW self.new_population = None # Adapters self.dbAdapter = None self.migrationAdapter = None self.time_init = None self.max_time = None self.interactiveMode = interactiveMode self.interactiveGen = -1 self.GPMode = False self.selector = FunctionSlot("Selector") self.stepCallback = FunctionSlot("Generation Step Callback") self.terminationCriteria = FunctionSlot("Termination Criteria") self.selector.set(constants.CDefGASelector) self.allSlots = (self.selector, self.stepCallback, self.terminationCriteria) self.internalParams = {} self.currentGeneration = 0 # GP Testing for classes in constants.CDefGPGenomes: if isinstance(self.internalPop.oneSelfGenome, classes): self.setGPMode(True) break log.debug("A GA Engine was created, nGenerations=%d", self.nGenerations) # New self.path = None
def __init__(self): """ Genome Constructor """ self.evaluator = FunctionSlot("Evaluator") self.initializator = FunctionSlot("Initializator") self.mutator = FunctionSlot("Mutator") self.crossover = FunctionSlot("Crossover") self.internalParams = {} self.score = 0.0 self.fitness = 0.0
def __init__(self): """ The constructor ... """ self.selector = FunctionSlot("Selector") self.GAEngine = None self.nMigrationRate = constants.CDefGenMigrationRate self.nIndividuals = constants.CDefMigrationNIndividuals self.nReplacement = constants.CDefGenMigrationReplacement self.networkCompression = 9
def __init__(self, genome): """ The GPopulation Class creator """ if isinstance(genome, GPopulation): self.oneSelfGenome = genome.oneSelfGenome self.internalPop = [] self.internalPopRaw = [] self.popSize = genome.popSize self.sortType = genome.sortType self.sorted = False self.minimax = genome.minimax self.scaleMethod = genome.scaleMethod self.allSlots = [self.scaleMethod] self.internalParams = genome.internalParams self.multiProcessing = genome.multiProcessing self.statted = False self.stats = Statistics() return log.debug("New population instance, %s class genomes.", genome.__class__.__name__) self.oneSelfGenome = genome self.internalPop = [] self.internalPopRaw = [] self.popSize = 0 self.sortType = constants.CDefPopSortType self.sorted = False self.minimax = constants.CDefPopMinimax self.scaleMethod = FunctionSlot("Scale Method") self.scaleMethod.set(constants.CDefPopScale) self.allSlots = [self.scaleMethod] self.internalParams = {} self.multiProcessing = (False, False, None) # Statistics self.statted = False self.stats = Statistics()