Skip to content
Closed
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
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,14 +76,6 @@ std::string ConnectedRoute::connected_rtes_line()
return line;
}

std::string ConnectedRoute::csv_line()
{ /* return csv line to insert into a table */
char fstr[32];
sprintf(fstr, "','%.15g'", mileage);
return "'" + system->systemname + "','" + route + "','" + banner + "','" + double_quotes(groupname)
+ "','" + (roots.size() ? roots[0]->root.data() : "ERROR_NO_ROOTS") + fstr;
}

std::string ConnectedRoute::readable_name()
{ /* return a string for a human-readable connected route name */
std::string ans = route + banner;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,6 @@ class ConnectedRoute
ConnectedRoute(std::string &, HighwaySystem *, ErrorList &);

std::string connected_rtes_line();
std::string csv_line();
std::string readable_name();
//std::string list_lines(int, int, std::string, size_t);
};
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/classes/Datacheck/Datacheck.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,7 +64,7 @@ void Datacheck::read_fps(std::string& path, ErrorList &el)
+ "], expected 6 fields, found " + std::to_string(NumFields));
continue;
}
if (always_error.find(fields[4]) != always_error.end())
if (always_error.count(fields[4]))
std::cout << "datacheckfps.csv line not allowed (always error): " << line << std::endl;
else fps.push_back(fields);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,8 +91,7 @@ HighwayGraph::HighwayGraph(WaypointQuadtree &all_waypoints, ElapsedTime &et)
w->vertex->visibility = 1;
// next, compare clinched_by sets; look for any element in the 1st not in the 2nd
else for (TravelerList *t : w->vertex->incident_t_edges.front()->segment->clinched_by)
if (w->vertex->incident_t_edges.back()->segment->clinched_by.find(t)
== w->vertex->incident_t_edges.back()->segment->clinched_by.end())
if (!w->vertex->incident_t_edges.back()->segment->clinched_by.count(t))
{ w->vertex->visibility = 1;
break;
}
Expand DownExpand Up@@ -228,7 +227,7 @@ inline void HighwayGraph::matching_vertices_and_edges
// Compute sets of edges for subgraphs, optionally
// restricted by region or system or placeradius.
// Keep a count of collapsed & traveled vertices as we go.
#define AREA (!g.placeradius || mvset.find(e->vertex1) != mvset.end() && mvset.find(e->vertex2) != mvset.end())
#define AREA (!g.placeradius || mvset.count(e->vertex1) && mvset.count(e->vertex2))
#define REGION (!g.regions || contains(*g.regions, e->segment->route->region))
for (HGVertex *v : mvset)
{ for (HGEdge *e : v->incident_s_edges)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,7 +59,7 @@ std::string HighwaySegment::segment_name()
+ other->str() + "] clinched by " + std::to_string(other->clinched_by.size()) + '\n';
}
else for (TravelerList *t : clinched_by)
if (other->clinched_by.find(t) == other->clinched_by.end())
if (other->clinched_by.count(t))
return t->traveler_name + " has clinched [" + str() + "], but not [" + other->str() + "]\n";
}
return "";
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,7 +164,7 @@ void HighwaySystem::stats_csv()
sysfile << '\n';
for (TravelerList *t : TravelerList::allusers)
// only include entries for travelers who have any mileage in system
if (t->system_region_mileages.find(this) != t->system_region_mileages.end())
if (t->system_region_mileages.count(this))
{ sprintf(fstr, ",%.2f", t->system_region_miles(this));
sysfile << t->traveler_name << fstr;
for (Region *region : regions)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,7 @@ void HighwaySystem::route_integrity(ErrorList& el)
std::string upper_label(lbegin);
upper(upper_label.data());
// if primary label not duplicated, add to pri_label_hash
if (r->alt_label_hash.find(upper_label) != r->alt_label_hash.end())
if (r->alt_label_hash.count(upper_label))
{ Datacheck::add(r, r->point_list[index]->label, "", "", "DUPLICATE_LABEL", "");
r->duplicate_labels.insert(upper_label);
}
Expand Down
26 changes: 5 additions & 21 deletions siteupdate/cplusplus/classes/Route/Route.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -90,7 +90,7 @@ Route::Route(std::string &line, HighwaySystem *sys, ErrorList &el)
// insert list name into pri_list_hash, checking for duplicate .list names
std::string list_name(readable_name());
upper(list_name.data());
if (alt_list_hash.find(list_name) != alt_list_hash.end())
if (alt_list_hash.count(list_name))
el.add_error("Duplicate main list name in " + root + ": '" + readable_name() +
"' already points to " + alt_list_hash.at(list_name)->root);
else if (!pri_list_hash.insert(std::pair<std::string,Route*>(list_name, this)).second)
Expand All@@ -100,7 +100,7 @@ Route::Route(std::string &line, HighwaySystem *sys, ErrorList &el)
for (std::string& a : alt_route_names)
{ list_name = rg_str + ' ' + a;
upper(list_name.data());
if (pri_list_hash.find(list_name) != pri_list_hash.end())
if (pri_list_hash.count(list_name))
el.add_error("Duplicate alt route name in " + root + ": '" + region->code + ' ' + a +
"' already points to " + pri_list_hash.at(list_name)->root);
else if (!alt_list_hash.insert(std::pair<std::string, Route*>(list_name, this)).second)
Expand DownExpand Up@@ -140,20 +140,6 @@ std::string Route::chopped_rtes_line()
return line;
}

std::string Route::csv_line()
{ /* return csv line to insert into a table */
// note: alt_route_names does not need to be in the db since
// list preprocessing uses alt or canonical and no longer cares
std::string line = "'" + system->systemname + "','" + region->code + "','" + route + "','" + banner
+ "','" + abbrev + "','" + double_quotes(city) + "','" + root + "','";
char mstr[51];
sprintf(mstr, "%.17g", mileage);
if (!strchr(mstr, '.')) strcat(mstr, ".0"); // add single trailing zero to ints for compatibility with Python
line += mstr;
line += "','" + std::to_string(rootOrder) + "'";
return line;
}

std::string Route::readable_name()
{ /* return a string for a human-readable route name */
return rg_str + " " + route + banner + abbrev;
Expand All@@ -175,9 +161,7 @@ std::string Route::name_no_abbrev()
double Route::clinched_by_traveler(TravelerList *t)
{ double miles = 0;
for (HighwaySegment *s : segment_list)
{ std::unordered_set<TravelerList*>::iterator t_found = s->clinched_by.find(t);
if (t_found != s->clinched_by.end()) miles += s->length;
}
if (s->clinched_by.count(t)) miles += s->length;
return miles;
}

Expand DownExpand Up@@ -230,14 +214,14 @@ void Route::write_nmp_merged()
wptfile.close();
}

void Route::store_traveled_segments(TravelerList* t, std::ofstream& log, unsigned int beg, unsigned int end)
void Route::store_traveled_segments(TravelerList* t, std::ofstream& log, std::string* update, unsigned int beg, unsigned int end)
{ // store clinched segments with traveler and traveler with segments
for (unsigned int pos = beg; pos < end; pos++)
{ HighwaySegment *hs = segment_list[pos];
hs->add_clinched_by(t);
t->clinched_segments.insert(hs);
}
if (last_update && t->updated_routes.insert(this).second && t->update && last_update[0] >= *t->update)
if (last_update && t->updated_routes.insert(this).second && update && last_update[0] >= *update)
log << "Route updated " << last_update[0] << ": " << readable_name() << '\n';
}

Expand Down
3 changes: 1 addition & 2 deletions siteupdate/cplusplus/classes/Route/Route.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -88,14 +88,13 @@ class Route
void print_route();
HighwaySegment* find_segment_by_waypoints(Waypoint*, Waypoint*);
std::string chopped_rtes_line();
std::string csv_line();
std::string readable_name();
std::string list_entry_name();
std::string name_no_abbrev();
double clinched_by_traveler(TravelerList *);
//std::string list_line(int, int);
void write_nmp_merged();
void store_traveled_segments(TravelerList*, std::ofstream &, unsigned int, unsigned int);
void store_traveled_segments(TravelerList*, std::ofstream&, std::string*, unsigned int, unsigned int);
void compute_stats_r();
void con_mismatch();
Waypoint* con_beg();
Expand Down
12 changes: 8 additions & 4 deletions siteupdate/cplusplus/classes/TravelerList/TravelerList.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@
#include "../../functions/upper.h"
#include <cstring>

TravelerList::TravelerList(std::string travname, std::string* updarr[], ErrorList* el)
TravelerList::TravelerList(std::string travname, ErrorList* el)
{ // initialize object variables
active_systems_traveled = 0;
active_systems_clinched = 0;
Expand All@@ -28,6 +28,7 @@ TravelerList::TravelerList(std::string travname, std::string* updarr[], ErrorLis
// variables used in construction
unsigned int list_entries = 0;
std::ofstream splist;
std::string* update;
if (Args::splitregionpath != "") splist.open(Args::splitregionpath+"/list_files/"+travname);

// init user log
Expand All@@ -38,13 +39,15 @@ TravelerList::TravelerList(std::string travname, std::string* updarr[], ErrorLis
log << ctime(&StartTime);
mtx.unlock();
// write last update date & time if known
if (updarr)
{ log << travname << " last updated: " << *updarr[1] << ' ' << *updarr[2] << ' ' << *updarr[3] << '\n';
try { std::string** updarr = TravelerList::listupdates.at(travname);
log << travname << " last updated: " << *updarr[1] << ' ' << *updarr[2] << ' ' << *updarr[3] << '\n';
update = updarr[1];
delete updarr[2];
delete updarr[3];
delete[] updarr;
} else update = 0;
} catch (const std::out_of_range& oor)
{ update = 0;
}

// read .list file into memory
// we can't getline here because it only allows one delimiter, and we need two; '\r' and '\n'.
Expand DownExpand Up@@ -136,6 +139,7 @@ TravelerList::TravelerList(std::string travname, std::string* updarr[], ErrorLis
#undef UPDATE_NOTE
}
delete[] listdata;
if (update) delete update;
log << "Processed " << list_entries << " good lines marking " << clinched_segments.size() << " segments traveled.\n";
log.close();
splist.close();
Expand Down
3 changes: 1 addition & 2 deletions siteupdate/cplusplus/classes/TravelerList/TravelerList.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,6 @@ class TravelerList
public:
std::unordered_set<HighwaySegment*> clinched_segments;
std::string traveler_name;
std::string *update;
std::unordered_map<Region*, double> active_preview_mileage_by_region; // total mileage per region, active+preview only
std::unordered_map<Region*, double> active_only_mileage_by_region; // total mileage per region, active only
std::unordered_map<HighwaySystem*, std::unordered_map<Region*, double>> system_region_mileages; // mileage per region per system
Expand All@@ -44,7 +43,7 @@ class TravelerList
static std::list<TravelerList*>::iterator tl_it;
static std::unordered_map<std::string, std::string**> listupdates;

TravelerList(std::string, std::string*[], ErrorList*);
TravelerList(std::string, ErrorList*);
double active_only_miles();
double active_preview_miles();
double system_region_miles(HighwaySystem *);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,11 +66,11 @@ if (lit1 == r->alt_label_hash.end() || lit2 == r->alt_label_hash.end())
}
// are either of the labels used duplicates?
char duplicate = 0;
if (r->duplicate_labels.find(fields[2]) != r->duplicate_labels.end())
if (r->duplicate_labels.count(fields[2]))
{ log << r->region->code << ": duplicate label " << fields[2] << " in " << r->root << '\n';
duplicate = 1;
}
if (r->duplicate_labels.find(fields[3]) != r->duplicate_labels.end())
if (r->duplicate_labels.count(fields[3]))
{ log << r->region->code << ": duplicate label " << fields[3] << " in " << r->root << '\n';
duplicate = 1;
}
Expand DownExpand Up@@ -112,7 +112,7 @@ else { r->system->lniu_mtx.lock();
index2 = lit1->second;
reverse = 1;
}
r->store_traveled_segments(this, log, index1, index2);
r->store_traveled_segments(this, log, update, index1, index2);
// new .list lines for region split-ups
if (Args::splitregion == r->region->code)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -92,11 +92,11 @@ if (lit1 == r1->alt_label_hash.end() || lit2 == r2->alt_label_hash.end())
}
// are either of the labels used duplicates?
char duplicate = 0;
if (r1->duplicate_labels.find(fields[2]) != r1->duplicate_labels.end())
if (r1->duplicate_labels.count(fields[2]))
{ log << r1->region->code << ": duplicate label " << fields[2] << " in " << r1->root << ".\n";
duplicate = 1;
}
if (r2->duplicate_labels.find(fields[5]) != r2->duplicate_labels.end())
if (r2->duplicate_labels.count(fields[5]))
{ log << r2->region->code << ": duplicate label " << fields[5] << " in " << r2->root << ".\n";
duplicate = 1;
}
Expand All@@ -119,8 +119,8 @@ if (r1 == r2)
continue;
}
if (index1 <= index2)
r1->store_traveled_segments(this, log, index1, index2);
else r1->store_traveled_segments(this, log, index2, index1);
r1->store_traveled_segments(this, log, update, index1, index2);
else r1->store_traveled_segments(this, log, update, index2, index1);
}
else { // user log warning for DISCONNECTED_ROUTE errors
if (r1->con_route->disconnected)
Expand All@@ -145,15 +145,15 @@ else { // user log warning for DISCONNECTED_ROUTE errors
}
// mark the beginning chopped route from index1 to its end
if (r1->is_reversed())
r1->store_traveled_segments(this, log, 0, index1);
else r1->store_traveled_segments(this, log, index1, r1->segment_list.size());
r1->store_traveled_segments(this, log, update, 0, index1);
else r1->store_traveled_segments(this, log, update, index1, r1->segment_list.size());
// mark the ending chopped route from its beginning to index2
if (r2->is_reversed())
r2->store_traveled_segments(this, log, index2, r2->segment_list.size());
else r2->store_traveled_segments(this, log, 0, index2);
r2->store_traveled_segments(this, log, update, index2, r2->segment_list.size());
else r2->store_traveled_segments(this, log, update, 0, index2);
// mark any intermediate chopped routes in their entirety.
for (size_t r = r1->rootOrder+1; r < r2->rootOrder; r++)
r1->con_route->roots[r]->store_traveled_segments(this, log, 0, r1->con_route->roots[r]->segment_list.size());
r1->con_route->roots[r]->store_traveled_segments(this, log, update, 0, r1->con_route->roots[r]->segment_list.size());
}
// both labels are valid; mark in use & proceed
r1->system->lniu_mtx.lock();
Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/classes/TravelerList/userlog.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,7 +65,7 @@ void TravelerList::userlog(ClinchedDBValues *clin_db_val, const double total_act
sysregions.sort(sort_regions_by_code);
for (Region *region : sysregions)
{ double system_region_mileage = 0;
if (system_region_mileages.count(h) && system_region_mileages.at(h).count(region))
if (system_region_mileages.at(h).count(region))
{ system_region_mileage = system_region_mileages.at(h).at(region);
sprintf(fstr, "%.15g", system_region_mileage);
if (!strchr(fstr, '.')) strcat(fstr, ".0");
Expand Down
37 changes: 12 additions & 25 deletions siteupdate/cplusplus/classes/Waypoint/Waypoint.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,16 +100,10 @@ Waypoint::Waypoint(char *line, Route *rte)
}

std::string Waypoint::str()
{ std::string ans = route->root + " " + label;
char coordstr[51];
sprintf(coordstr, "%.15g", lat);
if (!strchr(coordstr, '.')) strcat(coordstr, ".0"); // add single trailing zero to ints for compatibility with Python
ans += " (";
ans += coordstr;
ans += ',';
sprintf(coordstr, "%.15g", lng);
if (!strchr(coordstr, '.')) strcat(coordstr, ".0"); // add single trailing zero to ints for compatibility with Python
ans += coordstr;
{ std::string ans = route->root + " " + label + " (";
char s[51]; int
e=sprintf(s,"%.15g",lat); if (lat==int(lat)) strcpy(s+e,".0"); ans+=s; ans+=',';
e=sprintf(s,"%.15g",lng); if (lng==int(lng)) strcpy(s+e,".0"); ans+=s;
return ans + ')';
}

Expand DownExpand Up@@ -238,15 +232,11 @@ void Waypoint::nmplogs(std::unordered_set<std::string> &nmpfps, std::ofstream &n
// make sure we only plot once, since the NMP should be listed
// both ways (other_w in w's list, w in other_w's list)
if (sort_root_at_label(this, other_w))
{ char coordstr[51];

nmpnmp << root_at_label();
sprintf(coordstr, " %.15g", lat);
if (!strchr(coordstr, '.')) strcat(coordstr, ".0"); // add single trailing zero to ints for compatibility with Python
nmpnmp << coordstr;
sprintf(coordstr, " %.15g", lng);
if (!strchr(coordstr, '.')) strcat(coordstr, ".0"); // add single trailing zero to ints for compatibility with Python
nmpnmp << coordstr;
{ char s[51];
#define PYTHON_STYLE_FLOAT(F) e=sprintf(s," %.15g",F); if (F==int(F)) strcpy(s+e,".0"); nmpnmp<<s;
nmpnmp << root_at_label(); int
PYTHON_STYLE_FLOAT(lat)
PYTHON_STYLE_FLOAT(lng)
if (fp || li)
{ nmpnmp << ' ';
if (fp) nmpnmp << "FP";
Expand All@@ -255,18 +245,15 @@ void Waypoint::nmplogs(std::unordered_set<std::string> &nmpfps, std::ofstream &n
nmpnmp << '\n';

nmpnmp << other_w->root_at_label();
sprintf(coordstr, " %.15g", other_w->lat);
if (!strchr(coordstr, '.')) strcat(coordstr, ".0"); // add single trailing zero to ints for compatibility with Python
nmpnmp << coordstr;
sprintf(coordstr, " %.15g", other_w->lng);
if (!strchr(coordstr, '.')) strcat(coordstr, ".0"); // add single trailing zero to ints for compatibility with Python
nmpnmp << coordstr;
PYTHON_STYLE_FLOAT(other_w->lat)
PYTHON_STYLE_FLOAT(other_w->lng)
if (fp || li)
{ nmpnmp << ' ';
if (fp) nmpnmp << "FP";
if (li) nmpnmp << "LI";
}
nmpnmp << '\n';
#undef PYTHON_STYLE_FLOAT
}
}
// indicate if this was in the FP list or if it's off by exact amt
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ if (ap_coloc.size() == 2)
// if this is taken or if name_no_abbrev()s match, attempt to add in abbrevs if there's point in doing so
if (ap_coloc[0]->route->abbrev.size() || ap_coloc[1]->route->abbrev.size())
{ g->set_mtx[newname.back()].lock();
bool taken = g->vertex_names[newname.back()].find(newname) != g->vertex_names[newname.back()].end();
bool taken = g->vertex_names[newname.back()].count(newname);
g->set_mtx[newname.back()].unlock();
if (taken || ap_coloc[0]->route->name_no_abbrev() == ap_coloc[1]->route->name_no_abbrev())
{ const char *u0 = strchr(ap_coloc[0]->label.data(), '_');
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,7 +62,7 @@ void WaypointQuadtree::insert(Waypoint *w, bool init)
// DUPLICATE_COORDS datacheck
for (Waypoint* p : *other_w->colocated)
if (p->route == w->route)
{ char fstr[44];
{ char fstr[48];
sprintf(fstr, "(%.15g,%.15g)", w->lat, w->lng);
Datacheck::add(w->route, p->label, w->label, "", "DUPLICATE_COORDS", fstr);
}
Expand DownExpand Up@@ -294,6 +294,7 @@ void WaypointQuadtree::terminal_nodes(std::forward_list<WaypointQuadtree*>* node

void WaypointQuadtree::sort()
{ std::forward_list<WaypointQuadtree*>* nodes = new std::forward_list<WaypointQuadtree*>[Args::numthreads];
// deleted @ end of this function
size_t slot = 0;
terminal_nodes(nodes, slot);

Expand Down
Loading