Handle all automata through shared_ptr. (monstro patch)

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.
This commit is contained in:
Alexandre Duret-Lutz 2014-08-14 20:18:04 +02:00
parent ca85d4184d
commit 51151ab271
195 changed files with 1792 additions and 1837 deletions

View file

@ -30,6 +30,7 @@ tgba_HEADERS = \
bddprint.hh \
formula2bdd.hh \
futurecondcol.hh \
fwd.hh \
state.hh \
succiter.hh \
taatgba.hh \

View file

@ -349,27 +349,6 @@ namespace spot
priv_->free_anonymous_list_of.erase(me);
}
bool
bdd_dict::is_registered_proposition(const ltl::formula* f, const void* by_me)
{
fv_map::iterator fi = var_map.find(f);
if (fi == var_map.end())
return false;
ref_set& s = bdd_map[fi->second].refs;
return s.find(by_me) != s.end();
}
bool
bdd_dict::is_registered_acceptance_variable(const ltl::formula* f,
const void* by_me)
{
fv_map::iterator fi = acc_map.find(f);
if (fi == acc_map.end())
return false;
ref_set& s = bdd_map[fi->second].refs;
return s.find(by_me) != s.end();
}
std::ostream&
bdd_dict::dump(std::ostream& os) const
{

View file

@ -99,8 +99,17 @@ namespace spot
///
/// \return The variable number. Use bdd_ithvar() or bdd_nithvar()
/// to convert this to a BDD.
/// @{
int register_proposition(const ltl::formula* f, const void* for_me);
template <typename T>
int register_proposition(const ltl::formula* f,
std::shared_ptr<T> for_me)
{
return register_proposition(f, for_me.get());
}
/// @}
/// \brief Register BDD variables as atomic propositions.
///
/// Register all variables occurring in \a f as atomic propositions
@ -108,8 +117,16 @@ namespace spot
/// are already known from the dictionary (i.e., they have already
/// been registered by register_proposition() for another
/// automaton).
/// @{
void register_propositions(bdd f, const void* for_me);
template <typename T>
void register_propositions(bdd f, std::shared_ptr<T> for_me)
{
register_propositions(f, for_me.get());
}
/// @}
/// \brief Register an atomic proposition.
///
/// Return (and maybe allocate) a BDD variable designating an
@ -120,15 +137,32 @@ namespace spot
///
/// \return The variable number. Use bdd_ithvar() or bdd_nithvar()
/// to convert this to a BDD.
/// @{
int register_acceptance_variable(const ltl::formula* f, const void* for_me);
template <typename T>
int register_acceptance_variable(const ltl::formula* f,
std::shared_ptr<T> for_me)
{
return register_acceptance_variable(f, for_me.get());
}
/// @}
/// \brief Clone an acceptance variable VAR for FOR_ME.
///
/// This is used in products TGBAs when both operands share the
/// same acceptance variables but they need to be distinguished in
/// the result.
/// @{
int register_clone_acc(int var, const void* for_me);
template <typename T>
int register_clone_acc(int var, std::shared_ptr<T> for_me)
{
return register_clone_acc(var, for_me.get());
}
/// @}
/// \brief Register BDD variables as acceptance variables.
///
/// Register all variables occurring in \a f as acceptance variables
@ -136,8 +170,16 @@ namespace spot
/// are already known from the dictionary (i.e., they have already
/// been registered by register_acceptance_variable() for another
/// automaton).
/// @{
void register_acceptance_variables(bdd f, const void* for_me);
template <typename T>
void register_acceptance_variables(bdd f, std::shared_ptr<T> for_me)
{
register_acceptance_variables(f, for_me.get());
}
/// @}
/// \brief Convert one acceptance condition into the associated
/// formula.
///
@ -166,16 +208,47 @@ namespace spot
///
/// \return The variable number. Use bdd_ithvar() or bdd_nithvar()
/// to convert this to a BDD.
/// @{
int register_anonymous_variables(int n, const void* for_me);
template <typename T>
int register_anonymous_variables(int n, std::shared_ptr<T> for_me)
{
return register_anonymous_variables(n, for_me.get());
}
/// @}
/// \brief Duplicate the variable usage of another object.
///
/// This tells this dictionary that the \a for_me object will be
/// using the same BDD variables as the \a from_other objects.
/// This ensures that the variables won't be freed when \a
/// from_other is deleted if \a from_other is still alive.
/// @{
void register_all_variables_of(const void* from_other, const void* for_me);
template <typename T>
void register_all_variables_of(const void* from_other,
std::shared_ptr<T> for_me)
{
register_all_variables_of(from_other, for_me.get());
}
template <typename T>
void register_all_variables_of(std::shared_ptr<T> from_other,
const void* for_me)
{
register_all_variables_of(from_other.get(), for_me);
}
template <typename T, typename U>
void register_all_variables_of(std::shared_ptr<T> from_other,
std::shared_ptr<U> for_me)
{
register_all_variables_of(from_other.get(), for_me.get());
}
/// @}
/// \brief Register the same propositions as another object.
///
/// This tells this dictionary that the \a for_me object will be
@ -183,9 +256,32 @@ namespace spot
/// the \a from_other object. This ensures that the variables
/// won't be freed when \a from_other is deleted if \a from_other
/// is still alive.
/// @{
void register_all_propositions_of(const void* from_other,
const void* for_me);
template <typename T>
void register_all_propositions_of(const void* from_other,
std::shared_ptr<T> for_me)
{
register_all_propositions_of(from_other, for_me.get());
}
template <typename T>
void register_all_propositions_of(std::shared_ptr<T> from_other,
const void* for_me)
{
register_all_propositions_of(from_other.get(), for_me);
}
template <typename T, typename U>
void register_all_propositions_of(std::shared_ptr<T> from_other,
std::shared_ptr<U> for_me)
{
register_all_propositions_of(from_other.get(), for_me.get());
}
/// @}
/// \brief Release all variables used by an object.
///
/// Usually called in the destructor if \a me.
@ -193,16 +289,25 @@ namespace spot
/// \brief Release all variables of a given type, used by an
/// object.
/// @{
void unregister_all_typed_variables(var_type type, const void* me);
template <typename T>
void unregister_all_typed_variables(var_type type, std::shared_ptr<T> me)
{
unregister_all_typed_variables(type, me.get());
}
/// @}
/// \brief Release a variable used by \a me.
/// @{
void unregister_variable(int var, const void* me);
/// @{
/// Check whether formula \a f has already been registered by \a by_me.
bool is_registered_proposition(const ltl::formula* f, const void* by_me);
bool is_registered_acceptance_variable(const ltl::formula* f,
const void* by_me);
template <typename T>
void unregister_variable(int var, std::shared_ptr<T> me)
{
unregister_variable(var, me.get());
}
/// @}
/// \brief Dump all variables for debugging.

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2012, 2013 Laboratoire de Recherche et Développement de
// Copyright (C) 2012, 2013, 2014 Laboratoire de Recherche et Développement de
// l'Epita (LRDE).
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
@ -38,9 +38,19 @@ namespace spot
/// passing it right away to bdd_to_formula(), you should not forget
/// to unregister the variables that have been registered for \a
/// for_me. See bdd_dict::unregister_all_my_variables().
/// @{
SPOT_API bdd
formula_to_bdd(const ltl::formula* f, bdd_dict_ptr d, void* for_me);
template<typename T>
SPOT_API bdd
formula_to_bdd(const ltl::formula* f, bdd_dict_ptr d,
const std::shared_ptr<T>& for_me)
{
return formula_to_bdd(f, d, for_me.get());
}
/// @}
/// \brief Convert a BDD into a formula.
///
/// Format the BDD as an irredundant sum of product (see the

View file

@ -42,8 +42,8 @@ namespace spot
future_conds_[src] = res;
}
future_conditions_collector::future_conditions_collector(const tgba* aut,
bool show)
future_conditions_collector::future_conditions_collector
(const const_tgba_ptr& aut, bool show)
: tgba_scc(aut, show),
// Initialize future_conds_ with as much empty
// "cond_set"s as there are SCCs.

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2013 Laboratoire de recherche et développement
// Copyright (C) 2009, 2013, 2014 Laboratoire de recherche et développement
// de l'Epita.
//
// This file is part of Spot, a model checking library.
@ -45,7 +45,7 @@ namespace spot
/// If \a show is set to true, then the format_state() method will
/// include the set of conditions computed for the given state in
/// its output string.
future_conditions_collector(const tgba* aut, bool show = false);
future_conditions_collector(const const_tgba_ptr& aut, bool show = false);
virtual ~future_conditions_collector();
/// Returns the set of future conditions visible after \a s
@ -65,6 +65,17 @@ namespace spot
// strongly connected component.
};
typedef std::shared_ptr<future_conditions_collector>
future_conditions_collector_ptr;
typedef std::shared_ptr<const future_conditions_collector>
const_future_conditions_collector_ptr;
inline future_conditions_collector_ptr
make_future_conditions_collector(const const_tgba_ptr& aut, bool show = false)
{
return std::make_shared<future_conditions_collector>(aut, show);
}
}
#endif // SPOT_TGBA_FUTURECONDCOL_HH

