77#include " ../Waypoint/Waypoint.h"
88#include " ../../templates/contains.cpp"
99
10+ HGVertex* HGEdge::v_array;
11+
1012HGEdge::HGEdge (HighwaySegment *s)
1113{ // initial construction is based on a HighwaySegment
12- written = new char [Args::numthreads];
13- // deleted by HGEdge::detach
14- // we only need to initialize the first element, for master graphs.
15- // the rest will get zeroed out for each subgraph set.
16- written[0 ] = 0 ;
1714 vertex1 = s->waypoint1 ->hashpoint ()->vertex ;
1815 vertex2 = s->waypoint2 ->hashpoint ()->vertex ;
1916 format = simple | collapsed | traveled;
2017 segment_name = s->segment_name ();
21- vertex1->incident_s_edges .push_back (this );
22- vertex2->incident_s_edges .push_back (this );
23- vertex1->incident_c_edges .push_back (this );
24- vertex2->incident_c_edges .push_back (this );
25- vertex1->incident_t_edges .push_back (this );
26- vertex2->incident_t_edges .push_back (this );
18+ vertex1->incident_edges .push_back (this );
19+ vertex2->incident_edges .push_back (this );
20+ vertex1->edge_count ++;
21+ vertex2->edge_count ++;
2722 // canonical segment, used to reference region and list of travelers
2823 // assumption: each edge/segment lives within a unique region
2924 // and a 'multi-edge' would not be able to span regions as there
3025 // would be a required visible waypoint at the border
3126 segment = s;
3227}
3328
34- HGEdge::HGEdge (HGVertex *vertex, unsigned char fmt_mask)
29+ HGEdge::HGEdge (HGVertex *vertex, unsigned char fmt_mask, HGEdge * e1 , HGEdge * e2 )
3530{ // build by collapsing two existing edges around a common hidden vertex
36- written = new char [Args::numthreads];
37- // deleted by HGEdge::detach
38- written[0 ] = 0 ;
31+ c_idx = vertex - v_array;
3932 format = fmt_mask;
40- // we know there are exactly 2 incident edges, as we
41- // checked for that, and we will replace these two
42- // with the single edge we are constructing here...
43- HGEdge *edge1 = 0 ;
44- HGEdge *edge2 = 0 ;
45- if (fmt_mask & collapsed)
46- { // ...in the compressed graph, and/or...
47- edge1 = vertex->incident_c_edges .front ();
48- edge2 = vertex->incident_c_edges .back ();
49- }
50- if (fmt_mask & traveled)
51- { // ...in the traveled graph, as appropriate
52- edge1 = vertex->incident_t_edges .front ();
53- edge2 = vertex->incident_t_edges .back ();
54- }
33+ HGEdge *edge1 = e1 ;
34+ HGEdge *edge2 = e2 ;
5535 // segment names should match as routes should not start or end
5636 // nor should concurrencies begin or end at a hidden point
5737 if (edge1->segment_name != edge2->segment_name )
@@ -103,50 +83,31 @@ HGEdge::HGEdge(HGVertex *vertex, unsigned char fmt_mask)
10383 intermediate_point_string() << " to " << *(vertex2->unique_name) << std::endl;
10484 // std::cout << "DEBUG: new " << str() << std::endl;
10585
86+ // clear format bits of old edges
87+ edge1->format &= ~fmt_mask;
88+ edge2->format &= ~fmt_mask;
10689 // replace edge references at our endpoints with ourself
107- edge1->detach (fmt_mask);
108- edge2->detach (fmt_mask);
109- if (fmt_mask & collapsed)
110- { vertex1->incident_c_edges .push_back (this );
111- vertex2->incident_c_edges .push_back (this );
112- }
113- if (fmt_mask & traveled)
114- { vertex1->incident_t_edges .push_back (this );
115- vertex2->incident_t_edges .push_back (this );
116- }
90+ if (!edge1->format ) edge1->detach ();
91+ if (!edge2->format ) edge2->detach ();
92+ vertex1->incident_edges .push_back (this );
93+ vertex2->incident_edges .push_back (this );
11794}
11895
119- void HGEdge::detach () {return detach (format);}
120- void HGEdge::detach (unsigned char fmt_mask)
96+ void HGEdge::detach ()
12197{ // detach edge from vertices in graph(s) specified in fmt_mask
122- # define DETACH ( v ) \
123- for (std::list <HGEdge*>::iterator e = v.begin (); e != v.end (); e++) \
98+ auto detach = [&](std::vector<HGEdge*>& v) \
99+ { for (std::vector <HGEdge*>::iterator e = v.begin (); e != v.end (); e++) \
124100 if (*e == this ) \
125101 { v.erase (e); \
126102 break ; \
127103 }
128- if (fmt_mask & simple)
129- { DETACH (vertex1->incident_s_edges )
130- DETACH (vertex2->incident_s_edges )
131- }
132- if (fmt_mask & collapsed)
133- { DETACH (vertex1->incident_c_edges )
134- DETACH (vertex2->incident_c_edges )
135- }
136- if (fmt_mask & traveled)
137- { DETACH (vertex1->incident_t_edges )
138- DETACH (vertex2->incident_t_edges )
139- }
140- #undef DETACH
141- format &= ~fmt_mask;
142- if (!format)
143- { delete[] written;
144- delete this ;
145- }
104+ };
105+ detach (vertex1->incident_edges );
106+ detach (vertex2->incident_edges );
146107}
147108
148109// write line to tmg collapsed edge file
149- void HGEdge::collapsed_tmg_line (std::ofstream& file, char * fstr, unsigned int threadnum, std::list <HighwaySystem*> *systems)
110+ void HGEdge::collapsed_tmg_line (std::ofstream& file, char * fstr, unsigned int threadnum, std::vector <HighwaySystem*> *systems)
150111{ file << vertex1->c_vertex_num [threadnum] << ' ' << vertex2->c_vertex_num [threadnum] << ' ' ;
151112 segment->write_label (file, systems);
152113 for (HGVertex *intermediate : intermediate_points)
@@ -157,7 +118,7 @@ void HGEdge::collapsed_tmg_line(std::ofstream& file, char* fstr, unsigned int th
157118}
158119
159120// write line to tmg traveled edge file
160- void HGEdge::traveled_tmg_line (std::ofstream& file, char * fstr, unsigned int threadnum, std::list <HighwaySystem*> *systems, bool trav, char * code)
121+ void HGEdge::traveled_tmg_line (std::ofstream& file, char * fstr, unsigned int threadnum, std::vector <HighwaySystem*> *systems, bool trav, char * code)
161122{ file << vertex1->t_vertex_num [threadnum] << ' ' << vertex2->t_vertex_num [threadnum] << ' ' ;
162123 segment->write_label (file, systems);
163124 file << ' ' << (trav ? segment->clinchedby_code (code, threadnum) : " 0" );
@@ -169,7 +130,7 @@ void HGEdge::traveled_tmg_line(std::ofstream& file, char* fstr, unsigned int thr
169130}
170131
171132/* line appropriate for a tmg collapsed edge file, with debug info
172- std::string HGEdge::debug_tmg_line(std::list <HighwaySystem*> *systems, unsigned int threadnum)
133+ std::string HGEdge::debug_tmg_line(std::vector <HighwaySystem*> *systems, unsigned int threadnum)
173134{ std::string line = std::to_string(vertex1->c_vertex_num[threadnum]) + " [" + *vertex1->unique_name + "] " \
174135 + std::to_string(vertex2->c_vertex_num[threadnum]) + " [" + *vertex2->unique_name + "] " + label(systems);
175136 char fstr[58];
0 commit comments