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
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ CommonObjects = \
classes/GraphGeneration/PlaceRadius.o \
classes/HighwaySegment/HighwaySegment.o \
classes/HighwaySystem/HighwaySystem.o \
classes/HighwaySystem/route_integrity.o \
classes/Region/Region.o \
classes/Route/Route.o \
classes/Route/label_and_connect.o \
classes/Route/read_wpt.o \
classes/TravelerList/TravelerList.o \
classes/TravelerList/userlog.o \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ConnectedRoute::ConnectedRoute(std::string &line, HighwaySystem *sys, ErrorList
" in system " + system->systemname + '.');
}
}
if (roots.size() < 1) el.add_error("No roots in " + system->systemname + "_con.csv line: " + line);
if (roots.size() < 1) el.add_error("No valid roots in " + system->systemname + "_con.csv line: " + line);
}

std::string ConnectedRoute::connected_rtes_line()
Expand Down
5 changes: 4 additions & 1 deletion siteupdate/cplusplus/classes/Datacheck/Datacheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@ bool operator < (const Datacheck &a, const Datacheck &b)
std::list<std::string*> Datacheck::fps;

std::unordered_set<std::string> Datacheck::always_error
{ "ABBREV_AS_BANNER",
{ "ABBREV_AS_CHOP_BANNER",
"ABBREV_AS_CON_BANNER",
"BAD_ANGLE",
"CON_BANNER_MISMATCH",
"CON_ROUTE_MISMATCH",
"DISCONNECTED_ROUTE",
"DUPLICATE_LABEL",
"HIDDEN_TERMINUS",
Expand Down
5 changes: 4 additions & 1 deletion siteupdate/cplusplus/classes/Datacheck/Datacheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ class Datacheck
code is the error code | info is additional
string, one of: | information, if used:
-----------------------+--------------------------------------------
ABBREV_AS_BANNER | offending line # in chopped route CSV
ABBREV_AS_CHOP_BANNER | offending line # in chopped route CSV
ABBREV_AS_CON_BANNER | offending line # in connected route CSV
BAD_ANGLE |
BUS_WITH_I |
CON_BANNER_MISMATCH | Banner field in chopped & connected CSVs
CON_ROUTE_MISMATCH | Route field in chopped & connected CSVs
DISCONNECTED_ROUTE | adjacent root's expected connection point
DUPLICATE_COORDS | coordinate pair
DUPLICATE_LABEL |
Expand Down
7 changes: 7 additions & 0 deletions siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ size_t HighwaySystem::route_index(Route* r)
return -1; // error, Route not found
}

/* Return index of a specified ConnectedRoute within con_route_list */
size_t HighwaySystem::con_route_index(ConnectedRoute* cr)
{ for (size_t i = 0; i < con_route_list.size(); i++)
if (con_route_list[i] == cr) return i;
return -1; // error, ConnectedRoute not found
}

void HighwaySystem::insert_vertex(HGVertex* v)
{ lniu_mtx.lock(); // re-use an existing mutex...
vertices.insert(v);
Expand Down
4 changes: 3 additions & 1 deletion siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class HighwaySystem
char level; // 'a' for active, 'p' for preview, 'd' for devel

std::vector<Route*> route_list;
std::list<ConnectedRoute*> con_route_list;
std::vector<ConnectedRoute*> con_route_list;
std::unordered_map<Region*, double> mileage_by_region;
std::unordered_set<HGVertex*> vertices;
std::unordered_set<std::string>listnamesinuse, unusedaltroutenames;
Expand All @@ -54,5 +54,7 @@ class HighwaySystem
double total_mileage(); // Return total system mileage across all regions
std::string level_name(); // Return full "active" / "preview" / "devel" string"
size_t route_index(Route*); // Return index of a specified Route* within route_list
size_t con_route_index(ConnectedRoute*); // same thing for ConnectedRoutes
void route_integrity(ErrorList& el);
void insert_vertex(HGVertex*);
};
80 changes: 80 additions & 0 deletions siteupdate/cplusplus/classes/HighwaySystem/route_integrity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "HighwaySystem.h"
#include "../ConnectedRoute/ConnectedRoute.h"
#include "../Datacheck/Datacheck.h"
#include "../ErrorList/ErrorList.h"
#include "../Route/Route.h"
#include "../Waypoint/Waypoint.h"
#include "../../functions/upper.h"

void HighwaySystem::route_integrity(ErrorList& el)
{ for (Route* r : route_list)
{ // check for unconnected chopped routes
if (!r->con_route)
el.add_error(systemname + ".csv: root " + r->root + " not matched by any connected route root.");

// create label hashes and check for duplicates
for (unsigned int index = 0; index < r->point_list.size(); index++)
{ // ignore case and leading '+' or '*'
const char* lbegin = r->point_list[index]->label.data();
while (*lbegin == '+' || *lbegin == '*') lbegin++;
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())
{ Datacheck::add(r, r->point_list[index]->label, "", "", "DUPLICATE_LABEL", "");
r->duplicate_labels.insert(upper_label);
}
else if (!r->pri_label_hash.insert(std::pair<std::string, unsigned int>(upper_label, index)).second)
{ Datacheck::add(r, r->point_list[index]->label, "", "", "DUPLICATE_LABEL", "");
r->duplicate_labels.insert(upper_label);
}
for (std::string& a : r->point_list[index]->alt_labels)
{ // create canonical AltLabels
while (a[0] == '+' || a[0] == '*') a = a.data()+1;
upper(a.data());
// populate unused set
r->unused_alt_labels.insert(a);
// create label->index hashes and check if AltLabels duplicated
std::unordered_map<std::string, unsigned int>::iterator A = r->pri_label_hash.find(a);
if (A != r->pri_label_hash.end())
{ Datacheck::add(r, r->point_list[A->second]->label, "", "", "DUPLICATE_LABEL", "");
r->duplicate_labels.insert(a);
}
else if (!r->alt_label_hash.insert(std::pair<std::string, unsigned int>(a, index)).second)
{ Datacheck::add(r, a, "", "", "DUPLICATE_LABEL", "");
r->duplicate_labels.insert(a);
}
}
}
}

for (ConnectedRoute* cr : con_route_list)
{ if (cr->roots.empty()) continue; // because there could be an invalid _con.csv entry
// check cr->roots[0] by itself outside of loop
cr->roots[0]->con_mismatch();
for (size_t i = 1; i < cr->roots.size(); i++)
{ // check for mismatched route endpoints within connected routes
#define q cr->roots[i-1]
#define r cr->roots[i]
r->con_mismatch();
if ( q->point_list.size() > 1 && r->point_list.size() > 1 && !r->con_beg()->same_coords(q->con_end()) )
{ if ( q->con_beg()->same_coords(r->con_beg()) )
q->is_reversed = 1;
else if ( q->con_end()->same_coords(r->con_end()) )
r->is_reversed = 1;
else if ( q->con_beg()->same_coords(r->con_end()) )
{ q->is_reversed = 1;
r->is_reversed = 1;
}
else
{ Datacheck::add(r, r->con_beg()->label, "", "",
"DISCONNECTED_ROUTE", q->con_end()->root_at_label());
Datacheck::add(q, q->con_end()->label, "", "",
"DISCONNECTED_ROUTE", r->con_beg()->root_at_label());
}
}
#undef q
#undef r
}
}
}
15 changes: 15 additions & 0 deletions siteupdate/cplusplus/classes/Route/Route.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Route.h"
#include "../Args/Args.h"
#include "../ConnectedRoute/ConnectedRoute.h"
#include "../Datacheck/Datacheck.h"
#include "../DBFieldLength/DBFieldLength.h"
#include "../ErrorList/ErrorList.h"
Expand Down Expand Up @@ -248,6 +249,20 @@ Waypoint* Route::con_end()
{ return is_reversed ? point_list.front() : point_list.back();
}