44
src/tgba/fwd.hh Normal file
View file

@ -0,0 +1,44 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2014 Laboratoire de Recherche et Développement de
// l'Epita (LRDE).
//
// 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_TGBA_FWD_HH
# define SPOT_TGBA_FWD_HH
#include <memory>
namespace spot
{
class tgba;
typedef std::shared_ptr<tgba> tgba_ptr;
typedef std::shared_ptr<const tgba> const_tgba_ptr;
class tgba_digraph;
typedef std::shared_ptr<const tgba_digraph> const_tgba_digraph_ptr;
typedef std::shared_ptr<tgba_digraph> tgba_digraph_ptr;
class tgba_product;
typedef std::shared_ptr<const tgba_product> const_tgba_product_ptr;
typedef std::shared_ptr<tgba_product> tgba_product_ptr;
class tgba_sgba_proxy;
typedef std::shared_ptr<const tgba_sgba_proxy> const_tgba_sgba_proxy_ptr;
typedef std::shared_ptr<tgba_sgba_proxy> tgba_sgba_proxy_ptr;
}
#endif // SPOT_TGBA_FWD_HH

View file

@ -151,7 +151,7 @@ namespace spot
class SPOT_API taa_tgba_labelled : public taa_tgba
{
public:
taa_tgba_labelled(bdd_dict_ptr dict) : taa_tgba(dict) {};
taa_tgba_labelled(const bdd_dict_ptr& dict) : taa_tgba(dict) {};
void set_init_state(const label& s)
{
@ -319,10 +319,14 @@ namespace spot
};
class SPOT_API taa_tgba_string :
#ifndef SWIG
public taa_tgba_labelled<std::string, string_hash>
#else
public taa_tgba
#endif
{
public:
taa_tgba_string(bdd_dict_ptr dict) :
taa_tgba_string(const bdd_dict_ptr& dict) :
taa_tgba_labelled<std::string, string_hash>(dict) {};
~taa_tgba_string();
protected:
@ -330,17 +334,38 @@ namespace spot
virtual std::string clone_if(const std::string& label) const;
};
typedef std::shared_ptr<taa_tgba_string> taa_tgba_string_ptr;
typedef std::shared_ptr<const taa_tgba_string> const_taa_tgba_string_ptr;
inline taa_tgba_string_ptr make_taa_tgba_string(const bdd_dict_ptr& dict)
{
return std::make_shared<taa_tgba_string>(dict);
}
class SPOT_API taa_tgba_formula :
#ifndef SWIG
public taa_tgba_labelled<const ltl::formula*, ltl::formula_ptr_hash>
#else
public taa_tgba
#endif
{
public:
taa_tgba_formula(bdd_dict_ptr dict) :
taa_tgba_formula(const bdd_dict_ptr& dict) :
taa_tgba_labelled<const ltl::formula*, ltl::formula_ptr_hash>(dict) {};
~taa_tgba_formula();
protected:
virtual std::string label_to_string(const label_t& label) const;
virtual const ltl::formula* clone_if(const label_t& label) const;
};
typedef std::shared_ptr<taa_tgba_formula> taa_tgba_formula_ptr;
typedef std::shared_ptr<const taa_tgba_formula> const_taa_tgba_formula_ptr;
inline taa_tgba_formula_ptr make_taa_tgba_formula(const bdd_dict_ptr& dict)
{
return std::make_shared<taa_tgba_formula>(dict);
}
}
#endif // SPOT_TGBA_TAATGBA_HH

