# Using Improved Brainstorm Optimization Algorithm for Hardware/Software Partitioning
## 3 Hardware/Software Partitioning Based on BSO Algorithm
### The Application of the BSO Algorithm in Hardware/Software Partitioning  
In this paper, the BSO algorithm proposed in [20] is applied to solve the problem of hardware/software partitioning. Its pseudo-code is shown in Algorithm 1, where p_replace, p_one, p_one_center, p_two_center are thresholds between 0 and 1. ```
1 Visual_num = \(N\); Cluster_num = \(M\); /*Initializing the number of individuals and the number of clusters*/
2 Init_visual(); /*Generating \(N\) feasible solutions randomly*/
3 While the termination condition is not arrived
3.1 Cluster(); /*Clustering \(N\) individuals into \(M\) clusters*/
3.2 Fit_calculate(); /*Calculating the fitness value of each individual*/
3.3 Set_centers(); /*Setting the individual with the best fitness value in each cluster as the center of the cluster*/
3.4 Ifrandom(0,1) < p_replace)  Substitute_center(); /*Selecting a cluster center randomly and replace it by a randomly selected individual*/
4 EndIf
3.5 For(\(j\) = 1 to _Visual_num_)  If (random(0,1) < p_one)  Select_one_cluster(); /*Selecting a cluster randomly*/
5 If(random(0,1) < p_one_center)  New_individual = Create_individual_A(); /*Generating a new individual by method A. Method A is adding random information to the center of the selected cluster to generate a new individual*/
6 Else  New_individual = Create_individual_B(); /*Generating a new individual by method B. Method B is adding random information to a randomly selected individual in the selected cluster to generate a new individual*/
7 EndIf
8 Else  Select_two_cluster(); /*Selecting two different clusters randomly*/
9 If(random(0,1) < p_two_center)  New_individual = Create_individual_C(); /*Generating a new individual by method C. Method C is adding random information to the combination of the two selected cluster centers to generate a new individual. */
10 Else  New_individual = Create_individual_D(); /*Generating a new individual by method D. Method D is adding random information to the combination of two randomly selected individuals in the selected clusters to generate a new individual. */ EndIf
11 EndIf
12 Fit_new = Fit_calculate(New_individual); /*Calculating the fitness value of the new individual*/
13 If(ls_valid(New_individual)&&Fit_new < Fit_old) /*If the new individual meets the constraint and its fitness value is less than the original one*/
14 Substitute_individual(); /*Replacing the old individual by the new individual*/
15 Else  Keep_individual(); /*The old individual will be retained*/
16 EndIf
17 Endfor
18 Current_Iteration = Current_Iteration+1;
19 Endwhile
204 Output (solution); /*Outputting the optimal solution*/
```  
**Algorithm 1** Brainstorm optimization (BSO) applied to hardware/software partitioning. It can be seen from Algorithm 1 that the BSO algorithm mainly contains two steps in each iteration, clustering and updating. In the step of clustering, \(N\) individuals are clustered into \(M\) clusters based on the K-means algorithm and the center of each cluster is replaced by the individual with the best fitness value in the cluster. In the step of updating, individuals are updated successively. There are four methods to generate new individuals. 1. Selecting one cluster randomly, then adding random information to the center of cluster;2. Selecting one cluster randomly, then adding random information to a individual which is randomly selected from the cluster;
3. Selecting two clusters randomly, then adding random information to the combination of the centers of the two clusters;
4. Selecting two clusters randomly, then adding random information to the combination of two individuals which are randomly selected from the two clusters. When an individual is being updated, it should select a method to generate a new individual according to predefined probability and determine whether to replace the original individual with the new individual based on their fitness values.