| 21 | |
| 22 | @default_random_state |
| 23 | def do(self, problem, pop, inplace=True, *args, random_state=None, **kwargs): |
| 24 | |
| 25 | # if not inplace copy the population first |
| 26 | if not inplace: |
| 27 | pop = deepcopy(pop) |
| 28 | |
| 29 | n_mut = len(pop) |
| 30 | |
| 31 | # get the variables to be mutated |
| 32 | X = pop.get("X") |
| 33 | |
| 34 | # retrieve the mutation variables |
| 35 | Xp = self._do(problem, X, *args, random_state=random_state, **kwargs) |
| 36 | |
| 37 | # the likelihood for a mutation on the individuals |
| 38 | prob = get(self.prob, size=n_mut) |
| 39 | mut = random_state.random(size=n_mut) <= prob |
| 40 | |
| 41 | # store the mutated individual back to the population |
| 42 | pop[mut].set("X", Xp[mut]) |
| 43 | |
| 44 | return pop |
| 45 | |
| 46 | def _do(self, problem, X, *args, random_state=None, **kwargs): |
| 47 | return X |