View file

@ -53,9 +53,10 @@ namespace spot
}
state*
tgba::project_state(const state* s, const tgba* t) const
tgba::project_state(const state* s,
const const_tgba_ptr& t) const
{
if (t == this)
if (t.get() == this)
return s->clone();
return 0;
}

View file

@ -26,6 +26,7 @@
#include "state.hh"
#include "bdddict.hh"
#include "succiter.hh"
#include "fwd.hh"
namespace spot
{
@ -215,7 +216,8 @@ namespace spot
/// \return 0 if the projection fails (\a s is unrelated to \a t),
/// or a new \c state* (the projected state) that must be
/// destroyed by the caller.
virtual state* project_state(const state* s, const tgba* t) const;
virtual state* project_state(const state* s,
const const_tgba_ptr& t) const;
/// \brief Return the set of all acceptance conditions used
/// by this automaton.

View file

@ -20,6 +20,7 @@
#ifndef SPOT_TGBA_TGBAGRAPH_HH
# define SPOT_TGBA_TGBAGRAPH_HH
#include "fwd.hh"
#include "graph/graph.hh"
#include "graph/ngraph.hh"
#include "tgba/bdddict.hh"
@ -302,6 +303,17 @@ namespace spot
return g_.trans_data(t);
}
const tgba_graph_trans_data& trans_data(const tgba_succ_iterator* it) const
{
auto* i = down_cast<const tgba_digraph_succ_iterator<graph_t>*>(it);
return g_.trans_data(i->pos());
}
const tgba_graph_trans_data& trans_data(unsigned t) const
{
return g_.trans_data(t);
}
void set_acceptance_conditions(bdd all);
bdd set_single_acceptance_set();
@ -346,12 +358,12 @@ namespace spot
SPOT_RETURN(g_.transitions());
/// \brief Copy the acceptance conditions of another tgba.
void copy_acceptance_conditions_of(const tgba *a)
void copy_acceptance_conditions_of(const const_tgba_ptr& a)
{
set_acceptance_conditions(a->neg_acceptance_conditions());
}
void copy_ap_of(const tgba* a)
void copy_ap_of(const const_tgba_ptr& a)
{
dict_->register_all_propositions_of(a, this);
}
@ -420,6 +432,10 @@ namespace spot
};
inline tgba_digraph_ptr make_tgba_digraph(bdd_dict_ptr dict)
{
return std::make_shared<tgba_digraph>(dict);
}
}
#endif // SPOT_TGBA_TGBAGRAPH_HH

