@@ -115,6 +115,7 @@ namespace dsm {
115115 std::unordered_map<Id, double > streetAngles;
116116 std::unordered_map<Id, double > maxSpeeds;
117117 std::unordered_map<Id, int > nLanes;
118+ std::unordered_map<Id, std::string> streetNames;
118119 double higherSpeed{0 .}, lowerSpeed{std::numeric_limits<double >::max ()};
119120 int higherNLanes{0 }, lowerNLanes{std::numeric_limits<int >::max ()};
120121 if (inNeighbours.size () < 3 ) {
@@ -142,50 +143,59 @@ namespace dsm {
142143
143144 maxSpeeds.emplace (streetId, speed);
144145 nLanes.emplace (streetId, nLan);
146+ streetNames.emplace (streetId, pStreet->name ());
145147
146148 higherSpeed = std::max (higherSpeed, speed);
147149 lowerSpeed = std::min (lowerSpeed, speed);
148150
149151 higherNLanes = std::max (higherNLanes, nLan);
150152 lowerNLanes = std::min (lowerNLanes, nLan);
151153 }
152- if (higherSpeed != lowerSpeed) {
153- // Assign streets with higher speed to priority
154+ if (tl.streetPriorities ().empty ()) {
155+ /* ************************************************************
156+ * 1. Check for street names with multiple occurrences
157+ * ***********************************************************/
158+ std::unordered_map<std::string, int > counts;
159+ for (auto const & [streetId, name] : streetNames) {
160+ if (name.empty ()) {
161+ // Ignore empty names
162+ continue ;
163+ }
164+ if (!counts.contains (name)) {
165+ counts[name] = 1 ;
166+ } else {
167+ ++counts.at (name);
168+ }
169+ }
170+ for (auto const & [name, count] : counts) {
171+ Logger::debug (std::format (" Street name {} has {} occurrences" , name, count));
172+ }
173+ for (auto const & [streetId, name] : streetNames) {
174+ if (!name.empty () && counts.at (name) > 1 ) {
175+ tl.addStreetPriority (streetId);
176+ }
177+ }
178+ }
179+ if (tl.streetPriorities ().empty () && higherSpeed != lowerSpeed) {
180+ /* ************************************************************
181+ * 2. Check for street names with same max speed
182+ * ***********************************************************/
154183 for (auto const & [sid, speed] : maxSpeeds) {
155184 if (speed == higherSpeed) {
156185 tl.addStreetPriority (sid);
157186 }
158187 }
159- // continue;
160- } else if (higherNLanes != lowerNLanes) {
188+ }
189+ if (tl.streetPriorities ().empty () && higherNLanes != lowerNLanes) {
190+ /* ************************************************************
191+ * 2. Check for street names with same number of lanes
192+ * ***********************************************************/
161193 for (auto const & [sid, nLan] : nLanes) {
162194 if (nLan == higherNLanes) {
163195 tl.addStreetPriority (sid);
164196 }
165197 }
166- // continue;
167198 }
168- // Set first two elements of capacities to street priorities
169- // auto it{capacities.begin()};
170- // tl.addStreetPriority(it->first);
171- // ++it;
172- // if (it != capacities.end()) {
173- // tl.addStreetPriority(it->first);
174- // continue;
175- // }
176- // Id firstStreetId{streetAngles.begin()->first};
177- // tl.addStreetPriority(firstStreetId);
178- // for (auto const& [streetId, angle] : streetAngles) {
179- // if (streetId == firstStreetId) {
180- // continue;
181- // }
182- // if (angle == streetAngles.begin()->second) {
183- // tl.addStreetPriority(streetId);
184- // }
185- // }
186- // if (tl.streetPriorities().size() > 1) {
187- // continue;
188- // }
189199 if (tl.streetPriorities ().empty ()) {
190200 Logger::warning (std::format (" Failed to auto-init Traffic Light {}" , id));
191201 continue ;
0 commit comments