mutation_05_de_movement


This function mutates a solution using a differential evolution mutation (best/1).

x_i_new, of_i_new,\
    fit_i_new, neof = mutation_05_de_movement(obj_function, x_r0_old,
                                                x_r1_old, x_best,
                                                x_lower, x_upper,
                                                n_dimensions, f,
                                                none_variable=None)

Input variables

Name Description Type
obj_function Objective function. The Metapy user defined this function Py function (def)
x_r0_old Current design variables of the random \(r_0\) agent List
x_r1_old Current design variables of the random \(r_1\) agent List
x_best Best design variables from the population List
x_lower Lower limit of the design variables List
x_upper Upper limit of the design variables List
n_dimensions Problem dimension Integer
f Scaling factor Float
none_variable None variable. Default is None. User can use this variable in objective function None, list, float, dictionary, str or any

Output variables

Name Description Type
x_i_new Update variables of the \(i\) agent List
of_i_new Update objective function value of the \(i\) agent Float
fit_i_new Update fitness value of the \(i\) agent Float
neof Number of evaluations of the objective function Integer
report Report about the mutation process String

Example 1

# Import
from metapy_toolbox import mutation_05_de_movement # or import *

# Data

xR0 = [1.9, 2.1]
xR1 = [2.8, 4.4]
xBest = [1.5, 1.5]
xL = [1.0, 1.0]
xU = [5.0, 5.0]
d = len(xL)
f = 1.2

# Objective function

def objFunction(x, _):
    """Example objective function"""
    x0 = x[0]
    x1 = x[1]
    of = x0 ** 2 + x1 ** 2
    return of

# Call function

xNew, ofNew, fitNew, neof, report = mutation_05_de_movement(objFunction, xR0, xR1, xBest, xL, xU, d, f)

# Output details

print('x New: ', xNew)
print('of New: ', ofNew)
print('fit New: ', fitNew)
print('number of evalutions objective function: ', neof)
x New:  [1.0, 1.0]
of New:  2.0
fit New:  0.3333333333333333
number of evalutions objective function:  1

To check the movement report just apply the following instruction.

# Report details
arq = "report_example.txt"

# Writing report
with open(arq, "w") as file:
    file.write(report)

Open report_example.txt.

    current xr0 = [1.9, 2.1]
    current xr1 = [2.8, 4.4]
    current x_best = [1.5, 1.5]
    Dimension 0: rij = -0.8999999999999999, neighbor = 0.42000000000000015
    Dimension 1: rij = -2.3000000000000003, neighbor = -1.2600000000000002
    update x = [1.0, 1.0], of = 2.0, fit = 0.3333333333333333