twa: add accepting_run() and accepting_word() methods

Fixes #153.

* spot/twa/twa.cc, spot/twa/twa.hh: Add the methods.
* bin/autfilt.cc, bin/common_aoutput.hh, bin/ltlcross.cc,
tests/python/highlighting.ipynb, tests/python/word.ipynb: Use
them to simplify the code.
* NEWS: Mention them.
This commit is contained in:
Alexandre Duret-Lutz 2016-07-18 23:20:49 +02:00
parent 3836ea8d18
commit 014a9dbd6b
8 changed files with 145 additions and 71 deletions

View file

@ -23,6 +23,7 @@
#include <spot/twa/twa.hh>
#include <spot/twa/twagraph.hh>
#include <spot/twaalgos/gtec/gtec.hh>
#include <spot/twaalgos/word.hh>
#include <spot/twaalgos/remfin.hh>
#include <utility>
@ -69,6 +70,42 @@ namespace spot
return !couvreur99(a)->check();
}
twa_run_ptr
twa::accepting_run() const
{
if (acc().uses_fin_acceptance())
throw std::runtime_error("twa::accepting_run() does not work with "
"Fin acceptance (but twa:is_empty() and "
"twa::accepting_run() can)");
auto res = couvreur99(shared_from_this())->check();
if (!res)
return nullptr;
return res->accepting_run();
}
twa_word_ptr
twa::accepting_word() const
{
auto a = shared_from_this();
if (a->acc().uses_fin_acceptance())
{
auto aa = std::dynamic_pointer_cast<const twa_graph>(a);
if (!aa)
aa = make_twa_graph(a, prop_set::all());
a = remove_fin(aa);
}
if (auto run = a->accepting_run())
{
auto w = make_twa_word(run->reduce());
w->simplify();
return w;
}
else
{
return nullptr;
}
}
void
twa::set_named_prop(std::string s, std::nullptr_t)
{

View file

@ -39,6 +39,12 @@
namespace spot
{
struct twa_run;
typedef std::shared_ptr<twa_run> twa_run_ptr;
struct twa_word;
typedef std::shared_ptr<twa_word> twa_word_ptr;
/// \ingroup twa_essentials
/// \brief Abstract class for states.
class SPOT_API state
@ -821,9 +827,28 @@ namespace spot
}
///@}
/// Check whether the language of the automaton is empty.
/// \brief Check whether the language of the automaton is empty.
virtual bool is_empty() const;
/// \brief Return an accepting run if one exists.
///
/// Note that this method currently one works for Fin-less
/// acceptance. For acceptance conditions that contain Fin
/// acceptance, you can either rely on is_empty() and not use any
/// accepting run, or remove Fin acceptance using remove_fin() and
/// compute an accepting run on that larger automaton.
///
/// Return nullptr if no accepting run were found.
virtual twa_run_ptr accepting_run() const;
/// \brief Return an accepting word if one exists.
///
/// Note that this method DO works with Fin
/// acceptance.
///
/// Return nullptr if no accepting word were found.
virtual twa_word_ptr accepting_word() const;
private:
acc_cond acc_;