示例#1
0
 def init_population(self):
     for _ in range(self.population_number):
         size = self.cloudlet_num
         p = DParticle(size)
         p.solution = np.random.randint(0,
                                        self.machine_number,
                                        size=self.cloudlet_num)
         p.velocity = -5 + 10 * np.random.rand(self.cloudlet_num)
         p.fitness = calculate_fitness(p.solution, self.cloudlets, self.vms)
         self.particles.append(p)
示例#2
0
 def getSeries(self, v0):
     tempSet = [[0] * self.cloudlet_num] * 30
     tempSet[0] = [x / self.machine_number for x in v0]
     for i in range(1, 30):
         tempSet[i] = [x for x in logistic_function(tempSet[i - 1], 3.5)]
     for i in range(30):
         tempSet[i] = [int(self.machine_number * x) for x in tempSet[i]]
     # print(tempSet)
     tempFit = []
     for i in range(30):
         tempFit.append(
             calculate_fitness(tempSet[i], self.cloudlets, self.vms))
     best_score = 0
     best_solution = None
     for i in range(self.chaosNum):
         if tempFit[i] > best_score:
             best_score = tempFit[i]
             best_solution = tempSet[i]
     res = DParticle(self.cloudlet_num)
     res.velocity = self.gbest.velocity
     res.solution = best_solution
     res.fitness = best_score
     return res