General improved genetic algorithm to solve optimization problems with constraints (MATLAB code)

Table of contents

1 Overview

2 Genetic Algorithm

2.1 The basic concept of genetic algorithm

2.2 Characteristics of Genetic Algorithm 

2.3 Program Block Diagram 

3 running results

 4 General improved genetic algorithm to solve optimization problems with constraints (MATLAB code)


1 Overview

       Genetic Algorithm (GA) is an adaptive global optimization search algorithm formed by simulating the genetic and evolution process of organisms in the natural environment . It was first proposed by Professor JH Holland in the United States, and originated from the research on natural and artificial adaptive systems in the 1960s; in the 1970s, KADe Jong, based on the idea of ​​genetic algorithms, carried out a large number of pure numerical function optimization calculation experiments on computers80 In the 1990s, the genetic algorithm was summarized by DJGoldberg on the basis of a series of research work. Genetic algorithm is a random global search and optimization method developed by imitating the biological evolution mechanism in nature. It draws on Darwin's theory of evolution and Mendel's genetic theory, and is essentially a parallel, efficient, global search method, which can automatically acquire and accumulate knowledge about the search space during the search process, and adaptively control the search process in order to obtain the optimal solution. Genetic Algorithm Operation: Use the principle of "survival of the fittest" to successively generate an approximate optimal solution in the potential solution population. In each generation, individual selection is performed according to the fitness value of the individual in the problem domain and the reconstruction method borrowed from natural genetics, and a new approximate solution is generated. This process leads to the evolution of individuals in the population, and the resulting new individuals are better adapted to the environment than the original individuals.

       The theory of natural selection holds that the fittest survive, and that if organisms want to survive, they must fight for survival. The struggle for survival includes three aspects: intra-species struggle, inter-species struggle, and the struggle between organisms and the environment. In the struggle for survival, individuals with favorable mutations tend to survive, and have more opportunities to pass favorable mutations to offspring; individuals with unfavorable mutations are likely to be eliminated, and the chances of producing offspring will be much less. Therefore, all individuals who win in the struggle for survival are individuals with strong adaptability to the environment. Darwin called this process of survival of the fittest and elimination of the unfit in the struggle for survival natural selection . Darwin's theory of natural selection shows that heredity and variation are the internal factors that determine the evolution of organisms. Heredity refers to the similarity in traits between parents and offspring; variation refers to the differences in traits between parents and offspring, as well as between individuals in offspring. In organisms, heredity and variation are closely related. The hereditary traits of an organism tend to mutate, and some of the mutated traits can be inherited. Heredity can continuously transmit the traits of organisms to offspring, thus maintaining the characteristics of the species; mutation can change the traits of organisms, so as to adapt to new environments and continue to develop. Every life activity of a creature has its material basis, and so does heredity and variation of a creature. According to the research of modern cytology and genetics, the main carrier of genetic material is chromosome, and gene is a fragment with genetic effect, which stores genetic information, can be accurately copied, and can also undergo mutation. The organism itself selects and controls the inheritance of its traits through gene duplication and crossover. At the same time, through gene recombination, gene variation and variation in the structure and number of chromosomes, a variety of variation phenomena are produced. The genetic characteristics of organisms enable species in the biological world to remain relatively stable; the variation characteristics of organisms enable individual organisms to produce new traits, and even form new species, which promotes the evolution and development of organisms. Due to the possibility of genetic crossover and mutation in the reproduction of organisms, the continuous slight changes in biological traits are caused, which provide material conditions and basis for the directional selection of the external environment, and make the evolution of biological h2 possible .

2 Genetic Algorithm

2.1 The basic concept of genetic algorithm

In simple terms, the genetic algorithm uses population search technology to represent the population as a set of problem solutions, and generates a new generation of population by applying a series of genetic operations such as selection, crossover, and mutation to       the current population , and gradually evolves the population to include the approximate optimal Optimal state. Since genetic algorithm is a computing method formed by the interpenetration of natural genetics and computer science, some basic terms related to natural evolution are often used in genetic algorithm, and the corresponding relationship between terms is shown in Table 2.1.

Genetics term

Genetic Algorithm Terminology

group

feasible solution set

individual

Feasible solution

chromosome

Encoding of Feasible Solutions

Gene

feasibly decodable components

genetic form

genetic code

adaptability

objective function value

choose

select operation

cross

cross operation

Mutations

mutation operation

2.2 Characteristics of Genetic Algorithm 

Genetic algorithm is a parallel, efficient and global search method formed by simulating the genetic and evolutionary process of organisms in the natural environment. It mainly has the following characteristics:

