revamp the formula hierarchy (montro-patch)
Flatten the formula ltl::formula hiearchy into a single ltl::vnode that has an enumerator to distinguish the types of node, and a common interface to access children, update reference counts, etc. The ltl::formula class is now a thin wrapper around an ltl::vnode pointer to keep track of reference counts automatically. Visitor are not used anymore; we now have map() and traversor() methods that are more concise. This basically fixes #43, but should be followed by some fine tuning that should now be localized to the formula.hh and formula.cc files. Some statistics about this patch. I started working on it on Sep 9, had a first compiling version two weeks later on Sep 22, and it then took 5 days to fixes the ~70 distincts bugs that were introduced during the conversion. About 13200 lines were modified, and one third of those were removed. * src/ltlast/formula.cc, src/ltlast/formula.hh: Complete rewrite, including what was in separate nearby files. * src/ltlast/allnodes.hh, src/ltlast/atomic_prop.cc, src/ltlast/atomic_prop.hh, src/ltlast/binop.cc, src/ltlast/binop.hh, src/ltlast/bunop.cc, src/ltlast/bunop.hh, src/ltlast/constant.cc, src/ltlast/constant.hh, src/ltlast/multop.cc, src/ltlast/multop.hh, src/ltlast/unop.cc, src/ltlast/unop.hh, src/ltlvisit/dump.cc, src/ltlvisit/dump.hh, src/ltlast/predecl.hh: Delete these files. Their feature have been merged in formula.hh and formula.cc. * src/ltlast/visitor.hh, src/ltlvisit/clone.cc, src/ltlvisit/clone.hh, src/ltlvisit/dump.hh, src/ltlvisit/postfix.cc, src/ltlvisit/postfix.hh: Delete these files, as we do not use visitors anymore. * bench/stutter/stutter_invariance_formulas.cc, bench/stutter/stutter_invariance_randomgraph.cc, doc/org/tut01.org, doc/org/tut02.org, doc/org/tut10.org, doc/org/tut22.org, iface/ltsmin/ltsmin.cc, iface/ltsmin/ltsmin.hh, iface/ltsmin/modelcheck.cc, src/bin/autfilt.cc, src/bin/common_aoutput.cc, src/bin/common_aoutput.hh, src/bin/common_finput.cc, src/bin/common_finput.hh, src/bin/common_output.cc, src/bin/common_output.hh, src/bin/common_trans.cc, src/bin/common_trans.hh, src/bin/dstar2tgba.cc, src/bin/genltl.cc, src/bin/ltl2tgba.cc, src/bin/ltl2tgta.cc, src/bin/ltlcross.cc, src/bin/ltldo.cc, src/bin/ltlfilt.cc, src/bin/ltlgrind.cc, src/bin/randaut.cc, src/bin/randltl.cc, src/kripke/kripkeexplicit.cc, src/kripke/kripkeexplicit.hh, src/kripkeparse/kripkeparse.yy, src/ltlast/Makefile.am, src/ltlenv/declenv.cc, src/ltlenv/declenv.hh, src/ltlenv/defaultenv.cc, src/ltlenv/defaultenv.hh, src/ltlenv/environment.hh, src/ltlparse/ltlparse.yy, src/ltlparse/public.hh, src/ltlvisit/Makefile.am, src/ltlvisit/apcollect.cc, src/ltlvisit/apcollect.hh, src/ltlvisit/contain.cc, src/ltlvisit/contain.hh, src/ltlvisit/dot.cc, src/ltlvisit/dot.hh, src/ltlvisit/exclusive.cc, src/ltlvisit/exclusive.hh, src/ltlvisit/length.cc, src/ltlvisit/length.hh, src/ltlvisit/mark.cc, src/ltlvisit/mark.hh, src/ltlvisit/mutation.cc, src/ltlvisit/mutation.hh, src/ltlvisit/nenoform.cc, src/ltlvisit/nenoform.hh, src/ltlvisit/print.cc, src/ltlvisit/print.hh, src/ltlvisit/randomltl.cc, src/ltlvisit/randomltl.hh, src/ltlvisit/relabel.cc, src/ltlvisit/relabel.hh, src/ltlvisit/remove_x.cc, src/ltlvisit/remove_x.hh, src/ltlvisit/simpfg.cc, src/ltlvisit/simpfg.hh, src/ltlvisit/simplify.cc, src/ltlvisit/simplify.hh, src/ltlvisit/snf.cc, src/ltlvisit/snf.hh, src/ltlvisit/unabbrev.cc, src/ltlvisit/unabbrev.hh, src/parseaut/parseaut.yy, src/ta/taexplicit.cc, src/ta/tgtaexplicit.cc, src/taalgos/minimize.cc, src/taalgos/tgba2ta.cc, src/tests/bare.test, src/tests/checkpsl.cc, src/tests/checkta.cc, src/tests/complementation.cc, src/tests/consterm.cc, src/tests/emptchk.cc, src/tests/equalsf.cc, src/tests/ikwiad.cc, src/tests/isop.test, src/tests/kind.cc, src/tests/length.cc, src/tests/ltldo.test, src/tests/ltlfilt.test, src/tests/ltlgrind.test, src/tests/ltlprod.cc, src/tests/ltlrel.cc, src/tests/parse_print_test.cc, src/tests/parseaut.test, src/tests/parseerr.test, src/tests/randtgba.cc, src/tests/readltl.cc, src/tests/reduc.cc, src/tests/syntimpl.cc, src/tests/taatgba.cc, src/tests/tostring.cc, src/tests/twagraph.cc, src/tests/utf8.test, src/twa/acc.cc, src/twa/bdddict.cc, src/twa/bdddict.hh, src/twa/bddprint.cc, src/twa/formula2bdd.cc, src/twa/formula2bdd.hh, src/twa/taatgba.cc, src/twa/taatgba.hh, src/twa/twa.cc, src/twa/twa.hh src/twa/twagraph.cc, src/twa/twagraph.hh, src/twa/twasafracomplement.cc, src/twaalgos/compsusp.cc, src/twaalgos/compsusp.hh, src/twaalgos/dtgbasat.cc, src/twaalgos/hoa.cc, src/twaalgos/lbtt.cc, src/twaalgos/ltl2taa.cc, src/twaalgos/ltl2taa.hh, src/twaalgos/ltl2tgba_fm.cc, src/twaalgos/ltl2tgba_fm.hh, src/twaalgos/minimize.cc, src/twaalgos/minimize.hh, src/twaalgos/neverclaim.cc, src/twaalgos/postproc.cc, src/twaalgos/postproc.hh, src/twaalgos/powerset.cc, src/twaalgos/powerset.hh, src/twaalgos/randomgraph.cc, src/twaalgos/remprop.cc, src/twaalgos/remprop.hh, src/twaalgos/stats.cc, src/twaalgos/stats.hh, src/twaalgos/stutter.cc, src/twaalgos/stutter.hh, src/twaalgos/translate.cc, src/twaalgos/translate.hh, wrap/python/ajax/spotcgi.in, wrap/python/spot.py, wrap/python/spot_impl.i, wrap/python/Makefile.am, wrap/python/tests/automata-io.ipynb, wrap/python/tests/formulas.ipynb, wrap/python/tests/ltl2tgba.py, wrap/python/tests/ltlparse.py, wrap/python/tests/ltlsimple.py, wrap/python/tests/randltl.ipynb: Adjust to use the new interface. * src/sanity/style.test: Accept more C++11 patterns. * NEWS: Mention the change.
This commit is contained in:
parent
1628b188fe
commit
b77f7e24c3
177 changed files with 8295 additions and 13332 deletions
|
|
@ -23,6 +23,7 @@
|
|||
#include <set>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include "acc.hh"
|
||||
#include "priv/bddalloc.hh"
|
||||
#include "misc/minato.hh"
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include <sstream>
|
||||
#include <cassert>
|
||||
#include <ltlvisit/print.hh>
|
||||
#include <ltlast/atomic_prop.hh>
|
||||
#include <ltlast/formula.hh>
|
||||
#include <ltlenv/defaultenv.hh>
|
||||
#include "priv/bddalloc.hh"
|
||||
#include "bdddict.hh"
|
||||
|
|
@ -95,7 +95,7 @@ namespace spot
|
|||
}
|
||||
|
||||
int
|
||||
bdd_dict::register_proposition(const ltl::formula* f, const void* for_me)
|
||||
bdd_dict::register_proposition(ltl::formula f, const void* for_me)
|
||||
{
|
||||
int num;
|
||||
// Do not build a variable that already exists.
|
||||
|
|
@ -106,7 +106,6 @@ namespace spot
|
|||
}
|
||||
else
|
||||
{
|
||||
f = f->clone();
|
||||
num = priv_->allocate_variables(1);
|
||||
var_map[f] = num;
|
||||
bdd_map.resize(bdd_varnum());
|
||||
|
|
@ -118,7 +117,7 @@ namespace spot
|
|||
}
|
||||
|
||||
int
|
||||
bdd_dict::has_registered_proposition(const ltl::formula* f,
|
||||
bdd_dict::has_registered_proposition(ltl::formula f,
|
||||
const void* me)
|
||||
{
|
||||
auto ssi = var_map.find(f);
|
||||
|
|
@ -132,8 +131,8 @@ namespace spot
|
|||
}
|
||||
|
||||
int
|
||||
bdd_dict::register_acceptance_variable(const ltl::formula* f,
|
||||
const void* for_me)
|
||||
bdd_dict::register_acceptance_variable(ltl::formula f,
|
||||
const void* for_me)
|
||||
{
|
||||
int num;
|
||||
// Do not build an acceptance variable that already exists.
|
||||
|
|
@ -144,7 +143,6 @@ namespace spot
|
|||
}
|
||||
else
|
||||
{
|
||||
f = f->clone();
|
||||
num = priv_->allocate_variables(1);
|
||||
acc_map[f] = num;
|
||||
bdd_map.resize(bdd_varnum());
|
||||
|
|
@ -173,7 +171,7 @@ namespace spot
|
|||
register_acceptance_variables(bdd_low(f), for_me);
|
||||
}
|
||||
|
||||
const ltl::formula*
|
||||
ltl::formula
|
||||
bdd_dict::oneacc_to_formula(int var) const
|
||||
{
|
||||
assert(unsigned(var) < bdd_map.size());
|
||||
|
|
@ -182,7 +180,7 @@ namespace spot
|
|||
return i.f;
|
||||
}
|
||||
|
||||
const ltl::formula*
|
||||
ltl::formula
|
||||
bdd_dict::oneacc_to_formula(bdd oneacc) const
|
||||
{
|
||||
assert(oneacc != bddfalse);
|
||||
|
|
@ -276,7 +274,7 @@ namespace spot
|
|||
// Let's free it. First, we need to find
|
||||
// if this is a Var or an Acc variable.
|
||||
int n = 1;
|
||||
const ltl::formula* f = 0;
|
||||
ltl::formula f = nullptr;
|
||||
switch (bdd_map[v].type)
|
||||
{
|
||||
case var:
|
||||
|
|
@ -302,8 +300,6 @@ namespace spot
|
|||
// Actually release the associated BDD variables, and the
|
||||
// formula itself.
|
||||
priv_->release_variables(v, n);
|
||||
if (f)
|
||||
f->destroy();
|
||||
while (n--)
|
||||
bdd_map[v + n].type = anon;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,9 +66,9 @@ namespace spot
|
|||
~bdd_dict();
|
||||
|
||||
/// Formula-to-BDD-variable maps.
|
||||
typedef std::map<const ltl::formula*, int> fv_map;
|
||||
typedef std::map<ltl::formula, int> fv_map;
|
||||
/// BDD-variable-to-formula maps.
|
||||
typedef std::map<int, const ltl::formula*> vf_map;
|
||||
typedef std::map<int, ltl::formula> vf_map;
|
||||
|
||||
fv_map var_map; ///< Maps atomic propositions to BDD variables
|
||||
fv_map acc_map; ///< Maps acceptance conditions to BDD variables
|
||||
|
|
@ -80,7 +80,7 @@ namespace spot
|
|||
struct bdd_info {
|
||||
bdd_info() : type(anon) {}
|
||||
var_type type;
|
||||
const ltl::formula* f; // Used unless t==anon.
|
||||
ltl::formula f; // Used unless t==anon.
|
||||
ref_set refs;
|
||||
int clone_counts;
|
||||
};
|
||||
|
|
@ -99,11 +99,10 @@ 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);
|
||||
int register_proposition(ltl::formula f, const void* for_me);
|
||||
|
||||
template <typename T>
|
||||
int register_proposition(const ltl::formula* f,
|
||||
std::shared_ptr<T> for_me)
|
||||
int register_proposition(ltl::formula f, std::shared_ptr<T> for_me)
|
||||
{
|
||||
return register_proposition(f, for_me.get());
|
||||
}
|
||||
|
|
@ -115,11 +114,10 @@ namespace spot
|
|||
/// a non-negative value that is the BDD variable number.
|
||||
/// Otherwise this returns -1.
|
||||
/// @{
|
||||
int has_registered_proposition(const ltl::formula* f,
|
||||
const void* me);
|
||||
int has_registered_proposition(ltl::formula f, const void* me);
|
||||
|
||||
template <typename T>
|
||||
int has_registered_proposition(const ltl::formula* f,
|
||||
std::shared_ptr<T> for_me)
|
||||
int has_registered_proposition(ltl::formula f, std::shared_ptr<T> for_me)
|
||||
{
|
||||
return has_registered_proposition(f, for_me.get());
|
||||
}
|
||||
|
|
@ -136,11 +134,10 @@ 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);
|
||||
int register_acceptance_variable(ltl::formula f, const void* for_me);
|
||||
|
||||
template <typename T>
|
||||
int register_acceptance_variable(const ltl::formula* f,
|
||||
std::shared_ptr<T> for_me)
|
||||
int register_acceptance_variable(ltl::formula f, std::shared_ptr<T> for_me)
|
||||
{
|
||||
return register_acceptance_variable(f, for_me.get());
|
||||
}
|
||||
|
|
@ -172,7 +169,7 @@ namespace spot
|
|||
///
|
||||
/// The returned formula is not cloned, and is valid until the BDD
|
||||
/// variable used in \a oneacc are unregistered.
|
||||
const ltl::formula* oneacc_to_formula(bdd oneacc) const;
|
||||
ltl::formula oneacc_to_formula(bdd oneacc) const;
|
||||
|
||||
/// \brief Convert one acceptance condition into the associated
|
||||
/// formula.
|
||||
|
|
@ -182,7 +179,7 @@ namespace spot
|
|||
///
|
||||
/// The returned formula is not cloned, and is valid until the BDD
|
||||
/// variable \a var is unregistered.
|
||||
const ltl::formula* oneacc_to_formula(int var) const;
|
||||
ltl::formula oneacc_to_formula(int var) const;
|
||||
|
||||
/// \brief Register anonymous BDD variables.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace spot
|
|||
static bool utf8;
|
||||
|
||||
static
|
||||
std::ostream& print_(std::ostream& o, const ltl::formula* f)
|
||||
std::ostream& print_(std::ostream& o, ltl::formula f)
|
||||
{
|
||||
if (utf8)
|
||||
ltl::print_utf8_psl(o, f);
|
||||
|
|
@ -172,10 +172,7 @@ namespace spot
|
|||
std::ostream&
|
||||
bdd_print_formula(std::ostream& os, const bdd_dict_ptr& d, bdd b)
|
||||
{
|
||||
const ltl::formula* f = bdd_to_formula(b, d);
|
||||
print_(os, f);
|
||||
f->destroy();
|
||||
return os;
|
||||
return print_(os, bdd_to_formula(b, d));
|
||||
}
|
||||
|
||||
std::string
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2009, 2010, 2012, 2014 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
// Copyright (C) 2009, 2010, 2012, 2014, 2015 Laboratoire de Recherche
|
||||
// et Développement de l'Epita (LRDE).
|
||||
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris
|
||||
// 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
|
||||
// Université Pierre et Marie Curie.
|
||||
|
|
@ -22,8 +22,6 @@
|
|||
|
||||
#include <cassert>
|
||||
#include "formula2bdd.hh"
|
||||
#include "ltlast/allnodes.hh"
|
||||
#include "ltlast/visitor.hh"
|
||||
#include "misc/minato.hh"
|
||||
|
||||
namespace spot
|
||||
|
|
@ -32,163 +30,24 @@ namespace spot
|
|||
|
||||
namespace
|
||||
{
|
||||
class formula_to_bdd_visitor: public ltl::visitor
|
||||
{
|
||||
public:
|
||||
formula_to_bdd_visitor(const bdd_dict_ptr& d, void* owner)
|
||||
: d_(d), owner_(owner)
|
||||
{
|
||||
}
|
||||
|
||||
virtual
|
||||
~formula_to_bdd_visitor()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void
|
||||
visit(const atomic_prop* node)
|
||||
{
|
||||
res_ = bdd_ithvar(d_->register_proposition(node, owner_));
|
||||
}
|
||||
|
||||
virtual void
|
||||
visit(const constant* node)
|
||||
{
|
||||
switch (node->val())
|
||||
{
|
||||
case constant::True:
|
||||
res_ = bddtrue;
|
||||
return;
|
||||
case constant::False:
|
||||
res_ = bddfalse;
|
||||
return;
|
||||
case constant::EmptyWord:
|
||||
SPOT_UNIMPLEMENTED();
|
||||
}
|
||||
SPOT_UNREACHABLE();
|
||||
}
|
||||
|
||||
virtual void
|
||||
visit(const bunop*)
|
||||
{
|
||||
SPOT_UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
virtual void
|
||||
visit(const unop* node)
|
||||
{
|
||||
switch (node->op())
|
||||
{
|
||||
case unop::F:
|
||||
case unop::G:
|
||||
case unop::X:
|
||||
case unop::Closure:
|
||||
case unop::NegClosure:
|
||||
case unop::NegClosureMarked:
|
||||
SPOT_UNIMPLEMENTED();
|
||||
case unop::Not:
|
||||
{
|
||||
res_ = bdd_not(recurse(node->child()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
SPOT_UNREACHABLE();
|
||||
}
|
||||
|
||||
virtual void
|
||||
visit(const binop* node)
|
||||
{
|
||||
bdd f1 = recurse(node->first());
|
||||
bdd f2 = recurse(node->second());
|
||||
|
||||
switch (node->op())
|
||||
{
|
||||
case binop::Xor:
|
||||
res_ = bdd_apply(f1, f2, bddop_xor);
|
||||
return;
|
||||
case binop::Implies:
|
||||
res_ = bdd_apply(f1, f2, bddop_imp);
|
||||
return;
|
||||
case binop::Equiv:
|
||||
res_ = bdd_apply(f1, f2, bddop_biimp);
|
||||
return;
|
||||
case binop::U:
|
||||
case binop::R:
|
||||
case binop::W:
|
||||
case binop::M:
|
||||
case binop::UConcat:
|
||||
case binop::EConcat:
|
||||
case binop::EConcatMarked:
|
||||
SPOT_UNIMPLEMENTED();
|
||||
}
|
||||
SPOT_UNREACHABLE();
|
||||
}
|
||||
|
||||
virtual void
|
||||
visit(const multop* node)
|
||||
{
|
||||
int op = -1;
|
||||
switch (node->op())
|
||||
{
|
||||
case multop::And:
|
||||
op = bddop_and;
|
||||
res_ = bddtrue;
|
||||
break;
|
||||
case multop::Or:
|
||||
op = bddop_or;
|
||||
res_ = bddfalse;
|
||||
break;
|
||||
case multop::Concat:
|
||||
case multop::Fusion:
|
||||
case multop::AndNLM:
|
||||
case multop::OrRat:
|
||||
case multop::AndRat:
|
||||
SPOT_UNIMPLEMENTED();
|
||||
}
|
||||
assert(op != -1);
|
||||
unsigned s = node->size();
|
||||
for (unsigned n = 0; n < s; ++n)
|
||||
{
|
||||
res_ = bdd_apply(res_, recurse(node->nth(n)), op);
|
||||
}
|
||||
}
|
||||
|
||||
bdd
|
||||
result() const
|
||||
{
|
||||
return res_;
|
||||
}
|
||||
|
||||
bdd
|
||||
recurse(const formula* f) const
|
||||
{
|
||||
return formula_to_bdd(f, d_, owner_);
|
||||
}
|
||||
|
||||
private:
|
||||
bdd_dict_ptr d_;
|
||||
void* owner_;
|
||||
bdd res_;
|
||||
};
|
||||
|
||||
// Convert a BDD which is known to be a conjonction into a formula.
|
||||
static const ltl::formula*
|
||||
static formula
|
||||
conj_to_formula(bdd b, const bdd_dict_ptr d)
|
||||
{
|
||||
if (b == bddfalse)
|
||||
return constant::false_instance();
|
||||
multop::vec* v = new multop::vec;
|
||||
return formula::ff();
|
||||
std::vector<formula> v;
|
||||
while (b != bddtrue)
|
||||
{
|
||||
int var = bdd_var(b);
|
||||
const bdd_dict::bdd_info& i = d->bdd_map[var];
|
||||
assert(i.type == bdd_dict::var);
|
||||
const formula* res = i.f->clone();
|
||||
formula res = i.f;
|
||||
|
||||
bdd high = bdd_high(b);
|
||||
if (high == bddfalse)
|
||||
{
|
||||
res = unop::instance(unop::Not, res);
|
||||
res = formula::Not(res);
|
||||
b = bdd_low(b);
|
||||
}
|
||||
else
|
||||
|
|
@ -198,34 +57,89 @@ namespace spot
|
|||
b = high;
|
||||
}
|
||||
assert(b != bddfalse);
|
||||
v->push_back(res);
|
||||
v.push_back(res);
|
||||
}
|
||||
return multop::instance(multop::And, v);
|
||||
return formula::And(v);
|
||||
}
|
||||
|
||||
} // anonymous
|
||||
|
||||
bdd
|
||||
formula_to_bdd(const formula* f, const bdd_dict_ptr& d, void* for_me)
|
||||
formula_to_bdd(formula f, const bdd_dict_ptr& d, void* owner)
|
||||
{
|
||||
formula_to_bdd_visitor v(d, for_me);
|
||||
f->accept(v);
|
||||
return v.result();
|
||||
auto recurse = [&d, owner](formula f)
|
||||
{
|
||||
return formula_to_bdd(f, d, owner);
|
||||
};
|
||||
switch (f.kind())
|
||||
{
|
||||
case op::False:
|
||||
return bddfalse;
|
||||
case op::True:
|
||||
return bddtrue;
|
||||
case op::EmptyWord:
|
||||
case op::Star:
|
||||
case op::FStar:
|
||||
case op::F:
|
||||
case op::G:
|
||||
case op::X:
|
||||
case op::Closure:
|
||||
case op::NegClosure:
|
||||
case op::NegClosureMarked:
|
||||
case op::U:
|
||||
case op::R:
|
||||
case op::W:
|
||||
case op::M:
|
||||
case op::UConcat:
|
||||
case op::EConcat:
|
||||
case op::EConcatMarked:
|
||||
case op::Concat:
|
||||
case op::Fusion:
|
||||
case op::AndNLM:
|
||||
case op::OrRat:
|
||||
case op::AndRat:
|
||||
SPOT_UNIMPLEMENTED();
|
||||
case op::AP:
|
||||
return bdd_ithvar(d->register_proposition(f, owner));
|
||||
case op::Not:
|
||||
return bdd_not(recurse(f.nth(0)));
|
||||
case op::Xor:
|
||||
return bdd_apply(recurse(f.nth(0)), recurse(f.nth(1)), bddop_xor);
|
||||
case op::Implies:
|
||||
return bdd_apply(recurse(f.nth(0)), recurse(f.nth(1)), bddop_imp);
|
||||
case op::Equiv:
|
||||
return bdd_apply(recurse(f.nth(0)), recurse(f.nth(1)), bddop_biimp);
|
||||
case op::And:
|
||||
case op::Or:
|
||||
{
|
||||
int op = bddop_and;
|
||||
bdd res = bddtrue;
|
||||
if (f.is(ltl::op::Or))
|
||||
{
|
||||
op = bddop_or;
|
||||
res = bddfalse;
|
||||
}
|
||||
unsigned s = f.size();
|
||||
for (unsigned n = 0; n < s; ++n)
|
||||
res = bdd_apply(res, recurse(f.nth(n)), op);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
SPOT_UNREACHABLE();
|
||||
return bddfalse;
|
||||
}
|
||||
|
||||
const formula*
|
||||
formula
|
||||
bdd_to_formula(bdd f, const bdd_dict_ptr d)
|
||||
{
|
||||
if (f == bddfalse)
|
||||
return constant::false_instance();
|
||||
return formula::ff();
|
||||
|
||||
multop::vec* v = new multop::vec;
|
||||
std::vector<formula> v;
|
||||
|
||||
minato_isop isop(f);
|
||||
bdd cube;
|
||||
while ((cube = isop.next()) != bddfalse)
|
||||
v->push_back(conj_to_formula(cube, d));
|
||||
|
||||
return multop::instance(multop::Or, v);
|
||||
v.emplace_back(conj_to_formula(cube, d));
|
||||
return formula::Or(std::move(v));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2012, 2013, 2014 Laboratoire de Recherche et Développement de
|
||||
// l'Epita (LRDE).
|
||||
// Copyright (C) 2012, 2013, 2014, 2015 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
|
||||
// et Marie Curie.
|
||||
|
|
@ -39,11 +39,11 @@ namespace spot
|
|||
/// for_me. See bdd_dict::unregister_all_my_variables().
|
||||
/// @{
|
||||
SPOT_API bdd
|
||||
formula_to_bdd(const ltl::formula* f, const bdd_dict_ptr& d, void* for_me);
|
||||
formula_to_bdd(ltl::formula f, const bdd_dict_ptr& d, void* for_me);
|
||||
|
||||
template<typename T>
|
||||
SPOT_API bdd
|
||||
formula_to_bdd(const ltl::formula* f, const bdd_dict_ptr& d,
|
||||
formula_to_bdd(ltl::formula f, const bdd_dict_ptr& d,
|
||||
const std::shared_ptr<T>& for_me)
|
||||
{
|
||||
return formula_to_bdd(f, d, for_me.get());
|
||||
|
|
@ -57,7 +57,7 @@ namespace spot
|
|||
/// into their atomic propositions. This works only for Boolean
|
||||
/// formulas, and all the BDD variables used in \a f should have
|
||||
/// been registered in \a d. Although the result has type
|
||||
/// ltl::formula*, it obviously does not use any temporal operator.
|
||||
SPOT_API const
|
||||
ltl::formula* bdd_to_formula(bdd f, const bdd_dict_ptr d);
|
||||
/// ltl::formula, it obviously does not use any temporal operator.
|
||||
SPOT_API
|
||||
ltl::formula bdd_to_formula(bdd f, const bdd_dict_ptr d);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
#include <iostream>
|
||||
#include "twa/formula2bdd.hh"
|
||||
#include "ltlvisit/print.hh"
|
||||
#include "ltlvisit/clone.hh"
|
||||
#include "taatgba.hh"
|
||||
|
||||
namespace spot
|
||||
|
|
@ -47,10 +46,9 @@ namespace spot
|
|||
}
|
||||
|
||||
void
|
||||
taa_tgba::add_condition(transition* t, const ltl::formula* f)
|
||||
taa_tgba::add_condition(transition* t, ltl::formula f)
|
||||
{
|
||||
t->condition &= formula_to_bdd(f, get_dict(), this);
|
||||
f->destroy();
|
||||
}
|
||||
|
||||
state*
|
||||
|
|
@ -313,59 +311,19 @@ namespace spot
|
|||
| taa_tgba_string |
|
||||
`----------------*/
|
||||
|
||||
taa_tgba_string::~taa_tgba_string()
|
||||
{
|
||||
ns_map::iterator i;
|
||||
for (i = name_state_map_.begin(); i != name_state_map_.end(); ++i)
|
||||
{
|
||||
taa_tgba::state::iterator i2;
|
||||
for (i2 = i->second->begin(); i2 != i->second->end(); ++i2)
|
||||
delete *i2;
|
||||
delete i->second;
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
taa_tgba_string::label_to_string(const label_t& label) const
|
||||
{
|
||||
return label;
|
||||
}
|
||||
|
||||
std::string
|
||||
taa_tgba_string::clone_if(const label_t& label) const
|
||||
{
|
||||
return label;
|
||||
}
|
||||
|
||||
/*-----------------.
|
||||
| taa_tgba_formula |
|
||||
`-----------------*/
|
||||
|
||||
taa_tgba_formula::~taa_tgba_formula()
|
||||
{
|
||||
ns_map::iterator i;
|
||||
for (i = name_state_map_.begin(); i != name_state_map_.end();)
|
||||
{
|
||||
taa_tgba::state::iterator i2;
|
||||
for (i2 = i->second->begin(); i2 != i->second->end(); ++i2)
|
||||
delete *i2;
|
||||
// Advance the iterator before destroying the formula.
|
||||
const ltl::formula* s = i->first;
|
||||
delete i->second;
|
||||
++i;
|
||||
s->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
taa_tgba_formula::label_to_string(const label_t& label) const
|
||||
{
|
||||
return ltl::str_psl(label);
|
||||
}
|
||||
|
||||
const ltl::formula*
|
||||
taa_tgba_formula::clone_if(const label_t& label) const
|
||||
{
|
||||
return label->clone();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ namespace spot
|
|||
const state_set* dst;
|
||||
};
|
||||
|
||||
void add_condition(transition* t, const ltl::formula* f);
|
||||
void add_condition(transition* t, ltl::formula f);
|
||||
|
||||
/// TGBA interface.
|
||||
virtual ~taa_tgba();
|
||||
|
|
@ -66,8 +66,7 @@ namespace spot
|
|||
taa_tgba::state_set* init_;
|
||||
ss_vec state_set_vec_;
|
||||
|
||||
std::map<const ltl::formula*, acc_cond::mark_t,
|
||||
ltl::formula_ptr_less_than> acc_map_;
|
||||
std::map<ltl::formula, acc_cond::mark_t> acc_map_;
|
||||
|
||||
private:
|
||||
// Disallow copy.
|
||||
|
|
@ -151,11 +150,14 @@ namespace spot
|
|||
taa_tgba_labelled(const bdd_dict_ptr& dict) : taa_tgba(dict) {};
|
||||
|
||||
~taa_tgba_labelled()
|
||||
{
|
||||
auto i = acc_map_.begin();
|
||||
while (i != acc_map_.end())
|
||||
(i++)->first->destroy();
|
||||
}
|
||||
{
|
||||
for (auto i: name_state_map_)
|
||||
{
|
||||
for (auto i2: *i.second)
|
||||
delete i2;
|
||||
delete i.second;
|
||||
}
|
||||
}
|
||||
|
||||
void set_init_state(const label& s)
|
||||
{
|
||||
|
|
@ -190,13 +192,11 @@ namespace spot
|
|||
return create_transition(s, vec);
|
||||
}
|
||||
|
||||
void add_acceptance_condition(transition* t, const ltl::formula* f)
|
||||
void add_acceptance_condition(transition* t, ltl::formula f)
|
||||
{
|
||||
auto p = acc_map_.emplace(f, 0);
|
||||
if (p.second)
|
||||
p.first->second = acc_.marks({acc_.add_set()});
|
||||
else
|
||||
f->destroy();
|
||||
t->acceptance_conditions |= p.first->second;
|
||||
}
|
||||
|
||||
|
|
@ -246,10 +246,6 @@ namespace spot
|
|||
/// \brief Return a label as a string.
|
||||
virtual std::string label_to_string(const label_t& lbl) const = 0;
|
||||
|
||||
/// \brief Clone the label if necessary to assure it is owned by
|
||||
/// this, avoiding memory issues when label is a pointer.
|
||||
virtual label_t clone_if(const label_t& lbl) const = 0;
|
||||
|
||||
private:
|
||||
/// \brief Return the taa_tgba::state for \a name, creating it
|
||||
/// when it does not exist already.
|
||||
|
|
@ -258,10 +254,9 @@ namespace spot
|
|||
typename ns_map::iterator i = name_state_map_.find(name);
|
||||
if (i == name_state_map_.end())
|
||||
{
|
||||
const label& name_ = clone_if(name);
|
||||
taa_tgba::state* s = new taa_tgba::state;
|
||||
name_state_map_[name_] = s;
|
||||
state_name_map_[s] = name_;
|
||||
name_state_map_[name] = s;
|
||||
state_name_map_[s] = name;
|
||||
return s;
|
||||
}
|
||||
return i->second;
|
||||
|
|
@ -314,11 +309,11 @@ namespace spot
|
|||
{
|
||||
public:
|
||||
taa_tgba_string(const bdd_dict_ptr& dict) :
|
||||
taa_tgba_labelled<std::string>(dict) {};
|
||||
~taa_tgba_string();
|
||||
taa_tgba_labelled<std::string>(dict) {}
|
||||
~taa_tgba_string()
|
||||
{}
|
||||
protected:
|
||||
virtual std::string label_to_string(const std::string& label) const;
|
||||
virtual std::string clone_if(const std::string& label) const;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<taa_tgba_string> taa_tgba_string_ptr;
|
||||
|
|
@ -331,18 +326,18 @@ namespace spot
|
|||
|
||||
class SPOT_API taa_tgba_formula final:
|
||||
#ifndef SWIG
|
||||
public taa_tgba_labelled<const ltl::formula*>
|
||||
public taa_tgba_labelled<ltl::formula>
|
||||
#else
|
||||
public taa_tgba
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
taa_tgba_formula(const bdd_dict_ptr& dict) :
|
||||
taa_tgba_labelled<const ltl::formula*>(dict) {};
|
||||
~taa_tgba_formula();
|
||||
taa_tgba_labelled<ltl::formula>(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;
|
||||
|
|
|
|||
|
|
@ -39,8 +39,6 @@ namespace spot
|
|||
|
||||
twa::~twa()
|
||||
{
|
||||
for (auto* ap: aps_)
|
||||
ap->destroy();
|
||||
if (last_support_conditions_input_)
|
||||
last_support_conditions_input_->destroy();
|
||||
delete iter_cache_;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
#include <vector>
|
||||
#include "misc/casts.hh"
|
||||
#include "misc/hash.hh"
|
||||
#include "ltlast/atomic_prop.hh"
|
||||
#include "ltlast/formula.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
|
@ -594,11 +594,10 @@ namespace spot
|
|||
|
||||
/// \brief Register an atomic proposition designated by formula \a ap.
|
||||
///
|
||||
/// \return The variable number inside of the BDD.
|
||||
int register_ap(const ltl::formula* ap)
|
||||
/// \return The BDD variable number.
|
||||
int register_ap(ltl::formula ap)
|
||||
{
|
||||
aps_.push_back(dynamic_cast<const ltl::atomic_prop*>(ap));
|
||||
ap->clone();
|
||||
aps_.push_back(ap);
|
||||
int res = dict_->register_proposition(ap, this);
|
||||
bddaps_ &= bdd_ithvar(res);
|
||||
return res;
|
||||
|
|
@ -606,23 +605,15 @@ namespace spot
|
|||
|
||||
/// \brief Register an atomic proposition designated by string \a ap.
|
||||
///
|
||||
/// This string is converted into a formula and registered
|
||||
/// inside of the BDD manager.
|
||||
///
|
||||
/// \return The variable number inside of the BDD.
|
||||
int register_ap(std::string name,
|
||||
ltl::environment& e = ltl::default_environment::instance())
|
||||
/// \return The BDD variable number.
|
||||
int register_ap(std::string name)
|
||||
{
|
||||
auto* ap = e.require(name);
|
||||
aps_.push_back(dynamic_cast<const ltl::atomic_prop*>(ap));
|
||||
int res = dict_->register_proposition(ap, this);
|
||||
bddaps_ &= bdd_ithvar(res);
|
||||
return res;
|
||||
return register_ap(ltl::formula::ap(name));
|
||||
}
|
||||
|
||||
/// \brief Get the vector of atomic propositions used by this
|
||||
/// automaton.
|
||||
const std::vector<const ltl::atomic_prop*>& ap() const
|
||||
const std::vector<ltl::formula>& ap() const
|
||||
{
|
||||
return aps_;
|
||||
}
|
||||
|
|
@ -730,7 +721,7 @@ namespace spot
|
|||
void copy_ap_of(const const_twa_ptr& a)
|
||||
{
|
||||
get_dict()->register_all_propositions_of(a, this);
|
||||
for (auto *f: a->ap())
|
||||
for (auto f: a->ap())
|
||||
this->register_ap(f);
|
||||
}
|
||||
|
||||
|
|
@ -754,7 +745,7 @@ namespace spot
|
|||
mutable const state* last_support_conditions_input_;
|
||||
private:
|
||||
mutable bdd last_support_conditions_output_;
|
||||
std::vector<const ltl::atomic_prop*> aps_;
|
||||
std::vector<ltl::formula> aps_;
|
||||
bdd bddaps_;
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -18,13 +18,12 @@
|
|||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "twagraph.hh"
|
||||
#include "ltlast/constant.hh"
|
||||
#include "ltlvisit/print.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
void
|
||||
twa_graph::release_formula_namer(namer<const ltl::formula*>* namer,
|
||||
twa_graph::release_formula_namer(namer<ltl::formula>* namer,
|
||||
bool keep_names)
|
||||
{
|
||||
if (keep_names)
|
||||
|
|
@ -37,19 +36,10 @@ namespace spot
|
|||
{
|
||||
auto f = n[i];
|
||||
if (f)
|
||||
{
|
||||
(*v)[i] = str_psl(f);
|
||||
f->destroy();
|
||||
}
|
||||
(*v)[i] = str_psl(f);
|
||||
}
|
||||
set_named_prop("state-names", v);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto n: namer->names())
|
||||
if (n)
|
||||
n->destroy();
|
||||
}
|
||||
delete namer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -219,14 +219,14 @@ namespace spot
|
|||
return new named_graph<graph_t, State_Name, Name_Hash, Name_Equal>(g_);
|
||||
}
|
||||
|
||||
namer<const ltl::formula*>*
|
||||
namer<ltl::formula>*
|
||||
create_formula_namer()
|
||||
{
|
||||
return create_namer<const ltl::formula*>();
|
||||
return create_namer<ltl::formula>();
|
||||
}
|
||||
|
||||
void
|
||||
release_formula_namer(namer<const ltl::formula*>* namer, bool keep_names);
|
||||
release_formula_namer(namer<ltl::formula>* namer, bool keep_names);
|
||||
#endif
|
||||
|
||||
graph_t& get_graph()
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@
|
|||
#include "twa/twa.hh"
|
||||
#include "misc/hashfunc.hh"
|
||||
#include "ltlast/formula.hh"
|
||||
#include "ltlast/constant.hh"
|
||||
#include "twaalgos/dot.hh"
|
||||
#include "twa/twasafracomplement.hh"
|
||||
#include "twaalgos/degen.hh"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue