# Sustainable Parking Space Management Using Machine Learning and Swarm Theory--The SPARK System
## 3 Methodology Concept
### Applied Algorithms and Technologies in This Study
#### 3.3.3 The You Only Look Once (YOLO) Algorithm for Object Segmentation in Images
Let \(C\) represent the total cost for a given solution. The cost function \(C\) can be expressed as:  
\[C=\sum_{i=1}^{N}\left[P_{\text{out}}\ \cdot\ I_{\text{out},i}\right]+\sum_{i=1}^{N} \left[P_{\text{occupied}}\ \cdot\ \text{OP}_{\text{occupied},i}\right]+\sum_{i=1}^{N}\sum_{j=1}^{i-1}\left[P_{ \text{new}}\ \cdot\ \text{OP}_{\text{new},ij}\right] \tag{1}\]  
where:  
* \(N\) is number of vehicles. * \(P_{\text{out}}\ =5000\) is the penalty for a vehicle placed outside the designated parking area. * \(I_{\text{out},i}\) is an indicator function that equals 1 if the \(i\)-th vehicle is outside the parking area, and 0 otherwise. * \(P_{\text{occupied}}\ =300\) is the penalty per percentage of overlap with an already occupied space. * \(\text{OP}_{\text{occupied},i}\) is the percentage overlap of the \(i\)-th vehicle with an occupied area. * \(P_{\text{new}}\ =300\) is the penalty per percentage of overlap with another new vehicle. * \(\text{OP}_{\text{new},ij}\) is the percentage overlap between the \(i\)-th and \(j\)-th vehicles. As shown in Figure 6, the ABC optimization process for this study is as follows:  
The length of the longest edge of parking area is calculated. The length of occupied spaces is subtracted to find available spaces. ABC algorithm starts by randomly initializing vehicle positions for the determined number of vehicles. The algorithm iteratively optimizes these positions. Overlaps and out-of-bound placements are minimized. **Visualization and Final Output**  
Optimized parking spaces are visualized. Final results are saved and returned to original coordinates. Figure 6: Flowchart depicting the process for identifying optimal parking spaces using the ABC algorithm (Source: Author’s own elaboration). The process of finding the optimal parking configuration begins with data input and pre-processing. Initially, information regarding the parking area and occupied spaces is imported in shapefile format, allowing for the extraction and structuring of the geometric shapes for analysis. Following the data preparation, the coordinates of the parking area and the occupied spaces are normalized by subtracting the average values, resulting in more manageable numbers. To streamline the search process, the longest edge of the parking area is aligned with the x-axis, significantly reducing the search space for the ABC algorithm and improving the efficiency of the optimization. Next, the dimensions of the parking area, along with the desired spacing, are specified. The total length of the parking area along the x-axis is calculated, and the length of the occupied regions is subtracted to determine the available space for parking. The optimization then proceeds with the application of the ABC algorithm, which simulates the foraging behavior of bee colonies. The algorithm generates random configurations of parking spaces and iteratively searches for the optimal positions along the x-axis. A fitness function is used to assess each configuration, accounting for penalties related to overlaps and boundary violations. The search continues until the algorithm reaches the minimum cost or a specified number of iterations. Finally, after determining the optimal parking arrangement, the coordinates are reverted to their original scale. The optimized configuration is then visualized, and the results are saved in a shapefile format, enabling the layout to be displayed on a map for users. Figure 7 presents the results from the ABC optimization process, illustrating the placement of vehicles after different iteration counts. Figure 7: Optimally placed cars using the ABC algorithm for different iteration counts: (**a**) Displays the result after 5 iterations, showing the initial optimal car placements; (**b**) Shows the result after 500 iterations, representing the final optimal car placements (Source: Author’s own elaboration). Figure 8 presents the pseudo-code of the proposed optimization approach.