// datacheck
void Route::con_mismatch()
{ if (route != con_route->route)
Datacheck::add(this, "", "", "", "CON_ROUTE_MISMATCH",
route+" <-> "+con_route->route);
if (banner != con_route->banner)
if (abbrev.size() && abbrev == con_route->banner)
Datacheck::add(this, "", "", "", "ABBREV_AS_CON_BANNER", system->systemname + "_con.csv#L" +
std::to_string(system->con_route_index(con_route)+2));
else Datacheck::add(this, "", "", "", "CON_BANNER_MISMATCH",
(banner.size() ? banner : "(blank)") + " <-> " +
(con_route->banner.size() ? con_route->banner : "(blank)"));
}

// sort routes by most recent update for use at end of user logs
// all should have a valid updates entry pointer before being passed here
bool sort_route_updates_oldest(const Route *r1, const Route *r2)
Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/classes/Route/Route.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Route
void write_nmp_merged();
void store_traveled_segments(TravelerList*, std::ofstream &, unsigned int, unsigned int);
void compute_stats_r();
void label_and_connect(ErrorList&);
void con_mismatch();
Waypoint* con_beg();
Waypoint* con_end();
};
Expand Down
3 changes: 2 additions & 1 deletion siteupdate/cplusplus/classes/Route/compute_stats_r.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void Route::compute_stats_r()
// datachecks
if (abbrev.empty())
{ if ( banner.size() && !strncmp(banner.data(), city.data(), banner.size()) )
Datacheck::add(this, "", "", "", "ABBREV_AS_BANNER",
Datacheck::add(this, "", "", "", "ABBREV_AS_CHOP_BANNER",
system->systemname + ".csv#L" +
std::to_string(system->route_index(this)+2));
}
}
79 changes: 0 additions & 79 deletions siteupdate/cplusplus/classes/Route/label_and_connect.cpp

