當前位置: 首頁>>代碼示例>>Python>>正文


Python Algorithm.printFittest方法代碼示例

本文整理匯總了Python中algorithm.Algorithm.printFittest方法的典型用法代碼示例。如果您正苦於以下問題:Python Algorithm.printFittest方法的具體用法?Python Algorithm.printFittest怎麽用?Python Algorithm.printFittest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在algorithm.Algorithm的用法示例。


在下文中一共展示了Algorithm.printFittest方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from algorithm import Algorithm [as 別名]
# 或者: from algorithm.Algorithm import printFittest [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()
開發者ID:brianhang,項目名稱:tritonscheduler,代碼行數:58,代碼來源:main.py


注:本文中的algorithm.Algorithm.printFittest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。