View file

@ -72,14 +72,14 @@ namespace spot
return hash;
}
std::string format(const tgba* a) const
std::string format(const bdd_dict_ptr& d) const
{
std::ostringstream ss;
ss << "{rank: " << rank;
if (rank & 1)
{
ss << ", bdd: {" << condition.order() << ", "
<< bdd_format_accset(a->get_dict(), condition.get_bdd())
<< bdd_format_accset(d, condition.get_bdd())
<< "} ";
}
ss << '}';
@ -588,8 +588,8 @@ namespace spot
}
}
tgba_kv_complement::tgba_kv_complement(const tgba* a)
: automaton_(new tgba_sgba_proxy(a))
tgba_kv_complement::tgba_kv_complement(const const_tgba_ptr& a)
: automaton_(make_sgba(a))
{
get_dict()->register_all_variables_of(automaton_, this);
int v = get_dict()
@ -602,7 +602,6 @@ namespace spot
tgba_kv_complement::~tgba_kv_complement()
{
get_dict()->unregister_all_my_variables(this);
delete automaton_;
}
state*
@ -622,7 +621,7 @@ namespace spot
down_cast<const state_kv_complement*>(state);
assert(s);
return new tgba_kv_complement_succ_iterator(automaton_,
return new tgba_kv_complement_succ_iterator(automaton_.get(),
the_acceptance_cond_,
acc_list_, s);
}
@ -650,7 +649,7 @@ namespace spot
++i)
{
ss << " {" << automaton_->format_state(i->first.get())
<< ", " << i->second.format(this) << "}\n";
<< ", " << i->second.format(get_dict()) << "}\n";
}
ss << "} odd-less: {";

View file

@ -86,7 +86,7 @@ namespace spot
class SPOT_API tgba_kv_complement : public tgba
{
public:
tgba_kv_complement(const tgba* a);
tgba_kv_complement(const const_tgba_ptr& a);
virtual ~tgba_kv_complement();
// tgba interface
@ -104,12 +104,20 @@ namespace spot
/// They are inserted into \a acc_list_.
void get_acc_list();
private:
const tgba_sgba_proxy* automaton_;
const_tgba_sgba_proxy_ptr automaton_;
bdd the_acceptance_cond_;
unsigned nb_states_;
acc_list_t acc_list_;
}; // end class tgba_kv_complement.
typedef std::shared_ptr<tgba_kv_complement> tgba_kv_complement_ptr;
typedef std::shared_ptr<const tgba_kv_complement>
const_tgba_kv_complement_ptr;
inline tgba_kv_complement_ptr
make_kv_complement(const const_tgba_ptr& a)
{
return std::make_shared<tgba_kv_complement>(a);
}
} // end namespace spot.

View file

