mutation_04_de_movement
This function mutates a solution using a differential evolution mutation (rand/2).
x_i_new, of_i_new,\
fit_i_new, neof = mutation_04_de_movement(obj_function, x_r0_old,
x_r1_old, x_r2_old,
x_r3_old, x_r4_old,
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_r4_old | Current design variables of the random \(r_4\) agent | 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_04_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]
xR4 = [2.6, 3.7]
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_04_de_movement(objFunction, xR0, xR1, xR2, xR3, xR4, 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: [2.96, 5.0]
of New: 33.7616
fit New: 0.028767375494798856
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 xr4 = [2.6, 3.7]
Dimension 0: rij_1 = 0.3999999999999999, rij_2 = 0.3999999999999999, neighbor = 2.96
Dimension 1: rij_1 = 2.2, rij_2 = 0.2999999999999998, neighbor = 6.0
update x = [2.96, 5.0], of = 33.7616, fit = 0.028767375494798856