| Algorithm A1. Modified algorithm for region identification and grouping of participants based on clusters using K-means with node S |
| 1. Set S: node for participant’s smartphone |
| 2. Set Lat: Latitude |
| 3. Set Long: Longitude |
| 4. Set T: Time |
| 5. Set SA: Sub-arealist = [SA1, SA2, SA3,…, SAn] |
| 6. Set Dist: Distance |
| 7. K: Clusters of nodes into sub-areas |
| 8. TWindow: Time T, set for the location of nodes a threshold |
| 9. Start |
| 10. Input S: Output (Lat, Long, Time) |
| 11. Input Sub-area list [SA1, SA2, SA3,…, SAn, Lat, long, T] |
| 12. Output S clusters in Sub-areas, SAn |
| 13. While S is ready do |
| 14. For each S for participant in Sub-Arealist do |
| 15. Set locationUpdateWindow |
| 16. Set minT i.e., for location manager minimum power consumption with minT |
| Milliseconds between location update to reserve power |
| 17. Set minDist: as location transmission in case device moves using minDistance |
| meters |
| 18. TDifference = location.getT( )- currentbestlocation.getT( ) |
| If TDifference > TWindow then participant (node) have moved and transmit |
| the new location into a Crowd Controller Station (CCS) based on timestamp |
| change |
| 19. If (Lat, Long) in location context with Sub-arealist SAn are the same, |
| clusters set K using Dist between the nodes S |
| 20. Group S into SA1, SA2, SA3,…, SAn clusters |
| 21. Crowdcount = S + 1 |
| 22. End If |
| 23. End If |
| 24. End For |
| 25. End While |
| 26. End |