mutation_07_de_movement
This function mutates a solution using a differential evolution mutation (current-to-best/1).
x_i_new, of_i_new,\
fit_i_new, neof = mutation_07_de_movement(obj_function, x_r0_old,
x_r1_old, x_r2_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_i_old | Current design variables of the \(i\) agent | List |
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_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_07_de_movement # or import *
# Data
xI = [2.0, 2.0]
xR0 = [1.4, 2.6]
xR1 = [3.1, 4.7]
xR2 = [2.1, 4.9]
xBest = [1.2, 1.2]
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_07_de_movement(objFunction, xI, xR0, xR1, 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.8800000000000001, 1.1600000000000001]
of New: 4.880000000000001
fit New: 0.17006802721088432
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 xi = [2.0, 2.0]
current xr0 = [1.4, 2.6]
current xr1 = [3.1, 4.7]
current xr2 = [3.0, 4.0]
current x_best = [1.2, 1.2]
Dimension 0: rij_1 = -0.19999999999999996, rij_2 = 0.10000000000000009, neighbor = 1.8800000000000001
Dimension 1: rij_1 = -1.4000000000000001, rij_2 = 0.7000000000000002, neighbor = 1.1600000000000001
update x = [1.8800000000000001, 1.1600000000000001], of = 4.880000000000001, fit = 0.17006802721088432