new to stackoverflow and new to Python. I appreciate all help given! I'm trying to call the constructor for a class and hand it a populated list. However, when the object is created the list is empty. The debugger shows the list is populated
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)
And here is the first bit of the Genetics class:
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
...
any ideas?