mirror of
https://github.com/Jaxan/hybrid-ads.git
synced 2025-04-27 23:17:44 +02:00
Adds better (and more) command line option handling
This commit is contained in:
parent
80c4fac8f1
commit
00c1954eba
2 changed files with 73 additions and 46 deletions
65
src/main.cpp
65
src/main.cpp
|
@ -8,6 +8,8 @@
|
||||||
#include <test_suite.hpp>
|
#include <test_suite.hpp>
|
||||||
#include <transfer_sequences.hpp>
|
#include <transfer_sequences.hpp>
|
||||||
|
|
||||||
|
#include <docopt.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
@ -16,27 +18,46 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
static const char USAGE[] =
|
||||||
|
R"(Generate a test suite
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
main [options] <filename> (all|fixed|random) <max k> <rnd length>
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help Show this screen
|
||||||
|
--version Show version
|
||||||
|
--seed <seed> 32 bits seeds for deterministic execution
|
||||||
|
--no-ds Only use the classical algorithm (hsi)
|
||||||
|
--random-ds Choose randomly between the ds method or hsi method
|
||||||
|
--no-suffix Dont calculate anything smart, just do the random stuff
|
||||||
|
)";
|
||||||
|
|
||||||
using time_logger = silent_timer;
|
using time_logger = silent_timer;
|
||||||
|
|
||||||
int main(int argc, char *argv[]) try {
|
int main(int argc, char *argv[]) try {
|
||||||
if(argc != 5 && argc != 6) {
|
const auto args = docopt::docopt(USAGE, {argv + 1, argv + argc}, true, "5 aug 11:00");
|
||||||
cerr << "usage: main <filename> <max k> <rnd length> <all|fixed|random> [<seed>]" << endl;
|
|
||||||
return 1;
|
const string filename = args.at("<filename>").asString();
|
||||||
|
const bool use_stdio = filename == "=";
|
||||||
|
|
||||||
|
const auto k_max = args.at("<max k>").asLong();
|
||||||
|
const auto rnd_length = args.at("<rnd length>").asLong();
|
||||||
|
|
||||||
|
const bool streaming = args.at("all").asBool() || args.at("fixed").asBool();
|
||||||
|
const bool random_part = args.at("all").asBool() || args.at("random").asBool();
|
||||||
|
const bool no_suffix = args.at("--no-suffix").asBool();
|
||||||
|
|
||||||
|
const bool seed_provided = bool(args.at("--seed"));
|
||||||
|
const uint_fast32_t seed = seed_provided ? args.at("--seed").asLong() : 0;
|
||||||
|
|
||||||
|
const bool use_distinguishing_sequence = [&]{
|
||||||
|
if(args.at("--random-ds").asBool()) {
|
||||||
|
random_device rd;
|
||||||
|
return rd() - rd.min() < (rd.max() - rd.min()) / 2;
|
||||||
}
|
}
|
||||||
const string filename = argv[1];
|
return !args.at("--no-ds").asBool();
|
||||||
const bool use_stdio = filename == "--";
|
}();
|
||||||
|
|
||||||
const auto k_max = stoul(argv[2]);
|
|
||||||
const auto rnd_length = stoul(argv[3]);
|
|
||||||
|
|
||||||
const string mode = argv[4];
|
|
||||||
const bool streaming = mode == "all" || mode == "fixed";
|
|
||||||
const bool random_part = mode == "all" || mode == "random";
|
|
||||||
|
|
||||||
const bool seed_provided = argc == 6;
|
|
||||||
const uint_fast32_t seed = seed_provided ? stoul(argv[5]) : 0;
|
|
||||||
|
|
||||||
const bool use_distinguishing_sequence = true;
|
|
||||||
const bool randomize_prefixes = true;
|
const bool randomize_prefixes = true;
|
||||||
const bool randomize_hopcroft = true;
|
const bool randomize_hopcroft = true;
|
||||||
const bool randomize_lee_yannakakis = true;
|
const bool randomize_lee_yannakakis = true;
|
||||||
|
@ -75,6 +96,8 @@ int main(int argc, char *argv[]) try {
|
||||||
}();
|
}();
|
||||||
|
|
||||||
auto all_pair_separating_sequences = [&]{
|
auto all_pair_separating_sequences = [&]{
|
||||||
|
if(no_suffix) return splitting_tree(0, 0);
|
||||||
|
|
||||||
const auto splitting_tree_hopcroft = [&]{
|
const auto splitting_tree_hopcroft = [&]{
|
||||||
time_logger t("creating hopcroft splitting tree");
|
time_logger t("creating hopcroft splitting tree");
|
||||||
return create_splitting_tree(machine, randomize_hopcroft ? randomized_hopcroft_style : hopcroft_style, random_seeds[0]);
|
return create_splitting_tree(machine, randomize_hopcroft ? randomized_hopcroft_style : hopcroft_style, random_seeds[0]);
|
||||||
|
@ -84,6 +107,8 @@ int main(int argc, char *argv[]) try {
|
||||||
}();
|
}();
|
||||||
|
|
||||||
auto sequence = [&]{
|
auto sequence = [&]{
|
||||||
|
if(no_suffix) return adaptive_distinguishing_sequence(0, 0);
|
||||||
|
|
||||||
const auto tree = [&]{
|
const auto tree = [&]{
|
||||||
time_logger t("Lee & Yannakakis I");
|
time_logger t("Lee & Yannakakis I");
|
||||||
if(use_distinguishing_sequence)
|
if(use_distinguishing_sequence)
|
||||||
|
@ -112,6 +137,12 @@ int main(int argc, char *argv[]) try {
|
||||||
auto inputs = create_reverse_map(translation.input_indices);
|
auto inputs = create_reverse_map(translation.input_indices);
|
||||||
|
|
||||||
const auto separating_family = [&]{
|
const auto separating_family = [&]{
|
||||||
|
if(no_suffix) {
|
||||||
|
separating_set s{{word{}}};
|
||||||
|
vector<separating_set> suffixes(machine.graph_size, s);
|
||||||
|
return suffixes;
|
||||||
|
}
|
||||||
|
|
||||||
time_logger t("making seperating family");
|
time_logger t("making seperating family");
|
||||||
return create_separating_family(sequence, all_pair_separating_sequences);
|
return create_separating_family(sequence, all_pair_separating_sequences);
|
||||||
}();
|
}();
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include <transfer_sequences.hpp>
|
#include <transfer_sequences.hpp>
|
||||||
#include <trie.hpp>
|
#include <trie.hpp>
|
||||||
|
|
||||||
|
#include <docopt.h>
|
||||||
|
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
@ -12,28 +14,25 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
enum Method {
|
static const char USAGE[] =
|
||||||
hsi_method,
|
R"(FSM-based test methods
|
||||||
ds_plus_method,
|
|
||||||
};
|
|
||||||
|
|
||||||
static Method parse_method(string const & s) {
|
Usage:
|
||||||
if (s == "--W-method") return hsi_method;
|
methods (hsi|ads) [options] <file>
|
||||||
if (s == "--DS-method") return ds_plus_method;
|
|
||||||
throw runtime_error("No valid method specified");
|
Options:
|
||||||
}
|
-h, --help Show current help
|
||||||
|
--version Show version
|
||||||
|
-s <seed>, --seed <seed> Specify a seed
|
||||||
|
--non-random Iterate inputs in specified order (as occurring in input file)
|
||||||
|
-k <states> Testing extra states [default: 0]
|
||||||
|
)";
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
if (argc != 4 && argc != 5) {
|
const auto args = docopt::docopt(USAGE, {argv + 1, argv + argc}, true, __DATE__ __TIME__);
|
||||||
cerr << "usage: methods <file> <mode> <k_max> [<seed>]\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const string filename = argv[1];
|
const string filename = args.at("<file>").asString();
|
||||||
const Method method = parse_method(argv[2]);
|
const size_t k_max = args.at("-k").asLong() + 1;
|
||||||
const size_t k_max = std::stoul(argv[3]);
|
|
||||||
const bool seed_provided = argc == 5;
|
|
||||||
const uint_fast32_t seed = seed_provided ? stoul(argv[4]) : 0;
|
|
||||||
|
|
||||||
const auto machine = [&] {
|
const auto machine = [&] {
|
||||||
if (filename.find(".txt") != string::npos) {
|
if (filename.find(".txt") != string::npos) {
|
||||||
|
@ -48,8 +47,8 @@ int main(int argc, char * argv[]) {
|
||||||
|
|
||||||
const auto random_seeds = [&] {
|
const auto random_seeds = [&] {
|
||||||
vector<uint_fast32_t> seeds(3);
|
vector<uint_fast32_t> seeds(3);
|
||||||
if (seed_provided) {
|
if (args.at("--seed")) {
|
||||||
seed_seq s{seed};
|
seed_seq s{args.at("--seed").asLong()};
|
||||||
s.generate(seeds.begin(), seeds.end());
|
s.generate(seeds.begin(), seeds.end());
|
||||||
} else {
|
} else {
|
||||||
random_device rd;
|
random_device rd;
|
||||||
|
@ -59,21 +58,22 @@ int main(int argc, char * argv[]) {
|
||||||
}();
|
}();
|
||||||
|
|
||||||
auto sequence_fut = async([&] {
|
auto sequence_fut = async([&] {
|
||||||
if (method == hsi_method) {
|
if (args.at("hsi").asBool()) {
|
||||||
return create_adaptive_distinguishing_sequence(result(machine.graph_size));
|
return create_adaptive_distinguishing_sequence(result(machine.graph_size));
|
||||||
}
|
}
|
||||||
const auto tree = create_splitting_tree(machine, randomized_lee_yannakakis_style, random_seeds[0]);
|
const auto tree
|
||||||
|
= create_splitting_tree(machine, args.at("--non-random").asBool() ? lee_yannakakis_style : randomized_lee_yannakakis_style, random_seeds[0]);
|
||||||
return create_adaptive_distinguishing_sequence(tree);
|
return create_adaptive_distinguishing_sequence(tree);
|
||||||
});
|
});
|
||||||
|
|
||||||
auto pairs_fut = async([&] {
|
auto pairs_fut = async([&] {
|
||||||
const auto tree = create_splitting_tree(machine, randomized_min_hopcroft_style, random_seeds[1]);
|
const auto tree
|
||||||
|
= create_splitting_tree(machine, args.at("--non-random").asBool() ? min_hopcroft_style : randomized_min_hopcroft_style, random_seeds[1]);
|
||||||
return tree.root;
|
return tree.root;
|
||||||
});
|
});
|
||||||
|
|
||||||
auto prefixes_fut = async([&] {
|
auto prefixes_fut
|
||||||
return create_randomized_transfer_sequences(machine, 0, random_seeds[2]);
|
= async([&] { return create_randomized_transfer_sequences(machine, 0, random_seeds[2]); });
|
||||||
});
|
|
||||||
|
|
||||||
auto middles_fut = async([&] {
|
auto middles_fut = async([&] {
|
||||||
vector<word> all_sequences(1);
|
vector<word> all_sequences(1);
|
||||||
|
@ -85,18 +85,14 @@ int main(int argc, char * argv[]) {
|
||||||
return all_sequences;
|
return all_sequences;
|
||||||
});
|
});
|
||||||
|
|
||||||
// clog << "getting sequence and pairs" << endl;
|
auto suffixes_fut
|
||||||
auto suffixes_fut = async([&] {
|
= async([&] { return create_separating_family(sequence_fut.get(), pairs_fut.get()); });
|
||||||
return create_separating_family(sequence_fut.get(), pairs_fut.get());
|
|
||||||
});
|
|
||||||
|
|
||||||
// clog << "getting prefixes, middles and suffixes" << endl;
|
|
||||||
const auto prefixes = prefixes_fut.get();
|
const auto prefixes = prefixes_fut.get();
|
||||||
const auto middles = middles_fut.get();
|
const auto middles = middles_fut.get();
|
||||||
const auto suffixes = suffixes_fut.get();
|
const auto suffixes = suffixes_fut.get();
|
||||||
trie<input> test_suite;
|
trie<input> test_suite;
|
||||||
|
|
||||||
// clog << "start testing" << endl;
|
|
||||||
const state start = 0;
|
const state start = 0;
|
||||||
const word empty = {};
|
const word empty = {};
|
||||||
for (auto && p : prefixes) {
|
for (auto && p : prefixes) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue