本文整理匯總了Python中algorithm.Algorithm.initiate方法的典型用法代碼示例。如果您正苦於以下問題:Python Algorithm.initiate方法的具體用法?Python Algorithm.initiate怎麽用?Python Algorithm.initiate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類algorithm.Algorithm
的用法示例。
在下文中一共展示了Algorithm.initiate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from algorithm import Algorithm [as 別名]
# 或者: from algorithm.Algorithm import initiate [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()