Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions siteupdate/cplusplus/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
graphs
logs
nmp_merged
stats

siteupdate
TravelMapping.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,9 +19,10 @@ class GraphListEntry
PlaceRadius *placeradius;
std::string tag();

GraphListEntry(std::string r, std::string d, char f, char c, std::list<Region*> *rg, std::list<HighwaySystem*> *sys, PlaceRadius *pr)
GraphListEntry(std::string r, std::string d, unsigned int t, char f, char c, std::list<Region*> *rg, std::list<HighwaySystem*> *sys, PlaceRadius *pr)
{ root = r;
descr = d;
travelers = t;
form = f;
cat = c;

Expand Down
8 changes: 4 additions & 4 deletions siteupdate/cplusplus/classes/GraphGeneration/HGEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ std::string HGEdge::label(std::list<HighwaySystem*> *systems)
// line appropriate for a tmg collapsed edge file
std::string HGEdge::collapsed_tmg_line(std::list<HighwaySystem*> *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;
Expand All @@ -236,7 +236,7 @@ std::string HGEdge::collapsed_tmg_line(std::list<HighwaySystem*> *systems, unsig
std::string HGEdge::traveled_tmg_line(std::list<HighwaySystem*> *systems, std::list<TravelerList*> *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;
Expand All @@ -248,7 +248,7 @@ std::string HGEdge::traveled_tmg_line(std::list<HighwaySystem*> *systems, std::l
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);
char fstr[44];
char fstr[58];
for (HGVertex *intermediate : intermediate_points)
{ sprintf(fstr, "] %.15g %.15g", intermediate->lat, intermediate->lng);
line += " [" + *intermediate->unique_name + fstr;
Expand All @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions siteupdate/cplusplus/classes/GraphGeneration/HighwayGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class HighwayGraph
// number waypoint entries as we go
int s_vertex_num = 0;
for (std::pair<const Waypoint*, HGVertex*> 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;
Expand Down Expand Up @@ -426,7 +426,7 @@ class HighwayGraph
int c_vertex_num = 0;
for (std::pair<const Waypoint*, HGVertex*> 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;
Expand Down Expand Up @@ -462,7 +462,7 @@ class HighwayGraph
int t_vertex_num = 0;
for (std::pair<const Waypoint*, HGVertex*> 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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions siteupdate/cplusplus/classes/GraphGeneration/PlaceRadius.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) +\
Expand Down
8 changes: 3 additions & 5 deletions siteupdate/cplusplus/classes/Route/Route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TravelerList*>::iterator t_found = s->clinched_by.find(t);
if (t_found != s->clinched_by.end()) miles += s->length();
}
return miles;
}

Expand Down
20 changes: 10 additions & 10 deletions siteupdate/cplusplus/classes/TravelerList/userlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void userlog

log << "Overall by region: (each line reports active only then active+preview)\n";
std::list<Region*> travregions;
for (std::pair<Region*, double> rm : active_preview_mileage_by_region)
for (std::pair<Region* const, double> &rm : active_preview_mileage_by_region)
travregions.push_back(rm.first);
travregions.sort(sort_regions_by_code);
for (Region *region : travregions)
Expand Down Expand Up @@ -59,7 +59,7 @@ void userlog
{ if (h->mileage_by_region.size() > 1)
log << "System " << h->systemname << " by region:\n";
std::list<Region*> sysregions;
for (std::pair<Region*, double> rm : h->mileage_by_region)
for (std::pair<Region* const, double> &rm : h->mileage_by_region)
sysregions.push_back(rm.first);
sysregions.sort(sort_regions_by_code);
for (Region *region : sysregions)
Expand All @@ -83,11 +83,11 @@ void userlog
{ std::unordered_map<ConnectedRoute*, double> system_con_umap;
unsigned int num_con_rtes_clinched = 0;
log << "System " << h->systemname << " by route (traveled routes only):\n";
for (std::list<ConnectedRoute>::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)
Expand All @@ -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)
Expand All @@ -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';
}
}
Expand Down
20 changes: 10 additions & 10 deletions siteupdate/cplusplus/classes/Waypoint/Waypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) +\
Expand All @@ -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);
Expand Down
57 changes: 33 additions & 24 deletions siteupdate/cplusplus/functions/graph_generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ if (args.skipgraphs || args.errorcheck)
else { list<Region*> *regions;
list<HighwaySystem*> *systems;

graph_vector.emplace_back("tm-master", "All Travel Mapping Data", 's', 'M', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
graph_vector.emplace_back("tm-master", "All Travel Mapping Data", 'c', 'M', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
graph_vector.emplace_back("tm-master", "All Travel Mapping Data", 't', 'M', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
graph_vector.emplace_back("tm-master", "All Travel Mapping Data", 0,
's', 'M', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
graph_vector.emplace_back("tm-master", "All Travel Mapping Data", 0,
'c', 'M', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
graph_vector.emplace_back("tm-master", "All Travel Mapping Data", traveler_lists.size(),
't', 'M', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);

/*#ifdef threading_enabled
if (args.numthreads <= 1)
Expand Down Expand Up @@ -75,11 +78,11 @@ else { list<Region*> *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<Region*>*)0, (list<HighwaySystem*>*)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<Region*>*)0, (list<HighwaySystem*>*)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<Region*>*)0, (list<HighwaySystem*>*)0, &a);
}
// write new graph_vector entries to disk
Expand Down Expand Up @@ -114,11 +117,11 @@ else { list<Region*> *regions;
{ if (region.active_preview_mileage == 0) continue;
regions = new list<Region*>(1, &region);
// 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<HighwaySystem*>*)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<Region*>*)0, (list<HighwaySystem*>*)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<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
}
// write new graph_vector entries to disk
Expand Down Expand Up @@ -161,11 +164,11 @@ else { list<Region*> *regions;
if (h)
{ systems = new list<HighwaySystem*>(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<Region*>*)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<Region*>*)0, (list<HighwaySystem*>*)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<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
}
}
Expand Down Expand Up @@ -216,9 +219,12 @@ else { list<Region*> *regions;
{ systems->push_back(h);
break;
}
graph_vector.emplace_back(fields[1], fields[0], 's', 'S', (list<Region*>*)0, systems, (PlaceRadius*)0);
graph_vector.emplace_back(fields[1], fields[0], 'c', 'S', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
graph_vector.emplace_back(fields[1], fields[0], 't', 'S', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
graph_vector.emplace_back(fields[1], fields[0], 0,
's', 'S', (list<Region*>*)0, systems, (PlaceRadius*)0);
graph_vector.emplace_back(fields[1], fields[0], 0,
'c', 'S', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
graph_vector.emplace_back(fields[1], fields[0], traveler_lists.size(),
't', 'S', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
delete[] cline;
}
file.close();
Expand Down Expand Up @@ -267,9 +273,12 @@ else { list<Region*> *regions;
{ regions->push_back(&r);
break;
}
graph_vector.emplace_back(fields[1], fields[0], 's', 'R', regions, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
graph_vector.emplace_back(fields[1], fields[0], 'c', 'R', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
graph_vector.emplace_back(fields[1], fields[0], 't', 'R', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
graph_vector.emplace_back(fields[1], fields[0], 0,
's', 'R', regions, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
graph_vector.emplace_back(fields[1], fields[0], 0,
'c', 'R', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
graph_vector.emplace_back(fields[1], fields[0], traveler_lists.size(),
't', 'R', (list<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
delete[] cline;
}
file.close();
Expand Down Expand Up @@ -307,11 +316,11 @@ else { list<Region*> *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<HighwaySystem*>*)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<Region*>*)0, (list<HighwaySystem*>*)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<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
}
}
Expand Down Expand Up @@ -349,11 +358,11 @@ else { list<Region*> *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<HighwaySystem*>*)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<Region*>*)0, (list<HighwaySystem*>*)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<Region*>*)0, (list<HighwaySystem*>*)0, (PlaceRadius*)0);
}
}
Expand Down
8 changes: 5 additions & 3 deletions siteupdate/cplusplus/functions/sql_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down