mutation_06_de_movement


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

x_i_new, of_i_new,\
    fit_i_new, neof = mutation_06_de_movement(obj_function, x_r0_old,
                                                x_r1_old, x_r2_old,
                                                x_r3_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_r2_old Current design variables of the random \(r_2\) agent List
x_r3_old Current design variables of the random \(r_3\) 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_06_de_movement # or import *

# Data
xR0 = [2.0, 3.0]
xR1 = [4.0, 5.0]
xR2 = [3.6, 2.8]
xR3 = [3.0, 4.0]
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_06_de_movement(objFunction, xR0, xR1, xR2, xR3, 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 = [2.0, 3.0]
    current xr1 = [4.0, 5.0]
    current xr2 = [3.6, 2.8]
    current xr3 = [3.0, 4.0]
    current x_best = [1.5, 1.5]
    Dimension 0: rij_1 = -2.0, rij_2 = 0.6000000000000001, neighbor = -0.17999999999999983
    Dimension 1: rij_1 = -2.0, rij_2 = -1.2000000000000002, neighbor = -2.34
    update x = [1.0, 1.0], of = 2.0, fit = 0.3333333333333333