本文整理汇总了Python中algorithm.Algorithm.evolve方法的典型用法代码示例。如果您正苦于以下问题:Python Algorithm.evolve方法的具体用法?Python Algorithm.evolve怎么用?Python Algorithm.evolve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类algorithm.Algorithm
的用法示例。
在下文中一共展示了Algorithm.evolve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import evolve [as 别名]
def main():
"""
The main function of the program that turns user input into a schedule and
uses a genetic algorithm to find an optimal schedule.
"""
# Container for user input.
info = {}
# Get the desired term and courses.
if DEBUG:
info["term"] = "FA16"
info["courses"] = ["CSE 12", "CSE 15L", "DOC 1"]
elif handleInput(info):
return
print("Finding schedule data...")
# Get the schedule data for the given courses and term.
schedule = Schedule()
schedule.term = info["term"]
schedule.courses = info["courses"]
try:
scheduleData = schedule.retrieve()
except ClassParserError:
print("The Schedule of Classes data could not be loaded at this " \
"or you have provided an invalid class.")
return
# Make sure all of the desired classes were found.
for course in info["courses"]:
if course not in scheduleData:
print("'" + course + "' was not found in the Schedule of Classes!")
return
# Initiate the population.
algorithm = Algorithm(scheduleData)
algorithm.initiate(CAPACITY, CROSSOVER, MUTATE, ELITISM)
# Run the algorithm through the desired number of generations.
generation = 0
highest = 0
while generation < GENERATIONS:
algorithm.evolve()
generation += 1
print("Generating... "
+ str(int((generation / GENERATIONS) * 100)) + "%", end="\r")
print("\nDone!")
algorithm.printFittest()
示例2: execfile
# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import evolve [as 别名]
execfile("problems/"+problemName.lower()+".py")
# TODO optimizar esto para carga dinamica
if problemName == 'Griewank':
problem = Griewank(problemSize)
if problemName == 'Rastrigin':
problem = Rastrigin(problemSize)
if problemName == 'TSP':
problem = TSP(dataset,optimun)
logger = Logger(logger_level)
genome = ArrayGenome(problem.size, problem.lower, problem.upper)
techniqueSet = []
# Technique's definition
if 'RealUCUM' in techs:
techniqueSet.append(techniques.Genetic('RealUCUM','RealEncoding',genome,problem.initialize,problem.objective,logger,crossovers.uniform,mutators.uniform,0.9,0.01))
if 'RealBCUM' in techs:
techniqueSet.append(techniques.Genetic('RealBCUM','RealEncoding',genome,problem.initialize,problem.objective,logger,crossovers.blend,mutators.uniform,0.9,0.01))
if 'RealUCGM' in techs:
techniqueSet.append(techniques.Genetic('RealUCGM','RealEncoding',genome,problem.initialize,problem.objective,logger,crossovers.uniform,mutators.gaussian,0.9,0.01))
if 'RealBCGM' in techs:
techniqueSet.append(techniques.Genetic('RealBCGM','RealEncoding',genome,problem.initialize,problem.objective,logger,crossovers.blend,mutators.gaussian,0.9,0.01))
# Build algorithm and evolve
algorithm = Algorithm(Terminator(fitnessEvals), selectors.uniform, problem, populationSize, techniqueSet, logger)
algorithm.evolve()
logger.printResult(algorithm, problem)