A type such as 'const tgba_digraph*' and 'tgba_digraph*' are replaced by 'const_tgba_digraph_ptr' and 'tgba_digraph_ptr'. Additionally 'new tgba_digraph(...)' is replaced by 'make_tgba_digraph(...)'. This convention is followed by all automata types. Those smart pointers should normally be passed by const reference as input of function to avoid the atomic increments/decrements, but I probably missed a few, as this huge patch took me nearly 12h. * src/kripke/fwd.hh, src/tgba/fwd.hh: New files. * src/kripke/Makefile.am, src/tgba/Makefile.am: Adjust. * iface/dve2/dve2.cc, iface/dve2/dve2.hh, iface/dve2/dve2check.cc, src/bin/common_output.hh, src/bin/dstar2tgba.cc, src/bin/ltl2tgba.cc, src/bin/ltl2tgta.cc, src/bin/ltlcross.cc, src/bin/ltlfilt.cc, src/dstarparse/dra2ba.cc, src/dstarparse/dstar2tgba.cc, src/dstarparse/dstarparse.yy, src/dstarparse/nra2nba.cc, src/dstarparse/nsa2tgba.cc, src/dstarparse/public.hh, src/graphtest/tgbagraph.cc, src/kripke/fairkripke.hh, src/kripke/kripke.hh, src/kripke/kripkeexplicit.cc, src/kripke/kripkeexplicit.hh, src/kripke/kripkeprint.cc, src/kripke/kripkeprint.hh, src/kripkeparse/kripkeparse.yy, src/kripkeparse/public.hh, src/kripketest/parse_print_test.cc, src/ltlvisit/apcollect.cc, src/ltlvisit/apcollect.hh, src/ltlvisit/contain.cc, src/ltlvisit/contain.hh, src/neverparse/neverclaimparse.yy, src/neverparse/public.hh, src/priv/accmap.hh, src/priv/countstates.cc, src/priv/countstates.hh, src/saba/saba.hh, src/saba/sabacomplementtgba.cc, src/saba/sabacomplementtgba.hh, src/sabaalgos/sabadotty.cc, src/sabaalgos/sabadotty.hh, src/sabaalgos/sabareachiter.cc, src/sabaalgos/sabareachiter.hh, src/sabatest/sabacomplementtgba.cc, src/ta/ta.hh, src/ta/taexplicit.cc, src/ta/taexplicit.hh, src/ta/taproduct.cc, src/ta/taproduct.hh, src/ta/tgta.hh, src/ta/tgtaexplicit.cc, src/ta/tgtaexplicit.hh, src/ta/tgtaproduct.cc, src/ta/tgtaproduct.hh, src/taalgos/dotty.cc, src/taalgos/dotty.hh, src/taalgos/emptinessta.cc, src/taalgos/emptinessta.hh, src/taalgos/minimize.cc, src/taalgos/minimize.hh, src/taalgos/reachiter.cc, src/taalgos/reachiter.hh, src/taalgos/statessetbuilder.cc, src/taalgos/statessetbuilder.hh, src/taalgos/stats.cc, src/taalgos/stats.hh, src/taalgos/tgba2ta.cc, src/taalgos/tgba2ta.hh, src/tgba/bdddict.cc, src/tgba/bdddict.hh, src/tgba/formula2bdd.hh, src/tgba/futurecondcol.cc, src/tgba/futurecondcol.hh, src/tgba/taatgba.hh, src/tgba/tgba.cc, src/tgba/tgba.hh, src/tgba/tgbagraph.hh, src/tgba/tgbakvcomplement.cc, src/tgba/tgbakvcomplement.hh, src/tgba/tgbamask.cc, src/tgba/tgbamask.hh, src/tgba/tgbaproduct.cc, src/tgba/tgbaproduct.hh, src/tgba/tgbaproxy.cc, src/tgba/tgbaproxy.hh, src/tgba/tgbasafracomplement.cc, src/tgba/tgbasafracomplement.hh, src/tgba/tgbascc.cc, src/tgba/tgbascc.hh, src/tgba/tgbasgba.cc, src/tgba/tgbasgba.hh, src/tgba/wdbacomp.cc, src/tgba/wdbacomp.hh, src/tgbaalgos/bfssteps.cc, src/tgbaalgos/bfssteps.hh, src/tgbaalgos/complete.cc, src/tgbaalgos/complete.hh, src/tgbaalgos/compsusp.cc, src/tgbaalgos/compsusp.hh, src/tgbaalgos/cycles.hh, src/tgbaalgos/degen.cc, src/tgbaalgos/degen.hh, src/tgbaalgos/dotty.cc, src/tgbaalgos/dotty.hh, src/tgbaalgos/dottydec.cc, src/tgbaalgos/dottydec.hh, src/tgbaalgos/dtbasat.cc, src/tgbaalgos/dtbasat.hh, src/tgbaalgos/dtgbacomp.cc, src/tgbaalgos/dtgbacomp.hh, src/tgbaalgos/dtgbasat.cc, src/tgbaalgos/dtgbasat.hh, src/tgbaalgos/dupexp.cc, src/tgbaalgos/dupexp.hh, src/tgbaalgos/emptiness.cc, src/tgbaalgos/emptiness.hh, src/tgbaalgos/gtec/gtec.cc, src/tgbaalgos/gtec/gtec.hh, src/tgbaalgos/gtec/status.cc, src/tgbaalgos/gtec/status.hh, src/tgbaalgos/gv04.cc, src/tgbaalgos/gv04.hh, src/tgbaalgos/isdet.cc, src/tgbaalgos/isdet.hh, src/tgbaalgos/isweakscc.cc, src/tgbaalgos/lbtt.cc, src/tgbaalgos/lbtt.hh, src/tgbaalgos/ltl2taa.cc, src/tgbaalgos/ltl2taa.hh, src/tgbaalgos/ltl2tgba_fm.cc, src/tgbaalgos/ltl2tgba_fm.hh, src/tgbaalgos/magic.cc, src/tgbaalgos/magic.hh, src/tgbaalgos/minimize.cc, src/tgbaalgos/minimize.hh, src/tgbaalgos/ndfs_result.hxx, src/tgbaalgos/neverclaim.cc, src/tgbaalgos/neverclaim.hh, src/tgbaalgos/postproc.cc, src/tgbaalgos/postproc.hh, src/tgbaalgos/powerset.cc, src/tgbaalgos/powerset.hh, src/tgbaalgos/projrun.cc, src/tgbaalgos/projrun.hh, src/tgbaalgos/randomgraph.cc, src/tgbaalgos/randomgraph.hh, src/tgbaalgos/reachiter.cc, src/tgbaalgos/reachiter.hh, src/tgbaalgos/reducerun.cc, src/tgbaalgos/reducerun.hh, src/tgbaalgos/replayrun.cc, src/tgbaalgos/replayrun.hh, src/tgbaalgos/rundotdec.cc, src/tgbaalgos/rundotdec.hh, src/tgbaalgos/safety.cc, src/tgbaalgos/safety.hh, src/tgbaalgos/save.cc, src/tgbaalgos/save.hh, src/tgbaalgos/scc.cc, src/tgbaalgos/scc.hh, src/tgbaalgos/sccfilter.cc, src/tgbaalgos/sccfilter.hh, src/tgbaalgos/sccinfo.cc, src/tgbaalgos/sccinfo.hh, src/tgbaalgos/se05.cc, src/tgbaalgos/se05.hh, src/tgbaalgos/simulation.cc, src/tgbaalgos/simulation.hh, src/tgbaalgos/stats.cc, src/tgbaalgos/stats.hh, src/tgbaalgos/stripacc.cc, src/tgbaalgos/stripacc.hh, src/tgbaalgos/tau03.cc, src/tgbaalgos/tau03.hh, src/tgbaalgos/tau03opt.cc, src/tgbaalgos/tau03opt.hh, src/tgbaalgos/translate.cc, src/tgbaalgos/translate.hh, src/tgbaparse/public.hh, src/tgbaparse/tgbaparse.yy, src/tgbatest/complementation.cc, src/tgbatest/explprod.cc, src/tgbatest/ltl2tgba.cc, src/tgbatest/ltlprod.cc, src/tgbatest/maskacc.cc, src/tgbatest/powerset.cc, src/tgbatest/randtgba.cc, src/tgbatest/taatgba.cc, src/tgbatest/tgbaread.cc, src/tgbatest/tripprod.cc, wrap/python/ajax/spot.in, wrap/python/spot.i, wrap/python/tests/interdep.py: Use shared pointers for automata.
262 lines
9.1 KiB
C++
262 lines
9.1 KiB
C++
// -*- coding: utf-8 -*-
|
|
// Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Laboratoire de
|
|
// Recherche et Développement de l'Epita.
|
|
//
|
|
// This file is part of Spot, a model checking library.
|
|
//
|
|
// Spot is free software; you can redistribute it and/or modify it
|
|
// under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation; either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Spot is distributed in the hope that it will be useful, but WITHOUT
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
// License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#ifndef SPOT_TGBAALGOS_SCC_HH
|
|
# define SPOT_TGBAALGOS_SCC_HH
|
|
|
|
#include <map>
|
|
#include <stack>
|
|
#include <vector>
|
|
#include "tgba/tgba.hh"
|
|
#include <iosfwd>
|
|
#include "misc/hash.hh"
|
|
#include "misc/bddlt.hh"
|
|
|
|
namespace spot
|
|
{
|
|
|
|
struct SPOT_API scc_stats
|
|
{
|
|
/// Total number of SCCs.
|
|
unsigned scc_total;
|
|
/// Total number of accepting SCC.
|
|
unsigned acc_scc;
|
|
/// Total number of dead SCC.
|
|
///
|
|
/// An SCC is dead if no accepting SCC is reachable from it.
|
|
/// Note that an SCC can be neither dead nor accepting.
|
|
unsigned dead_scc;
|
|
|
|
/// Number of maximal accepting paths.
|
|
///
|
|
/// A path is maximal and accepting if it ends in an accepting
|
|
/// SCC that has only dead (i.e. non accepting) successors, or no
|
|
/// successors at all.
|
|
unsigned acc_paths;
|
|
/// Number of paths to a terminal dead SCC.
|
|
///
|
|
/// A terminal dead SCC is a dead SCC without successors.
|
|
unsigned dead_paths;
|
|
unsigned self_loops;
|
|
|
|
/// A map of the useless SCCs.
|
|
std::vector<bool> useless_scc_map;
|
|
|
|
/// The set of useful acceptance conditions (i.e. acceptance
|
|
/// conditions that are not always implied by other acceptance
|
|
/// conditions).
|
|
bdd useful_acc;
|
|
|
|
std::ostream& dump(std::ostream& out) const;
|
|
};
|
|
|
|
/// Build a map of Strongly Connected components in in a TGBA.
|
|
class SPOT_API scc_map
|
|
{
|
|
public:
|
|
typedef std::map<unsigned, bdd> succ_type;
|
|
typedef std::set<bdd, bdd_less_than> cond_set;
|
|
|
|
/// \brief Constructor.
|
|
///
|
|
/// This will note compute the map initially. You should call
|
|
/// build_map() to do so.
|
|
scc_map(const const_tgba_ptr& aut);
|
|
|
|
~scc_map();
|
|
|
|
/// Actually compute the graph of strongly connected components.
|
|
void build_map();
|
|
|
|
/// Get the automaton for which the map has been constructed.
|
|
const_tgba_ptr get_aut() const;
|
|
|
|
/// \brief Get the number of SCC in the automaton.
|
|
///
|
|
/// SCCs are labelled from 0 to scc_count()-1.
|
|
///
|
|
/// \pre This should only be called once build_map() has run.
|
|
unsigned scc_count() const;
|
|
|
|
/// \brief Get number of the SCC containing the initial state.
|
|
///
|
|
/// \pre This should only be called once build_map() has run.
|
|
unsigned initial() const;
|
|
|
|
/// \brief Successor SCCs of a SCC.
|
|
///
|
|
/// \pre This should only be called once build_map() has run.
|
|
const succ_type& succ(unsigned n) const;
|
|
|
|
/// \brief Return whether an SCC is trivial.
|
|
///
|
|
/// Trivial SCCs have one state and no self-loop.
|
|
///
|
|
/// \pre This should only be called once build_map() has run.
|
|
bool trivial(unsigned n) const;
|
|
|
|
/// \brief Return whether an SCC is accepting.
|
|
///
|
|
/// \pre This should only be called once build_map() has run.
|
|
bool accepting(unsigned n) const;
|
|
|
|
/// \brief Return the set of conditions occurring in an SCC.
|
|
///
|
|
/// \pre This should only be called once build_map() has run.
|
|
const cond_set& cond_set_of(unsigned n) const;
|
|
|
|
/// \brief Return the set of atomic properties occurring on the
|
|
/// transitions leaving states from SCC \a n.
|
|
///
|
|
/// The transitions considered are all transitions inside SCC
|
|
/// \a n, as well as the transitions leaving SCC \a n.
|
|
///
|
|
/// \return a BDD that is a conjuction of all atomic properties
|
|
/// occurring on the transitions leaving the states of SCC \a n.
|
|
///
|
|
/// \pre This should only be called once build_map() has run.
|
|
bdd ap_set_of(unsigned n) const;
|
|
|
|
/// \brief Return the set of atomic properties reachable from this SCC.
|
|
///
|
|
/// \return a BDD that is a conjuction of all atomic properties
|
|
/// occurring on the transitions reachable from this SCC n.
|
|
///
|
|
/// \pre This should only be called once build_map() has run.
|
|
bdd aprec_set_of(unsigned n) const;
|
|
|
|
/// \brief Return the set of acceptance conditions occurring in an SCC.
|
|
///
|
|
/// \pre This should only be called once build_map() has run.
|
|
bdd acc_set_of(unsigned n) const;
|
|
|
|
/// \brief Return the set of useful acceptance conditions of SCC \a n.
|
|
///
|
|
/// Useless acceptances conditions are always implied by other acceptances
|
|
/// conditions. This returns all the other acceptance conditions.
|
|
bdd useful_acc_of(unsigned n) const;
|
|
|
|
/// \brief Return the set of states of an SCC.
|
|
///
|
|
/// The states in the returned list are still owned by the scc_map
|
|
/// instance. They should NOT be destroyed by the client code.
|
|
///
|
|
/// \pre This should only be called once build_map() has run.
|
|
const std::list<const state*>& states_of(unsigned n) const;
|
|
|
|
/// \brief Return one state of an SCC.
|
|
///
|
|
/// The state in the returned list is still owned by the scc_map
|
|
/// instance. It should NOT be destroyed by the client code.
|
|
///
|
|
/// \pre This should only be called once build_map() has run.
|
|
const state* one_state_of(unsigned n) const;
|
|
|
|
/// \brief Return the number of the SCC a state belongs too.
|
|
///
|
|
/// \pre This should only be called once build_map() has run.
|
|
unsigned scc_of_state(const state* s) const;
|
|
|
|
/// \brief Return the number of self loops in the automaton.
|
|
unsigned self_loops() const;
|
|
|
|
protected:
|
|
bdd update_supp_rec(unsigned state);
|
|
int relabel_component();
|
|
|
|
struct scc
|
|
{
|
|
public:
|
|
scc(int index) : index(index), acc(bddfalse),
|
|
supp(bddtrue), supp_rec(bddfalse),
|
|
trivial(true), useful_acc(bddfalse) {};
|
|
/// Index of the SCC.
|
|
int index;
|
|
/// The union of all acceptance conditions of transitions which
|
|
/// connect the states of the connected component.
|
|
bdd acc;
|
|
/// States of the component.
|
|
std::list<const state*> states;
|
|
/// Set of conditions used in the SCC.
|
|
cond_set conds;
|
|
/// Conjunction of atomic propositions used in the SCC.
|
|
bdd supp;
|
|
/// Conjunction of atomic propositions used in the SCC.
|
|
bdd supp_rec;
|
|
/// Successor SCC.
|
|
succ_type succ;
|
|
/// Trivial SCC have one state and no self-loops.
|
|
bool trivial;
|
|
/// \brief Set of acceptance combinations used in the SCC.
|
|
///
|
|
/// Note that the encoding used here differs from the
|
|
/// encoding used in automata.
|
|
/// If some transitions of the automaton are labeled by
|
|
/// Acc[a]&!Acc[b]&!Acc[c] | !Acc[a]&Acc[b]&!Acc[c]
|
|
/// an other transitions are labeled by
|
|
/// !Acc[a]&Acc[b]&!Acc[c] | !Acc[a]&!Acc[b]&Acc[c]
|
|
/// then useful_acc will contain
|
|
/// Acc[a]&Acc[b]&!Acc[c] | !Acc[a]&Acc[b]&Acc[c]
|
|
bdd useful_acc;
|
|
};
|
|
|
|
const_tgba_ptr aut_; // Automata to decompose.
|
|
typedef std::list<scc> stack_type;
|
|
stack_type root_; // Stack of SCC roots.
|
|
std::stack<bdd> arc_acc_; // A stack of acceptance conditions
|
|
// between each of these SCC.
|
|
std::stack<bdd> arc_cond_; // A stack of conditions
|
|
// between each of these SCC.
|
|
typedef std::unordered_map<const state*, int,
|
|
state_ptr_hash, state_ptr_equal> hash_type;
|
|
hash_type h_; // Map of visited states. Values >= 0
|
|
// designate maximal SCC. Values < 0
|
|
// number states that are part of
|
|
// incomplete SCCs being completed.
|
|
int num_; // Number of visited nodes, negated.
|
|
typedef std::pair<const spot::state*, tgba_succ_iterator*> pair_state_iter;
|
|
std::stack<pair_state_iter> todo_; // DFS stack. Holds (STATE,
|
|
// ITERATOR) pairs where
|
|
// ITERATOR is an iterator over
|
|
// the successors of STATE.
|
|
// ITERATOR should always be
|
|
// freed when TODO is popped,
|
|
// but STATE should not because
|
|
// it is used as a key in H.
|
|
|
|
typedef std::vector<scc> scc_map_type;
|
|
scc_map_type scc_map_; // Map of constructed maximal SCC.
|
|
// SCC number "n" in H_ corresponds to entry
|
|
// "n" in SCC_MAP_.
|
|
unsigned self_loops_; // Self loops count.
|
|
};
|
|
|
|
SPOT_API scc_stats
|
|
build_scc_stats(const const_tgba_ptr& a);
|
|
SPOT_API scc_stats
|
|
build_scc_stats(const scc_map& m);
|
|
|
|
SPOT_API std::ostream&
|
|
dump_scc_dot(const const_tgba_ptr& a,
|
|
std::ostream& out, bool verbose = false);
|
|
SPOT_API std::ostream&
|
|
dump_scc_dot(const scc_map& m, std::ostream& out, bool verbose = false);
|
|
}
|
|
|
|
#endif // SPOT_TGBAALGOS_SCC_HH
|