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
# -----------------------------------------------------------------
评论列表
文章目录