diff --git a/siteupdate/cplusplus/.gitignore b/siteupdate/cplusplus/.gitignore new file mode 100644 index 00000000..4789733f --- /dev/null +++ b/siteupdate/cplusplus/.gitignore @@ -0,0 +1,7 @@ +graphs +logs +nmp_merged +stats + +siteupdate +TravelMapping.sql diff --git a/siteupdate/cplusplus/classes/GraphGeneration/GraphListEntry.cpp b/siteupdate/cplusplus/classes/GraphGeneration/GraphListEntry.cpp index 345d6097..163fc0ac 100644 --- a/siteupdate/cplusplus/classes/GraphGeneration/GraphListEntry.cpp +++ b/siteupdate/cplusplus/classes/GraphGeneration/GraphListEntry.cpp @@ -7,6 +7,7 @@ class GraphListEntry std::string descr; unsigned int vertices; unsigned int edges; + unsigned int travelers; char form; std::string format(); char cat; @@ -18,9 +19,10 @@ class GraphListEntry PlaceRadius *placeradius; std::string tag(); - GraphListEntry(std::string r, std::string d, char f, char c, std::list *rg, std::list *sys, PlaceRadius *pr) + GraphListEntry(std::string r, std::string d, unsigned int t, char f, char c, std::list *rg, std::list *sys, PlaceRadius *pr) { root = r; descr = d; + travelers = t; form = f; cat = c; diff --git a/siteupdate/cplusplus/classes/GraphGeneration/HGEdge.cpp b/siteupdate/cplusplus/classes/GraphGeneration/HGEdge.cpp index fc3f4848..8aa7ae5a 100644 --- a/siteupdate/cplusplus/classes/GraphGeneration/HGEdge.cpp +++ b/siteupdate/cplusplus/classes/GraphGeneration/HGEdge.cpp @@ -224,7 +224,7 @@ std::string HGEdge::label(std::list *systems) // line appropriate for a tmg collapsed edge file std::string HGEdge::collapsed_tmg_line(std::list *systems, unsigned int threadnum) { std::string line = std::to_string(vertex1->c_vertex_num[threadnum]) + " " + std::to_string(vertex2->c_vertex_num[threadnum]) + " " + label(systems); - char fstr[43]; + char fstr[57]; for (HGVertex *intermediate : intermediate_points) { sprintf(fstr, " %.15g %.15g", intermediate->lat, intermediate->lng); line += fstr; @@ -236,7 +236,7 @@ std::string HGEdge::collapsed_tmg_line(std::list *systems, unsig std::string HGEdge::traveled_tmg_line(std::list *systems, std::list *traveler_lists, unsigned int threadnum) { std::string line = std::to_string(vertex1->t_vertex_num[threadnum]) + " " + std::to_string(vertex2->t_vertex_num[threadnum]) + " " + label(systems); line += " " + segment->clinchedby_code(traveler_lists, threadnum); - char fstr[43]; + char fstr[57]; for (HGVertex *intermediate : intermediate_points) { sprintf(fstr, " %.15g %.15g", intermediate->lat, intermediate->lng); line += fstr; @@ -248,7 +248,7 @@ std::string HGEdge::traveled_tmg_line(std::list *systems, std::l std::string HGEdge::debug_tmg_line(std::list *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); - char fstr[44]; + char fstr[58]; for (HGVertex *intermediate : intermediate_points) { sprintf(fstr, "] %.15g %.15g", intermediate->lat, intermediate->lng); line += " [" + *intermediate->unique_name + fstr; @@ -274,7 +274,7 @@ std::string HGEdge::str() std::string HGEdge::intermediate_point_string() { if (intermediate_points.empty()) return " None"; std::string line = ""; - char fstr[42]; + char fstr[56]; for (HGVertex *i : intermediate_points) { sprintf(fstr, "%.15g %.15g", i->lat, i->lng); line += " [" + *i->unique_name + "] " + fstr; diff --git a/siteupdate/cplusplus/classes/GraphGeneration/HighwayGraph.cpp b/siteupdate/cplusplus/classes/GraphGeneration/HighwayGraph.cpp index 2032f8b7..99706dc1 100644 --- a/siteupdate/cplusplus/classes/GraphGeneration/HighwayGraph.cpp +++ b/siteupdate/cplusplus/classes/GraphGeneration/HighwayGraph.cpp @@ -383,7 +383,7 @@ class HighwayGraph // number waypoint entries as we go int s_vertex_num = 0; for (std::pair wv : vertices) - { char fstr[42]; + { char fstr[56]; sprintf(fstr, "%.15g %.15g", wv.second->lat, wv.second->lng); tmgfile << *(wv.second->unique_name) << ' ' << fstr << '\n'; wv.second->s_vertex_num[0] = s_vertex_num; @@ -426,7 +426,7 @@ class HighwayGraph int c_vertex_num = 0; for (std::pair wv : vertices) if (wv.second->visibility == 2) - { char fstr[42]; + { char fstr[56]; sprintf(fstr, "%.15g %.15g", wv.second->lat, wv.second->lng); tmgfile << *(wv.second->unique_name) << ' ' << fstr << '\n'; wv.second->c_vertex_num[threadnum] = c_vertex_num; @@ -462,7 +462,7 @@ class HighwayGraph int t_vertex_num = 0; for (std::pair wv : vertices) if (wv.second->visibility >= 1) - { char fstr[42]; + { char fstr[56]; sprintf(fstr, "%.15g %.15g", wv.second->lat, wv.second->lng); tmgfile << *(wv.second->unique_name) << ' ' << fstr << '\n'; wv.second->t_vertex_num[threadnum] = t_vertex_num; @@ -490,6 +490,7 @@ class HighwayGraph tmgfile.close(); mtptr->vertices = num_traveled_vertices(); mtptr->edges = num_traveled_edges; + mtptr->travelers = traveler_lists.size(); } // write a subset of the data, @@ -530,7 +531,7 @@ class HighwayGraph unsigned int cv = 0; unsigned int tv = 0; for (HGVertex *v : mv) - { char fstr[43]; + { char fstr[57]; sprintf(fstr, " %.15g %.15g", v->lat, v->lng); // all vertices for simple graph simplefile << *(v->unique_name) << fstr << '\n'; diff --git a/siteupdate/cplusplus/classes/GraphGeneration/PlaceRadius.cpp b/siteupdate/cplusplus/classes/GraphGeneration/PlaceRadius.cpp index 71f6515e..056c4b9c 100644 --- a/siteupdate/cplusplus/classes/GraphGeneration/PlaceRadius.cpp +++ b/siteupdate/cplusplus/classes/GraphGeneration/PlaceRadius.cpp @@ -22,10 +22,10 @@ class PlaceRadius bool contains_vertex(HGVertex *v) { /* return whether v's coordinates are within this area */ // convert to radians to compute distance - double rlat1 = lat * Waypoint::pi/180; - double rlng1 = lng * Waypoint::pi/180; - double rlat2 = v->lat * Waypoint::pi/180; - double rlng2 = v->lng * Waypoint::pi/180; + double rlat1 = lat * (Waypoint::pi/180); + double rlng1 = lng * (Waypoint::pi/180); + double rlat2 = v->lat * (Waypoint::pi/180); + double rlng2 = v->lng * (Waypoint::pi/180); double ans = acos(cos(rlat1)*cos(rlng1)*cos(rlat2)*cos(rlng2) +\ cos(rlat1)*sin(rlng1)*cos(rlat2)*sin(rlng2) +\ diff --git a/siteupdate/cplusplus/classes/Route/Route.cpp b/siteupdate/cplusplus/classes/Route/Route.cpp index 29354b9d..44596331 100644 --- a/siteupdate/cplusplus/classes/Route/Route.cpp +++ b/siteupdate/cplusplus/classes/Route/Route.cpp @@ -170,11 +170,9 @@ std::string Route::name_no_abbrev() double Route::clinched_by_traveler(TravelerList *t) { double miles = 0; for (HighwaySegment *s : segment_list) - for (TravelerList *tl : s->clinched_by) - if (t == tl) - { miles += s->length(); - break; - } + { std::unordered_set::iterator t_found = s->clinched_by.find(t); + if (t_found != s->clinched_by.end()) miles += s->length(); + } return miles; } diff --git a/siteupdate/cplusplus/classes/TravelerList/userlog.cpp b/siteupdate/cplusplus/classes/TravelerList/userlog.cpp index 969a7e7c..f1f0e014 100644 --- a/siteupdate/cplusplus/classes/TravelerList/userlog.cpp +++ b/siteupdate/cplusplus/classes/TravelerList/userlog.cpp @@ -15,7 +15,7 @@ void userlog log << "Overall by region: (each line reports active only then active+preview)\n"; std::list travregions; - for (std::pair rm : active_preview_mileage_by_region) + for (std::pair &rm : active_preview_mileage_by_region) travregions.push_back(rm.first); travregions.sort(sort_regions_by_code); for (Region *region : travregions) @@ -59,7 +59,7 @@ void userlog { if (h->mileage_by_region.size() > 1) log << "System " << h->systemname << " by region:\n"; std::list sysregions; - for (std::pair rm : h->mileage_by_region) + for (std::pair &rm : h->mileage_by_region) sysregions.push_back(rm.first); sysregions.sort(sort_regions_by_code); for (Region *region : sysregions) @@ -83,11 +83,11 @@ void userlog { std::unordered_map system_con_umap; unsigned int num_con_rtes_clinched = 0; log << "System " << h->systemname << " by route (traveled routes only):\n"; - for (std::list::iterator cr = h->con_route_list.begin(); cr != h->con_route_list.end(); cr++) + for (ConnectedRoute &cr : h->con_route_list) { double con_total_miles = 0; double con_clinched_miles = 0; std::string to_write = ""; - for (Route *r : cr->roots) + for (Route *r : cr.roots) { // find traveled mileage on this by this user double miles = r->clinched_by_traveler(this); if (miles) @@ -103,10 +103,10 @@ void userlog con_total_miles += r->mileage; } if (con_clinched_miles) - { system_con_umap[&*cr] = con_clinched_miles; + { system_con_umap[&cr] = con_clinched_miles; char clinched = '0'; /*yDEBUG - if (traveler_name == "oscar" && cr->system->systemname == "usaus" && cr->route == "US85") + if (traveler_name == "oscar" && cr.system->systemname == "usaus" && cr.route == "US85") printf("\nOscar on US85:\ncon_clinched_miles = %.17f\n con_total_miles = %.17f\n", con_clinched_miles, con_total_miles);//*/ if (con_clinched_miles == con_total_miles) @@ -115,11 +115,11 @@ void userlog } sprintf(fstr, "%.15g", con_clinched_miles); if (!strchr(fstr, '.')) strcat(fstr, ".0"); - clin_db_val->add_ccr("('" + cr->roots[0]->root + "','" + traveler_name + + clin_db_val->add_ccr("('" + cr.roots[0]->root + "','" + traveler_name + "','" + std::string(fstr) + "','" + clinched + "')"); - log << cr->readable_name() << ": " << format_clinched_mi(con_clinched_miles, con_total_miles) << '\n'; - if (cr->roots.size() == 1) - log << " (" << cr->roots[0]->readable_name() << " only)\n"; + log << cr.readable_name() << ": " << format_clinched_mi(con_clinched_miles, con_total_miles) << '\n'; + if (cr.roots.size() == 1) + log << " (" << cr.roots[0]->readable_name() << " only)\n"; else log << to_write << '\n'; } } diff --git a/siteupdate/cplusplus/classes/Waypoint/Waypoint.cpp b/siteupdate/cplusplus/classes/Waypoint/Waypoint.cpp index a52441d6..88d4d478 100644 --- a/siteupdate/cplusplus/classes/Waypoint/Waypoint.cpp +++ b/siteupdate/cplusplus/classes/Waypoint/Waypoint.cpp @@ -82,10 +82,10 @@ double Waypoint::distance_to(Waypoint *other) including the factor defined by the CHM project to adjust for unplotted curves in routes */ // convert to radians - double rlat1 = lat * pi/180; - double rlng1 = lng * pi/180; - double rlat2 = other->lat * pi/180; - double rlng2 = other->lng * pi/180; + double rlat1 = lat * (pi/180); + double rlng1 = lng * (pi/180); + double rlat2 = other->lat * (pi/180); + double rlng2 = other->lng * (pi/180); double ans = acos(cos(rlat1)*cos(rlng1)*cos(rlat2)*cos(rlng2) +\ cos(rlat1)*sin(rlng1)*cos(rlat2)*sin(rlng2) +\ @@ -97,12 +97,12 @@ double Waypoint::angle(Waypoint *pred, Waypoint *succ) { /* return the angle in degrees formed by the waypoints between the line from pred to self and self to succ */ // convert to radians - double rlatself = lat * pi/180; - double rlngself = lng * pi/180; - double rlatpred = pred->lat * pi/180; - double rlngpred = pred->lng * pi/180; - double rlatsucc = succ->lat * pi/180; - double rlngsucc = succ->lng * pi/180; + double rlatself = lat * (pi/180); + double rlngself = lng * (pi/180); + double rlatpred = pred->lat * (pi/180); + double rlngpred = pred->lng * (pi/180); + double rlatsucc = succ->lat * (pi/180); + double rlngsucc = succ->lng * (pi/180); double x0 = cos(rlngpred)*cos(rlatpred); double x1 = cos(rlngself)*cos(rlatself); diff --git a/siteupdate/cplusplus/functions/graph_generation.cpp b/siteupdate/cplusplus/functions/graph_generation.cpp index 34070999..b94d2579 100644 --- a/siteupdate/cplusplus/functions/graph_generation.cpp +++ b/siteupdate/cplusplus/functions/graph_generation.cpp @@ -22,9 +22,12 @@ if (args.skipgraphs || args.errorcheck) else { list *regions; list *systems; - graph_vector.emplace_back("tm-master", "All Travel Mapping Data", 's', 'M', (list*)0, (list*)0, (PlaceRadius*)0); - graph_vector.emplace_back("tm-master", "All Travel Mapping Data", 'c', 'M', (list*)0, (list*)0, (PlaceRadius*)0); - graph_vector.emplace_back("tm-master", "All Travel Mapping Data", 't', 'M', (list*)0, (list*)0, (PlaceRadius*)0); + graph_vector.emplace_back("tm-master", "All Travel Mapping Data", 0, + 's', 'M', (list*)0, (list*)0, (PlaceRadius*)0); + graph_vector.emplace_back("tm-master", "All Travel Mapping Data", 0, + 'c', 'M', (list*)0, (list*)0, (PlaceRadius*)0); + graph_vector.emplace_back("tm-master", "All Travel Mapping Data", traveler_lists.size(), + 't', 'M', (list*)0, (list*)0, (PlaceRadius*)0); /*#ifdef threading_enabled if (args.numthreads <= 1) @@ -75,11 +78,11 @@ else { list *regions; // add entries to graph_vector for (PlaceRadius &a : area_list) - { graph_vector.emplace_back(a.base + to_string(a.r) + "-area", a.place + " (" + to_string(a.r) + " mi radius)", + { graph_vector.emplace_back(a.base + to_string(a.r) + "-area", a.place + " (" + to_string(a.r) + " mi radius)", 0, 's', 'a', (list*)0, (list*)0, &a); - graph_vector.emplace_back(a.base + to_string(a.r) + "-area", a.place + " (" + to_string(a.r) + " mi radius)", + graph_vector.emplace_back(a.base + to_string(a.r) + "-area", a.place + " (" + to_string(a.r) + " mi radius)", 0, 'c', 'a', (list*)0, (list*)0, &a); - graph_vector.emplace_back(a.base + to_string(a.r) + "-area", a.place + " (" + to_string(a.r) + " mi radius)", + graph_vector.emplace_back(a.base + to_string(a.r) + "-area", a.place + " (" + to_string(a.r) + " mi radius)", traveler_lists.size(), 't', 'a', (list*)0, (list*)0, &a); } // write new graph_vector entries to disk @@ -114,11 +117,11 @@ else { list *regions; { if (region.active_preview_mileage == 0) continue; regions = new list(1, ®ion); // deleted on termination of program - graph_vector.emplace_back(region.code + "-region", region.name + " (" + region.type + ")", + graph_vector.emplace_back(region.code + "-region", region.name + " (" + region.type + ")", 0, 's', 'r', regions, (list*)0, (PlaceRadius*)0); - graph_vector.emplace_back(region.code + "-region", region.name + " (" + region.type + ")", + graph_vector.emplace_back(region.code + "-region", region.name + " (" + region.type + ")", 0, 'c', 'r', (list*)0, (list*)0, (PlaceRadius*)0); - graph_vector.emplace_back(region.code + "-region", region.name + " (" + region.type + ")", + graph_vector.emplace_back(region.code + "-region", region.name + " (" + region.type + ")", traveler_lists.size(), 't', 'r', (list*)0, (list*)0, (PlaceRadius*)0); } // write new graph_vector entries to disk @@ -161,11 +164,11 @@ else { list *regions; if (h) { systems = new list(1, h); // deleted on termination of program - graph_vector.emplace_back(h->systemname + "-system", h->systemname + " (" + h->fullname + ")", + graph_vector.emplace_back(h->systemname + "-system", h->systemname + " (" + h->fullname + ")", 0, 's', 's', (list*)0, systems, (PlaceRadius*)0); - graph_vector.emplace_back(h->systemname + "-system", h->systemname + " (" + h->fullname + ")", + graph_vector.emplace_back(h->systemname + "-system", h->systemname + " (" + h->fullname + ")", 0, 'c', 's', (list*)0, (list*)0, (PlaceRadius*)0); - graph_vector.emplace_back(h->systemname + "-system", h->systemname + " (" + h->fullname + ")", + graph_vector.emplace_back(h->systemname + "-system", h->systemname + " (" + h->fullname + ")", traveler_lists.size(), 't', 's', (list*)0, (list*)0, (PlaceRadius*)0); } } @@ -216,9 +219,12 @@ else { list *regions; { systems->push_back(h); break; } - graph_vector.emplace_back(fields[1], fields[0], 's', 'S', (list*)0, systems, (PlaceRadius*)0); - graph_vector.emplace_back(fields[1], fields[0], 'c', 'S', (list*)0, (list*)0, (PlaceRadius*)0); - graph_vector.emplace_back(fields[1], fields[0], 't', 'S', (list*)0, (list*)0, (PlaceRadius*)0); + graph_vector.emplace_back(fields[1], fields[0], 0, + 's', 'S', (list*)0, systems, (PlaceRadius*)0); + graph_vector.emplace_back(fields[1], fields[0], 0, + 'c', 'S', (list*)0, (list*)0, (PlaceRadius*)0); + graph_vector.emplace_back(fields[1], fields[0], traveler_lists.size(), + 't', 'S', (list*)0, (list*)0, (PlaceRadius*)0); delete[] cline; } file.close(); @@ -267,9 +273,12 @@ else { list *regions; { regions->push_back(&r); break; } - graph_vector.emplace_back(fields[1], fields[0], 's', 'R', regions, (list*)0, (PlaceRadius*)0); - graph_vector.emplace_back(fields[1], fields[0], 'c', 'R', (list*)0, (list*)0, (PlaceRadius*)0); - graph_vector.emplace_back(fields[1], fields[0], 't', 'R', (list*)0, (list*)0, (PlaceRadius*)0); + graph_vector.emplace_back(fields[1], fields[0], 0, + 's', 'R', regions, (list*)0, (PlaceRadius*)0); + graph_vector.emplace_back(fields[1], fields[0], 0, + 'c', 'R', (list*)0, (list*)0, (PlaceRadius*)0); + graph_vector.emplace_back(fields[1], fields[0], traveler_lists.size(), + 't', 'R', (list*)0, (list*)0, (PlaceRadius*)0); delete[] cline; } file.close(); @@ -307,11 +316,11 @@ else { list *regions; // does it have at least two? if none, no data, // if 1 we already generated a graph for that one region if (regions->size() < 2) delete regions; - else { graph_vector.emplace_back(c.first + "-country", c.second + " All Routes in Country", + else { graph_vector.emplace_back(c.first + "-country", c.second + " All Routes in Country", 0, 's', 'c', regions, (list*)0, (PlaceRadius*)0); - graph_vector.emplace_back(c.first + "-country", c.second + " All Routes in Country", + graph_vector.emplace_back(c.first + "-country", c.second + " All Routes in Country", 0, 'c', 'c', (list*)0, (list*)0, (PlaceRadius*)0); - graph_vector.emplace_back(c.first + "-country", c.second + " All Routes in Country", + graph_vector.emplace_back(c.first + "-country", c.second + " All Routes in Country", traveler_lists.size(), 't', 't', (list*)0, (list*)0, (PlaceRadius*)0); } } @@ -349,11 +358,11 @@ else { list *regions; regions->push_back(&r); // generate for any continent with at least 1 region with mileage if (regions->size() < 1) delete regions; - else { graph_vector.emplace_back(c.first + "-continent", c.second + " All Routes on Continent", + else { graph_vector.emplace_back(c.first + "-continent", c.second + " All Routes on Continent", 0, 's', 'C', regions, (list*)0, (PlaceRadius*)0); - graph_vector.emplace_back(c.first + "-continent", c.second + " All Routes on Continent", + graph_vector.emplace_back(c.first + "-continent", c.second + " All Routes on Continent", 0, 'c', 'C', (list*)0, (list*)0, (PlaceRadius*)0); - graph_vector.emplace_back(c.first + "-continent", c.second + " All Routes on Continent", + graph_vector.emplace_back(c.first + "-continent", c.second + " All Routes on Continent", traveler_lists.size(), 't', 'C', (list*)0, (list*)0, (PlaceRadius*)0); } } diff --git a/siteupdate/cplusplus/functions/sql_file.cpp b/siteupdate/cplusplus/functions/sql_file.cpp index 0e8ce3cc..4ce66e13 100644 --- a/siteupdate/cplusplus/functions/sql_file.cpp +++ b/siteupdate/cplusplus/functions/sql_file.cpp @@ -328,14 +328,16 @@ else { cout << et.et() << "Writing database file " << args.databasename << ".sql } } - sqlfile << "CREATE TABLE graphs (filename VARCHAR(32), descr VARCHAR(100), vertices INTEGER, edges INTEGER, "; + sqlfile << "CREATE TABLE graphs (filename VARCHAR(32), descr VARCHAR(100), vertices INTEGER, edges INTEGER, travelers INTEGER, "; sqlfile << "format VARCHAR(10), category VARCHAR(12), FOREIGN KEY (category) REFERENCES graphTypes(category));\n"; if (graph_vector.size()) { sqlfile << "INSERT INTO graphs VALUES\n"; for (size_t g = 0; g < graph_vector.size(); g++) { if (g) sqlfile << ','; - sqlfile << "('" << graph_vector[g].filename() << "','" << double_quotes(graph_vector[g].descr) << "','" << graph_vector[g].vertices - << "','" << graph_vector[g].edges << "','" << graph_vector[g].format() << "','" << graph_vector[g].category() << "')\n"; + sqlfile << "('" << graph_vector[g].filename() << "','" << double_quotes(graph_vector[g].descr) + << "','" << graph_vector[g].vertices << "','" << graph_vector[g].edges + << "','" << graph_vector[g].travelers << "','" << graph_vector[g].format() + << "','" << graph_vector[g].category() << "')\n"; } sqlfile << ";\n"; }