mutation_03_de_movement
This function mutates a solution using a differential evolution mutation (rand/1).
x_i_new, of_i_new,\
fit_i_new, neof = mutation_03_de_movement(obj_function,
x_r0_old, x_r1_old,
x_r2_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_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
Use the mutation_03_de_movement
function to generate a new solution from three existing solutions. Use the range \(\mathbf{x}_L = [1.0, 1.0]\) and \(\mathbf{x}_L = [5.0, 5.0]\). Consider current solutions \(\mathbf{x}_{r0} = [2.0, 3.0]\), \(\mathbf{x}_{r1} = [4.0, 5.0]\) and \(\mathbf{x}_{r2} = [3.6, 2.8]\). Use a scale factor equals 2.0.
# Import
from metapy_toolbox import mutation_03_de_movement # or import *
# Data
xR0 = [2.0, 3.0]
xR1 = [4.0, 5.0]
xR2 = [3.6, 2.8]
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_03_de_movement(objFunction, xR0, xR1, xR2, 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.48, 5.0]
of New: 31.1504
fit New: 0.031103812083208913
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 x0 = [2, 3]
current x1 = [4, 5]
current x2 = [3.6, 2.8]
Dimension 0: rij = 0.3999999999999999, neighbor = 2.48
Dimension 1: rij = 2.2, neighbor = 5.640000000000001
update x = [2.48, 5.0], of = 31.1504, fit = 0.031103812083208913