Repository navigation
Description
from #420:
https://forum.travelmapping.net/index.php?topic=4015.msg22719#msg22719
nc.us015;US15/401Bus;;;LABEL_SELFREF;
There are a lot of these cases in HighwayData. The idea is, it's (US15/401)(Bus) rather than (US15)/(401Bus).
It makes sense to continue to allow them, and not force a bunch of conversions toUS15Bus/401Bus
DataProcessing/siteupdate/cplusplus/classes/Waypoint/Waypoint.cpp
Lines 343 to 351 in cc9da66
| bool Waypoint::banner_after_slash(const char* slash) | |
| { // return whether colocated with a bannered route of same designation whose banner | |
| // is contained in this waypoint's label after a slash, before underscore if exists | |
| if (colocated) | |
| for (Waypoint* w : *colocated) | |
| if (w != this && w->route->banner.size() && w->route->route == route->route && strdstr(slash+1, w->route->banner.data(), '_')) | |
| return 1; | |
| return 0; | |
| } |
DataProcessing/siteupdate/python-teresco/siteupdate.py
Lines 828 to 835 in 124f24b
| def banner_after_slash(self, postslash): | |
| """return whether colocated with a bannered route of same designation whose banner | |
| is contained in this waypoint's label after a slash, before underscore if exists""" | |
| if self.colocated is not None: | |
| for w in self.colocated: | |
| if w != self and len(w.route.banner) and w.route.route == self.route.route and w.route.banner in postslash: | |
| return True | |
| return False |
These functions were tailor-made for the LABEL_SELFREF datacheck & can't be used for CWN purposes without modification.
route->route / self.route.route can be replaced with a reference passed into the function.
As for how we'd wanna tie this into the CWN routine itself, I haven't thought that through yet.
Useful in 3+_intersection cases. Others?
NH11TrkWCl@NH12/103_E&NH12@NH12TrkWCl_N&NH12TrkWCl@NH12_N&NH103@NH11/12TrkWCl
NH11TrkWCl@NH120_N&NH12TrkECl@NH120_N&NH103TrkCla@NH120_N&NH120@NH11/12Trk
could become
NH11TrkWCl/NH12_N/NH12TrkWCl_N/NH103_E
NH11TrkWCl/NH12TrkECl/NH103TrkCla/NH120_N
Maybe. Or something. Haven't fully thought it through yet.
Activity
yakra commentedon May 1, 2022
Not quite.
*colocated.ap_coloc.yakra commentedon May 2, 2022
Here's where I'm at with this...
I'll link to the existing version of the 3+_intersection code like this so GitHub doesn't paste the whole thing in. This'll already be a long post (apologies in advance)...
To start off, let's convert from a traditional C-style
forloop to a C++11 Range-based for loop, for brevity & readability.This gives us an easier basis of comparison for the in-dev version I'll paste in next...
In addition to the main purpose of this issue as noted in the OP, let's also take care of this longstanding comment while making changes:
DataProcessing/siteupdate/python-teresco/siteupdate.py
Lines 643 to 644 in 124f24b
Here's what I'm working with now:
Now let's examine the changes in detail.
^This is just a minor efficiency tweak; no change in output. No need to create new string objects when pointers into the existing
chararray work fine.std::string other_no_abbrevis gonzo, replaced with a new function that goes through a route's .list name components (route, banner, abbrev) in finer detail. This new function is called here:Here's how it works under the hood:
(
strdstris defined here.)And now, suffixes:
We don't need to start our search before
endmatch. We know there won't be any underscores beforeendmatchin our string, because if there were, eitherendmatchinstead, orRoute::label_matchwould have failed to match some part of the .list name, returned 0, and we'd not even be inside thisifblock.Nota bene: this all depends on list names not containing underscores anywhere. I've confirmed via grepping system CSVs that none do, but maybe this could be something to watch out for?
None of the suffix changes alter our output. That all happens as a result of
Route::label_match.For suffix comparisons, let's take the comment out and just look at the "before" conditional:
if (suffix && (!strcmp(check->label.data()+other_no_abbrev.size(), suffix) || check->label.data()+other_no_abbrev.size() == ap_coloc[other]->route->abbrev + suffix )) suffixes[other] = suffix;other_no_abbrevis gone now, of course.check->label.data()+other_no_abbrev.size()is ourendmatchvalue, asendmatchpoints to the next char after the matching text. So let's replace it & clean up the formatting:if (suffix && (!strcmp(endmatch, suffix) || endmatch == ap_coloc[other]->route->abbrev + suffix)) suffixes[other] = suffix;Recall that
suffix = strchr(endmatch, '_');this means that ifsuffixis anything other thanendmatchitself,strcmpwill return a non-match. Thus this can be simplified to:if (suffix && (endmatch == suffix || endmatch == ap_coloc[other]->route->abbrev + suffix)) suffixes[other] = suffix;Now let's turn our attention to
|| endmatch == ap_coloc[other]->route->abbrev + suffix.If the abbrev matches after the route and banner,
Route::label_matchreturns anendmatchvalue pointing to the next char after the abbrev in our label. So we're already pastap_coloc[other]->route->abbrev, and only need to worry about matchingsuffix. Thus we can simplify to:if (suffix && endmatch == suffix) suffixes[other] = suffix;...which is what's in the big WIP code block above.
And yes, this could be further simplified --
if (*endmatch == '_') suffixes[other] = endmatch;, without definingsuffixor callingstrchrat all. But let's stop short of doing that for now. I'll explain why in a future post.@jteresco, does everything make sense so far? Any questions?
Results so far:
147 changes to label simplification. That's a small enough amount to review manually. The diffs all fall into 3 categories:
3+_intersection->Keep_failsafe, due to the checks for false matches.F2SMavsF2sMaorMEX140CaCvsMEX140Cac.MI35Esc_N.Six of "NY9A", half a dozen of "NY9Ams"... :)
3+_intersectioncases that gain some more suffixes.Sometimes, a route that didn't match as an
otherbefore will match now, due to its banner being located after a slash in a waypoint label.Or, a route that only matched a suffixless label will now match a suffixed one.
After: Route SS73VarPal matches label SS73/73Var_E. Gets _E suffix.
Bottom: No match for US15BusCul as other -> match @ US15/15Bus_S
Keep_failsafe->3+_intersection, due to a banner being detected after a slashUS13/460Bus_S becomes a match for US13BusSuf
US13/58Bus_S becomes a match for US13BusSuf
I saw a lot of benefit in VA, the Carolinas, and GA. Especially in GA, where there's lots of multiplexing and lots of high-colocation locations. Six of the 12 longest graph labels are there. Of these, 5 now get simplified via
3+_intersection, including the longest graph label:GA12TrkMad@US129/441_S&GA24@US129/441Byp_S&GA24BypMad@GA24_S&US129@US129/441Byp_S&US129BypMad@US129_S&US278TrkMad@US129/441_S&US441@US129/441Byp_S&US441BypMad@US441_S -> GA12TrkMad/GA24_S/GA24BypMad/US129_S/US129BypMad_S/US278TrkMad/US441_S/US441BypMad166 -> 82 bytes. That's a win!yakra commentedon May 3, 2022
The next proposed change:
Instead, let's do
if (suffix) suffixes[other] = suffix;How does this change the outcome of the conditional? When does
suffixexist but not equalendmatch?Possible values for
*endmatch:\0: End of string; no suffix possible. No difference in the conditional._: suffix == endmatch. No difference in the conditional.(: This indicates aRte(Exit)type label.There should be a colocated point with just the exit number as its label. Meaning, we don't meet the "each label starts with some route number" criterion for simplfication.
Unless that point is magically missing (e.g., NMP). In which case, well... GIGO? 😀
Even if this does happen, a
Rte(Exit)_Suftype label indicates a loop route or a US19TrkPit type scenario. In which unlikely case adding a suffix isn't much worse than existing cases like N264_W/R23/R23 or LA29/LA95/LA1174_S./: This is where things are likely to change, where a suffix exists but doesn't start right atendmatch.We're no longer worried about false matches (e.g.
"NY50/67".startswith("NY5")), as those are already excluded viaRoute::label_match. We know our label matches theotherroute.The only reason
suffixis not right atendmatchis because there's a 2nd route in our waypoint label, after the matching text, after the slash, before the suffix.We should be able to safely say the suffix applies to both routes. So let's include it!
If the purpose of suffixes is to reduce the chance of conflicting names, this helps with that:
The 8-line difference can be accounted for by:
What do we get now instead?
Less ambiguity for the win!
That one
Exit/Intersectioncase in the mix is interesting. G6 doesn't get a suffix there.I don't suggest
3+_intersectionbe moved beforeExit/Intersectionthough. That yields anotherAppended region.The only differences in waypointsimplification.log are:
yakra commentedon May 4, 2022
Route::label_match:
if (banner.size())->if (banner.size() && banner[0] != '-')for French departmental "banners"