autfilt: add highlighting options for nondeterminism

Fixes #123.

* bin/autfilt.cc: Add options --highlight-nondet-states=NUM,
 --highlight-nondet-edges=NUM, and  --highlight-nondet=NUM.
* spot/twaalgos/isdet.cc,
spot/twaalgos/isdet.hh (highlight_nondet_states,
highlight_nondet_edges): New functions.
* tests/core/det.test: Add test cases.
* NEWS: Mention them.
This commit is contained in:
Alexandre Duret-Lutz 2016-07-18 13:12:58 +02:00
parent 39332fb118
commit b6cd54ab16
5 changed files with 186 additions and 5 deletions

View file

@ -73,6 +73,53 @@ namespace spot
return !count_nondet_states_aux<false>(aut);
}
void
highlight_nondet_states(twa_graph_ptr& aut, unsigned color)
{
if (aut->prop_deterministic())
return;
unsigned ns = aut->num_states();
auto* highlight = new std::map<unsigned, unsigned>;
for (unsigned src = 0; src < ns; ++src)
{
bdd available = bddtrue;
for (auto& t: aut->out(src))
if (!bdd_implies(t.cond, available))
highlight->emplace(src, color);
else
available -= t.cond;
}
aut->prop_deterministic(highlight->empty());
aut->set_named_prop("highlight-states", highlight);
}
void
highlight_nondet_edges(twa_graph_ptr& aut, unsigned color)
{
if (aut->prop_deterministic())
return;
unsigned ns = aut->num_states();
auto* highlight = new std::map<unsigned, unsigned>;
for (unsigned src = 0; src < ns; ++src)
{
// Make a first pass to gather non-deterministic labels
bdd available = bddtrue;
bdd extra = bddfalse;
for (auto& t: aut->out(src))
if (!bdd_implies(t.cond, available))
extra |= (t.cond - available);
else
available -= t.cond;
// Second pass to gather the relevant edges.
if (extra != bddfalse)
for (auto& t: aut->out(src))
if ((t.cond & extra) != bddfalse)
highlight->emplace(aut->get_graph().index_of_edge(t), color);
}
aut->prop_deterministic(highlight->empty());
aut->set_named_prop("highlight-edges", highlight);
}
bool
is_complete(const const_twa_graph_ptr& aut)
{

View file

@ -46,12 +46,32 @@ namespace spot
SPOT_API bool
is_deterministic(const const_twa_graph_ptr& aut);
/// \brief Highlight nondeterministic states
///
/// A state is nondeterministic if it has two outgoing edges whose
/// labels are not incompatibles.
///
/// \param aut the automaton to process
/// \param color the color to give to nondeterministic states.
SPOT_API void
highlight_nondet_states(twa_graph_ptr& aut, unsigned color);
/// \brief Highlight nondeterministic edges
///
/// An edge is nondeterministic if there exist another edge leaving
/// the same source state, with a compatible label (i.e., the
/// conjunction of the two labels is not false).
///
/// \param aut the automaton to process
/// \param color the color to give to nondeterministic edges.
SPOT_API void
highlight_nondet_edges(twa_graph_ptr& aut, unsigned color);
/// @}
/// \brief Return true iff \a aut is complete.
///
/// An automaton is complete if its translation relation is total,
/// i.e., each state as a successor for any possible configuration.
SPOT_API bool
is_complete(const const_twa_graph_ptr& aut);
/// @}
}