# differential_evolution_driver.py#

Driver for a differential evolution genetic algorithm.

TODO: add better references than: https://en.wikipedia.org/wiki/Differential_evolution

Most of this driver (except execute_ga) is based on SimpleGA, so the following may still apply:

The following reference is only for the penalty function: Smith, A. E., Coit, D. W. (1995) Penalty functions. In: Handbook of Evolutionary Computation, 97(1).

The following reference is only for weighted sum multi-objective optimization: Sobieszczanski-Sobieski, J., Morris, A. J., van Tooren, M. J. L. (2015) Multidisciplinary Design Optimization Supported by Knowledge Based Engineering. John Wiley & Sons, Ltd.

classopenmdao.drivers.differential_evolution_driver.DifferentialEvolution(objfun,comm=None,model_mpi=None)[source]Bases:

`object`

Differential Evolution Genetic Algorithm.

TODO : add better references than: https://en.wikipedia.org/wiki/Differential_evolution

- Parameters:

objfunfunctionObjective callback function.

commMPI communicator or NoneThe MPI communicator that will be used objective evaluation for each generation.

model_mpiNone or tupleIf the model in objfun is also parallel, then this will contain a tuple with the the total number of population points to evaluate concurrently, and the color of the point to evaluate on this rank.

- Attributes:

commMPI communicator or NoneThe MPI communicator that will be used objective evaluation for each generation.

lchromintChromosome length.

model_mpiNone or tupleIf the model in objfun is also parallel, then this will contain a tuple with the the total number of population points to evaluate concurrently, and the color of the point to evaluate on this rank.

npopintPopulation size.

objfunfunctionObjective function callback.

- __init__(
objfun,comm=None,model_mpi=None)[source]Initialize genetic algorithm object.

- execute_ga(
x0,vlb,vub,pop_size,max_gen,random_state,F=0.5,Pc=0.5)[source]Perform the genetic algorithm.

- Parameters:

x0ndarrayInitial design values.

vlbndarrayLower bounds array.

vubndarrayUpper bounds array.

pop_sizeintNumber of points in the population.

max_genintNumber of generations to run the GA.

random_stateintSeed-number which controls the random draws.

FfloatDifferential rate.

PcfloatCrossover rate.

- Returns:

- ndarray
Best design point.

- float
Objective value at best design point.

- int
Number of successful function evaluations.

classopenmdao.drivers.differential_evolution_driver.DifferentialEvolutionDriver(**kwargs)[source]Bases:

`Driver`

Driver for a differential evolution genetic algorithm.

This algorithm requires that inputs are floating point numbers.

- Parameters:

**kwargsdict of keyword argumentsKeyword arguments that will be mapped into the Driver options.

- Attributes:

_problem_commMPI.Comm or NoneThe MPI communicator for the Problem.

_concurrent_pop_sizeintNumber of points to run concurrently when model is a parallel one.

_concurrent_colorintColor of current rank when running a parallel model.

_desvar_idxdictKeeps track of the indices for each desvar, since DifferentialEvolution sees an array of design variables.

_ga<DifferentialEvolution>Main genetic algorithm lies here.

_nfitintNumber of successful function evaluations.

_randomstateintSeed-number which controls the random draws.

- __init__(
**kwargs)[source]Initialize the DifferentialEvolutionDriver driver.

- add_recorder(
recorder)Add a recorder to the driver.

- Parameters:

recorderCaseRecorderA recorder instance.

- check_relevance()
Check if there are constraints that don’t depend on any design vars.

This usually indicates something is wrong with the problem formulation.

- cleanup()
Clean up resources prior to exit.

- declare_coloring(
num_full_jacs=3,tol=1e-25,orders=None,perturb_size=1e-09,min_improve_pct=5.0,show_summary=True,show_sparsity=False)Set options for total deriv coloring.

- Parameters:

num_full_jacsintNumber of times to repeat partial jacobian computation when computing sparsity.

tolfloatTolerance used to determine if an array entry is nonzero during sparsity determination.

ordersintNumber of orders above and below the tolerance to check during the tolerance sweep.

perturb_sizefloatSize of input/output perturbation during generation of sparsity.

min_improve_pctfloatIf coloring does not improve (decrease) the number of solves more than the given percentage, coloring will not be used.

show_summaryboolIf True, display summary information after generating coloring.

show_sparsityboolIf True, display sparsity with coloring info after generating coloring.

- get_constraint_values(
ctype='all',lintype='all',driver_scaling=True)Return constraint values.

- Parameters:

ctypestrDefault is ‘all’. Optionally return just the inequality constraints with ‘ineq’ or the equality constraints with ‘eq’.

lintypestrDefault is ‘all’. Optionally return just the linear constraints with ‘linear’ or the nonlinear constraints with ‘nonlinear’.

driver_scalingboolWhen True, return values that are scaled according to either the adder and scaler or the ref and ref0 values that were specified when add_design_var, add_objective, and add_constraint were called on the model. Default is True.

- Returns:

- dict
Dictionary containing values of each constraint.

- get_design_var_values(
get_remote=True,driver_scaling=True)Return the design variable values.

- Parameters:

get_remotebool or NoneIf True, retrieve the value even if it is on a remote process. Note that if the variable is remote on ANY process, this function must be called on EVERY process in the Problem’s MPI communicator. If False, only retrieve the value if it is on the current process, or only the part of the value that’s on the current process for a distributed variable.

driver_scalingboolWhen True, return values that are scaled according to either the adder and scaler or the ref and ref0 values that were specified when add_design_var, add_objective, and add_constraint were called on the model. Default is True.

- Returns:

- dict
Dictionary containing values of each design variable.

- get_driver_derivative_calls()[source]
Return number of derivative evaluations made during a driver run.

- Returns:

- int
Number of derivative evaluations made during a driver run.

- get_driver_objective_calls()[source]
Return number of objective evaluations made during a driver run.

- Returns:

- int
Number of objective evaluations made during a driver run.

- get_exit_status()
Return exit status of driver run.

- Returns:

- str
String indicating result of driver run.

- get_objective_values(
driver_scaling=True)Return objective values.

- Parameters:

driver_scalingboolWhen True, return values that are scaled according to either the adder and scaler or the ref and ref0 values that were specified when add_design_var, add_objective, and add_constraint were called on the model. Default is True.

- Returns:

- dict
Dictionary containing values of each objective.

- get_reports_dir()
Get the path to the directory where the report files should go.

If it doesn’t exist, it will be created.

- Returns:

- str
The path to the directory where reports should be written.

propertymsginfoReturn info to prepend to messages.

- Returns:

- str
Info to prepend to messages.

- objective_callback(
x,icase)[source]Evaluate problem objective at the requested point.

In case of multi-objective optimization, a simple weighted sum method is used:

\[f = (\sum_{k=1}^{N_f} w_k \cdot f_k)^a\]where \(N_f\) is the number of objectives and \(a>0\) is an exponential weight. Choosing \(a=1\) is equivalent to the conventional weighted sum method.

The weights given in the options are normalized, so:

\[\sum_{k=1}^{N_f} w_k = 1\]If one of the objectives \(f_k\) is not a scalar, its elements will have the same weights, and it will be normed with length of the vector.

Takes into account constraints with a penalty function.

All constraints are converted to the form of \(g_i(x) \leq 0\) for inequality constraints and \(h_i(x) = 0\) for equality constraints. The constraint vector for inequality constraints is the following:

\[ \begin{align}\begin{aligned}g = [g_1, g_2 \dots g_N], g_i \in R^{N_{g_i}}\\h = [h_1, h_2 \dots h_N], h_i \in R^{N_{h_i}}\end{aligned}\end{align} \]The number of all constraints:

\[N_g = \sum_{i=1}^N N_{g_i}, N_h = \sum_{i=1}^N N_{h_i}\]The fitness function is constructed with the penalty parameter \(p\) and the exponent \(\kappa\):

\[\Phi(x) = f(x) + p \cdot \sum_{k=1}^{N^g}(\delta_k \cdot g_k)^{\kappa} + p \cdot \sum_{k=1}^{N^h}|h_k|^{\kappa}\]where \(\delta_k = 0\) if \(g_k\) is satisfied, 1 otherwise

Note

The values of \(\kappa\) and \(p\) can be defined as driver options.

- Parameters:

xndarrayValue of design variables.

icaseintCase number, used for identification when run in parallel.

- Returns:

- float
Objective value.

- bool
Success flag, True if successful.

- int
Case number, used for identification when run in parallel.

- record_iteration()
Record an iteration of the current Driver.

- run()[source]
Execute the genetic algorithm.

- Returns:

- bool
Failure flag; True if failed to converge, False is successful.

- scaling_report(
outfile='driver_scaling_report.html',title=None,show_browser=True,jac=True)Generate a self-contained html file containing a detailed connection viewer.

Optionally pops up a web browser to view the file.

- Parameters:

outfilestr, optionalThe name of the output html file. Defaults to ‘driver_scaling_report.html’.

titlestr, optionalSets the title of the web page.

show_browserbool, optionalIf True, pop up a browser to view the generated html file. Defaults to True.

jacboolIf True, show jacobian information.

- Returns:

- dict
Data used to create html file.

- set_design_var(
name,value,set_remote=True)Set the value of a design variable.

‘name’ can be a promoted output name or an alias.

- Parameters:

namestrGlobal pathname of the design variable.

valuefloat or ndarrayValue for the design variable.

set_remoteboolIf True, set the global value of the variable (value must be of the global size). If False, set the local value of the variable (value must be of the local size).

- use_fixed_coloring(
coloring=<object object>)Tell the driver to use a precomputed coloring.

- Parameters:

coloringstrA coloring filename. If no arg is passed, filename will be determined automatically.