35 cout <<
"Usage: " << name <<
" <options>" << endl
36 <<
" -m <int> tree size (edges) (default: 1000)" << endl
37 <<
" -n <int> number of trees to test (default: 100)" << endl
38 <<
" -l <int> number of different labels to assign to the nodes (default: 2)" << endl
39 <<
" -s <int> seed (default: 12345678)" << endl
40 <<
" -r <file> set output file for edge compression ratios (default: no output)" << endl
41 <<
" -o <file> set output file for debug information (default: no output)" << endl
42 <<
" -w <path> set output folder for generated trees as XML files (default: don't write)" << endl
43 <<
" -t <int> number of threads to use (default: #cores)" << endl
44 <<
" -v verbose" << endl
45 <<
" -vv extra verbose" << endl;
51 const int numLabels,
const bool useRePair,
const bool verbose,
const bool extraVerbose,
55 if (verbose) cout << endl <<
"Round " << iteration <<
", seed is " <<seed << endl;
68 if (verbose) cout <<
"Generated " << tree.
summary() <<
" in " << timer.
get() <<
"ms" << endl;
72 const string filename(treePath +
"/" + std::to_string(iteration) +
"_orig.xml");
75 if (verbose) cout <<
"Wrote orginial trimmed XML file in " << timer.
get() <<
"ms: " << tree.
summary() << endl;
96 cout <<
"Top DAG construction took " << timer.
get() <<
"ms" << endl;
117 if (verbose) cout <<
"Unpacked top tree in " << timer.
get() <<
"ms" << flush;
122 std::cerr <<
"Top Tree unpacking produced incorrect result for seed " << seed << endl;
125 if (verbose) cout <<
"; checked in " << timer.
get() <<
"ms" << endl;
129 if (treePath !=
"") {
130 const string filename(treePath +
"/" + std::to_string(iteration) +
"_unpacked.xml");
133 if (verbose) cout <<
"Wrote recovered tree in " << timer.
get() <<
"ms" << endl;
142 int main(
int argc,
char **argv) {
145 if (argParser.
isSet(
"h") || argParser.
isSet(
"-help")) {
150 const int size = argParser.
get<
int>(
"m", 1000);
151 const int numIterations = argParser.
get<
int>(
"n", 100);
152 const uint numLabels = argParser.
get<uint>(
"l", 2);
153 const uint seed = argParser.
get<uint>(
"s", 12345678);
154 const bool useRePair = argParser.
isSet(
"r");
155 const bool verbose = argParser.
isSet(
"v") || argParser.
isSet(
"vv");
156 const bool extraVerbose = argParser.
isSet(
"vv");
157 const string ratioFilename = argParser.
get<
string>(
"r",
"");
158 const string debugFilename = argParser.
get<
string>(
"o",
"");
159 const string treePath = argParser.
get<
string>(
"w",
"");
161 if (treePath !=
"") {
165 int numWorkers(std::thread::hardware_concurrency());
166 numWorkers = argParser.
get<
int>(
"t", numWorkers);
169 Statistics statistics(ratioFilename, debugFilename);
172 cout <<
"Running experiments with " << numIterations <<
" trees of size " << size <<
" with " << numLabels
173 <<
" different labels" << flush;
176 vector<uint> seeds(numIterations);
177 if (numIterations > 1) {
178 std::seed_seq seedSeq({(uint)size, (uint)numIterations, numLabels, seed});
179 seedSeq.generate(seeds.begin(), seeds.end());
186 auto worker = [&](
int start,
int end) {
188 for (
int i = start; i < end; ++i) {
189 runIteration(i, engine, seeds[i], size, numLabels, useRePair, verbose, extraVerbose, statistics, bar, treePath);
193 const int treesPerThread = numIterations / numWorkers;
194 const int leftovers = numIterations % numWorkers;
196 vector<std::thread> workers;
198 cout <<
" using " << numWorkers <<
" threads" << endl;
200 int min(0), max(treesPerThread);
201 for (
int i = 0; i < numWorkers; ++i) {
205 workers.push_back(std::thread(worker, min, max));
207 max += treesPerThread;
210 for (std::thread &worker : workers) {
217 statistics.
dump(std::cerr);
Transform a tree into its top tree.
Ordered tree data structure.
void undraw()
remove all traces of the bar from the output stream
double mergeDuration
the time it took to transform the tree into its top tree (in milliseconds)
double generationDuration
the time it took to generate the tree (in milliseconds)
Unpack a TopTree into its original OrderedTree.
bool isSet(const string &arg) const
check whether an argument was set
void dump(std::ostream &os) const
double avgDepth
average depth of the tree's nodes
uint_fast64_t height
height of the tree
double statDuration
the time spent on statistical stuff
int main(int argc, char **argv)
double unpackDuration
the time spent unpacking trees
bool isEqual(const OrderedTree< NodeType, EdgeType > &other, LabelType &labels, LabelType &otherLabels, const bool verbose=false) const
Parse command-line arguments.
void construct(DebugInfo *debugInfo=NULL)
void addDebugInfo(const DebugInfo &info)
add a debug info object
Unpack a binary DAG to its original top tree.
Holds debug information about a tree compression run.
void runIteration(const int iteration, RandomGeneratorType &generator, const uint seed, const int size, const int numLabels, const bool useRePair, const bool verbose, const bool extraVerbose, Statistics &statistics, ProgressBar &bar, const string &treePath)
T get(const string &key, const T defaultValue=T())
Generates ordered unlabelled trees uniformly at random.
Transform a tree into its top tree.
double ioDuration
the time spent on I/O
string summary() const
A one-line summary of the tree.
bool makePathRecursive(std::string path, int permissions=0755)
XML tree writer (empty template for overloading)
A binary DAG that is specialised to be a top tree's minimal DAG.
void generateTree(TreeType &tree, const int numEdges, const bool verbose=false)
void construct(DebugInfo *debugInfo=NULL, const double minRatio=1.2)
std::mt19937 RandomGeneratorType
the type of random generator used
A key-value label storage.