ltldo: add support for -n

Fixes #287.

* bin/ltldo.cc: Implement it.
* tests/core/ltldo.test: Test it.
* NEWS: Mention the new feature.
This commit is contained in:
Alexandre Duret-Lutz 2017-10-05 17:17:57 +02:00
parent 584430803d
commit 33af116fb8
3 changed files with 33 additions and 5 deletions

2
NEWS
View file

@ -34,6 +34,8 @@ New in spot 2.4.1.dev (not yet released)
- ltlsynt is a new tool for synthesizing AIGER circuits from LTL/PSL - ltlsynt is a new tool for synthesizing AIGER circuits from LTL/PSL
formulas. formulas.
- ltldo learned to limit the number of automata it outputs using -n.
Library: Library:
- Rename three methods of spot::scc_info. New names are clearer. The - Rename three methods of spot::scc_info. New names are clearer. The

View file

@ -57,10 +57,12 @@ enum {
static const argp_option options[] = static const argp_option options[] =
{ {
/**************************************************/
{ nullptr, 0, nullptr, 0, "Error handling:", 4 }, { nullptr, 0, nullptr, 0, "Error handling:", 4 },
{ "errors", OPT_ERRORS, "abort|warn|ignore", 0, { "errors", OPT_ERRORS, "abort|warn|ignore", 0,
"how to deal with tools returning with non-zero exit codes or " "how to deal with tools returning with non-zero exit codes or "
"automata that ltldo cannot parse (default: abort)", 0 }, "automata that ltldo cannot parse (default: abort)", 0 },
/**************************************************/
{ nullptr, 0, nullptr, 0, "Output selection:", 5 }, { nullptr, 0, nullptr, 0, "Output selection:", 5 },
{ "smallest", OPT_SMALLEST, "FORMAT", OPTION_ARG_OPTIONAL, { "smallest", OPT_SMALLEST, "FORMAT", OPTION_ARG_OPTIONAL,
"for each formula select the smallest automaton given by all " "for each formula select the smallest automaton given by all "
@ -68,6 +70,8 @@ static const argp_option options[] =
{ "greatest", OPT_GREATEST, "FORMAT", OPTION_ARG_OPTIONAL, { "greatest", OPT_GREATEST, "FORMAT", OPTION_ARG_OPTIONAL,
"for each formula select the greatest automaton given by all " "for each formula select the greatest automaton given by all "
"translators, using FORMAT for ordering (default is %s,%e)", 0 }, "translators, using FORMAT for ordering (default is %s,%e)", 0 },
{ "max-count", 'n', "NUM", 0, "output at most NUM automata", 0 },
/**************************************************/
{ nullptr, 0, nullptr, 0, "Miscellaneous options:", -1 }, { nullptr, 0, nullptr, 0, "Miscellaneous options:", -1 },
{ nullptr, 0, nullptr, 0, nullptr, 0 } { nullptr, 0, nullptr, 0, nullptr, 0 }
}; };
@ -121,6 +125,7 @@ static errors_type errors_opt;
static int best_type = 0; // -1 smallest, 1 greatest, 0 no selection static int best_type = 0; // -1 smallest, 1 greatest, 0 no selection
static const char* best_format = "%s,%e"; static const char* best_format = "%s,%e";
static int opt_max_count = -1;
static char const *const errors_args[] = static char const *const errors_args[] =
{ {
@ -167,6 +172,9 @@ parse_opt(int key, char* arg, struct argp_state*)
if (arg) if (arg)
best_format = arg; best_format = arg;
break; break;
case 'n':
opt_max_count = to_pos_int(arg);
break;
case ARGP_KEY_ARG: case ARGP_KEY_ARG:
if (arg[0] == '-' && !arg[1]) if (arg[0] == '-' && !arg[1])
jobs.emplace_back(arg, true); jobs.emplace_back(arg, true);
@ -318,6 +326,19 @@ namespace
return 0; return 0;
} }
void output_aut(const spot::twa_graph_ptr& aut,
spot::process_timer& ptimer,
spot::formula f,
const char* filename, int loc,
const char* csv_prefix, const char* csv_suffix)
{
static long int output_count = 0;
++output_count;
printer.print(aut, ptimer, f, filename, loc, nullptr,
csv_prefix, csv_suffix);
if (opt_max_count >= 0 && output_count >= opt_max_count)
abort_run = true;
}
int int
process_formula(spot::formula f, process_formula(spot::formula f,
@ -385,17 +406,18 @@ namespace
} }
else else
{ {
printer.print(aut, timer, f, filename, linenum, output_aut(aut, timer, f, filename, linenum,
nullptr, prefix, suffix); prefix, suffix);
if (abort_run)
break;
} }
} }
} }
if (best_aut) if (best_aut)
{ {
cmdname = best_cmdname; cmdname = best_cmdname;
printer.print(best_aut, best_timer, output_aut(best_aut, best_timer, f, filename, linenum,
f, filename, linenum, prefix, suffix);
nullptr, prefix, suffix);
} }
spot::cleanup_tmpfiles(); spot::cleanup_tmpfiles();

View file

@ -148,6 +148,10 @@ $ltldo '{name} foo/bar/ltl2baextended' -f GFa 2>stderr && exit 1
grep 'error:.*foo/bar/ltl2baextended -f .*>.*' stderr grep 'error:.*foo/bar/ltl2baextended -f .*>.*' stderr
test 2 = `genltl --and-gf=1..4 | ltldo ltl2tgba -n2 | autfilt -c`
test 3 = `genltl --and-gf=1..2 | ltldo ltl2tgba 'ltl2tgba -s' -n3 | autfilt -c`
genltl --rv-counter=9 | ltldo ltl2tgba --stats=' genltl --rv-counter=9 | ltldo ltl2tgba --stats='
print("%[up]R + %[uc]R + %[sp]R + %[sc]R - %R\n"); print("%[up]R + %[uc]R + %[sp]R + %[sc]R - %R\n");
die if abs(%[up]R + %[uc]R + %[sp]R + %[sc]R - %R) > 0.02;' > code.pl die if abs(%[up]R + %[uc]R + %[sp]R + %[sc]R - %R) > 0.02;' > code.pl