This file was deleted.

7 changes: 3 additions & 4 deletions siteupdate/cplusplus/siteupdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,14 @@ int main(int argc, char *argv[])

#include "tasks/concurrency_detection.cpp"

cout << et.et() << "Processing waypoint labels and checking for unconnected chopped routes." << endl;
cout << et.et() << "Creating label hashes and checking route integrity." << endl;
#ifdef threading_enabled
HighwaySystem::it = HighwaySystem::syslist.begin();
THREADLOOP thr[t] = thread(LabelConThread, t, &list_mtx, &el);
THREADLOOP thr[t] = thread(RteIntThread, t, &list_mtx, &el);
THREADLOOP thr[t].join();
#else
for (HighwaySystem *h : HighwaySystem::syslist)
for (Route* r : h->route_list)
r->label_and_connect(el);
h->route_integrity(el);
#endif

#include "tasks/read_updates.cpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void LabelConThread(unsigned int id, std::mutex* hs_mtx, ErrorList* el)
void RteIntThread(unsigned int id, std::mutex* hs_mtx, ErrorList* el)
{ //printf("Starting LabelConThread %02i\n", id); fflush(stdout);
while (HighwaySystem::it != HighwaySystem::syslist.end())
{ hs_mtx->lock();
Expand All @@ -11,6 +11,6 @@ void LabelConThread(unsigned int id, std::mutex* hs_mtx, ErrorList* el)
HighwaySystem::it++;
//printf("LabelConThread %02i HighwaySystem::it++\n", id); fflush(stdout);
hs_mtx->unlock();
for (Route* r : h->route_list) r->label_and_connect(*el);
h->route_integrity(*el);
}
}
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/threads/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#include "CompStatsRThread.cpp"
#include "CompStatsTThread.cpp"
#include "ConcAugThread.cpp"
#include "LabelConThread.cpp"
#include "MasterTmgThread.cpp"
#include "NmpMergedThread.cpp"
#include "NmpSearchThread.cpp"
#include "ReadListThread.cpp"
#include "ReadWptThread.cpp"
#include "RteIntThread.cpp"
#include "SubgraphThread.cpp"
#include "UserLogThread.cpp"
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/threads/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class WaypointQuadtree;
void CompStatsRThread(unsigned int, std::mutex*);
void CompStatsTThread(unsigned int, std::mutex*);
void ConcAugThread (unsigned int, std::mutex*, std::list<std::string>*);
void LabelConThread (unsigned int, std::mutex*, ErrorList*);
void MasterTmgThread(HighwayGraph*, std::mutex*, std::mutex*, WaypointQuadtree*, ElapsedTime*);
void NmpMergedThread (unsigned int, std::mutex*);
void NmpSearchThread (unsigned int, std::mutex*, WaypointQuadtree*);
void ReadListThread (unsigned int, std::mutex*, ErrorList*);
void ReadWptThread (unsigned int, std::mutex*, ErrorList*, WaypointQuadtree*);
void RteIntThread (unsigned int, std::mutex*, ErrorList*);
void SubgraphThread (unsigned int, std::mutex*, std::mutex*, HighwayGraph*, WaypointQuadtree*, ElapsedTime*);
void UserLogThread (unsigned int, std::mutex*, ClinchedDBValues*, const double, const double);
Loading