@ -76,63 +76,81 @@ namespace spot
transitions::const_iterator it_;
};
}
tgba_mask::tgba_mask(const tgba* masked,
const state* init)
: tgba_proxy(masked),
init_(init)
{
if (!init)
init_ = masked->get_init_state();
}
tgba_mask::~tgba_mask()
{
init_->destroy();
}
state* tgba_mask::get_init_state() const
{
return init_->clone();
}
tgba_succ_iterator*
tgba_mask::succ_iter(const state* state) const
{
succ_iter_filtered* res;
if (iter_cache_)
/// \ingroup tgba_on_the_fly_algorithms
/// \brief A masked TGBA (abstract).
///
/// Ignores some states from a TGBA. What state are preserved or
/// ignored is controlled by the wanted() method.
///
/// This is an abstract class. You should inherit from it and
/// supply a wanted() method to specify which states to keep.
class tgba_mask: public tgba_proxy
{
protected:
/// \brief Constructor.
/// \param masked The automaton to mask
/// \param init Any state to use as initial state. This state will be
/// destroyed by the destructor.
tgba_mask(const const_tgba_ptr& masked, const state* init = 0):
tgba_proxy(masked),
init_(init)
{
res = down_cast<succ_iter_filtered*>(iter_cache_);
res->trans_.clear();
iter_cache_ = nullptr;
if (!init)
init_ = masked->get_init_state();
}
else
public:
virtual ~tgba_mask()
{
res = new succ_iter_filtered;
init_->destroy();
}
for (auto it: original_->succ(state))
virtual state* get_init_state() const
{
const spot::state* s = it->current_state();
bdd acc = it->current_acceptance_conditions();
if (!wanted(s, acc))
return init_->clone();
}
virtual tgba_succ_iterator*
succ_iter(const state* local_state) const
{
succ_iter_filtered* res;
if (iter_cache_)
{
s->destroy();
continue;
res = down_cast<succ_iter_filtered*>(iter_cache_);
res->trans_.clear();
iter_cache_ = nullptr;
}
res->trans_.emplace_back(transition {s, it->current_condition(), acc});
else
{
res = new succ_iter_filtered;
}
for (auto it: original_->succ(local_state))
{
const spot::state* s = it->current_state();
bdd acc = it->current_acceptance_conditions();
if (!wanted(s, acc))
{
s->destroy();
continue;
}
res->trans_.emplace_back(transition {s, it->current_condition(),
acc});
}
return res;
}
return res;
}
namespace
{
virtual bool wanted(const state* s, const bdd& acc) const = 0;
protected:
const state* init_;
};
class tgba_mask_keep: public tgba_mask
{
const state_set& mask_;
public:
tgba_mask_keep(const tgba* masked,
tgba_mask_keep(const const_tgba_ptr& masked,
const state_set& mask,
const state* init)
: tgba_mask(masked, init),
@ -151,7 +169,7 @@ namespace spot
{
const state_set& mask_;
public:
tgba_mask_ignore(const tgba* masked,
tgba_mask_ignore(const const_tgba_ptr& masked,
const state_set& mask,
const state* init)
: tgba_mask(masked, init),
@ -170,7 +188,7 @@ namespace spot
{
const bdd& mask_;
public:
tgba_mask_acc_ignore(const tgba* masked,
tgba_mask_acc_ignore(const const_tgba_ptr& masked,
const bdd& mask,
const state* init)
: tgba_mask(masked, init),
@ -184,32 +202,30 @@ namespace spot
}
};
}
const tgba*
build_tgba_mask_keep(const tgba* to_mask,
const_tgba_ptr
build_tgba_mask_keep(const const_tgba_ptr& to_mask,
const state_set& to_keep,
const state* init)
{
return new tgba_mask_keep(to_mask, to_keep, init);
return std::make_shared<tgba_mask_keep>(to_mask, to_keep, init);
}
const tgba*
build_tgba_mask_ignore(const tgba* to_mask,
const_tgba_ptr
build_tgba_mask_ignore(const const_tgba_ptr& to_mask,
const state_set& to_ignore,
const state* init)
{
return new tgba_mask_ignore(to_mask, to_ignore, init);
return std::make_shared<tgba_mask_ignore>(to_mask, to_ignore, init);
}
const tgba*
build_tgba_mask_acc_ignore(const tgba* to_mask,
const_tgba_ptr
build_tgba_mask_acc_ignore(const const_tgba_ptr& to_mask,
const bdd to_ignore,
const state* init)
{
return new tgba_mask_acc_ignore(to_mask, to_ignore, init);
return std::make_shared<tgba_mask_acc_ignore>(to_mask, to_ignore, init);
}
}

View file

@ -26,45 +26,14 @@
namespace spot
{
/// \ingroup tgba_on_the_fly_algorithms
/// \brief A masked TGBA (abstract).
///
/// Ignores some states from a TGBA. What state are preserved or
/// ignored is controlled by the wanted() method.
///
/// This is an abstract class. You should inherit from it and
/// supply a wanted() method to specify which states to keep.
class SPOT_API tgba_mask: public tgba_proxy
{
protected:
/// \brief Constructor.
/// \param masked The automaton to mask
/// \param init Any state to use as initial state. This state will be
/// destroyed by the destructor.
tgba_mask(const tgba* masked, const state* init = 0);
public:
virtual ~tgba_mask();
virtual state* get_init_state() const;
virtual tgba_succ_iterator*
succ_iter(const state* local_state) const;
virtual bool wanted(const state* s, const bdd& acc) const = 0;
protected:
const state* init_;
};
/// \ingroup tgba_on_the_fly_algorithms
/// \brief Mask a TGBA, keeping a given set of states.
///
/// Mask the TGBA \a to_mask, keeping only the
/// states from \a to_keep. The initial state
/// can optionally be reset to \a init.
SPOT_API const tgba*
build_tgba_mask_keep(const tgba* to_mask,
SPOT_API const_tgba_ptr
build_tgba_mask_keep(const const_tgba_ptr& to_mask,
const state_set& to_keep,
const state* init = 0);
@ -74,8 +43,8 @@ namespace spot
/// Mask the TGBA \a to_mask, keeping only the states that are not
/// in \a to_ignore. The initial state can optionally be reset to
/// \a init.
SPOT_API const tgba*
build_tgba_mask_ignore(const tgba* to_mask,
SPOT_API const_tgba_ptr
build_tgba_mask_ignore(const const_tgba_ptr& to_mask,
const state_set& to_ignore,
const state* init = 0);
@ -91,8 +60,8 @@ namespace spot
/// set of all acceptance set) is not changed, because so far this
/// function is only needed in graph algorithms that do not call
/// all_acceptance_conditions().
SPOT_API const tgba*
build_tgba_mask_acc_ignore(const tgba* to_mask,
SPOT_API const_tgba_ptr
build_tgba_mask_acc_ignore(const const_tgba_ptr& to_mask,
const bdd to_ignore,
const state* init = 0);

View file

@ -89,8 +89,8 @@ namespace spot
{
}
void recycle(const tgba* l, tgba_succ_iterator* left,
const tgba* r, tgba_succ_iterator* right)
void recycle(const const_tgba_ptr& l, tgba_succ_iterator* left,
const_tgba_ptr r, tgba_succ_iterator* right)
{
l->release_iter(left_);
left_ = left;
@ -284,7 +284,8 @@ namespace spot
////////////////////////////////////////////////////////////
// tgba_product
tgba_product::tgba_product(const tgba* left, const tgba* right)
tgba_product::tgba_product(const const_tgba_ptr& left,
const const_tgba_ptr& right)
: dict_(left->get_dict()), left_(left), right_(right),
pool_(sizeof(state_product))
{
@ -293,11 +294,11 @@ namespace spot
// If one of the side is a Kripke structure, it is easier to deal
// with (we don't have to fix the acceptance conditions, and
// computing the successors can be improved a bit).
if (dynamic_cast<const kripke*>(left_))
if (dynamic_cast<const kripke*>(left_.get()))
{
left_kripke_ = true;
}
else if (dynamic_cast<const kripke*>(right_))
else if (dynamic_cast<const kripke*>(right_.get()))
{
std::swap(left_, right_);
left_kripke_ = true;
@ -428,11 +429,11 @@ namespace spot
}
state*
tgba_product::project_state(const state* s, const tgba* t) const
tgba_product::project_state(const state* s, const const_tgba_ptr& t) const
{
const state_product* s2 = down_cast<const state_product*>(s);
assert(s2);
if (t == this)
if (t.get() == this)
return s2->clone();
state* res = left_->project_state(s2->left(), t);
if (res)
@ -470,7 +471,8 @@ namespace spot
//////////////////////////////////////////////////////////////////////
// tgba_product_init
tgba_product_init::tgba_product_init(const tgba* left, const tgba* right,
tgba_product_init::tgba_product_init(const const_tgba_ptr& left,
const const_tgba_ptr& right,
const state* left_init,
const state* right_init)
: tgba_product(left, right),

View file

@ -85,7 +85,7 @@ namespace spot
/// \param left The left automata in the product.
/// \param right The right automata in the product.
/// Do not be fooled by these arguments: a product is commutative.
tgba_product(const tgba* left, const tgba* right);
tgba_product(const const_tgba_ptr& left, const const_tgba_ptr& right);
virtual ~tgba_product();
@ -101,7 +101,7 @@ namespace spot
virtual std::string
transition_annotation(const tgba_succ_iterator* t) const;
virtual state* project_state(const state* s, const tgba* t) const;
virtual state* project_state(const state* s, const const_tgba_ptr& t) const;
virtual bdd all_acceptance_conditions() const;
virtual bdd neg_acceptance_conditions() const;
@ -111,8 +111,8 @@ namespace spot
protected:
bdd_dict_ptr dict_;
const tgba* left_;
const tgba* right_;
const_tgba_ptr left_;
const_tgba_ptr right_;
bool left_kripke_;
bdd left_acc_complement_;
bdd right_acc_complement_;
@ -131,7 +131,7 @@ namespace spot
class SPOT_API tgba_product_init: public tgba_product
{
public:
tgba_product_init(const tgba* left, const tgba* right,
tgba_product_init(const const_tgba_ptr& left, const const_tgba_ptr& right,
const state* left_init, const state* right_init);
virtual state* get_init_state() const;
protected:
@ -139,6 +139,20 @@ namespace spot
const state* right_init_;
};
inline tgba_product_ptr product(const const_tgba_ptr& left,
const const_tgba_ptr& right)
{
return std::make_shared<tgba_product>(left, right);
}
inline tgba_product_ptr product_at(const const_tgba_ptr& left,
const const_tgba_ptr& right,
const state* left_init,
const state* right_init)
{
return std::make_shared<tgba_product_init>(left, right,
left_init, right_init);
}
}
#endif // SPOT_TGBA_TGBAPRODUCT_HH

View file

@ -21,7 +21,7 @@
namespace spot
{
tgba_proxy::tgba_proxy(const tgba* original)
tgba_proxy::tgba_proxy(const const_tgba_ptr& original)
: original_(original)
{
get_dict()->register_all_variables_of(original, this);
@ -67,7 +67,7 @@ namespace spot
}
state*
tgba_proxy::project_state(const state* s, const tgba* t) const
tgba_proxy::project_state(const state* s, const const_tgba_ptr& t) const
{
return original_->project_state(s, t);
}
@ -90,4 +90,3 @@ namespace spot
return original_->support_conditions(state);
}
}

View file

@ -36,7 +36,7 @@ namespace spot
class SPOT_API tgba_proxy: public tgba
{
protected:
tgba_proxy(const tgba* original);
tgba_proxy(const const_tgba_ptr& original);
public:
virtual ~tgba_proxy();
@ -53,7 +53,7 @@ namespace spot
virtual std::string
transition_annotation(const tgba_succ_iterator* t) const;
virtual state* project_state(const state* s, const tgba* t) const;
virtual state* project_state(const state* s, const const_tgba_ptr& t) const;
virtual bdd all_acceptance_conditions() const;
@ -61,7 +61,7 @@ namespace spot
protected:
virtual bdd compute_support_conditions(const state* state) const;
const tgba* original_;
const_tgba_ptr original_;
};
}

View file

@ -53,7 +53,7 @@ namespace spot
/// \brief Automaton with Safra's tree as states.
struct safra_tree_automaton
{
safra_tree_automaton(const tgba_digraph* sba);
safra_tree_automaton(const const_tgba_digraph_ptr& sba);
~safra_tree_automaton();
typedef std::map<bdd, const safra_tree*, bdd_less_than> transition_list;
typedef
@ -66,14 +66,14 @@ namespace spot
int get_nb_acceptance_pairs() const;
safra_tree* get_initial_state() const;
void set_initial_state(safra_tree* s);
const tgba_digraph* get_sba(void) const
const const_tgba_digraph_ptr& get_sba(void) const
{
return a_;
}
private:
mutable int max_nb_pairs_;
safra_tree* initial_state;
const tgba_digraph* a_;
const_tgba_digraph_ptr a_;
};
/// \brief A Safra tree, used as state during the determinization
@ -569,12 +569,13 @@ namespace spot
class safra_determinisation
{
public:
static safra_tree_automaton* create_safra_automaton(const tgba* a);
static safra_tree_automaton*
create_safra_automaton(const const_tgba_ptr& a);
private:
typedef std::set<int> atomic_list_t;
typedef std::set<bdd, bdd_less_than> conjunction_list_t;
static void retrieve_atomics(const safra_tree* node,
tgba_digraph* sba_aut,
tgba_digraph_ptr sba_aut,
safra_tree::cache_t& cache,
atomic_list_t& atomic_list);
static void set_atomic_list(atomic_list_t& list, bdd condition);
@ -584,7 +585,7 @@ namespace spot
/// \brief The body of Safra's construction.
safra_tree_automaton*
safra_determinisation::create_safra_automaton(const tgba* a)
safra_determinisation::create_safra_automaton(const const_tgba_ptr& a)
{
// initialization.
auto sba_aut = degeneralize(a);
@ -664,7 +665,7 @@ namespace spot
/// of the states in the label of the node.
void
safra_determinisation::retrieve_atomics(const safra_tree* node,
tgba_digraph* sba_aut,
tgba_digraph_ptr sba_aut,
safra_tree::cache_t& cache,
atomic_list_t& atomic_list)
{
@ -1031,7 +1032,7 @@ namespace spot
// safra_tree_automaton
////////////////////////
safra_tree_automaton::safra_tree_automaton(const tgba_digraph* a)
safra_tree_automaton::safra_tree_automaton(const const_tgba_digraph_ptr& a)
: max_nb_pairs_(-1), initial_state(0), a_(a)
{
a->get_dict()->register_all_variables_of(a, this);
@ -1041,7 +1042,6 @@ namespace spot
{
for (auto& p: automaton)
delete p.first;
delete a_;
}
int
@ -1074,7 +1074,7 @@ namespace spot
// tgba_safra_complement
//////////////////////////
tgba_safra_complement::tgba_safra_complement(const tgba* a)
tgba_safra_complement::tgba_safra_complement(const const_tgba_ptr& a)
: automaton_(a), safra_(safra_determinisation::create_safra_automaton(a))
{
assert(safra_ || !"safra construction fails");
@ -1304,7 +1304,7 @@ namespace spot
// display_safra: debug routine.
//////////////////////////////
void display_safra(const tgba_safra_complement* a)
void display_safra(const const_tgba_safra_complement_ptr& a)
{
test::print_safra_automaton(static_cast<safra_tree_automaton*>
(a->get_safra()));

View file

@ -50,7 +50,7 @@ namespace spot
class SPOT_API tgba_safra_complement : public tgba
{
public:
tgba_safra_complement(const tgba* a);
tgba_safra_complement(const const_tgba_ptr& a);
virtual ~tgba_safra_complement();
// tgba interface.
@ -70,7 +70,7 @@ namespace spot
protected:
virtual bdd compute_support_conditions(const state* state) const;
private:
const tgba* automaton_;
const_tgba_ptr automaton_;
void* safra_;
#if TRANSFORM_TO_TBA
bdd the_acceptance_cond_;
@ -83,12 +83,21 @@ namespace spot
#endif
};
typedef std::shared_ptr<tgba_safra_complement> tgba_safra_complement_ptr;
typedef std::shared_ptr<const tgba_safra_complement>
const_tgba_safra_complement_ptr;
inline tgba_safra_complement_ptr
make_safra_complement(const const_tgba_ptr& a)
{
return std::make_shared<tgba_safra_complement>(a);
}
/// \brief Produce a dot output of the Safra automaton associated
/// to \a a.
///
/// \param a The \c tgba_safra_complement with an intermediate Safra
/// automaton to display
void SPOT_API display_safra(const tgba_safra_complement* a);
void SPOT_API display_safra(const const_tgba_safra_complement_ptr& a);
}
#endif // SPOT_TGBA_TGBASAFRACOMPLEMENT_HH

View file

@ -23,7 +23,7 @@
namespace spot
{
tgba_scc::tgba_scc(const tgba* aut, bool show)
tgba_scc::tgba_scc(const const_tgba_ptr& aut, bool show)
: aut_(aut), scc_map_(aut), show_(show)
{
scc_map_.build_map();
@ -82,7 +82,7 @@ namespace spot
}
state*
tgba_scc::project_state(const state* s, const tgba* t) const
tgba_scc::project_state(const state* s, const const_tgba_ptr& t) const
{
return aut_->project_state(s, t);
}

View file

@ -40,7 +40,7 @@ namespace spot
/// If \a show is set to true, then the format_state() method will
/// include the SCC number computed for the given state in its
/// output string.
tgba_scc(const tgba* aut, bool show = false);
tgba_scc(const const_tgba_ptr& aut, bool show = false);
virtual ~tgba_scc();
/// Returns the number of the SCC \a s belongs to.
@ -62,14 +62,14 @@ namespace spot
virtual std::string
transition_annotation(const tgba_succ_iterator* t) const;
virtual state* project_state(const state* s, const tgba* t) const;
virtual state* project_state(const state* s, const const_tgba_ptr& t) const;
virtual bdd all_acceptance_conditions() const;
virtual bdd neg_acceptance_conditions() const;
virtual bdd compute_support_conditions(const state* state) const;
protected:
const tgba* aut_; // The wrapped TGBA.
const_tgba_ptr aut_; // The wrapped TGBA.
scc_map scc_map_; // SCC informations.
bool show_; // Wether to show future conditions
// in the output of format_state().

View file

@ -165,7 +165,8 @@ namespace spot
} // anonymous
tgba_sgba_proxy::tgba_sgba_proxy(const tgba* a, bool no_zero_acc)
tgba_sgba_proxy::tgba_sgba_proxy(const const_tgba_ptr& a,
bool no_zero_acc)
: a_(a), emulate_acc_cond_(false)
{
if (no_zero_acc && a_->number_of_acceptance_conditions() == 0)

View file

@ -36,7 +36,7 @@ namespace spot
class SPOT_API tgba_sgba_proxy : public tgba
{
public:
tgba_sgba_proxy(const tgba* a, bool no_zero_acc = true);
tgba_sgba_proxy(const const_tgba_ptr& a, bool no_zero_acc = true);
virtual ~tgba_sgba_proxy();
@ -57,7 +57,7 @@ namespace spot
virtual bdd compute_support_conditions(const state* state) const;
private:
const tgba* a_;
const_tgba_ptr a_;
// If the automaton has no acceptance condition,
// every state is accepting.
bool emulate_acc_cond_;
@ -67,5 +67,10 @@ namespace spot
tgba_sgba_proxy& operator=(const tgba_sgba_proxy&) SPOT_DELETED;
};
inline tgba_sgba_proxy_ptr make_sgba(const const_tgba_ptr& a,
bool no_zero_acc = true)
{
return std::make_shared<tgba_sgba_proxy>(a, no_zero_acc);
}
}
#endif // SPOT_TGBA_TGBASGBA_HH

View file

@ -95,7 +95,7 @@ namespace spot
{
}
void recycle(const tgba* a, tgba_succ_iterator* it)
void recycle(const const_tgba_ptr& a, tgba_succ_iterator* it)
{
a->release_iter(it_);
it_ = it;
@ -183,7 +183,7 @@ namespace spot
class tgba_wdba_comp_proxy: public tgba
{
public:
tgba_wdba_comp_proxy(const tgba* a)
tgba_wdba_comp_proxy(const const_tgba_ptr& a)
: a_(a), the_acceptance_cond_(a->all_acceptance_conditions())
{
if (the_acceptance_cond_ == bddfalse)
@ -247,12 +247,12 @@ namespace spot
}
virtual state*
project_state(const state* s, const tgba* t) const
project_state(const state* s, const const_tgba_ptr& t) const
{
const state_wdba_comp_proxy* s2 =
down_cast<const state_wdba_comp_proxy*>(s);
assert(s2);
if (t == this)
if (t.get() == this)
return s2->clone();
return a_->project_state(s2->real_state(), t);
}
@ -277,7 +277,7 @@ namespace spot
return bddtrue;
}
const tgba* a_;
const_tgba_ptr a_;
private:
bdd the_acceptance_cond_;
@ -288,9 +288,9 @@ namespace spot
}
tgba*
wdba_complement(const tgba* aut)
const_tgba_ptr
wdba_complement(const const_tgba_ptr& aut)
{
return new tgba_wdba_comp_proxy(aut);
return std::make_shared<tgba_wdba_comp_proxy>(aut);
}
}

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2013 Laboratoire de Recherche et Développement
// Copyright (C) 2011, 2013, 2014 Laboratoire de Recherche et Développement
// de l'Epita.
//
// This file is part of Spot, a model checking library.
@ -28,8 +28,8 @@ namespace spot
/// \brief Complement a weak deterministic Büchi automaton
/// \param aut a weak deterministic Büchi automaton to complement
/// \return a new automaton that recognizes the complement language
SPOT_API tgba*
wdba_complement(const tgba* aut);
SPOT_API const_tgba_ptr
wdba_complement(const const_tgba_ptr& aut);
}
#endif