randaut: add a --colored option
Fixes #83. * src/bin/randaut.cc: Add option. * src/twaalgos/randomgraph.cc, src/twaalgos/randomgraph.hh: Honor it. * src/tests/randaut.test: Add tests. * doc/org/randaut.org: Document it.
This commit is contained in:
parent
97665a584e
commit
715805fad3
5 changed files with 148 additions and 33 deletions
|
|
@ -69,6 +69,7 @@ a high density of transitions, and 3 to 4 atomic propositions:\n\
|
|||
|
||||
enum {
|
||||
OPT_SEED = 1,
|
||||
OPT_COLORED,
|
||||
};
|
||||
|
||||
static const argp_option options[] =
|
||||
|
|
@ -83,6 +84,9 @@ static const argp_option options[] =
|
|||
"use a negative value for unbounded generation", 0 },
|
||||
{ "ba", 'B', 0, 0,
|
||||
"build a Buchi automaton (implies --acceptance=Buchi --state-acc)", 0 },
|
||||
{ "colored", OPT_COLORED, 0, 0,
|
||||
"build an automaton in which each transition (or state if combined with "
|
||||
"-S) belong to a single acceptance set", 0 },
|
||||
{ "density", 'd', "FLOAT", 0, "density of the transitions (0.2)", 0 },
|
||||
{ "deterministic", 'D', 0, 0, "build a complete, deterministic automaton ",
|
||||
0 },
|
||||
|
|
@ -138,10 +142,11 @@ static const char* opt_seed_str = "0";
|
|||
static int opt_automata = 1;
|
||||
static range opt_states = { 10, 10 };
|
||||
static float opt_density = 0.2;
|
||||
static range opt_acc_sets = { 0, 0 };
|
||||
static range opt_acc_sets = { -1, 0 };
|
||||
static float opt_acc_prob = 0.2;
|
||||
static bool opt_deterministic = false;
|
||||
static bool opt_state_acc = false;
|
||||
static bool opt_colored = false;
|
||||
static bool ba_wanted = false;
|
||||
static bool generic_wanted = false;
|
||||
static bool gba_wanted = false;
|
||||
|
|
@ -224,6 +229,9 @@ parse_opt(int key, char* arg, struct argp_state* as)
|
|||
opt_uniq =
|
||||
std::unique_ptr<unique_aut_t>(new std::set<std::vector<tr_t>>());
|
||||
break;
|
||||
case OPT_COLORED:
|
||||
opt_colored = true;
|
||||
break;
|
||||
case OPT_SEED:
|
||||
opt_seed = to_int(arg);
|
||||
opt_seed_str = arg;
|
||||
|
|
@ -290,6 +298,16 @@ main(int argc, char** argv)
|
|||
if (automaton_format == Spin)
|
||||
ba_options();
|
||||
|
||||
if (opt_colored && opt_acc_sets.min == -1 && !generic_wanted)
|
||||
error(2, 0, "--colored requires at least one acceptance set; "
|
||||
"use --acceptance");
|
||||
if (opt_colored && opt_acc_sets.min == 0)
|
||||
error(2, 0, "--colored requires at least one acceptance set; "
|
||||
"fix the range of --acceptance");
|
||||
|
||||
if (opt_acc_sets.min == -1)
|
||||
opt_acc_sets.min = 0;
|
||||
|
||||
try
|
||||
{
|
||||
spot::srand(opt_seed);
|
||||
|
|
@ -328,12 +346,16 @@ main(int argc, char** argv)
|
|||
{
|
||||
code = spot::parse_acc_code(opt_acceptance);
|
||||
accs = code.used_sets().max_set();
|
||||
if (opt_colored && accs == 0)
|
||||
error(2, 0, "--colored requires at least one acceptance set; "
|
||||
"fix the range of --acceptance");
|
||||
}
|
||||
|
||||
auto aut =
|
||||
spot::random_graph(size, opt_density, &aprops, d,
|
||||
accs, opt_acc_prob, 0.5,
|
||||
opt_deterministic, opt_state_acc);
|
||||
opt_deterministic, opt_state_acc,
|
||||
opt_colored);
|
||||
|
||||
if (opt_acceptance)
|
||||
aut->set_acceptance(accs, code);
|
||||
|
|
|
|||
|
|
@ -133,3 +133,15 @@ AP: 2 "p0" "p1"
|
|||
AP: 3 "p0" "p1" "p2"
|
||||
EOF
|
||||
diff output expected
|
||||
|
||||
$randaut -A3 --colored 2 -H | grep 'properties:.*colored'
|
||||
$randaut -S -A'parity min even 3' --colored 2 -H | grep 'properties:.*colored'
|
||||
|
||||
$randaut --colored 2 2>stderr && exit 1
|
||||
grep 'randaut: --colored requires' stderr
|
||||
$randaut -A0..2 --colored 2 2>stderr && exit 1
|
||||
grep 'randaut: --colored requires' stderr
|
||||
$randaut -S -A'parity min even 0..3' -q -n10 --colored 2 2>stderr && exit 1
|
||||
grep 'randaut: --colored requires' stderr
|
||||
|
||||
:
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ namespace spot
|
|||
|
||||
namespace
|
||||
{
|
||||
unsigned
|
||||
static unsigned
|
||||
random_deterministic_labels_rec(std::vector<bdd>& labels, int *props,
|
||||
int props_n, bdd current, unsigned n)
|
||||
{
|
||||
|
|
@ -69,7 +69,7 @@ namespace spot
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<bdd>
|
||||
static std::vector<bdd>
|
||||
random_deterministic_labels(int *props, int props_n, unsigned n)
|
||||
{
|
||||
std::vector<bdd> bddvec;
|
||||
|
|
@ -77,16 +77,23 @@ namespace spot
|
|||
return bddvec;
|
||||
}
|
||||
|
||||
acc_cond::mark_t
|
||||
random_acc_cond(twa_graph_ptr aut, unsigned n_accs, float a)
|
||||
static acc_cond::mark_t
|
||||
random_acc(unsigned n_accs, float a)
|
||||
{
|
||||
acc_cond::mark_t m = 0U;
|
||||
for (unsigned i = 0U; i < n_accs; ++i)
|
||||
if (drand() < a)
|
||||
m |= aut->acc().mark(i);
|
||||
m.set(i);
|
||||
return m;
|
||||
}
|
||||
|
||||
static acc_cond::mark_t
|
||||
random_acc1(unsigned n_accs)
|
||||
{
|
||||
auto u = static_cast<unsigned>(mrand(static_cast<int>(n_accs)));
|
||||
return acc_cond::mark_t({u});
|
||||
}
|
||||
|
||||
bdd
|
||||
random_labels(int* props, int props_n, float t)
|
||||
{
|
||||
|
|
@ -118,7 +125,7 @@ namespace spot
|
|||
random_graph(int n, float d,
|
||||
const ltl::atomic_prop_set* ap, const bdd_dict_ptr& dict,
|
||||
unsigned n_accs, float a, float t,
|
||||
bool deterministic, bool state_acc)
|
||||
bool deterministic, bool state_acc, bool colored)
|
||||
{
|
||||
assert(n > 0);
|
||||
auto res = make_twa_graph(dict);
|
||||
|
|
@ -188,12 +195,12 @@ namespace spot
|
|||
unsigned dst;
|
||||
acc_cond::mark_t m = 0U;
|
||||
if (state_acc)
|
||||
m = random_acc_cond(res, n_accs, a);
|
||||
m = colored ? random_acc1(n_accs) : random_acc(n_accs, a);
|
||||
|
||||
for (auto& l: labels)
|
||||
{
|
||||
if (!state_acc)
|
||||
m = random_acc_cond(res, n_accs, a);
|
||||
m = colored ? random_acc1(n_accs) : random_acc(n_accs, a);
|
||||
|
||||
// No connection to unreachable successors so far. This
|
||||
// is our last chance, so force it now.
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ namespace spot
|
|||
/// is true.
|
||||
/// \param deterministic build a complete and deterministic automaton
|
||||
/// \param state_acc build an automaton with state-based acceptance
|
||||
/// \param colored build an automaton in which each transition (or state)
|
||||
/// belongs to a single acceptance set.
|
||||
///
|
||||
/// This algorithms is adapted from the one in Fig 6.2 page 48 of
|
||||
/** \verbatim
|
||||
|
|
@ -81,7 +83,8 @@ namespace spot
|
|||
random_graph(int n, float d,
|
||||
const ltl::atomic_prop_set* ap, const bdd_dict_ptr& dict,
|
||||
unsigned n_accs = 0, float a = 0.1, float t = 0.5,
|
||||
bool deterministic = false, bool state_acc = false);
|
||||
bool deterministic = false, bool state_acc = false,
|
||||
bool colored = false);
|
||||
|
||||
/// Build a random acceptance where each acceptance sets is used once.
|
||||
SPOT_API acc_cond::acc_code random_acceptance(unsigned n_accs);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue