r"""This is the :math:`(\mu~,~\lambda)` evolutionary algorithm. :param population: A list of individuals. :param toolbox: A :class:`~deap.base.Toolbox` that contains the evolution operators. :param mu: The number of individuals to select for the next generation.
(population, toolbox, mu, lambda_, cxpb, mutpb, ngen,
stats=None, halloffame=None, verbose=__debug__)
| 338 | |
| 339 | |
| 340 | def eaMuCommaLambda(population, toolbox, mu, lambda_, cxpb, mutpb, ngen, |
| 341 | stats=None, halloffame=None, verbose=__debug__): |
| 342 | r"""This is the :math:`(\mu~,~\lambda)` evolutionary algorithm. |
| 343 | |
| 344 | :param population: A list of individuals. |
| 345 | :param toolbox: A :class:`~deap.base.Toolbox` that contains the evolution |
| 346 | operators. |
| 347 | :param mu: The number of individuals to select for the next generation. |
| 348 | :param lambda\_: The number of children to produce at each generation. |
| 349 | :param cxpb: The probability that an offspring is produced by crossover. |
| 350 | :param mutpb: The probability that an offspring is produced by mutation. |
| 351 | :param ngen: The number of generation. |
| 352 | :param stats: A :class:`~deap.tools.Statistics` object that is updated |
| 353 | inplace, optional. |
| 354 | :param halloffame: A :class:`~deap.tools.HallOfFame` object that will |
| 355 | contain the best individuals, optional. |
| 356 | :param verbose: Whether or not to log the statistics. |
| 357 | :returns: The final population |
| 358 | :returns: A class:`~deap.tools.Logbook` with the statistics of the |
| 359 | evolution |
| 360 | |
| 361 | The algorithm takes in a population and evolves it in place using the |
| 362 | :func:`varOr` function. It returns the optimized population and a |
| 363 | :class:`~deap.tools.Logbook` with the statistics of the evolution. The |
| 364 | logbook will contain the generation number, the number of evaluations for |
| 365 | each generation and the statistics if a :class:`~deap.tools.Statistics` is |
| 366 | given as argument. The *cxpb* and *mutpb* arguments are passed to the |
| 367 | :func:`varOr` function. The pseudocode goes as follow :: |
| 368 | |
| 369 | evaluate(population) |
| 370 | for g in range(ngen): |
| 371 | offspring = varOr(population, toolbox, lambda_, cxpb, mutpb) |
| 372 | evaluate(offspring) |
| 373 | population = select(offspring, mu) |
| 374 | |
| 375 | First, the individuals having an invalid fitness are evaluated. Second, |
| 376 | the evolutionary loop begins by producing *lambda_* offspring from the |
| 377 | population, the offspring are generated by the :func:`varOr` function. The |
| 378 | offspring are then evaluated and the next generation population is |
| 379 | selected from **only** the offspring. Finally, when |
| 380 | *ngen* generations are done, the algorithm returns a tuple with the final |
| 381 | population and a :class:`~deap.tools.Logbook` of the evolution. |
| 382 | |
| 383 | .. note:: |
| 384 | |
| 385 | Care must be taken when the lambda:mu ratio is 1 to 1 as a |
| 386 | non-stochastic selection will result in no selection at all as the |
| 387 | operator selects *lambda* individuals from a pool of *mu*. |
| 388 | |
| 389 | |
| 390 | This function expects :meth:`toolbox.mate`, :meth:`toolbox.mutate`, |
| 391 | :meth:`toolbox.select` and :meth:`toolbox.evaluate` aliases to be |
| 392 | registered in the toolbox. This algorithm uses the :func:`varOr` |
| 393 | variation. |
| 394 | """ |
| 395 | assert lambda_ >= mu, "lambda must be greater or equal to mu." |
| 396 | |
| 397 | # Evaluate the individuals with an invalid fitness |