* tests/core/randtgba.cc: Remove code related to random formulas.

This commit is contained in:
Alexandre Duret-Lutz 2018-05-21 15:42:21 +02:00
parent 6e8af75ee9
commit 924a642939

View file

@ -33,7 +33,6 @@
#include <vector> #include <vector>
#include <spot/tl/parse.hh> #include <spot/tl/parse.hh>
#include <spot/tl/apcollect.hh> #include <spot/tl/apcollect.hh>
#include <spot/tl/randomltl.hh>
#include <spot/tl/print.hh> #include <spot/tl/print.hh>
#include <spot/tl/length.hh> #include <spot/tl/length.hh>
#include <spot/tl/simplify.hh> #include <spot/tl/simplify.hh>
@ -122,22 +121,6 @@ syntax(char* prog)
<< " [0.5]" << std::endl << " [0.5]" << std::endl
<< " -det generate a deterministic and complete graph [false]" << " -det generate a deterministic and complete graph [false]"
<< std::endl << std::endl
<< "LTL Formula Generation Options:" << std::endl
<< " -dp dump priorities, do not generate any formula"
<< std::endl
<< " -f N size of the formula [15]" << std::endl
<< " -F N number of formulae to generate [0]" << std::endl
<< " -l N simplify formulae using all available reductions"
<< " and reject those" << std::endl
<< " strictly smaller than N" << std::endl
<< " -i FILE do not generate formulae, read them from FILE"
<< std::endl
<< " -p S priorities to use" << std::endl
<< " -S N skip N formulae before starting to use them"
<< std::endl
<< " (useful to replay a specific seed when -u is used)"
<< std::endl
<< " -u generate unique formulae" << std::endl
<< std::endl << std::endl
<< "Emptiness-Check Options:" << std::endl << "Emptiness-Check Options:" << std::endl
<< " -A FILE use all algorithms listed in FILE" << std::endl << " -A FILE use all algorithms listed in FILE" << std::endl
@ -164,7 +147,7 @@ syntax(char* prog)
<< std::endl << std::endl
<< "Use -dp to see the list of KEYs." << std::endl << "Use -dp to see the list of KEYs." << std::endl
<< std::endl << std::endl
<< "When -F or -i is used, a random graph a synchronized with" << "When -i is used, a random graph a synchronized with"
<< " each formula." << std::endl << "If -e N is additionally used" << " each formula." << std::endl << "If -e N is additionally used"
<< " N random graphs are generated for each formula." << std::endl; << " N random graphs are generated for each formula." << std::endl;
exit(2); exit(2);
@ -488,65 +471,10 @@ print_ar_stats(ar_stats_type& ar_stats, const std::string& s)
std::cout << std::setiosflags(old); std::cout << std::setiosflags(old);
} }
static spot::formula
generate_formula(const spot::random_ltl& rl,
spot::tl_simplifier& simp,
int opt_f, int opt_s,
int opt_l = 0, bool opt_u = false)
{
static std::set<std::string> unique;
int max_tries_u = 1000;
while (max_tries_u--)
{
spot::srand(opt_s++);
spot::formula f;
int max_tries_l = 1000;
while (max_tries_l--)
{
f = rl.generate(opt_f);
if (opt_l)
{
f = simp.simplify(f);
if (spot::length(f) < opt_l)
continue;
}
else
{
assert(spot::length(f) <= opt_f);
}
break;
}
if (max_tries_l < 0)
{
assert(opt_l);
std::cerr << "Failed to generate non-reducible formula "
<< "of size " << opt_l << " or more." << std::endl;
return nullptr;
}
std::string txt = spot::str_psl(f);
if (!opt_u || unique.insert(txt).second)
return f;
}
assert(opt_u);
std::cerr << "Failed to generate another unique formula."
<< std::endl;
return nullptr;
}
int int
main(int argc, char** argv) main(int argc, char** argv)
{ {
bool opt_paper = false; bool opt_paper = false;
bool opt_dp = false;
int opt_f = 15;
int opt_F = 0;
char* opt_p = nullptr;
char* opt_i = nullptr;
std::istream *formula_file = nullptr;
int opt_l = 0;
bool opt_u = false;
int opt_S = 0;
int opt_n_acc = 0; int opt_n_acc = 0;
float opt_a = 0.0; float opt_a = 0.0;
@ -571,7 +499,6 @@ main(int argc, char** argv)
int exit_code = 0; int exit_code = 0;
spot::twa_graph_ptr formula = nullptr;
spot::twa_graph_ptr product = nullptr; spot::twa_graph_ptr product = nullptr;
spot::option_map options; spot::option_map options;
@ -674,24 +601,6 @@ main(int argc, char** argv)
{ {
opt_dot = true; opt_dot = true;
} }
else if (!strcmp(argv[argn], "-i"))
{
if (argc < argn + 2)
syntax(argv[0]);
opt_i = argv[++argn];
if (strcmp(opt_i, "-"))
{
formula_file = new std::ifstream(opt_i);
if (!*formula_file)
{
delete formula_file;
std::cerr << "Failed to open " << opt_i << std::endl;
exit(2);
}
}
else
formula_file = &std::cin;
}
else if (!strcmp(argv[argn], "-m")) else if (!strcmp(argv[argn], "-m"))
{ {
opt_reduce = true; opt_reduce = true;
@ -724,12 +633,6 @@ main(int argc, char** argv)
opt_ec_seed = to_int_nonneg(argv[++argn], "-s"); opt_ec_seed = to_int_nonneg(argv[++argn], "-s");
spot::srand(opt_ec_seed); spot::srand(opt_ec_seed);
} }
else if (!strcmp(argv[argn], "-S"))
{
if (argc < argn + 2)
syntax(argv[0]);
opt_S = to_int_pos(argv[++argn], "-S");
}
else if (!strcmp(argv[argn], "-t")) else if (!strcmp(argv[argn], "-t"))
{ {
if (argc < argn + 2) if (argc < argn + 2)
@ -744,66 +647,12 @@ main(int argc, char** argv)
{ {
opt_Z = opt_z = true; opt_Z = opt_z = true;
} }
else if (!strcmp(argv[argn], "-dp"))
{
opt_dp = true;
}
else if (!strcmp(argv[argn], "-f"))
{
if (argc < argn + 2)
syntax(argv[0]);
opt_f = to_int_pos(argv[++argn], "-f");
}
else if (!strcmp(argv[argn], "-F"))
{
if (argc < argn + 2)
syntax(argv[0]);
opt_F = to_int_nonneg(argv[++argn], "-F");
}
else if (!strcmp(argv[argn], "-p"))
{
if (argc < argn + 2)
syntax(argv[0]);
opt_p = argv[++argn];
}
else if (!strcmp(argv[argn], "-l"))
{
if (argc < argn + 2)
syntax(argv[0]);
opt_l = to_int_nonneg(argv[++argn], "-l");
}
else if (!strcmp(argv[argn], "-u"))
{
opt_u = true;
}
else else
{ {
ap->insert(env.require(argv[argn])); ap->insert(env.require(argv[argn]));
} }
} }
spot::random_ltl rl(ap);
const char* tok = rl.parse_options(opt_p);
if (tok)
{
std::cerr << "failed to parse probabilities near `"
<< tok << '\'' << std::endl;
exit(2);
}
if (opt_l > opt_f)
{
std::cerr << "-l's argument (" << opt_l << ") should not be larger than "
<< "-f's (" << opt_f << ')' << std::endl;
exit(2);
}
if (opt_dp)
{
rl.dump_priorities(std::cout);
exit(0);
}
if (ec_algos.empty()) if (ec_algos.empty())
{ {
const char** i = default_algos; const char** i = default_algos;
@ -817,8 +666,9 @@ main(int argc, char** argv)
spot::timer_map tm_ec; spot::timer_map tm_ec;
spot::timer_map tm_ar; spot::timer_map tm_ar;
std::set<int> failed_seeds; std::set<int> failed_seeds;
int init_opt_ec = opt_ec;
spot::atomic_prop_set* apf = new spot::atomic_prop_set; spot::atomic_prop_set* apf = new spot::atomic_prop_set;
for (auto i: *ap)
apf->insert(i);
if (opt_ec) if (opt_ec)
{ {
@ -839,50 +689,7 @@ main(int argc, char** argv)
do do
{ {
if (opt_F)
{
spot::formula f =
generate_formula(rl, simp, opt_f, opt_ec_seed, opt_l, opt_u);
if (!f)
exit(1);
formula = spot::ltl_to_tgba_fm(f, dict, true);
}
else if (opt_i)
{
if (formula_file->good())
{
std::string input;
if (std::getline(*formula_file, input, '\n').fail())
break;
else if (input == "")
break;
auto pf = spot::parse_infix_psl(input, env);
if (pf.format_errors(std::cerr))
{
exit_code = 1;
break;
}
formula = spot::ltl_to_tgba_fm(pf.f, dict, true);
auto* tmp = spot::atomic_prop_collect(pf.f);
for (auto i: *tmp)
apf->insert(i);
delete tmp;
}
else
{
if (formula_file->bad())
std::cerr << "Failed to read " << opt_i << std::endl;
break;
}
}
for (auto i: *ap)
apf->insert(i);
if (!opt_S)
{
do
{
if (opt_ec && !opt_paper) if (opt_ec && !opt_paper)
std::cout << "seed: " << opt_ec_seed << std::endl; std::cout << "seed: " << opt_ec_seed << std::endl;
spot::srand(opt_ec_seed); spot::srand(opt_ec_seed);
@ -891,8 +698,6 @@ main(int argc, char** argv)
spot::twa_graph_ptr a = spot::twa_graph_ptr a =
spot::random_graph(opt_n, opt_d, apf, dict, spot::random_graph(opt_n, opt_d, apf, dict,
opt_n_acc, opt_a, opt_t, opt_det); opt_n_acc, opt_a, opt_t, opt_det);
if (formula)
a = spot::product(formula, a);
int real_n_acc = a->acc().num_sets(); int real_n_acc = a->acc().num_sets();
@ -1092,19 +897,7 @@ main(int argc, char** argv)
} }
} }
while (opt_ec); while (opt_ec);
}
else
{
--opt_S;
opt_ec_seed += init_opt_ec;
}
if (opt_F)
--opt_F;
opt_ec = init_opt_ec;
apf->clear(); apf->clear();
}
while (opt_F || opt_i);
if (!opt_paper && opt_z) if (!opt_paper && opt_z)
{ {
@ -1246,12 +1039,6 @@ main(int argc, char** argv)
std::cout << std::endl; std::cout << std::endl;
} }
if (opt_i && strcmp(opt_i, "-"))
{
dynamic_cast<std::ifstream*>(formula_file)->close();
delete formula_file;
}
delete ap; delete ap;
delete apf; delete apf;
return exit_code; return exit_code;