## 2 Introduction to the Details of the Algorithm
### Sheep Flock Optimization Algorithm (SFOA)
#### 2.2.3. Building, Using, and Updating the Prior Knowledge Set  
This paper aims to utilize the population information of a flock of sheep to address the problem of algorithms becoming stuck in local optima. In this paper, we introduce a prior knowledge set, which is denoted as \(\theta\). When the historical best fitness level of a sheep remains unchanged for a long time, it is eliminated and stored in the prior knowledge set \(\theta\). During the reproduction process of the sheep flock, the newly generated sheep must be sufficiently far from all the sheep in the prior knowledge set \(\theta\) to be allowed into the generation process. When the set \(\theta\) is sufficiently large, the algorithm can prevent the sheep population generated through reproduction from becoming stuck in known local optima. However, the \(\theta\) set requires a significant amount of memory resources, and the algorithm spends considerable time calculating distances during the reproduction phase. On the other hand, when the set \(\theta\) is too small, it fails to capture the population information in the later stages, leading to the algorithm still becoming stuck in new local optima later on. To overcome the aforementioned issues, this study introduces a secondary prior knowledge set, which is denoted as \(\theta t\). When the data stored in the prior knowledge set \(\theta\) reach its maximum capacity, the eliminated sheep are stored in \(\theta t\). The purpose of \(\theta t\) is to preserve the latest information from the current population and use it as the basis for updating the prior knowledge set \(\theta\). This allows \(\theta\) to utilize a smaller space to store useful and cutting-edge population information. As the algorithm runs, sheep are continuously eliminated. To maintain the stability of the sheep population, this study stipulates that when the total number of sheep in the population is less than the threshold value \(NumberLeast\), the sheep population undergoes a reproductive operation. The steps used to generate a sheep \(\
abla\) through reproduction are as follows. (1) Create a sheep denoted as \(\
abla\), and randomly initialize its position \(P^{\
abla}\). (2) For each sheep \(Y\) in the candidate prior knowledge set \(\theta\), calculate the distance \(d_{\
abla,Y}\), where \(\
abla\) represents the newly generated sheep and \(Y\) represents a sheep \(Y\) in the prior knowledge set \(\theta\). \(d_{\
abla,Y}\) is recorded as the _Dis_ attribute of sheep \(Y\), representing the distance between the newly generated sheep \(\
abla\) and sheep \(Y\). (3) If \(min_{Y=1}^{length(\theta)}\{d_{\
abla,Y}\}>d_{2}\), where \(length(\theta)\) is the size of the set \(\theta\), then the newly generated sheep \(\
abla\) is far from all the sheep in \(\theta\), and the generation of sheep \(\
abla\) is allowed. The eliminated sheep in the population are replaced with sheep \(\
abla\), and the algorithm ends. (4) If \(min_{Y=1}^{length(\theta)}\{d_{\
abla,Y}\}\leq d_{2}\), where \(d_{2}\) represents a threshold value, this indicates that the newly generated sheep \(\
abla\) is close to the sheep in the set \(\theta\). It is considered probable that sheep \(\
abla\) will fall into a local optimum. Therefore, the generation of sheep \(\
abla\) is not allowed, and the process returns to step (1). The pseudo-code for the sheep reproduction operation is shown in Algorithm 3. ```
input : \(\theta\); the index of the sheep to be replaced in the \(SheepList:n\) output : \(SheepList\)
1 : Retrieve the \(k-\) th sheep from the flock : \(SheepList[k]\)
2 : Retrieve the \(Dis\) attribute of \(Y\) from the prior knowledge set : \(Y\).