(1) The genetic algorithm takes the encoding of the decision variable as the operation object. This way of encoding decision variables makes it possible to use concepts such as chromosomes and genes in biology for reference in the process of optimization calculations, imitate the mechanisms of heredity and evolution in nature, and apply genetic operators conveniently. Especially for some optimization problems that only have the concept of code but no concept of value, or it is difficult to have the concept of value, the encoding processing method shows its unique advantages.

(2) The genetic algorithm directly uses the objective function value as the search information . It only uses the fitness function value transformed from the objective function value to determine the further search direction and search range without requiring other auxiliary information such as the derivative value of the objective function. In practical applications, many functions cannot or are difficult to be derived, or even do not exist at all. For the optimization and combinatorial optimization of such objective functions, the genetic algorithm shows its high superiority, because it avoids the problem of function derivation. obstacle.

(3) The genetic algorithm uses the search information of multiple search points at the same time . The search process of the genetic algorithm for the optimal solution starts from an initial group composed of many individuals, rather than from a single individual.

Operations such as selection, crossover, and mutation are performed on this group to generate a new generation of groups, which includes a lot of group information. This information can avoid searching some unnecessary points, which is equivalent to searching more points, which is a kind of implicit parallelism unique to genetic algorithm.

(4) Genetic Algorithm is a probability-based search technique . Genetic Algorithm is an adaptive probability search technology, and its operations such as selection, crossover, and mutation are all carried out in a probabilistic manner, thus increasing the flexibility of its search process. Although this probabilistic characteristic will also produce some individuals with low fitness in the population, as the evolution process proceeds, more and more excellent individuals will always be produced in the new population. Compared with some other algorithms, the robustness of the genetic algorithm makes the influence of the parameters on its search effect as small as possible. (5) Genetic algorithm has the characteristics of self-organization, self-adaptation and self-learning. When the genetic algorithm uses the evolutionary process to obtain information to organize its own search, individuals with high fitness have a higher probability of survival and obtain a genetic structure that is more adaptable to the environment. At the same time, the genetic algorithm has scalability, and it is easy to combine with other algorithms to generate a hybrid algorithm that combines the advantages of both parties.

2.3 Program Block Diagram 

          

The operation flow of the genetic algorithm is shown in Figure 2.1. The specific steps are as follows:

(1) Initialization . Set the evolution algebra counter g=0, set the maximum evolution algebra G, and randomly generate NP individuals as the initial population P(0).

(2) Individual evaluation . Calculate the fitness of each individual in the population P().

(3) Select operation . The selection operator acts on the population, and according to the fitness of the individual, according to certain rules or methods, select some excellent individuals to inherit to the next generation population

(4) Cross operation . Apply the crossover operator to the population, and exchange some chromosomes between the selected pairs of individuals with a certain probability to generate new individuals.

(5) Variation operation . Apply the mutation operator to the population, and change one or some gene values ​​to other alleles with a certain probability for the selected individual. After the population P(i) undergoes selection, crossover and mutation operations, the next generation population P(t+1) is obtained. Calculate its fitness value, and sort according to the fitness value, ready for the next genetic operation.

(6) Termination condition judgment : if g<G, then g=g+1, go to step (2); if g>G, then the individual with the maximum fitness obtained in this evolution process is output as the optimal solution , to terminate the calculation.

Part of the code:

function New_Population = EnviornmentalSelection(Population,Offspring,state)
% 本函数用来挑选新的种群

N = length(Population);
New_Population = Population;

%% 基本思路如下:为了确保种群的多样性,采用一对一替换机制。只有后代表现强于父代才会发生替换。
for i=1:N
    pcv = Population(i).con;
    ccv = Offspring(i).con;
    pf = Population(i).obj;
    cf = Offspring(i).obj;
    if (pcv == 0 && ccv == 0) % 采用 feasible rules 挑选新解
        if pf < cf
            New_Population(i) = Population(i);
        else
            New_Population(i) = Offspring(i);
        end
    else
        if pcv < ccv
            New_Population(i) = Population(i);
        else
            New_Population(i) = Offspring(i);
        end
    end
end

% %% 此处采用精英保留策略,每一次迭代之后,挑选指定数量的最佳解替换最劣解,其中数量于概率根据迭代进度计算
% objs = [New_Population.obj];
% cons = [New_Population.cons];
% [~,index] = sortrows([cons' objs']);
% n = ceil((1-state)*(N/100));
% if rand>state*state/2
%     New_Population(index(end-n+1:end)) = New_Population(index(1:n));
% end

3 running results

 4 General improved genetic algorithm to solve optimization problems with constraints (MATLAB code)

Blog homepage: @果格格果树果

Guess you like

Origin blog.csdn.net/weixin_61181717/article/details/128097603