pyleecan.Classes.OptiGenAlgNsga2Deap module

Method code available at https://github.com/Eomys/pyleecan/tree/master/pyleecan/Methods/Optimization/OptiGenAlgNsga2Deap

class OptiGenAlgNsga2Deap(toolbox=None, selector=None, crossover=None, mutator=None, p_cross=0.9, p_mutate=0.1, size_pop=40, nb_gen=100, problem=- 1, xoutput=- 1, logger_name='Pyleecan.OptiSolver', is_keep_all_output=False, init_dict=None, init_str=None)[source]

Bases: OptiGenAlg

Multi-objectives optimization problem with some constraints

VERSION = 1
solve(xoutput=None)

Method to perform NSGA-II using DEAP tools

Parameters:

self (OptiGenAlgNsga2Deap) – Solver to perform NSGA-II

Returns:

  • multi_output (OutputMultiOpti) – class containing the results

  • xoutput (XOutput) – class containing the results of the simulations

mutate(indiv)
Mutate the individual design variables with different strategies according to the variables types :
  • interval : Polynomial Bounded mutation or user defined

  • set : Resampling the variable according to its initialization function

  • pyleecan : Resampling the variable according to its initialization function

Parameters:
  • solver (Solver) – solver to perform the genetic algorithm with DEAP

  • indiv (individual (e.g. OptiGenAlgIndivDeap)) – individual to mutate

Returns:

is_mutation – True if at least one mutation occured

Return type:

boolean

cross(indiv1, indiv2)

Perform the crossover (One crossover by default)

Parameters:
  • self (OptiGenNsga2Deap) – Optimization solver

  • indiv1 (individual) – first individual to modify

  • indiv2 (individual) – second individual to modify

Returns:

is_cross – True if the crossover append

Return type:

bool

create_toolbox()

OptiGenAlgNsga2Deap method to create DEAP toolbox :param self: :type self: OptiGenAlgNsga2Deap

Returns:

self – OptiGenAlgNsga2Deap with toolbox created

Return type:

OptiGenAlgNsga2Deap

check_optimization_input()

Check optimization parameters before solving the problem

Parameters:

solver (Solver) – solver to perform the genetic algorithm with DEAP

delete_toolbox()

OptiGenAlgNsga2Deap method to delete DEAP toolbox :param self: :type self: OptiGenAlgNsga2Deap

plot_pareto(x_symbol, y_symbol, c_symbol=None, cmap=None, ax=None, title=None, grid=False, is_show_fig=True, save_path=None)

Plot the pareto front for 2 objective functions

Parameters:
  • self (OptiGenAlgNsga2Deap) –

  • x_symbol (str) – symbol of the first objective function

  • y_symbol (str) – symbol of the second objective function

  • c_symbol (str) – optional symbol to set the plot colors

  • cmap (colormap) – optional colormap

  • is_show_fig (bool) – True to show figure after plot

  • save_path (str) – full path of the png file where the figure is saved if save_path is not None

save(save_path='', is_folder=False, type_handle_old=2, type_compression=0)

Save the object to the save_path

Parameters:
  • self – A pyleecan object

  • save_path (str) – path to the folder to save the object

  • is_folder (bool) – to split the object in different files: separate simulation machine and materials (json only)

  • type_handle_old (int) – How to handle old file in folder mode (0:Nothing, 1:Delete, 2:Move to “Backup” folder)

  • type_compression (int) – Available only for json, 0: no compression, 1: gzip

get_logger()

Get the object logger or its parent’s one

Parameters:

obj – A pyleecan object

Returns:

logger – Pyleecan object dedicated logger

Return type:

logging.Logger

compare(other, name='self', ignore_list=None, is_add_value=False)[source]

Compare two objects and return list of differences

as_dict(type_handle_ndarray=0, keep_function=False, **kwargs)[source]

Convert this object in a json serializable dict (can be use in __init__). type_handle_ndarray: int

How to handle ndarray (0: tolist, 1: copy, 2: nothing)

keep_functionbool

True to keep the function object, else return str

Optional keyword input parameter is for internal use only and may prevent json serializability.

copy()[source]

Creates a deepcopy of the object

property toolbox

DEAP toolbox

Type:

deap.base.Toolbox