Skip to content

Commit

Permalink
vtF3
Browse files Browse the repository at this point in the history
edge labels: instead of std::string construction & copying, just insert its components into the ofstream
TMGf3 bugfix
  • Loading branch information
yakra committed Jan 14, 2021
1 parent d2b66ce commit 94130de
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
23 changes: 13 additions & 10 deletions siteupdate/cplusplus/classes/GraphGeneration/HGEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,23 @@ HGEdge::~HGEdge()
}

// compute an edge label, optionally resticted by systems
std::string HGEdge::label(std::list<HighwaySystem*> *systems)
{ std::string the_label;
void HGEdge::write_label(std::ofstream& file, std::list<HighwaySystem*> *systems)
{ bool write_comma = 0;
for (std::pair<std::string, HighwaySystem*> &ns : route_names_and_systems)
{ // test whether system in systems
if (!systems || contains(*systems, ns.second))
if (the_label.empty())
the_label = ns.first;
else the_label += "," + ns.first;
if (!write_comma)
{ file << ns.first;
write_comma = 1;
}
else file << "," << ns.first;
}
return the_label;
}

// write line to tmg collapsed edge file
void HGEdge::collapsed_tmg_line(std::ofstream& file, char* fstr, unsigned int threadnum, std::list<HighwaySystem*> *systems)
{ file << vertex1->c_vertex_num[threadnum] << ' ' << vertex2->c_vertex_num[threadnum] << ' ' << label(systems);
{ file << vertex1->c_vertex_num[threadnum] << ' ' << vertex2->c_vertex_num[threadnum] << ' ';
write_label(file, systems);
for (HGVertex *intermediate : intermediate_points)
{ sprintf(fstr, " %.15g %.15g", intermediate->lat, intermediate->lng);
file << fstr;
Expand All @@ -225,7 +227,8 @@ void HGEdge::collapsed_tmg_line(std::ofstream& file, char* fstr, unsigned int th

// write line to tmg traveled edge file
void HGEdge::traveled_tmg_line(std::ofstream& file, char* fstr, unsigned int threadnum, std::list<HighwaySystem*> *systems, std::list<TravelerList*> *traveler_lists)
{ file << vertex1->t_vertex_num[threadnum] << ' ' << vertex2->t_vertex_num[threadnum] << ' ' << label(systems);
{ file << vertex1->t_vertex_num[threadnum] << ' ' << vertex2->t_vertex_num[threadnum] << ' ';
write_label(file, systems);
file << ' ' << segment->clinchedby_code(traveler_lists, threadnum);
for (HGVertex *intermediate : intermediate_points)
{ sprintf(fstr, " %.15g %.15g", intermediate->lat, intermediate->lng);
Expand All @@ -234,7 +237,7 @@ void HGEdge::traveled_tmg_line(std::ofstream& file, char* fstr, unsigned int thr
file << '\n';
}

// line appropriate for a tmg collapsed edge file, with debug info
/* line appropriate for a tmg collapsed edge file, with debug info
std::string HGEdge::debug_tmg_line(std::list<HighwaySystem*> *systems, unsigned int threadnum)
{ std::string line = std::to_string(vertex1->c_vertex_num[threadnum]) + " [" + *vertex1->unique_name + "] " \
+ std::to_string(vertex2->c_vertex_num[threadnum]) + " [" + *vertex2->unique_name + "] " + label(systems);
Expand All @@ -244,7 +247,7 @@ std::string HGEdge::debug_tmg_line(std::list<HighwaySystem*> *systems, unsigned
line += " [" + *intermediate->unique_name + fstr;
}
return line;
}
}*/

// printable string for this edge
std::string HGEdge::str()
Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/classes/GraphGeneration/HGEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class HGEdge
~HGEdge();

void detach(unsigned char);
std::string label(std::list<HighwaySystem*> *);
void write_label(std::ofstream&, std::list<HighwaySystem*> *);
void collapsed_tmg_line(std::ofstream&, char*, unsigned int, std::list<HighwaySystem*>*);
void traveled_tmg_line (std::ofstream&, char*, unsigned int, std::list<HighwaySystem*>*, std::list<TravelerList*>*);
std::string debug_tmg_line(std::list<HighwaySystem*> *, unsigned int);
Expand Down
12 changes: 8 additions & 4 deletions siteupdate/cplusplus/classes/GraphGeneration/HighwayGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ void HighwayGraph::write_master_graphs_tmg(std::vector<GraphListEntry> &graph_ve
{ for (HGEdge *e : wv.second->incident_s_edges)
if (!e->s_written)
{ e->s_written = 1;
simplefile << e->vertex1->s_vertex_num[0] << ' ' << e->vertex2->s_vertex_num[0] << ' ' << e->label(0) << '\n';
simplefile << e->vertex1->s_vertex_num[0] << ' ' << e->vertex2->s_vertex_num[0] << ' ';
e->write_label(simplefile, 0);
simplefile << '\n';
}
// write edges if vertex is visible...
if (wv.second->visibility >= 1)
Expand Down Expand Up @@ -408,9 +410,11 @@ void HighwayGraph::write_subgraphs_tmg
}
// write edges
for (HGEdge *e : mse)
simplefile << e->vertex1->s_vertex_num[threadnum] << ' '
<< e->vertex2->s_vertex_num[threadnum] << ' '
<< e->label(graph_vector[graphnum].systems) << '\n';
{ simplefile << e->vertex1->s_vertex_num[threadnum] << ' '
<< e->vertex2->s_vertex_num[threadnum] << ' ';
e->write_label(simplefile, graph_vector[graphnum].systems);
simplefile << '\n';
}
char fstr[57];
for (HGEdge *e : mce)
e->collapsed_tmg_line(collapfile, fstr, threadnum, graph_vector[graphnum].systems);
Expand Down

0 comments on commit 94130de

Please sign in to comment.