(self, obj_function, steady, cost, model)
| 23 | self.gbest_fitness = 0 |
| 24 | |
| 25 | def evaluate(self, obj_function, steady, cost, model): |
| 26 | fitness = obj_function(self.position, steady, cost, model) |
| 27 | # Check the personal best |
| 28 | if fitness > self.pbest_fitness: |
| 29 | self.pbest_fitness = fitness |
| 30 | self.pbest_position = self.position |
| 31 | # Check the global best |
| 32 | if fitness > self.gbest_fitness: |
| 33 | self.gbest_fitness = fitness |
| 34 | self.gbest_position = self.position |
| 35 | |
| 36 | def update_velocity(self, w, c1, c2): |
| 37 | r1 = random() |