Function optimal value solution matlab simulation based on artificial fish swarm optimization algorithm

Table of contents

1. Overview of artificial fish school optimization algorithm

2. Principle of artificial fish school optimization algorithm

2.1 Definition of artificial fish schools

2.2 Simulation of fish school behavior

(1) Foraging behavior

(2) Group behavior

(3) Tailgating behavior

2.3 Behavior selection strategy

3. Algorithm process

4.MATLAB program

5. Algorithm performance analysis


         In optimization problems, finding the optimal value of a function is a classic and important task. Such problems widely exist in many fields such as engineering, economics, and scientific computing. Although traditional optimization methods such as gradient descent and Newton's method perform well on some problems, they often fall into local optimal solutions when dealing with complex functions such as high-dimensional, non-convex, and multimodal functions, making it difficult to find the global optimal. In recent years, swarm intelligence optimization algorithms have received widespread attention. One of them, the Artificial Fish Swarm Algorithm (AFSA), simulates the intelligent characteristics of fish schools in their behaviors such as foraging, swarming, and tail chasing. , which can effectively search for global optimal solutions in complex solution spaces.

1. Overview of artificial fish school optimization algorithm

       The artificial fish school optimization algorithm is a group intelligence optimization algorithm that simulates the behavior of fish schools in nature. By simulating the behaviors of fish schools such as foraging, swarming, and chasing, the algorithm can adaptively find the optimal solution in the search space. Compared with traditional optimization algorithms, AFSA has the following characteristics:

  1. Strong global search ability: By simulating the group behavior of fish schools, the algorithm can search for optimal solutions globally and avoid falling into local optima.
  2. High robustness: It is not sensitive to initial solutions and parameter settings, and can work stably in different problems and environments.
  3. Easy to implement parallelization: Individuals in the fish school can be searched in parallel, which is suitable for implementation in a parallel computing environment.

2. Principle of artificial fish school optimization algorithm

        Artificial fish (AF) are imitations of real fish used for analysis and problem interpretation (Neshat, Sepidnam, Sargolzaei, and Toosi (2012)). Fish mostly live in areas with abundant food, and they move to areas with more food by following other fish or looking for food alone. Areas with the most fish usually have the most food. The next behavior of each artificial fish depends on its current state and the local environmental state. AF affects the environment through its own behavior and the behavior of its companions.

2.1 Definition of artificial fish schools

       In AFSA, each artificial fish represents a solution vector, and its position represents a point in the solution space. Each fish has its own visual field (Visual Field) and movement step (Step Length), which are used to determine the local area of ​​​​search.

2.2 Simulation of fish school behavior

AFSA simulates three basic behaviors of fish schools: foraging behavior, swarming behavior and tailing behavior.

(1) Foraging behavior

        Foraging behavior is the basic survival activity of fish schools. In AFSA, foraging behavior simulates the process of fish randomly searching for food in the search space. Suppose the current position of the artificial fish is (X), and randomly select a point (X_{rand}) within its field of view. If the function value of (X_{rand}) is better than (X), then move to (X_{rand}) one step, otherwise reselect within the current field of view. The mathematical expression of foraging behavior is as follows:

Among them, (Xj) is the position after movement.

(2) Group behavior

        Schooling behavior is a group behavior adopted by fish schools to avoid danger or improve foraging efficiency. In AFSA, swarming behavior simulates the process of fish moving toward the center of the partner within the field of view. Suppose the current position of the artificial fish is (X), and the center position of the partner within its field of view is (X_{center}). If the function value of (X_{center}) is better than (X), and the number of partners reaches a certain proportion, then Move one step toward (X_{center}). The mathematical expression of swarming behavior is as follows:

Among them, (X_{next}) is the position after movement, (Step) is the movement step size.

(3) Tailgating behavior

        Tail chasing behavior is a kind of following behavior in fish schools, that is, fish will follow a partner that has found food within the field of vision. In AFSA, tail chasing behavior simulates the process of fish moving to the position of the best partner within the field of view. Suppose the current position of the artificial fish is (X), and the optimal partner position within its field of view is (X_{best}). If the function value of (X_{best}) is better than (X), and the number of partners reaches a certain proportion, Then move one step towards (X_{best}). The mathematical expression of rear-end collision behavior is as follows:

Among them, (X_{next}) is the position after movement, (Step) is the movement step size.

2.3 Behavior selection strategy

       In AFSA, each artificial fish will choose a behavior to perform based on the current environment and status. Usually, the selection strategy is based on certain probabilistic or deterministic rules. For example, you can set a probability value (p), generate a random number during each iteration, and choose to perform foraging behavior, swarming behavior, or tail-chasing behavior based on the size of the random number.

3. Algorithm process

The basic process of AFSA is as follows:

  1. Initialization: Set parameters such as fish school size, number of iterations, field of view, and movement step length, and randomly initialize the position of the fish school.
  2. Iterative search: For each artificial fish, select a behavior to execute according to the behavior selection strategy, and update the position of the fish.
  3. Evaluation: Calculate the function value of each fish's location and update the global optimal solution.
  4. Termination condition: Determine whether the maximum number of iterations is reached or other termination conditions are met. If so, the algorithm ends and the global optimal solution is output; otherwise, return to step 2 to continue iteration.

4.MATLAB program

..................................................................
%% 第二步:迭代过程
while k<=K
    NewX=zeros(M,N);
    NewY=zeros(1,N);
    for n=1:N
        x=X(:,n);
        Xnb=AFneighbour(n,X,V);%AFneighbour(n,X,V)找出人工鱼感知范围内的邻居,在下方定义
        NN=size(Xnb,2);
        if NN==0
            xx=AFprey(x,V,L,LB,UB);%AFprey(x,V,L,LB,UB)人工鱼觅食行为的子函数,在下方定义
        elseif NN>=3
            xx=AFswarm(x,Xnb,N,Delta,V,L,LB,UB);
        else
            xx=AFprey(x,V,L,LB,UB);
        end
        NewX(:,n)=xx;
    end
    for n=1:N
        NewY(n)=FIT(NewX(:,n));
    end
    X=NewX;
    Y=NewY;
    ALLX{k}=X;
    ALLY(k,:)=Y;
    minY=min(Y);
    pos=find(Y==minY);
    BESTX{k}=X(:,pos(1));
    BESTY(k)=minY;
    disp(k);
    k=k+1;
end
%% 绘图
BESTY2=BESTY;
BESTX2=BESTX;
for k=1:K
    TempY=BESTY(1:k);
    minTempY=min(TempY);
    posY=find(TempY==minTempY);
    BESTY2(k)=minTempY;
    BESTX2{k}=BESTX{posY(1)};
end
BESTY=BESTY2;
BESTX=BESTX2;
%plot(BESTY,'r*');
figure(1)
plot(-BESTY,'-ko','MarkerEdgeColor','r','MarkerFaceColor','r','MarkerSize',2)
ylabel('函数值')
xlabel('迭代次数')
title('收敛情况')
grid on
up4014

5. Algorithm performance analysis

       As a swarm intelligence optimization algorithm, AFSA shows good performance in solving function optimal value problems. It has strong global search capabilities and can effectively search for global optimal solutions in complex solution spaces. At the same time, the algorithm is insensitive to the initial solution and parameter settings and has high robustness. However, AFSA also has some shortcomings, such as relatively slow convergence speed and easy falling into local optimality. In response to these problems, researchers have proposed a series of improvement strategies, such as introducing elite strategies, adaptively adjusting parameters, etc., to further improve the performance of the algorithm.

        The artificial fish swarm optimization algorithm is a swarm intelligence optimization algorithm that simulates the behavior of fish swarms in nature. It has the advantages of strong global search capability and high robustness. When solving the function optimal value problem, this algorithm can effectively search for the global optimal solution in complex solution space. In the future, with the continuous development and improvement of swarm intelligence optimization algorithms, AFSA is expected to be applied and promoted in more fields. At the same time, in response to the shortcomings and challenges of AFSA, researchers will continue to explore and improve algorithm performance to meet the needs of practical applications.

Guess you like

Origin blog.csdn.net/ccsss22/article/details/135433939