Пример #1
0
 def run1(self):
     timeStep = 1
     while timeStep <= self.timeSteps:
         self.paramsGA1["simulator"].clear()
         self.paramsGA1["timeSteps"] = timeStep
         ga1 = GA1(self.paramsGA1)
         bestIndividuals = ga1.run()
         newPopulation = self.addTimeStep(bestIndividuals)
         self.paramsGA1["populationGA1"] = newPopulation
         if timeStep <= self.timeSteps//2:
             timeStep *= 2
         elif timeStep < self.timeSteps and timeStep > self.timeSteps//2:
             timeStep = self.timeSteps
         elif timeStep == self.timeSteps:
             break
     bestIndividual = newPopulation[0][0:self.params["crossroads"]]
     self.params["simulator"].clear()
     self.params["simulator"].setState(bestIndividual)
     fitness = 0
     for timeStep in range(self.params["timeSteps"]):
         population = []
         for individual in newPopulation:
             population.append(
                 individual[timeStep*self.params["crossroads"]:(timeStep+1)*self.params["crossroads"]])
         print("Timtestep: " + str(timeStep))
         self.paramsGA2["densities"] = None
         self.paramsGA2["population"] = population
         ga2 = GA2(self.paramsGA2)
         best, bestIndividual = ga2.run()
         fitness += best
         self.params["simulator"].setState(bestIndividual)
     print(fitness)
     self.params["simulator"].exit()
     return fitness
Пример #2
0
 def __init__(self, params):
     self.params = params
     self.timeSteps = params["timeSteps"]
     self.paramsListGA1 = ["crossover", "mutate", "select", "populationGA1", "numGeneration1",
                           "crossroads", "timeSteps", "numIndividuals1", "fitnessGA1", "simulator", "minLim", "maxLim"]
     self.paramsGA1 = dict((k, params[k])
                           for k in self.paramsListGA1 if k in params)
     self.ga1 = GA1(self.paramsGA1)
Пример #3
0
 def run(self, params):
     timeSteps = params["timeSteps"]
     paramsListGA1 = ["crossover", "mutate", "select", "numGeneration1", "crossroads", "timeSteps", "numIndividuals1", "fitnessGA1", "simulator", "minLim", "maxLim"]
     paramsGA1 = dict((k, params[k]) for k in paramsListGA1 if k in params)
     ga1 = GA1(paramsGA1)
     bestIndividual, score, improvement = ga1.run()
     params["simulator"].exit()
     return improvement
Пример #4
0
 def addTimeStep(self, bestIndividuals):
     ga1 = GA1(self.paramsGA1)
     prevTimeSteps = (len(bestIndividuals[0])//self.paramsGA1["crossroads"])
     if (prevTimeSteps) <= self.timeSteps//2:
         newTimeSteps = prevTimeSteps*2
         self.paramsGA1["timeSteps"] = newTimeSteps
         for individual in bestIndividuals:
             individual += individual
     else:
         newTimeSteps = self.timeSteps
         self.paramsGA1["timeSteps"] = newTimeSteps
         for individual in bestIndividuals:
             individual += individual[len(individual)-(
                 self.paramsGA1["crossroads"]*(newTimeSteps - prevTimeSteps)):len(individual)]
     ga1 = GA1(self.paramsGA1)
     newPopulation = ga1.makePopulation(bestIndividuals)
     del ga1
     return newPopulation
Пример #5
0
 def run2(self):
     self.paramsGA1["simulator"].clear()
     ga1 = GA1(self.paramsGA1)
     fitness, improvement, individual = ga1.run()
     individual = individual[0]
     positions = {}
     for i in range(self.timeSteps):
         positions[i] = self.paramsGA1["simulator"].getPositions(
             individual[i * self.params["crossroads"]:(i + 1) *
                        self.params["crossroads"]])
     self.params["simulator"].exit()
     return positions, individual, improvement
 def run1(self):
     timeStep = 1
     while timeStep <= self.timeSteps:
         self.paramsGA1["simulator"].clear()
         self.paramsGA1["timeSteps"] = timeStep
         ga1 = GA1(self.paramsGA1)
         bestIndividuals = ga1.run()
         newPopulation = self.addTimeStep(bestIndividuals)
         self.paramsGA1["populationGA1"] = newPopulation
         if timeStep <= self.timeSteps // 2:
             timeStep *= 2
         elif timeStep < self.timeSteps and timeStep > self.timeSteps // 2:
             timeStep = self.timeSteps
         elif timeStep == self.timeSteps:
             break
     self.params["simulator"].exit()
Пример #7
0
 def run1(self):
     timeStep = 0
     newPopulation = []
     while timeStep < self.timeSteps:
         self.paramsGA1["simulator"].clear()
         self.paramsGA1["timeSteps"] = timeStep
         ga1 = GA1(self.paramsGA1)
         bestIndividuals = ga1.run()
         newPopulation = self.addTimeStep(bestIndividuals)
         self.paramsGA1["populationGA1"] = newPopulation
         if timeStep <= (self.timeSteps - 1) // 2:
             timeStep *= 2
         elif timeStep < (self.timeSteps -
                          1) and timeStep > (self.timeSteps - 1) // 2:
             timeStep = (self.timeSteps - 1)
         elif timeStep == (self.timeSteps - 1):
             break
     bestIndividual = newPopulation[0]
     for i in range(self.timeSteps):
         self.positions[i] = self.paramsGA1["simulator"].getPositions(
             bestIndividual[i * self.params["crossroads"]:(i + 1) *
                            self.params["crossroads"]])
     self.params["simulator"].exit()
     return newPopulation