Learning Mathematical Modeling (10): Genetic Algorithms

Introduction to Genetic Algorithms • Genetic Algorithms (Genetic Algorithms) is a widely used and efficient random search and optimization method
developed based on the principle of biological evolution theory .
Its main feature is the group search strategy and
the information exchange between individuals in the group, and the search does not depend on gradient information.
It was developed by Professor Holland of the University of Michigan in the early 1970s . Genetic Algorithms are by far
the most well-known of the evolutionary algorithms.
• Genetic algorithm is mainly applied in solving complex optimization problems and industrial engineering, and has achieved some convincing results,
so it has attracted many people's attention. Successful applications of genetic algorithms include: job scheduling and sequencing, reliability design,
vehicle routing and scheduling, grouping technology, equipment layout and allocation, traffic problems, and so on.
Characteristics of Genetic Algorithm
• The processing object of genetic algorithm is not the parameter itself, but the individual who encodes the parameter set. This operation allows the genetic algorithm
to operate directly on the structural object.
• Many traditional search algorithms are single-point search algorithms, which are easy to fall into local optimal solutions. The genetic algorithm processes multiple individuals in the group at the same time, that is, evaluates multiple solutions in the search
space, which reduces the risk of falling into a local optimal solution, and the algorithm itself is easy to achieve parallelization.
• The genetic algorithm basically does not use the knowledge of the search space or other auxiliary information, but only uses the fitness function value to evaluate the individual, and performs genetic operations on this basis
. The fitness function is not limited by continuous differentiability, and its domain of definition can be set arbitrarily.
This feature greatly expands the application range of genetic algorithm .
• Genetic algorithm does not use deterministic rules, but uses probabilistic transition rules to guide the search direction.
• Self-organizing, self-adapting and self-learning. The genetic algorithm uses the information obtained in the evolutionary process to self-organize the search. Individuals with a high degree of fitness have a higher
probability of survival and can obtain a genetic structure that is more suitable for the environment.

Basic Concepts in Genetic Algorithm
Population: Also known as population and chromosome group, it is a collection of individuals and represents a subset of the solution space of the problem.
String (string) and string space: String is the expression form of an individual, corresponding to a chromosome in genetics, and corresponding to a solution to a practical problem.
Population size: The number of individuals in a chromosome group is called the size of the population or population size.
Gene: refers to a segment of a chromosome, which can be a numerical value, a set of numbers, or a string of characters.
Crossover: refers to the exchange of positions of one or several genes on two chromosomes under certain conditions.
Exchange probability: a threshold less than 1 to judge whether the exchange condition is met.
Mutation: refers to the random change of one or several gene values ​​on a chromosome under certain conditions.
Mutation probability: a threshold value less than 1 to judge whether the mutation condition is met.
Offspring: A new individual formed after chromosome exchange or mutation.
Fitness (fittness): The index value used to measure the pros and cons of individuals in the population (degree of compliance), which is usually expressed in numerical form.
Selection: According to the fitness value corresponding to the chromosome and the requirements of the problem, the chromosomes in the population are screened. The higher the fitness of the chromosome, the greater the probability of preservation, and vice versa, the smaller it is, or even eliminated.
Genetic Algorithm Termination Rules
Given a maximum genetic algebra MAXGEN, the algorithm iteration stops when MAXGEN is reached.
When the optimal individual of two generations in the evolution is smaller than the required deviation x, the algorithm terminates.
All individuals or individuals above the specified ratio converge, and the calculation stops at this time.
The maximum computation time limit was reached.
Syntax Toolbox implementations of related functions
insert image description here:

%plotobjective(@shufcn,[-2,2;-2,2]);
%目标函数
fun = @lincontest6;
%需要优化的函数变量的个数
number = 2;
%不等式约束
A = [1 1;-1 2;2 1];%线性不等式的约束条件
b = [2;2;3];%线性不等式的约束条件
%等式约束
Aeq = [];%系数
beq = [];%边界值
%边界约束
lb = zeros(2,1);%下边界
ub = [];%上边界
%非线性约束
%nonlcon
% % 定义约束函数
% function [c, ceq] = nonlcon(x)
%     c = [-(x(1) + x(2) - 1)]; % 不等式约束 x1 + x2 ≥ 1
%     ceq = []; % 没有等式约束,设为空
% end
[x,fval,exitflag,output] = ga(@lincontest6,2,A,b,Aeq,beq,lb,ub);
disp("最优的参数");
disp(x)
disp("最优值");
disp(fval)
disp("显示遗传代数");
disp(output.generations)
disp("显示调用目标函数的次数");
disp(output.funccount)

Effect
Optimization terminated: average change in the fitness value less than options.FunctionTolerance.
Most parameters
0.6670 1.3340

Optimization terminated: maximum number of generations exceeded.
Optimal parameter
0.6670 1.3340

Optimal value
-8.2258

Display Genetic Algebra
200

Display the number of calls to the target function
9453

Guess you like

Origin blog.csdn.net/qq_60498436/article/details/132147027