Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{fmt}: #585 phase 1 take 2 #628

Merged
merged 6 commits into from
Jun 5, 2024
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 SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This document is intended to describe how one can set up an environment to run T

Standard tools expected include `bash`, `bzip2`, a GNU version of `make` (often named `gmake`), `ssh`.

There are two versions of the site update program: one written in Python and one in C++. Both produce the same result. The Python version requires a Python3 installation (as of this writing, Python 3.9.13). Below, we will assume that Python can be launched with the command "python3". The C++ version requires a C++ compiler (as of this writing, FreeBSD clang 13.0.0).
There are two versions of the site update program: one written in Python and one in C++. Both produce the same result. The Python version requires a Python3 installation (as of this writing, Python 3.9.13). Below, we will assume that Python can be launched with the command "python3". The C++ version requires a C++ compiler (as of this writing, FreeBSD clang 13.0.0) and the [{fmt}](https://fmt.dev/) library (as of this writing, {fmt} 10.2.0).

### Cloning Needed Repositories

Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ifeq ($(OS), Linux)
endif

CXX = clang++
CXXFLAGS = -O3 -std=c++11 -Wno-comment -Wno-dangling-else -Wno-logical-op-parentheses
CXXFLAGS = -O3 -std=c++11 -isystem /usr/local/include -Wno-comment -Wno-dangling-else -Wno-logical-op-parentheses

STObjects = \
classes/GraphGeneration/HighwayGraphST.o \
Expand Down
6 changes: 3 additions & 3 deletions siteupdate/cplusplus/classes/Args/Args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* e */ bool Args::errorcheck = 0;
/* k */ bool Args::skipgraphs = 0;
/* v */ bool Args::mtvertices = 0;
/* C */ bool Args::mtcsvfiles = 0;
/* C */ bool Args::stcsvfiles = 0;
/* E */ bool Args::edgecounts = 0;
/* b */ bool Args::bitsetlogs = 0;
/* w */ std::string Args::datapath = "../../HighwayData";
Expand Down Expand Up @@ -34,7 +34,7 @@ bool Args::init(int argc, char *argv[])
{ if ARG(0, "-e", "--errorcheck") errorcheck = 1;
else if ARG(0, "-k", "--skipgraphs") skipgraphs = 1;
else if ARG(0, "-v", "--mt-vertices") mtvertices = 1;
else if ARG(0, "-C", "--mt-csvs") mtcsvfiles = 1;
else if ARG(0, "-C", "--st-csvs") stcsvfiles = 1;
else if ARG(0, "-E", "--edge-counts") edgecounts = 1;
else if ARG(0, "-b", "--bitset-logs") bitsetlogs = 1;
else if ARG(0, "-h", "--help") {show_help(); return 1;}
Expand Down Expand Up @@ -127,7 +127,7 @@ void Args::show_help()
std::cout << " Number of digits (1-9) after decimal point in\n";
std::cout << " timestamp readouts\n";
std::cout << " -v, --mt-vertices Multi-threaded vertex construction\n";
std::cout << " -C, --mt-csvs Multi-threaded stats csv files\n";
std::cout << " -C, --st-csvs Single-threaded stats csv files\n";
std::cout << " -E, --edge-counts Report the quantity of each format graph edge\n";
std::cout << " -b, --bitset-logs Write TMBitset RAM use logs for region & system\n";
std::cout << " vertices & edges\n";
Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/classes/Args/Args.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Args
/* e */ static bool errorcheck;
/* T */ static int timeprecision;
/* v */ static bool mtvertices;
/* C */ static bool mtcsvfiles;
/* C */ static bool stcsvfiles;
/* E */ static bool edgecounts;
/* b */ static bool bitsetlogs;
/* L */ static int colocationlimit;
Expand Down
18 changes: 12 additions & 6 deletions siteupdate/cplusplus/classes/GraphGeneration/HGEdge.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define FMT_HEADER_ONLY
#include "HGEdge.h"
#include "HGVertex.h"
#include "../Args/Args.h"
Expand All @@ -6,6 +7,7 @@
#include "../Route/Route.h"
#include "../Waypoint/Waypoint.h"
#include "../../templates/contains.cpp"
#include <fmt/format.h>

HGVertex* HGEdge::v_array;

Expand Down Expand Up @@ -107,21 +109,25 @@ void HGEdge::detach()
}

// write line to tmg collapsed edge file
void HGEdge::collapsed_tmg_line(std::ofstream& file, unsigned int threadnum, std::vector<HighwaySystem*> *systems)
void HGEdge::collapsed_tmg_line(std::ofstream& file, char* fstr, unsigned int threadnum, std::vector<HighwaySystem*> *systems)
{ file << vertex1->c_vertex_num[threadnum] << ' ' << vertex2->c_vertex_num[threadnum] << ' ';
segment->write_label(file, systems);
for (HGVertex *intermediate : intermediate_points)
file << ' ' << intermediate->lat << ' ' << intermediate->lng;
{ *fmt::format_to(fstr, " {:.15} {:.15}", intermediate->lat, intermediate->lng) = 0;
file << fstr;
}
file << '\n';
}

// write line to tmg traveled edge file
void HGEdge::traveled_tmg_line(std::ofstream& file, unsigned int threadnum, std::vector<HighwaySystem*> *systems, bool trav, char* code)
void HGEdge::traveled_tmg_line(std::ofstream& file, char* fstr, unsigned int threadnum, std::vector<HighwaySystem*> *systems, bool trav, char* code)
{ file << vertex1->t_vertex_num[threadnum] << ' ' << vertex2->t_vertex_num[threadnum] << ' ';
segment->write_label(file, systems);
file << ' ' << (trav ? segment->clinchedby_code(code, threadnum) : "0");
for (HGVertex *intermediate : intermediate_points)
file << ' ' << intermediate->lat << ' ' << intermediate->lng;
{ *fmt::format_to(fstr, " {:.15} {:.15}", intermediate->lat, intermediate->lng) = 0;
file << fstr;
}
file << '\n';
}

Expand All @@ -131,7 +137,7 @@ std::string HGEdge::debug_tmg_line(std::vector<HighwaySystem*> *systems, unsigne
+ std::to_string(vertex2->c_vertex_num[threadnum]) + " [" + *vertex2->unique_name + "] " + label(systems);
char fstr[58];
for (HGVertex *intermediate : intermediate_points)
{ sprintf(fstr, "] %.15g %.15g", intermediate->lat, intermediate->lng);
{ *fmt::format_to(fstr, "] {:.15} {:.15}", intermediate->lat, intermediate->lng) = 0;
line += " [" + *intermediate->unique_name + fstr;
}
return line;
Expand All @@ -157,7 +163,7 @@ std::string HGEdge::intermediate_point_string()
std::string line = "";
char fstr[56];
for (HGVertex *i : intermediate_points)
{ sprintf(fstr, "%.15g %.15g", i->lat, i->lng);
{ *fmt::format_to(fstr, "{:.15} {:.15}", i->lat, i->lng) = 0;
line += " [" + *i->unique_name + "] " + fstr;
}
return line;
Expand Down
4 changes: 2 additions & 2 deletions siteupdate/cplusplus/classes/GraphGeneration/HGEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class HGEdge
HGEdge(HGVertex *, unsigned char, HGEdge*, HGEdge*);

void detach();
void collapsed_tmg_line(std::ofstream&, unsigned int, std::vector<HighwaySystem*>*);
void traveled_tmg_line (std::ofstream&, unsigned int, std::vector<HighwaySystem*>*, bool, char*);
void collapsed_tmg_line(std::ofstream&, char*, unsigned int, std::vector<HighwaySystem*>*);
void traveled_tmg_line (std::ofstream&, char*, unsigned int, std::vector<HighwaySystem*>*, bool, char*);
std::string debug_tmg_line(std::vector<HighwaySystem*> *, unsigned int);
std::string str();
std::string intermediate_point_string();
Expand Down
44 changes: 22 additions & 22 deletions siteupdate/cplusplus/classes/GraphGeneration/HighwayGraph.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define FMT_HEADER_ONLY
#include "HighwayGraph.h"
#include "GraphListEntry.h"
#include "HGEdge.h"
Expand All @@ -13,6 +14,7 @@
#include "../Waypoint/Waypoint.h"
#include "../WaypointQuadtree/WaypointQuadtree.h"
#include "../../templates/contains.cpp"
#include <fmt/format.h>
#include <fstream>
#include <thread>

Expand Down Expand Up @@ -345,9 +347,9 @@ void HighwayGraph::bitsetlogs(HGVertex* hp_end)
// for intermediate "shaping points" along the edge, ordered from endpoint 1 to endpoint 2.
//
void HighwayGraph::write_master_graphs_tmg()
{ std::ofstream simplefile(Args::graphfilepath + "/tm-master-simple.tmg"); simplefile.precision(15);
std::ofstream collapfile(Args::graphfilepath + "/tm-master.tmg"); collapfile.precision(15);
std::ofstream travelfile(Args::graphfilepath + "/tm-master-traveled.tmg"); travelfile.precision(15);
{ std::ofstream simplefile(Args::graphfilepath + "/tm-master-simple.tmg");
std::ofstream collapfile(Args::graphfilepath + "/tm-master.tmg");
std::ofstream travelfile(Args::graphfilepath + "/tm-master-traveled.tmg");
simplefile << "TMG 1.0 simple\n";
collapfile << "TMG 1.0 collapsed\n";
travelfile << "TMG 2.0 traveled\n";
Expand All @@ -359,14 +361,13 @@ void HighwayGraph::write_master_graphs_tmg()
unsigned int sv = 0;
unsigned int cv = 0;
unsigned int tv = 0;
char fstr[57];
for (HGVertex& v : vertices)
{ auto write_vertex = [&](std::ofstream& tmg)
{ tmg << *(v.unique_name) << ' ' << v.lat << ' ' << v.lng << '\n';
};
{ *fmt::format_to(fstr, " {:.15} {:.15}", v.lat, v.lng) = 0;
switch (v.visibility) // fall-thru is a Good Thing!
{ case 2: write_vertex(collapfile); v.c_vertex_num[0] = cv++;
case 1: write_vertex(travelfile); v.t_vertex_num[0] = tv++;
default: write_vertex(simplefile); v.s_vertex_num[0] = sv++;
{ case 2: collapfile << *(v.unique_name) << fstr << '\n'; v.c_vertex_num[0] = cv++;
case 1: travelfile << *(v.unique_name) << fstr << '\n'; v.t_vertex_num[0] = tv++;
default: simplefile << *(v.unique_name) << fstr << '\n'; v.s_vertex_num[0] = sv++;
}
}

Expand All @@ -380,10 +381,10 @@ void HighwayGraph::write_master_graphs_tmg()
//TODO: multiple functions performing the same instructions for multiple files?
for (HGEdge *e = edges.begin(), *end = edges.end(); e != end; ++e)
{ if (e->format & HGEdge::collapsed)
e->collapsed_tmg_line(collapfile, 0, 0);
e->collapsed_tmg_line(collapfile, fstr, 0, 0);
if (e->format & HGEdge::traveled)
{ for (char*n=cbycode; n<cbycode+nibbles; ++n) *n = '0';
e->traveled_tmg_line(travelfile, 0, 0, TravelerList::allusers.size, cbycode);
e->traveled_tmg_line(travelfile, fstr, 0, 0, TravelerList::allusers.size, cbycode);
}
if (e->format & HGEdge::simple)
{ simplefile << e->vertex1->s_vertex_num[0] << ' '
Expand Down Expand Up @@ -418,9 +419,9 @@ void HighwayGraph::write_subgraphs_tmg
{ unsigned int cv_count = 0, sv_count = 0, tv_count = 0;
unsigned int ce_count = 0, se_count = 0, te_count = 0;
GraphListEntry* g = GraphListEntry::entries.data()+graphnum;
std::ofstream simplefile(Args::graphfilepath+'/'+g -> filename()); simplefile.precision(15);
std::ofstream collapfile(Args::graphfilepath+'/'+g[1].filename()); collapfile.precision(15);
std::ofstream travelfile(Args::graphfilepath+'/'+g[2].filename()); travelfile.precision(15);
std::ofstream simplefile(Args::graphfilepath+'/'+g -> filename());
std::ofstream collapfile(Args::graphfilepath+'/'+g[1].filename());
std::ofstream travelfile(Args::graphfilepath+'/'+g[2].filename());
TMBitset<HGVertex*, uint64_t> mv; // vertices matching all criteria
TMBitset<HGEdge*, uint64_t> me; // edges matching all criteria
std::vector<TravelerList*> traveler_lists;
Expand Down Expand Up @@ -455,14 +456,13 @@ void HighwayGraph::write_subgraphs_tmg
unsigned int sv = 0;
unsigned int cv = 0;
unsigned int tv = 0;
char fstr[57];
for (HGVertex *v : mv)
{ auto write_vertex = [&](std::ofstream& tmg)
{ tmg << *(v->unique_name) << ' ' << v->lat << ' ' << v->lng << '\n';
};
{ *fmt::format_to(fstr, " {:.15} {:.15}", v->lat, v->lng) = 0;
switch(v->visibility) // fall-thru is a Good Thing!
{ case 2: write_vertex(collapfile); v->c_vertex_num[threadnum] = cv++;
case 1: write_vertex(travelfile); v->t_vertex_num[threadnum] = tv++;
default: write_vertex(simplefile); v->s_vertex_num[threadnum] = sv++;
{ case 2: collapfile << *(v->unique_name) << fstr << '\n'; v->c_vertex_num[threadnum] = cv++;
case 1: travelfile << *(v->unique_name) << fstr << '\n'; v->t_vertex_num[threadnum] = tv++;
default: simplefile << *(v->unique_name) << fstr << '\n'; v->s_vertex_num[threadnum] = sv++;
}
}

Expand All @@ -481,10 +481,10 @@ void HighwayGraph::write_subgraphs_tmg
simplefile << '\n';
}
if (e->format & HGEdge::collapsed)
e->collapsed_tmg_line(collapfile, threadnum, g->systems);
e->collapsed_tmg_line(collapfile, fstr, threadnum, g->systems);
if (e->format & HGEdge::traveled)
{ for (char*n=cbycode; n<cbycode+nibbles; ++n) *n = '0';
e->traveled_tmg_line (travelfile, threadnum, g->systems, travnum, cbycode);
e->traveled_tmg_line (travelfile, fstr, threadnum, g->systems, travnum, cbycode);
}
}
delete[] cbycode;
Expand Down
25 changes: 14 additions & 11 deletions siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define FMT_HEADER_ONLY
#include "HighwaySystem.h"
#include "../Args/Args.h"
#include "../ConnectedRoute/ConnectedRoute.h"
Expand All @@ -11,6 +12,7 @@
#include "../TravelerList/TravelerList.h"
#include "../Waypoint/Waypoint.h"
#include "../../functions/tmstring.h"
#include <fmt/format.h>
#include <fstream>

TMArray<HighwaySystem> HighwaySystem::syslist;
Expand Down Expand Up @@ -219,24 +221,25 @@ void HighwaySystem::stats_csv()
sysfile << '\n';
for (TravelerList& t : TravelerList::allusers)
{ // only include entries for travelers who have any mileage in system
auto it = t.system_region_mileages.find(this);
if (it != t.system_region_mileages.end())
{ sprintf(fstr, ",%.2f", t.system_miles(this));
auto srm_it = t.system_region_mileages.find(this);
if (srm_it != t.system_region_mileages.end())
{ *fmt::format_to(fstr, ",{:.2f}", t.system_miles(this)) = 0;
sysfile << t.traveler_name << fstr;
for (Region *region : regions)
try { sprintf(fstr, ",%.2f", it->second.at(region));
sysfile << fstr;
}
catch (const std::out_of_range& oor)
{ sysfile << ",0";
}
{ auto trm_it = srm_it->second.find(region);
if (trm_it != srm_it->second.end())
{ *fmt::format_to(fstr, ",{:.2f}", trm_it->second) = 0;
sysfile << fstr;
}
else sysfile << ",0";
}
sysfile << '\n';
}
}
sprintf(fstr, "TOTAL,%.2f", total_mileage());
*fmt::format_to(fstr, "TOTAL,{:.2f}", total_mileage()) = 0;
sysfile << fstr;
for (Region *region : regions)
{ sprintf(fstr, ",%.2f", mileage_by_region.at(region));
{ *fmt::format_to(fstr, ",{:.2f}", mileage_by_region.at(region)) = 0;
sysfile << fstr;
}
sysfile << '\n';
Expand Down
Loading