0

stackoverflow の新機能であり、Python の新機能です。与えられたすべての助けに感謝します! クラスのコンストラクターを呼び出して、入力されたリストを渡そうとしています。ただし、オブジェクトが作成されるとき、リストは空です。デバッガーは、リストが入力されていることを示します

    manager = PathManager()

    # create cities
    city1  = City(60, 200)
    manager.addCity(city1)

    city2  = City(180, 200)
    manager.addCity(city2)

    city3  = City(80, 180)
    manager.addCity(city3)

    city4  = City(140, 180)
    manager.addCity(city4)

    city5  = City(20, 160)
    manager.addCity(city5)

    city6  = City(100, 160)
    manager.addCity(city6)

    city7  = City(200, 160)
    manager.addCity(city7)

    city8  = City(140, 140)
    manager.addCity(city8)

    city9  = City(40, 120)
    manager.addCity(city9)

    city10 = City(100, 120)
    manager.addCity(city10)

    pop = Population(manager, True)
    # debugger shows pop is a list containing expected elements

    # call the classmethod      
    pop = Genetics.evolvePop(pop, manager)

そして、ここに遺伝学クラスの最初の部分があります:

class Genetics:

# default values
global elitism, tournSize, mutRate
mutRate = 0.015
tournSize = 5
elitism = True

# evolve the population one generation
@classmethod
#@fixme -- pop is empty... why?
def evolvePop(cls, pop, manager):
    newPop = Population(manager, False)

    # testing
    #cls.tournamentSelection(pop, manager).displayCities())

    elitismOffset = 0
    if elitism:
        newPop.paths.insert(0, pop.getFittestPath())
        # remove old end
        if len(newPop.paths) > 10:
            newPop.paths.pop()
        elitismOffset = 1

    # crossover the population
    for index in range(elitismOffset, 10):
        #newPath = cls.crossover(cls.tournamentSelection(pop, manager), cls.tournamentSelection(pop, manager), manager)
        pathOne = cls.tournamentSelection(pop, manager); print('path one')
        pathOne.displayCities()
        pathTwo = cls.tournamentSelection(pop, manager); print('path two')
        pathTwo.displayCities()
        newPath = cls.crossover(pathOne, pathTwo, manager)
        newPop.storePath(index, newPath)
    # mutate the population for randomness
    #print(len(newPop))
    #for index in range(elitismOffset, len(newPop)):
        #cls.mutate(newPop.paths[index])

    return newPop
    ...

何か案は?

4

0 に答える 0