# 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
The variation of the cost function value over iterations and elapsed time is presented in Figure 9, which also illustrates the optimization performance for a sample application. **INPUT:**  
- C: Cost function representing the quality of parking slot arrangement  
- _ParkingArea_: Shapefile delineating the boundary of the parking area  
- _OccupiedSpaces_: Shapefiles of currently occupied spaces (derived from YOLO segmentation)  
- _ParkingDimensions_: Dimensions of a single parking slot (length, width)  
- _Spacing_: Distance between adjacent parking slots  
- _SN_: Colony size (number of bees in the optimization algorithm)  
- _MCN_: Maximum number of iterations (stopping criterion)  
- _AngleLimits_: Range of permissible angles for slot rotation (minimum, maximum)  
**OUTPUT:**  
- _BestSlots_: Optimal positions (x, y) and rotation angles for each parking slot  
- _BestCost_: The minimum cost achieved, reflecting an optimal arrangement  
**STEP 1: Preprocessing**  
1. Load the _ParkingArea_ and normalize its geometry with respect to its centroid. 2. Load _OccupiedSpaces_ and apply the same normalization for consistency. 3. Align the longest edge of the _ParkingArea_ with the x-axis to reduce the search space dimensionality. 4. Compute the bounding box of the _ParkingArea_ along both x and y axes. 5. Calculate the total length of the _ParkingArea_ along the x-axis (_TotalLength_). 6. Deduct the total length of occupied spaces to determine the available parking length (_AvailableLength_). 7. Compute the maximum number of parking slots (\(N\)) based on _ParkingDimensions_ and the defined _Spacing_. 8. Generate \(N\) rectangular polygons, each representing a potential parking slot. **STEP 2: Artificial Bee Colony (ABC) Optimization**  
9. Initialize the population with random x, y positions and rotation angles for each slot within the bounds of the _ParkingArea_ and '_AngleLimits_. 10. Evaluate the initial fitness of the population using the cost function \(C\). - Objective: Minimize \(C\), where \(C=0\) indicates no overlaps or boundary violations. 11. For each cycle (from \(1\) to _MCN_):  
a) **Employed Bee Phase**:  
- Generate new solutions by modifying current solutions (local exploration within bounds). - Evaluate the cost function \(C\) for the newly generated solutions. - Retain the better solution (either the original or the new one) via greedy selection. b) **Onlooker Bee Phase**:  
- Calculate the probability of selection for each solution based on its fitness. - Generate new solutions by focusing on promising candidates. - Evaluate the cost function for these new solutions and apply greedy selection. c) **Scout Bee Phase**:  
- Identify abandoned solutions that fail to improve after a defined number of iterations. - Replace abandoned solutions with new random solutions within permissible bounds. d) **Update**:  
- Record the best solution discovered so far (_BestSlots, BestCost_). e) **Final Condition:**  
- If \(C=0\), terminate the optimization process early. 12. Increment the cycle counter and repeat. **STEP 3: Post-Processing**  
13. Transform the optimal x, y positions and angles of parking slots back to the original coordinate system. 14. Visualize the final parking layout to ensure interpretability and accuracy. 15. Save the optimized layout as a shapefile for further analysis and visualisation in SPARK system. Figure 8: Pseudo-code of the proposed optimization approach (Source: Author’s own elaboration).