Commit 8c972ad3 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Cleanup the minimize.hh interface.

* src/tgbaalgos/minimize.hh, src/tgbaalgos/minimize.cc
(minimize): Split into ...
(minimize_wdba, minimize_monitor): ... these two functions.
* src/tgbatest/ltl2tgba.cc (main): Adjust the call to
minimize_monitor.
* wrap/python/cgi-bin/ltl2tgba.in: Adjust the calls to
minimize_monitor and minimize_obligation.
* wrap/python/spot.i: Declare minimize_monitor, minimize_wdba,
minimize_obligations.
* src/tgba/tgbaexplicit.hh (tgba_explicit_string)
(tgba_explicit_formula, tgba_explicit_number): Add fake
declarations so that SWIG can see they inherits from tgba.
parent 92126a6c
2011-01-05 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Cleanup the minimize.hh interface.
* src/tgbaalgos/minimize.hh, src/tgbaalgos/minimize.cc
(minimize): Split into ...
(minimize_wdba, minimize_monitor): ... these two functions.
* src/tgbatest/ltl2tgba.cc (main): Adjust the call to
minimize_monitor.
* wrap/python/cgi-bin/ltl2tgba.in: Adjust the calls to
minimize_monitor and minimize_obligation.
* wrap/python/spot.i: Declare minimize_monitor, minimize_wdba,
minimize_obligations.
* src/tgba/tgbaexplicit.hh (tgba_explicit_string)
(tgba_explicit_formula, tgba_explicit_number): Add fake
declarations so that SWIG can see they inherits from tgba.
2011-01-05 Alexandre Duret-Lutz <adl@lrde.epita.fr> 2011-01-05 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Cleanup the DFA minimization algorithm. Cleanup the DFA minimization algorithm.
......
// Copyright (C) 2009, 2010 Laboratoire de Recherche et Développement // Copyright (C) 2009, 2010, 2011 Laboratoire de Recherche et Développement
// de l'Epita (LRDE). // de l'Epita (LRDE).
// Copyright (C) 2003, 2004, 2006 Laboratoire d'Informatique de // Copyright (C) 2003, 2004, 2006 Laboratoire d'Informatique de
// Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC), // Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
...@@ -313,6 +313,7 @@ namespace spot ...@@ -313,6 +313,7 @@ namespace spot
}; };
#ifndef SWIG
class tgba_explicit_string: class tgba_explicit_string:
public tgba_explicit_labelled<std::string, string_hash> public tgba_explicit_labelled<std::string, string_hash>
{ {
...@@ -333,7 +334,13 @@ namespace spot ...@@ -333,7 +334,13 @@ namespace spot
name_state_map_[alias_name] = add_state(real_name); name_state_map_[alias_name] = add_state(real_name);
} }
}; };
#else
class tgba_explicit_string: public tgba
{
};
#endif
#ifndef SWIG
class tgba_explicit_formula: class tgba_explicit_formula:
public tgba_explicit_labelled<const ltl::formula*, ltl::formula_ptr_hash> public tgba_explicit_labelled<const ltl::formula*, ltl::formula_ptr_hash>
{ {
...@@ -345,7 +352,13 @@ namespace spot ...@@ -345,7 +352,13 @@ namespace spot
virtual state* add_default_init(); virtual state* add_default_init();
virtual std::string format_state(const spot::state* s) const; virtual std::string format_state(const spot::state* s) const;
}; };
#else
class tgba_explicit_formula: public tgba
{
};
#endif
#ifndef SWIG
class tgba_explicit_number: class tgba_explicit_number:
public tgba_explicit_labelled<int, std::tr1::hash<int> > public tgba_explicit_labelled<int, std::tr1::hash<int> >
{ {
...@@ -357,6 +370,11 @@ namespace spot ...@@ -357,6 +370,11 @@ namespace spot
virtual state* add_default_init(); virtual state* add_default_init();
virtual std::string format_state(const spot::state* s) const; virtual std::string format_state(const spot::state* s) const;
}; };
#else
class tgba_explicit_number: public tgba
{
};
#endif
} }
#endif // SPOT_TGBA_TGBAEXPLICIT_HH #endif // SPOT_TGBA_TGBAEXPLICIT_HH
...@@ -506,7 +506,20 @@ namespace spot ...@@ -506,7 +506,20 @@ namespace spot
} }
tgba_explicit_number* minimize(const tgba* a, bool monitor) tgba_explicit_number* minimize_monitor(const tgba* a)
{
hash_set* final = new hash_set;
tgba_explicit_number* det_a;
{
power_map pm;
det_a = tgba_powerset(a, pm);
}
// final is empty: there is no acceptance condition
return minimize_dfa(det_a, final);
}
tgba_explicit_number* minimize_wdba(const tgba* a)
{ {
hash_set* final = new hash_set; hash_set* final = new hash_set;
tgba_explicit_number* det_a; tgba_explicit_number* det_a;
...@@ -515,57 +528,54 @@ namespace spot ...@@ -515,57 +528,54 @@ namespace spot
power_map pm; power_map pm;
det_a = tgba_powerset(a, pm); det_a = tgba_powerset(a, pm);
if (!monitor) // For each SCC of the deterministic automaton, determine if
// it is accepting or not.
scc_map sm(det_a);
sm.build_map();
unsigned scc_count = sm.scc_count();
std::vector<bool> accepting(scc_count);
// SCC are numbered in topological order
for (unsigned n = 0; n < scc_count; ++n)
{ {
// For each SCC of the deterministic automaton, determine if bool acc = true;
// it is accepting or not.
scc_map sm(det_a);
sm.build_map();
unsigned scc_count = sm.scc_count();
std::vector<bool> accepting(scc_count);
// SCC are numbered in topological order
for (unsigned n = 0; n < scc_count; ++n)
{
bool acc = true;
if (sm.trivial(n)) if (sm.trivial(n))
{
// Trivial SCCs are accepting if all their
// successors are accepting.
// This corresponds to the algorithm in Fig. 1 of
// "Efficient minimization of deterministic weak
// omega-automata" written by Christof Löding and
// published in Information Processing Letters 79
// (2001) pp 105--109. Except we do not keep track
// of the actual color associated to each SCC.
const scc_map::succ_type& succ = sm.succ(n);
for (scc_map::succ_type::const_iterator i = succ.begin();
i != succ.end(); ++i)
{ {
// Trivial SCCs are accepting if all their if (!accepting[i->first])
// successors are accepting.
// This corresponds to the algorithm in Fig. 1 of
// "Efficient minimization of deterministic weak
// omega-automata" written by Christof Löding and
// published in Information Processing Letters 79
// (2001) pp 105--109. Except we do not keep track
// of the actual color associated to each SCC.
const scc_map::succ_type& succ = sm.succ(n);
for (scc_map::succ_type::const_iterator i = succ.begin();
i != succ.end(); ++i)
{ {
if (!accepting[i->first]) acc = false;
{ break;
acc = false;
break;
}
} }
} }
else }
{ else
// Regular SCCs are accepting if any of their loop {
// corresponds to an accepting // Regular SCCs are accepting if any of their loop
acc = wdba_scc_is_accepting(det_a, n, a, sm, pm); // corresponds to an accepting
} acc = wdba_scc_is_accepting(det_a, n, a, sm, pm);
}
accepting[n] = acc; accepting[n] = acc;
if (acc) if (acc)
{ {
std::list<const state*> l = sm.states_of(n); std::list<const state*> l = sm.states_of(n);
std::list<const state*>::const_iterator il; std::list<const state*>::const_iterator il;
for (il = l.begin(); il != l.end(); ++il) for (il = l.begin(); il != l.end(); ++il)
final->insert((*il)->clone()); final->insert((*il)->clone());
}
} }
} }
} }
...@@ -577,8 +587,7 @@ namespace spot ...@@ -577,8 +587,7 @@ namespace spot
minimize_obligation(const tgba* aut_f, minimize_obligation(const tgba* aut_f,
const ltl::formula* f, const tgba* aut_neg_f) const ltl::formula* f, const tgba* aut_neg_f)
{ {
// WDBA minimization tgba_explicit_number* min_aut_f = minimize_wdba(aut_f);
tgba_explicit_number* min_aut_f = minimize(aut_f);
// If aut_f is a safety automaton, the WDBA minimization must be // If aut_f is a safety automaton, the WDBA minimization must be
// correct. // correct.
......
...@@ -26,101 +26,99 @@ ...@@ -26,101 +26,99 @@
namespace spot namespace spot
{ {
/// \brief Use the powerset construction to minimize a TGBA. /// \addtogroup tgba_reduction
/// @{
/// \brief Construct a minimal deterministic monitor.
/// ///
/// If \a monitor is set to \c false (the default), then the /// The automaton will be converted into minimal deterministic
/// minimized automaton is correct only for properties that belong /// monitor. All useless SCCs should have been previously removed
/// to the class of "obligation properties". This algorithm assumes /// (using scc_filter() for instance). Then the automaton will be
/// that the given automaton expresses an obligation properties and /// determinized and minimized using the standard DFA construction
/// will return an automaton that is bogus (i.e. not equivalent to /// as if all states where accepting states.
/// the original) if that is not the case.
///
/// Please see the following paper for a discussion of this
/// technique.
/// ///
/// For more detail about monitors, see the following paper:
/// \verbatim /// \verbatim
/// @InProceedings{ dax.07.atva, /// @InProceedings{ tabakov.10.rv,
/// author = {Christian Dax and Jochen Eisinger and Felix Klaedtke}, /// author = {Deian Tabakov and Moshe Y. Vardi},
/// title = {Mechanizing the Powerset Construction for Restricted /// title = {Optimized Temporal Monitors for SystemC{$^*$}},
/// Classes of {$\omega$}-Automata}, /// booktitle = {Proceedings of the 10th International Conferance
/// year = 2007, /// on Runtime Verification},
/// series = {Lecture Notes in Computer Science}, /// pages = {436--451},
/// publisher = {Springer-Verlag}, /// year = 2010,
/// volume = 4762, /// volume = {6418},
/// booktitle = {Proceedings of the 5th International Symposium on /// series = {Lecture Notes in Computer Science},
/// Automated Technology for Verification and Analysis /// month = nov,
/// (ATVA'07)}, /// publisher = {Spring-Verlag}
/// editor = {Kedar S. Namjoshi and Tomohiro Yoneda and Teruo Higashino
/// and Yoshio Okamura},
/// month = oct
/// } /// }
/// \endverbatim /// \endverbatim
/// (Note: although the above paper uses Spot, this function did not
/// exist in Spot at that time.)
/// ///
/// Dax et al. suggest one way to check whether a property /// \param a the automaton to convert into a minimal deterministic monitor
/// \f$\varphi\f$ expressed as an LTL formula is an obligation: /// \pre Dead SCCs should have been removed from \a a before
/// translate the formula and its negation as two automata \f$A_f\f$ /// calling this function.
/// and \f$A_{\lnot f}\f$, then minimize both automata and check tgba_explicit_number* minimize_monitor(const tgba* a);
/// that the two products $\f \mathrm{minimize(A_{\lnot f})\otimes
/// A_f\f$ and $\f \mathrm{minimize(A_f)\otimes A_{\lnot f}\f$ are /// \brief Minimize a Büchi automaton in the WDBA class.
/// empty. If that is the case, then the minimization was correct.
/// ///
/// You may also want to check if \$A_f\$ is a safety automaton /// This takes a TGBA whose language is representable by
/// using the is_safety_automaton() function. Since safety /// a Weak Deterministic Büchi Automaton, and construct
/// properties are a subclass of obligation properties, you can /// a minimal WDBA for this language.
/// apply the minimization without further test. Note however that
/// this is only a sufficient condition.
/// ///
/// If \a monitor is set to \c true, the automaton will be converted /// If the input automaton does not represent a WDBA language,
/// into minimal deterministic monitor. All useless SCCs should /// the resulting automaton is still a WDBA, but it will not
/// have been previously removed (using scc_filter() for instance). /// be equivalent to the original automaton. Use the
/// Then the automaton will be reduced as if all states where /// minimize_obligation() function if you are not sure whether
/// accepting states. /// it is safe to call this function.
///
/// Please see the following paper for a discussion of this
/// technique.
/// ///
/// For more detail about monitors, see the following paper:
/// \verbatim /// \verbatim
/// @InProceedings{ tabakov.10.rv, /// @InProceedings{ dax.07.atva,
/// author = {Deian Tabakov and Moshe Y. Vardi}, /// author = {Christian Dax and Jochen Eisinger and Felix Klaedtke},
/// title = {Optimized Temporal Monitors for SystemC{$^*$}}, /// title = {Mechanizing the Powerset Construction for Restricted
/// booktitle = {Proceedings of the 10th International Conferance /// Classes of {$\omega$}-Automata},
/// on Runtime Verification}, /// year = 2007,
/// pages = {436--451}, /// series = {Lecture Notes in Computer Science},
/// year = 2010, /// publisher = {Springer-Verlag},
/// volume = {6418}, /// volume = 4762,
/// series = {Lecture Notes in Computer Science}, /// booktitle = {Proceedings of the 5th International Symposium on
/// month = nov, /// Automated Technology for Verification and Analysis
/// publisher = {Spring-Verlag} /// (ATVA'07)},
/// editor = {Kedar S. Namjoshi and Tomohiro Yoneda and Teruo Higashino
/// and Yoshio Okamura},
/// month = oct
/// } /// }
/// \endverbatim /// \endverbatim
/// (Note: although the above paper uses Spot, this function did not tgba_explicit_number* minimize_wdba(const tgba* a);
/// exist at that time.)
tgba_explicit_number* minimize(const tgba* a, bool monitor = false);
/// \brief Minimize an automaton if it represents an obligation property. /// \brief Minimize an automaton if it represents an obligation property.
/// ///
/// This function attempt to minimize the automaton \a aut_f using the /// This function attempts to minimize the automaton \a aut_f using the
/// algorithm implemented in the minimize() function, and presented /// algorithm implemented in the minimize_wdba() function, and presented
/// by the following paper: /// by the following paper:
/// ///
/// \verbatim /// \verbatim
/// @InProceedings{ dax.07.atva, /// @InProceedings{ dax.07.atva,
/// author = {Christian Dax and Jochen Eisinger and Felix Klaedtke}, /// author = {Christian Dax and Jochen Eisinger and Felix Klaedtke},
/// title = {Mechanizing the Powerset Construction for Restricted /// title = {Mechanizing the Powerset Construction for Restricted
/// Classes of {$\omega$}-Automata}, /// Classes of {$\omega$}-Automata},
/// year = 2007, /// year = 2007,
/// series = {Lecture Notes in Computer Science}, /// series = {Lecture Notes in Computer Science},
/// publisher = {Springer-Verlag}, /// publisher = {Springer-Verlag},
/// volume = 4762, /// volume = 4762,
/// booktitle = {Proceedings of the 5th International Symposium on /// booktitle = {Proceedings of the 5th International Symposium on
/// Automated Technology for Verification and Analysis /// Automated Technology for Verification and Analysis
/// (ATVA'07)}, /// (ATVA'07)},
/// editor = {Kedar S. Namjoshi and Tomohiro Yoneda and Teruo Higashino /// editor = {Kedar S. Namjoshi and Tomohiro Yoneda and Teruo Higashino
/// and Yoshio Okamura}, /// and Yoshio Okamura},
/// month = oct /// month = oct
/// } /// }
/// \endverbatim /// \endverbatim
/// ///
/// Because it is hard to determine if an automaton correspond /// Because it is hard to determine if an automaton corresponds
/// to an obligation property, you should supply either the formula /// to an obligation property, you should supply either the formula
/// \a f expressed by the automaton \a aut_f, or \a aut_neg_f the negation /// \a f expressed by the automaton \a aut_f, or \a aut_neg_f the negation
/// of the automaton \a aut_neg_f. /// of the automaton \a aut_neg_f.
...@@ -135,16 +133,18 @@ namespace spot ...@@ -135,16 +133,18 @@ namespace spot
/// ///
/// The function proceeds as follows. If the formula \a f or the /// The function proceeds as follows. If the formula \a f or the
/// automaton \a aut can easily be proved to represent an obligation /// automaton \a aut can easily be proved to represent an obligation
/// formula, then the result of \code minimize(aut) is returned. /// formula, then the result of <code>minimize(aut)</code> is
/// Otherwise, if \a aut_neg_f was not supplied but \a f was, \a /// returned. Otherwise, if \a aut_neg_f was not supplied but \a f
/// aut_neg_f is built from the negation of \a f. Then we check /// was, \a aut_neg_f is built from the negation of \a f. Then we
/// that \code product(aut,!minimize(aut_f)) and \code /// check that <code>product(aut,!minimize(aut_f))</code> and <code>
/// product(aut_neg_f,minize(aut)) are both empty. If they are, the /// product(aut_neg_f,minize(aut))</code> are both empty. If they
/// the minimization was sound. (See the paper for full details.) /// are, the the minimization was sound. (See the paper for full
/// details.)
const tgba* minimize_obligation(const tgba* aut_f, const tgba* minimize_obligation(const tgba* aut_f,
const ltl::formula* f = 0, const ltl::formula* f = 0,
const tgba* aut_neg_f = 0); const tgba* aut_neg_f = 0);
/// @}
} }
#endif /* !SPOT_TGBAALGOS_MINIMIZE_HH */ #endif /* !SPOT_TGBAALGOS_MINIMIZE_HH */
...@@ -954,7 +954,7 @@ main(int argc, char** argv) ...@@ -954,7 +954,7 @@ main(int argc, char** argv)
if (opt_monitor) if (opt_monitor)
{ {
tm.start("Monitor minimization"); tm.start("Monitor minimization");
a = minimized = minimize(a, true); a = minimized = minimize_monitor(a);
tm.stop("Monitor minimization"); tm.stop("Monitor minimization");
} }
......
#!@PYTHON@ #!@PYTHON@
# -*- mode: python; coding: iso-8859-1 -*- # -*- mode: python; coding: iso-8859-1 -*-
# Copyright (C) 2007, 2009, 2010 Laboratoire de Recherche et Dveloppement # Copyright (C) 2007, 2009, 2010, 2011 Laboratoire de Recherche et
# de l'Epita (LRDE). # Dveloppement de l'Epita (LRDE).
# Copyright (C) 2003, 2004, 2006 Laboratoire d'Informatique de # Copyright (C) 2003, 2004, 2006 Laboratoire d'Informatique de
# Paris 6 (LIP6), dpartement Systmes Rpartis Coopratifs (SRC), # Paris 6 (LIP6), dpartement Systmes Rpartis Coopratifs (SRC),
# Universit Pierre et Marie Curie. # Universit Pierre et Marie Curie.
...@@ -572,9 +572,9 @@ elif trans_taa: ...@@ -572,9 +572,9 @@ elif trans_taa:
automaton = spot.ltl_to_taa(f, dict, refined_rules) automaton = spot.ltl_to_taa(f, dict, refined_rules)
if reduce_dmonitor: if reduce_dmonitor:
automaton = spot.minimize(automaton, True) automaton = spot.minimize_monitor(automaton)
elif reduce_wdba: elif reduce_wdba:
automaton = spot.minimize(automaton, False) automaton = spot.minimize_obligation(automaton)
elif reduce_scc: elif reduce_scc:
# Do not suppress all useless acceptance conditions if # Do not suppress all useless acceptance conditions if
# degeneralization is requested: keeping those that lead to # degeneralization is requested: keeping those that lead to
......
// Copyright (C) 2009, 2010 Laboratoire de Recherche et Dveloppement // Copyright (C) 2009, 2010, 2011 Laboratoire de Recherche et Dveloppement
// de l'Epita (LRDE). // de l'Epita (LRDE).
// Copyright (C) 2003, 2004, 2005, 2006 Laboratoire d'Informatique // Copyright (C) 2003, 2004, 2005, 2006 Laboratoire d'Informatique
// de Paris 6 (LIP6), dpartement Systmes Rpartis Coopratifs (SRC), // de Paris 6 (LIP6), dpartement Systmes Rpartis Coopratifs (SRC),
...@@ -147,7 +147,9 @@ using namespace spot; ...@@ -147,7 +147,9 @@ using namespace spot;
%feature("new") spot::ltl_to_taa; %feature("new") spot::ltl_to_taa;
%feature("new") spot::ltl_to_tgba_fm; %feature("new") spot::ltl_to_tgba_fm;
%feature("new") spot::ltl_to_tgba_lacim; %feature("new") spot::ltl_to_tgba_lacim;
%feature("new") spot::minimize; %feature("new") spot::minimize_wdba;
%feature("new") spot::minimize_monitor;
%feature("new") spot::minimize_obligation;
%feature("new") spot::reduc_tgba_sim; %feature("new") spot::reduc_tgba_sim;
%feature("new") spot::scc_filter; %feature("new") spot::scc_filter;
%feature("new") spot::tgba_dupexp_bfs; %feature("new") spot::tgba_dupexp_bfs;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment