You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
traveled graphs: record only relevant travelers #199
@jteresco noted that many of our graphs will have lots of segments with very few travelers, meaning many 0 digits, and floated the idea of saving space in traveled graph files. #196 (comment)
I considered run-length encoding of 0s, ultimately dropping the idea on simplicity grounds. #196 (comment)
An idea that will help out in subgraphs is to only record travelers who've clinched at least one segment contained in the graph. For example:
in TX, right now there are only 129 travelers, meaning we can use 33 characters per clinchedby_code, instead of 60.
in PE, right now there are only 17 travelers, meaning we can use 5 characters per clinchedby_code, instead of 60.
Advantages:
Requires no changes to the TMG 2.0 traveled"specification", keeping the hex clinchedby_code encoded simply & intuitively.
Limitations:
The more travelers we have in a dataset, the smaller the savings, all the way up to tm-master-traveled.tmg, with no savings at all (assuming each traveler has at least one segment traveled).
Disadvantages:
Using the full traveler list for all graphs, we can potentially save time (how much?) by generating clinchedby_codes during graph setup, and looking them up, instead of regenerating, for all subgraphs.
With subgraphs using different traveler lists and thus different clinchedby_codes for each segment, this is no longer an option.
Implementation:
We'd have to reassign traveler numbers for each graph.
Python, with graphs generated one at a time, is no big deal. Just reuse TravelerList.traveler_num.
C++, with multi-threaded subgraph generation, is more complicated.
Either create a TravelerList->traveler_num hash table for each graph, or
Better yet (faster/less complicated), store TravelerList::traveler_num as an array of numthreads elements, and reassign for each graph.
In this last example, note the absence of travelers listed at the end, and the extra space between the label and the shaping points, where the clinchedby_code would otherwise go.
Something to watch out for when writing a routine that reads these files. @jteresco, thoughts?
Simply having two spaces between the label & shapers can be less than straightforward, depending on the specifics of the language one is working with. For example, take
4 2 N5 1.025665 10.859213
In Python .split()ing the line yields 6 fields, the 4th of which has zero length. SFSG...
In C++, we can't use strtok, as that will result in 5 fields. We'll have to find a different solution.
A single 0 at first made me bristle a bit, as that to me suggests 1-4 travelers.
But is it really so bad? We're already dealing with cases where there are fewer travelers than the array can store (1/4 in MEX-CAM; 5/8 in MEX-QROO).
Another option would be to store the number of travelers in the header:
TMG 2.0 traveled
6 4 0
Advantages: Marginally less storage space in zero-traveler graphs. We know how many travelers there are before reading the list in the last line; this could potentially simplify things down the road.
Disadvantages:
It's still a tiny bit more complicated to code: If num_travelers == 0, don't attempt to read a hex code.
This means a change to the TMG 2.0 traveled "specification", making the files the the students have obsolete, as well as, potentially, code to read & process the files.
To just give a straight answer to your question:
Does it make sense to record a 0 there when there are no travelers, just to simplify reading?
Yes.
This would simplify reading, and as such, makes sense.
It's effectively just another normal case of extra bits at the end of the array that aren't used by any traveler.
I almost went & implemented the single-0 hex code for zero-traveler graphs, but had one thought...
Normally, a single 0 would mean one to four travelers. The single line at the end of the file lists who they are, and thus gives us the actual number of travelers: ABW-region-traveled.tmg: bejacob dharwood froggie kjslaughter AZE-region-traveled.tmg: ua747sp
Right now, I'm not writing a terminating line feed after the list of traveler names. Meaning, in cases where there are no travelers, there's one single line feed after the list of edges. Thus many text editors would interpret the final edge as being the final line.
Seems a Good Thing would be to add in that one final line feed; that way, all traveled graphs would still contain the "line" listing all the travelers, even if it's a blank one listing nobody. @jteresco, thoughts as to implementation, for HDX and/or whatever else?
I'd like to keep at least the blank line there. There's also minimal cost and a small potential benefit for those parsing the file to start the list of travelers with a traveler count. I think there's also a small potential benefit for that number of users and maybe even the user list to come before the edges that contain that info. The main downside to me is that it is a more significant deviation from the previous tmg file formats.
Agreed. Let's definitely do that. (Here, I'm interpreting the word "there" to mean "in the file", though not necessarily any specific place therein yet.)
There's also minimal cost and a small potential benefit for those parsing the file to start the list of travelers with a traveler count.
Not strictly necessary as I see it; when we encounter a string of n hex characters, we know we need an array of 4*n travelers.
But I agree; minimal cost and a small potential benefit.
Not knowing the number of travelers in advance, we'd have to do things a bit differently when parsing the first line, complicates things a bit. Having the number of travelers would simplify.
I think there's also a small potential benefit for that number of users and maybe even the user list to come before the edges that contain that info. The main downside to me is that it is a more significant deviation from the previous tmg file formats.
How about recording the number of travelers in the second header line as noted above, after the number of vertices & edges? (Minor drawback here is slightly different files from what you & your students already have. Existing code to read traveled TMGs may need to be changed.)
The user list itself could stay at the end.
IMO this makes parsing the file more convenient, while minimizing the deviation from the previous tmg file formats. The lines for vertices and edges would still be in the same place relative to the beginning of the file.
Shall we still keep the single-0 hex code for zero-traveler graphs, to simplify reading the edge lines?
Otherwise, we'd have to account for two spaces between the edge label and shaping points (or a trailing space on lines with no shapers), which could be an annoyance.
Use a single-0 hex code for each edge in zero-traveler graphs.
Arguably a more clear way to say "The hex code here actually stores no data; just ignore it" than having two whitespace characters between the edge name & shaping points.
To do or not to do?:
Add the number of travelers to the second header line. Pro: Knowing the traveler count in advance simplifies setup of the traveler array (or however we choose to implement things) when parsing the first hex code. Con: Slight difference to how things are done in the files we already have out there.
I don't see any drawback to keeping the user list at the end of the file. Users would simply be anonymous while parsing the edges, and then have their names assigned when finished.
Another idea that just occurred to me: Bypass writing a traveled graph altogether in cases where the graph has no travelers.
I'm not sure how much I like this, though...
Slight pain to implement in Python.
A little bit more of a pain to implement in C++.
Potential to confuse students & other users when looking for a certain graph in the HDX or download page -- "Why is there no GNQ-region-traveled.tmg?"
Could needlessly complicate setting up the revamped graph download page.
It's probably best for consistency & simplicity's sake to include all three formats for every graph, even in cases where there are no travelers.
Activity
[-]traveled graphs: record only relevant travlelers[/-][+]traveled graphs: record only relevant travelers[/+]yakra commentedon Mar 30, 2019
On BiggaTomato, this takes only 4.7s (3%) longer than the code in #201.
Some stats:
Some examples:
MEX-QROO-region-traveled.tmg has 5 travelers:
MEX-CAM-region-traveled.tmg has 1 traveler:
GNQ-region-traveled.tmg has no travelers:
In this last example, note the absence of travelers listed at the end, and the extra space between the label and the shaping points, where the clinchedby_code would otherwise go.
Something to watch out for when writing a routine that reads these files.
@jteresco, thoughts?
traveled graphs: record only relevant travelers
jteresco commentedon Mar 31, 2019
Does it make sense to record a 0 there when there are no travelers, just to simplify reading?
yakra commentedon Mar 31, 2019
Bear with me; thinking this thru out loud...
.split()ing the line yields 6 fields, the 4th of which has zero length. SFSG...strtok, as that will result in 5 fields. We'll have to find a different solution.0at first made me bristle a bit, as that to me suggests 1-4 travelers.But is it really so bad? We're already dealing with cases where there are fewer travelers than the array can store (1/4 in MEX-CAM; 5/8 in MEX-QROO).
To just give a straight answer to your question:
Yes.
This would simplify reading, and as such, makes sense.
It's effectively just another normal case of extra bits at the end of the array that aren't used by any traveler.
yakra commentedon Apr 7, 2019
I almost went & implemented the single-
0hex code for zero-traveler graphs, but had one thought...Normally, a single
0would mean one to four travelers. The single line at the end of the file lists who they are, and thus gives us the actual number of travelers:ABW-region-traveled.tmg:
bejacob dharwood froggie kjslaughterAZE-region-traveled.tmg:
ua747spRight now, I'm not writing a terminating line feed after the list of traveler names. Meaning, in cases where there are no travelers, there's one single line feed after the list of edges. Thus many text editors would interpret the final edge as being the final line.
Seems a Good Thing would be to add in that one final line feed; that way, all traveled graphs would still contain the "line" listing all the travelers, even if it's a blank one listing nobody.
@jteresco, thoughts as to implementation, for HDX and/or whatever else?
jteresco commentedon Apr 8, 2019
I'd like to keep at least the blank line there. There's also minimal cost and a small potential benefit for those parsing the file to start the list of travelers with a traveler count. I think there's also a small potential benefit for that number of users and maybe even the user list to come before the edges that contain that info. The main downside to me is that it is a more significant deviation from the previous tmg file formats.
yakra commentedon Apr 8, 2019
Agreed. Let's definitely do that. (Here, I'm interpreting the word "there" to mean "in the file", though not necessarily any specific place therein yet.)
Not strictly necessary as I see it; when we encounter a string of n hex characters, we know we need an array of 4*n travelers.
But I agree; minimal cost and a small potential benefit.
Not knowing the number of travelers in advance, we'd have to do things a bit differently when parsing the first line, complicates things a bit. Having the number of travelers would simplify.
How about recording the number of travelers in the second header line as noted above, after the number of vertices & edges? (Minor drawback here is slightly different files from what you & your students already have. Existing code to read traveled TMGs may need to be changed.)
The user list itself could stay at the end.
IMO this makes parsing the file more convenient, while minimizing the deviation from the previous tmg file formats. The lines for vertices and edges would still be in the same place relative to the beginning of the file.
Shall we still keep the single-
0hex code for zero-traveler graphs, to simplify reading the edge lines?Otherwise, we'd have to account for two spaces between the edge label and shaping points (or a trailing space on lines with no shapers), which could be an annoyance.
yakra commentedon Apr 11, 2019
The 3 steps I see doing to get this going:
Definitely doDONE:Most likely do:
0hex code for each edge in zero-traveler graphs.Arguably a more clear way to say "The hex code here actually stores no data; just ignore it" than having two whitespace characters between the edge name & shaping points.
To do or not to do?:
Pro: Knowing the traveler count in advance simplifies setup of the traveler array (or however we choose to implement things) when parsing the first hex code.
Con: Slight difference to how things are done in the files we already have out there.
Another idea that just occurred to me: Bypass writing a traveled graph altogether in cases where the graph has no travelers.
I'm not sure how much I like this, though...
It's probably best for consistency & simplicity's sake to include all three formats for every graph, even in cases where there are no travelers.
finalizing traveled graphs
yakra commentedon Apr 23, 2019
single
0hex codes and # of travelers in header line implemented.Python: yakra#84
C++: 652efe3
C++: finalizing traveled graphs