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:
Alexandre Duret-Lutz 2015-09-24 19:44:00 +02:00
parent 1628b188fe
commit b77f7e24c3
177 changed files with 8295 additions and 13332 deletions

View file

@ -25,9 +25,7 @@
#include "minimize.hh"
#include "simulation.hh"
#include "safety.hh"
#include "ltlast/allnodes.hh"
#include "ltlvisit/print.hh"
#include "ltlvisit/clone.hh"
#include <queue>
#include <sstream>
#include "ltlenv/environment.hh"
@ -36,163 +34,111 @@ namespace spot
{
namespace
{
typedef std::map<const ltl::formula*, bdd> formula_bdd_map;
// An environment to store atomic proposition associated to
// suspended variable. (We don't use the default environment to
// avoid conflicts with user-defined atomic propositions that
// would share the same name.)
class suspended_environment: public ltl::environment
{
public:
const ltl::formula*
require(const std::string& s)
{
return ltl::atomic_prop::instance(s, *this);
}
const std::string&
name() const
{
static std::string name("suspended environment");
return name;
}
};
static suspended_environment suspenv;
typedef std::map<ltl::formula, bdd> formula_bdd_map;
typedef std::vector<ltl::formula> vec;
// Rewrite the suspendable subformulae "s" of an LTL formula in
// the form Gg where "g" is an atomic proposition representing
// "s". At the same time, populate maps that associate "s" to "g"
// and vice-versa.
class ltl_suspender_visitor: public ltl::clone_visitor
class ltl_suspender_visitor final
{
public:
typedef std::map<const ltl::formula*, const ltl::formula*> fmap_t;
typedef std::map<ltl::formula, ltl::formula> fmap_t;
ltl_suspender_visitor(fmap_t& g2s, fmap_t& a2o, bool oblig)
: g2s_(g2s), a2o_(a2o), oblig_(oblig)
{
}
void
visit(const ltl::multop* mo)
ltl::formula
visit(ltl::formula f)
{
ltl::multop::type op = mo->op();
switch (op)
switch (ltl::op op = f.kind())
{
case ltl::multop::Or:
case ltl::multop::And:
case ltl::op::Or:
case ltl::op::And:
{
ltl::multop::vec* res = new ltl::multop::vec;
ltl::multop::vec* oblig = oblig_ ? new ltl::multop::vec : 0;
ltl::multop::vec* susp = new ltl::multop::vec;
unsigned mos = mo->size();
vec res;
vec oblig;
vec susp;
unsigned mos = f.size();
for (unsigned i = 0; i < mos; ++i)
{
const ltl::formula* c = mo->nth(i);
if (c->is_boolean())
res->push_back(c->clone());
else if (oblig_ && c->is_syntactic_obligation())
oblig->push_back(c->clone());
else if (c->is_eventual() && c->is_universal())
susp->push_back(c->clone());
ltl::formula c = f.nth(i);
if (c.is_boolean())
res.push_back(c);
else if (oblig_ && c.is_syntactic_obligation())
oblig.push_back(c);
else if (c.is_eventual() && c.is_universal())
susp.push_back(c);
else
res->push_back(recurse(c));
res.push_back(recurse(c));
}
if (!oblig_ || oblig->empty())
if (!oblig.empty())
{
delete oblig;
res.push_back(recurse(ltl::formula::multop(op, oblig)));
}
else
if (!susp.empty())
{
const ltl::formula* o = ltl::multop::instance(op, oblig);
res->push_back(recurse(o));
o->destroy();
}
if (susp->empty())
{
delete susp;
}
else
{
const ltl::formula* o = ltl::multop::instance(op, susp);
ltl::formula o = ltl::formula::multop(op, susp);
// Rewrite 'o' as 'G"o"'
const ltl::formula* g = recurse(o);
o->destroy();
if (op == ltl::multop::And)
ltl::formula g = recurse(o);
if (op == ltl::op::And)
{
res->push_back(g);
res.push_back(g);
}
else
{
// res || susp -> (res && G![susp]) || G[susp])
const ltl::formula* r = ltl::multop::instance(op, res);
const ltl::unop* u =
down_cast<const ltl::unop*>(g);
const ltl::formula* gn =
ltl::unop::instance
(ltl::unop::G, ltl::unop::instance
(ltl::unop::Not, u->child()->clone()));
result_ = ltl::multop::instance
(ltl::multop::Or, ltl::multop::instance
(ltl::multop::And, r, gn),
g);
return;
auto r = ltl::formula::multop(op, res);
auto gn = ltl::formula::G(ltl::formula::Not(g.nth(0)));
return ltl::formula::Or({ltl::formula::And({r, gn}), g});
}
}
result_ = ltl::multop::instance(op, res);
return ltl::formula::multop(op, res);
}
break;
case ltl::multop::OrRat:
case ltl::multop::AndRat:
case ltl::multop::AndNLM:
case ltl::multop::Concat:
case ltl::multop::Fusion:
this->ltl::clone_visitor::visit(mo);
break;
default:
return f.map([this](ltl::formula f)
{
return this->recurse(f);
});
}
}
const ltl::formula*
recurse(const ltl::formula* f)
ltl::formula
recurse(ltl::formula f)
{
const ltl::formula* res;
if (f->is_boolean())
return f->clone();
if (oblig_ && f->is_syntactic_obligation())
ltl::formula res;
if (f.is_boolean())
return f;
if (oblig_ && f.is_syntactic_obligation())
{
fmap_t::const_iterator i = assoc_.find(f);
if (i != assoc_.end())
return i->second->clone();
return i->second;
std::ostringstream s;
s << "";
print_psl(s, f) << "";
res = suspenv.require(s.str());
// We have to clone f, because it is not always a sub-tree
// of the original formula. (Think n-ary operators.)
a2o_[res] = f->clone();
print_psl(s << "", f) << "";
res = ltl::formula::ap(s.str());
a2o_[res] = f;
assoc_[f] = res;
return res;
}
if (f->is_eventual() && f->is_universal())
if (f.is_eventual() && f.is_universal())
{
fmap_t::const_iterator i = assoc_.find(f);
if (i != assoc_.end())
return ltl::unop::instance(ltl::unop::G, i->second->clone());
return ltl::formula::G(i->second);
std::ostringstream s;
s << '[';
print_psl(s, f) << ']';
res = suspenv.require(s.str());
// We have to clone f, because it is not always a sub-tree
// of the original formula. (Think n-ary operators.)
g2s_[res] = f->clone();
print_psl(s << '[', f) << "]$";
res = ltl::formula::ap(s.str());
g2s_[res] = f;
assoc_[f] = res;
return ltl::unop::instance(ltl::unop::G, res);
return ltl::formula::G(res);
}
f->accept(*this);
return result_;
return visit(f);
}
private:
@ -210,7 +156,7 @@ namespace spot
static
twa_graph_ptr
susp_prod(const const_twa_ptr& left, const ltl::formula* f, bdd v)
susp_prod(const const_twa_ptr& left, ltl::formula f, bdd v)
{
bdd_dict_ptr dict = left->get_dict();
auto right =
@ -320,7 +266,7 @@ namespace spot
twa_graph_ptr
compsusp(const ltl::formula* f, const bdd_dict_ptr& dict,
compsusp(ltl::formula f, const bdd_dict_ptr& dict,
bool no_wdba, bool no_simulation,
bool early_susp, bool no_susp_product, bool wdba_smaller,
bool oblig)
@ -328,7 +274,7 @@ namespace spot
ltl_suspender_visitor::fmap_t g2s;
ltl_suspender_visitor::fmap_t a2o;
ltl_suspender_visitor v(g2s, a2o, oblig);
const ltl::formula* g = v.recurse(f);
ltl::formula g = v.recurse(f);
// Translate the patched formula, and remove useless SCCs.
twa_graph_ptr res =
@ -392,14 +338,6 @@ namespace spot
if ((allaccap & i->second) == allaccap)
res = susp_prod(res, i->first, i->second);
g->destroy();
for (ltl_suspender_visitor::fmap_t::iterator i = g2s.begin();
i != g2s.end(); ++i)
i->second->destroy();
for (ltl_suspender_visitor::fmap_t::iterator i = a2o.begin();
i != a2o.end(); ++i)
i->second->destroy();
return res;
}
}

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2012, 2013, 2014 Laboratoire de Recherche et
// Copyright (C) 2012, 2013, 2014, 2015 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
@ -49,7 +49,7 @@ namespace spot
/// long-term stability should better use the services of the
/// spot::translator class instead.
SPOT_API twa_graph_ptr
compsusp(const ltl::formula* f, const bdd_dict_ptr& dict,
compsusp(ltl::formula f, const bdd_dict_ptr& dict,
bool no_wdba = false, bool no_simulation = false,
bool early_susp = false, bool no_susp_product = false,
bool wdba_smaller = false, bool oblig = false);

View file

@ -26,7 +26,6 @@
#include <utility>
#include "sccinfo.hh"
#include "twa/bddprint.hh"
#include "ltlast/constant.hh"
#include "stats.hh"
#include "ltlenv/defaultenv.hh"
#include "misc/satsolver.hh"

View file

@ -32,7 +32,7 @@
#include "misc/bddlt.hh"
#include "misc/minato.hh"
#include "twa/formula2bdd.hh"
#include "ltlast/atomic_prop.hh"
#include "ltlast/formula.hh"
namespace spot
{
@ -292,11 +292,7 @@ namespace spot
<< "AP: " << nap;
auto d = aut->get_dict();
for (auto& i: md.vap)
{
auto f = ltl::is_atomic_prop(d->bdd_map[i].f);
assert(f);
escape_str(os << " \"", f->name()) << '"';
}
escape_str(os << " \"", d->bdd_map[i].f.ap_name()) << '"';
os << nl;
unsigned num_acc = aut->num_sets();

View file

@ -103,11 +103,8 @@ namespace spot
body_ << s << ' ';
body_ << "-1 ";
}
const ltl::formula* f = bdd_to_formula(si->current_condition(),
aut_->get_dict());
print_lbt_ltl(body_, f);
f->destroy();
body_ << '\n';
print_lbt_ltl(body_, bdd_to_formula(si->current_condition(),
aut_->get_dict())) << '\n';
}
void

View file

@ -19,8 +19,6 @@
#include <utility>
#include <algorithm>
#include "ltlast/visitor.hh"
#include "ltlast/allnodes.hh"
#include "ltlvisit/unabbrev.hh"
#include "ltlvisit/nenoform.hh"
#include "ltlvisit/contain.hh"
@ -33,14 +31,14 @@ namespace spot
using namespace ltl;
/// \brief Recursively translate a formula into a TAA.
class ltl2taa_visitor : public visitor
class ltl2taa_visitor
{
public:
ltl2taa_visitor(const taa_tgba_formula_ptr& res,
language_containment_checker* lcc,
bool refined = false, bool negated = false)
: res_(res), refined_(refined), negated_(negated),
lcc_(lcc), init_(), succ_(), to_free_()
lcc_(lcc), init_(), succ_()
{
}
@ -52,116 +50,116 @@ namespace spot
taa_tgba_formula_ptr&
result()
{
for (unsigned i = 0; i < to_free_.size(); ++i)
to_free_[i]->destroy();
res_->set_init_state(init_);
return res_;
}
void
visit(const atomic_prop* node)
visit(formula f)
{
const formula* f = node; // Handle negation
if (negated_)
{
f = unop::instance(unop::Not, node->clone());
to_free_.push_back(f);
}
init_ = f;
std::vector<const formula*> empty;
taa_tgba::transition* t = res_->create_transition(init_, empty);
res_->add_condition(t, f->clone());
succ_state ss = { empty, f, empty };
succ_.push_back(ss);
}
void
visit(const constant* node)
{
init_ = node;
switch (node->val())
{
case constant::True:
switch (f.kind())
{
std::vector<const formula*> empty;
res_->create_transition(init_, empty);
succ_state ss = { empty, node, empty };
succ_.push_back(ss);
case op::False:
return;
}
case constant::False:
return;
case constant::EmptyWord:
SPOT_UNIMPLEMENTED();
}
SPOT_UNREACHABLE();
}
void
visit(const unop* node)
{
negated_ = node->op() == unop::Not;
ltl2taa_visitor v = recurse(node->child());
init_ = node;
switch (node->op())
{
case unop::X:
{
std::vector<const formula*> dst;
std::vector<const formula*> a;
if (v.succ_.empty()) // Handle X(0)
case op::True:
{
std::vector<formula> empty;
res_->create_transition(init_, empty);
succ_state ss = { empty, f, empty };
succ_.push_back(ss);
return;
dst.push_back(v.init_);
res_->create_transition(init_, dst);
succ_state ss =
{ dst, constant::true_instance(), a };
succ_.push_back(ss);
return;
}
case unop::F:
case unop::G:
}
case op::EmptyWord:
SPOT_UNIMPLEMENTED();
case op::AP:
{
if (negated_)
f = formula::Not(f);
init_ = f;
std::vector<formula> empty;
taa_tgba::transition* t = res_->create_transition(init_, empty);
res_->add_condition(t, f);
succ_state ss = { empty, f, empty };
succ_.push_back(ss);
return;
}
case op::X:
{
ltl2taa_visitor v = recurse(f.nth(0));
std::vector<formula> dst;
std::vector<formula> a;
if (v.succ_.empty()) // Handle X(0)
return;
dst.push_back(v.init_);
res_->create_transition(init_, dst);
succ_state ss = { dst, formula::tt(), a };
succ_.push_back(ss);
return;
}
case op::F:
case op::G:
SPOT_UNIMPLEMENTED(); // TBD
return;
case unop::Not:
// Done in recurse
succ_ = v.succ_;
return;
case unop::Closure:
case unop::NegClosure:
case unop::NegClosureMarked:
case op::Not:
{
negated_ = true;
ltl2taa_visitor v = recurse(f.nth(0));
// Done in recurse
succ_ = v.succ_;
return;
}
case op::Closure:
case op::NegClosure:
case op::NegClosureMarked:
case op::Star:
case op::FStar:
case op::Xor:
case op::Implies:
case op::Equiv:
case op::UConcat:
case op::EConcat:
case op::EConcatMarked:
case op::Concat:
case op::Fusion:
case op::AndNLM:
case op::AndRat:
case op::OrRat:
SPOT_UNIMPLEMENTED();
}
SPOT_UNREACHABLE();
case op::U:
case op::W:
case op::R:
case op::M:
visit_binop(f);
return;
case op::And:
case op::Or:
visit_multop(f);
return;
}
}
void
visit(const bunop*)
visit_binop(formula f)
{
SPOT_UNIMPLEMENTED();
}
ltl2taa_visitor v1 = recurse(f.nth(0));
ltl2taa_visitor v2 = recurse(f.nth(1));
void
visit(const binop* node)
{
ltl2taa_visitor v1 = recurse(node->first());
ltl2taa_visitor v2 = recurse(node->second());
init_ = node;
std::vector<succ_state>::iterator i1;
std::vector<succ_state>::iterator i2;
taa_tgba::transition* t = 0;
bool contained = false;
bool strong = false;
switch (node->op())
switch (f.kind())
{
case binop::U:
case op::U:
strong = true;
// fall thru
case binop::W:
case op::W:
if (refined_)
contained = lcc_->contained(node->second(), node->first());
contained = lcc_->contained(f.nth(0), f.nth(1));
for (i1 = v1.succ_.begin(); i1 != v1.succ_.end(); ++i1)
{
// Refined rule
@ -171,46 +169,44 @@ namespace spot
i1->Q.push_back(init_); // Add the initial state
if (strong)
i1->acc.push_back(node->second());
i1->acc.push_back(f.nth(1));
t = res_->create_transition(init_, i1->Q);
res_->add_condition(t, i1->condition->clone());
res_->add_condition(t, i1->condition);
if (strong)
res_->add_acceptance_condition(t, node->second()->clone());
res_->add_acceptance_condition(t, f.nth(1));
else
for (unsigned i = 0; i < i1->acc.size(); ++i)
res_->add_acceptance_condition(t, i1->acc[i]->clone());
res_->add_acceptance_condition(t, i1->acc[i]);
succ_.push_back(*i1);
}
for (i2 = v2.succ_.begin(); i2 != v2.succ_.end(); ++i2)
{
t = res_->create_transition(init_, i2->Q);
res_->add_condition(t, i2->condition->clone());
res_->add_condition(t, i2->condition);
succ_.push_back(*i2);
}
return;
case binop::M: // Strong Release
case op::M: // Strong Release
strong = true;
case binop::R: // Weak Release
case op::R: // Weak Release
if (refined_)
contained = lcc_->contained(node->first(), node->second());
contained = lcc_->contained(f.nth(0), f.nth(1));
for (i2 = v2.succ_.begin(); i2 != v2.succ_.end(); ++i2)
{
for (i1 = v1.succ_.begin(); i1 != v1.succ_.end(); ++i1)
{
std::vector<const formula*> u; // Union
std::vector<const formula*> a; // Acceptance conditions
std::vector<formula> u; // Union
std::vector<formula> a; // Acceptance conditions
std::copy(i1->Q.begin(), i1->Q.end(), ii(u, u.end()));
const formula* f = i1->condition->clone(); // Refined rule
formula f = i1->condition; // Refined rule
if (!refined_ || !contained)
{
std::copy(i2->Q.begin(), i2->Q.end(), ii(u, u.end()));
f = multop::instance(multop::And, f,
i2->condition->clone());
f = formula::And({f, i2->condition});
}
to_free_.push_back(f);
t = res_->create_transition(init_, u);
res_->add_condition(t, f->clone());
res_->add_condition(t, f);
succ_state ss = { u, f, a };
succ_.push_back(ss);
}
@ -222,113 +218,102 @@ namespace spot
i2->Q.push_back(init_); // Add the initial state
t = res_->create_transition(init_, i2->Q);
res_->add_condition(t, i2->condition->clone());
res_->add_condition(t, i2->condition);
if (strong)
{
i2->acc.push_back(node->first());
res_->add_acceptance_condition(t, node->first()->clone());
i2->acc.push_back(f.nth(0));
res_->add_acceptance_condition(t, f.nth(0));
}
else if (refined_)
for (unsigned i = 0; i < i2->acc.size(); ++i)
res_->add_acceptance_condition(t, i2->acc[i]->clone());
res_->add_acceptance_condition(t, i2->acc[i]);
succ_.push_back(*i2);
}
return;
case binop::Xor:
case binop::Implies:
case binop::Equiv:
case binop::UConcat:
case binop::EConcat:
case binop::EConcatMarked:
default:
SPOT_UNIMPLEMENTED();
}
SPOT_UNREACHABLE();
}
void
visit(const multop* node)
visit_multop(formula f)
{
bool ok = true;
std::vector<ltl2taa_visitor> vs;
for (unsigned n = 0; n < node->size(); ++n)
for (unsigned n = 0, s = f.size(); n < s; ++n)
{
vs.push_back(recurse(node->nth(n)));
vs.push_back(recurse(f.nth(n)));
if (vs[n].succ_.empty()) // Handle 0
ok = false;
}
init_ = node;
std::vector<succ_state>::iterator i;
taa_tgba::transition* t = 0;
switch (node->op())
{
case multop::And:
switch (f.kind())
{
if (!ok)
return;
std::vector<succ_state> p = all_n_tuples(vs);
for (unsigned n = 0; n < p.size(); ++n)
case op::And:
{
if (refined_)
{
std::vector<const formula*> v; // All sub initial states.
sort(p[n].Q.begin(), p[n].Q.end());
for (unsigned m = 0; m < node->size(); ++m)
if (!ok)
return;
std::vector<succ_state> p = all_n_tuples(vs);
for (unsigned n = 0; n < p.size(); ++n)
{
if (!binary_search(p[n].Q.begin(), p[n].Q.end(), vs[m].init_))
break;
v.push_back(vs[m].init_);
}
if (refined_)
{
std::vector<formula> v; // All sub initial states.
sort(p[n].Q.begin(), p[n].Q.end());
for (unsigned m = 0; m < f.size(); ++m)
{
if (!binary_search(p[n].Q.begin(), p[n].Q.end(),
vs[m].init_))
break;
v.push_back(vs[m].init_);
}
if (v.size() == node->size())
{
std::vector<const formula*> Q;
sort(v.begin(), v.end());
for (unsigned m = 0; m < p[n].Q.size(); ++m)
if (!binary_search(v.begin(), v.end(), p[n].Q[m]))
Q.push_back(p[n].Q[m]);
Q.push_back(init_);
t = res_->create_transition(init_, Q);
res_->add_condition(t, p[n].condition->clone());
for (unsigned i = 0; i < p[n].acc.size(); ++i)
res_->add_acceptance_condition(t, p[n].acc[i]->clone());
if (v.size() == f.size())
{
std::vector<formula> Q;
sort(v.begin(), v.end());
for (unsigned m = 0; m < p[n].Q.size(); ++m)
if (!binary_search(v.begin(), v.end(), p[n].Q[m]))
Q.push_back(p[n].Q[m]);
Q.push_back(init_);
t = res_->create_transition(init_, Q);
res_->add_condition(t, p[n].condition);
for (unsigned i = 0; i < p[n].acc.size(); ++i)
res_->add_acceptance_condition(t, p[n].acc[i]);
succ_.push_back(p[n]);
continue;
}
}
t = res_->create_transition(init_, p[n].Q);
res_->add_condition(t, p[n].condition);
succ_.push_back(p[n]);
continue;
}
}
t = res_->create_transition(init_, p[n].Q);
res_->add_condition(t, p[n].condition->clone());
succ_.push_back(p[n]);
return;
}
case op::Or:
for (unsigned n = 0, s = f.size(); n < s; ++n)
for (auto i: vs[n].succ_)
{
t = res_->create_transition(init_, i.Q);
res_->add_condition(t, i.condition);
succ_.push_back(i);
}
return;
}
case multop::Or:
for (unsigned n = 0; n < node->size(); ++n)
for (i = vs[n].succ_.begin(); i != vs[n].succ_.end(); ++i)
{
t = res_->create_transition(init_, i->Q);
res_->add_condition(t, i->condition->clone());
succ_.push_back(*i);
}
return;
case multop::Concat:
case multop::Fusion:
case multop::AndNLM:
case multop::AndRat:
case multop::OrRat:
default:
SPOT_UNIMPLEMENTED();
}
}
SPOT_UNREACHABLE();
}
ltl2taa_visitor
recurse(const formula* f)
recurse(formula f)
{
ltl2taa_visitor v(res_, lcc_, refined_, negated_);
f->accept(v);
for (unsigned i = 0; i < v.to_free_.size(); ++i)
to_free_.push_back(v.to_free_[i]);
v.visit(f);
return v;
}
@ -338,20 +323,18 @@ namespace spot
bool negated_;
language_containment_checker* lcc_;
typedef std::insert_iterator<std::vector<const formula*>> ii;
typedef std::insert_iterator<std::vector<formula>> ii;
struct succ_state
{
std::vector<const formula*> Q; // States
const formula* condition;
std::vector<const formula*> acc;
std::vector<formula> Q; // States
formula condition;
std::vector<formula> acc;
};
const formula* init_;
formula init_;
std::vector<succ_state> succ_;
std::vector<const formula*> to_free_;
public:
std::vector<succ_state>
all_n_tuples(const std::vector<ltl2taa_visitor>& vs)
@ -364,24 +347,22 @@ namespace spot
while (pos[0] != 0)
{
std::vector<const formula*> u; // Union
std::vector<const formula*> a; // Acceptance conditions
const formula* f = constant::true_instance();
std::vector<formula> u; // Union
std::vector<formula> a; // Acceptance conditions
formula f = formula::tt();
for (unsigned i = 0; i < vs.size(); ++i)
{
if (vs[i].succ_.empty())
continue;
const succ_state& ss(vs[i].succ_[pos[i] - 1]);
std::copy(ss.Q.begin(), ss.Q.end(), ii(u, u.end()));
f = multop::instance(multop::And, ss.condition->clone(), f);
f = formula::And({ss.condition, f});
for (unsigned i = 0; i < ss.acc.size(); ++i)
{
const formula* g = ss.acc[i]->clone();
formula g = ss.acc[i];
a.push_back(g);
to_free_.push_back(g);
}
}
to_free_.push_back(f);
succ_state ss = { u, f, a };
product.push_back(ss);
@ -404,22 +385,18 @@ namespace spot
} // anonymous
taa_tgba_formula_ptr
ltl_to_taa(const ltl::formula* f,
ltl_to_taa(ltl::formula f,
const bdd_dict_ptr& dict, bool refined_rules)
{
// TODO: implement translation of F and G
auto f1 = ltl::unabbreviate(f, "^ieFG");
auto f2 = ltl::negative_normal_form(f1);
f1->destroy();
auto f2 = ltl::negative_normal_form(ltl::unabbreviate(f, "^ieFG"));
auto res = make_taa_tgba_formula(dict);
language_containment_checker* lcc =
new language_containment_checker(make_bdd_dict(),
false, false, false, false);
ltl2taa_visitor v(res, lcc, refined_rules);
f2->accept(v);
auto taa = v.result(); // Careful: before the destroy!
f2->destroy();
v.visit(f2);
auto taa = v.result();
delete lcc;
taa->acc().set_generalized_buchi();
return taa;

View file

@ -1,6 +1,6 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2010, 2013, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
// Copyright (C) 2009, 2010, 2013, 2014, 2015 Laboratoire de Recherche
// et Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
@ -48,6 +48,6 @@ namespace spot
/// \param refined_rules If this parameter is set, refined rules are used.
/// \return A spot::taa that recognizes the language of \a f.
SPOT_API taa_tgba_formula_ptr
ltl_to_taa(const ltl::formula* f, const bdd_dict_ptr& dict,
ltl_to_taa(ltl::formula f, const bdd_dict_ptr& dict,
bool refined_rules = false);
}

File diff suppressed because it is too large Load diff

View file

@ -140,7 +140,7 @@ namespace spot
///
/// \return A spot::twa_graph that recognizes the language of \a f.
SPOT_API twa_graph_ptr
ltl_to_tgba_fm(const ltl::formula* f, const bdd_dict_ptr& dict,
ltl_to_tgba_fm(ltl::formula f, const bdd_dict_ptr& dict,
bool exprop = false, bool symb_merge = true,
bool branching_postponement = false,
bool fair_loop_approx = false,

View file

@ -33,7 +33,6 @@
#include <vector>
#include <sstream>
#include "minimize.hh"
#include "ltlast/allnodes.hh"
#include "misc/hash.hh"
#include "misc/bddlt.hh"
#include "twaalgos/product.hh"
@ -593,7 +592,7 @@ namespace spot
twa_graph_ptr
minimize_obligation(const const_twa_graph_ptr& aut_f,
const ltl::formula* f,
ltl::formula f,
const_twa_graph_ptr aut_neg_f,
bool reject_bigger)
{
@ -614,7 +613,7 @@ namespace spot
// if f is a syntactic obligation formula, the WDBA minimization
// must be correct.
if (f && f->is_syntactic_obligation())
if (f && f.is_syntactic_obligation())
return min_aut_f;
// If aut_f is a guarantee automaton, the WDBA minimization must be
@ -629,10 +628,7 @@ namespace spot
{
// If we know the formula, simply build the automaton for
// its negation.
const ltl::formula* neg_f =
ltl::unop::instance(ltl::unop::Not, f->clone());
aut_neg_f = ltl_to_tgba_fm(neg_f, aut_f->get_dict());
neg_f->destroy();
aut_neg_f = ltl_to_tgba_fm(ltl::formula::Not(f), aut_f->get_dict());
// Remove useless SCCs.
aut_neg_f = scc_filter(aut_neg_f, true);
}

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Laboratoire de
// Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Laboratoire de
// Recherche et Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
@ -151,7 +151,7 @@ namespace spot
/// that the minimized WDBA is correct.
SPOT_API twa_graph_ptr
minimize_obligation(const const_twa_graph_ptr& aut_f,
const ltl::formula* f = 0,
ltl::formula f = nullptr,
const_twa_graph_ptr aut_neg_f = nullptr,
bool reject_bigger = false);
/// @}

View file

@ -151,7 +151,7 @@ namespace spot
os_ << " :: atomic { (";
else
os_ << " :: (";
const ltl::formula* f = bdd_to_formula(t.cond, aut_->get_dict());
ltl::formula f = bdd_to_formula(t.cond, aut_->get_dict());
// This is actually a Boolean formula, but the LTL printer
// is all we have.
print_spin_ltl(os_, f, true);
@ -166,7 +166,6 @@ namespace spot
os_ << ") -> goto ";
print_state(t.dst);
}
f->destroy();
os_ << '\n';
}
if (!did_output)

View file

@ -144,7 +144,7 @@ namespace spot
#define SBACC_ (pref_ & SBAcc)
twa_graph_ptr
postprocessor::run(twa_graph_ptr a, const ltl::formula* f)
postprocessor::run(twa_graph_ptr a, ltl::formula f)
{
if (type_ != Generic && !a->acc().is_generalized_buchi())
a = to_generalized_buchi(a);
@ -300,7 +300,7 @@ namespace spot
twa_graph_ptr tmpd = nullptr;
if (PREF_ == Deterministic
&& f
&& f->is_syntactic_recurrence()
&& f.is_syntactic_recurrence()
&& sim->num_sets() > 1)
tmpd = degeneralize_tba(sim);

View file

@ -99,8 +99,7 @@ namespace spot
///
/// The returned automaton might be a new automaton,
/// or an in-place modification of the \a input automaton.
twa_graph_ptr run(twa_graph_ptr input,
const ltl::formula* f);
twa_graph_ptr run(twa_graph_ptr input, ltl::formula f);
protected:
twa_graph_ptr do_simul(const twa_graph_ptr& input, int opt);

View file

@ -35,7 +35,6 @@
#include "twaalgos/sccfilter.hh"
#include "twaalgos/ltl2tgba_fm.hh"
#include "twaalgos/dtgbacomp.hh"
#include "ltlast/unop.hh"
#include "misc/bitvect.hh"
#include "misc/bddlt.hh"
@ -405,13 +404,13 @@ namespace spot
tba_determinize_check(const twa_graph_ptr& aut,
unsigned threshold_states,
unsigned threshold_cycles,
const ltl::formula* f,
ltl::formula f,
const_twa_graph_ptr neg_aut)
{
if (f == 0 && neg_aut == 0)
return 0;
if (f == nullptr && neg_aut == nullptr)
return nullptr;
if (aut->num_sets() > 1)
return 0;
return nullptr;
auto det = tba_determinize(aut, threshold_states, threshold_cycles);
@ -420,11 +419,7 @@ namespace spot
if (neg_aut == nullptr)
{
const ltl::formula* neg_f =
ltl::unop::instance(ltl::unop::Not, f->clone());
neg_aut = ltl_to_tgba_fm(neg_f, aut->get_dict());
neg_f->destroy();
neg_aut = ltl_to_tgba_fm(ltl::formula::Not(f), aut->get_dict());
// Remove useless SCCs.
neg_aut = scc_filter(neg_aut, true);
}

View file

@ -133,7 +133,7 @@ namespace spot
tba_determinize_check(const twa_graph_ptr& aut,
unsigned threshold_states = 0,
unsigned threshold_cycles = 0,
const ltl::formula* f = 0,
const_twa_graph_ptr neg_aut = 0);
ltl::formula f = nullptr,
const_twa_graph_ptr neg_aut = nullptr);
}

View file

@ -24,7 +24,6 @@
#include "twa/twagraph.hh"
#include "misc/random.hh"
#include "misc/bddlt.hh"
#include "ltlast/atomic_prop.hh"
#include <sstream>
#include <list>
#include <set>

View file

@ -18,7 +18,6 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "remprop.hh"
#include "ltlenv/defaultenv.hh"
#include "twaalgos/mask.hh"
#include "misc/casts.hh"
#include <ctype.h>
@ -26,16 +25,6 @@
namespace spot
{
remove_ap::~remove_ap()
{
for (auto& ap: props_exist)
ap->destroy();
for (auto& ap: props_pos)
ap->destroy();
for (auto& ap: props_neg)
ap->destroy();
}
namespace
{
static
@ -56,7 +45,6 @@ namespace spot
void remove_ap::add_ap(const char* arg)
{
auto& env = spot::ltl::default_environment::instance();
auto start = arg;
while (*start)
{
@ -66,7 +54,7 @@ namespace spot
break;
if (*start == ',' || *start == '=')
unexpected_char(arg, start);
const spot::ltl::atomic_prop* the_ap = nullptr;
ltl::formula the_ap = nullptr;
if (*start == '"')
{
@ -84,8 +72,7 @@ namespace spot
throw std::invalid_argument(s);
}
std::string ap(start, end - start);
auto* t = env.require(ap);
the_ap = down_cast<const spot::ltl::atomic_prop*>(t);
the_ap = ltl::formula::ap(ap);
do
++end;
while (*end == ' ' || *end == '\t');
@ -100,8 +87,7 @@ namespace spot
while (rend > start && (rend[-1] == ' ' || rend[-1] == '\t'))
--rend;
std::string ap(start, rend - start);
auto* t = env.require(ap);
the_ap = down_cast<const spot::ltl::atomic_prop*>(t);
the_ap = ltl::formula::ap(ap);
start = end;
}
if (*start)

View file

@ -20,18 +20,17 @@
#pragma once
#include <vector>
#include "ltlast/atomic_prop.hh"
#include "ltlast/formula.hh"
#include "twa/twagraph.hh"
namespace spot
{
class SPOT_API remove_ap
{
std::set<const ltl::atomic_prop*> props_exist;
std::set<const ltl::atomic_prop*> props_pos;
std::set<const ltl::atomic_prop*> props_neg;
std::set<ltl::formula> props_exist;
std::set<ltl::formula> props_pos;
std::set<ltl::formula> props_neg;
public:
~remove_ap();
void add_ap(const char* ap_csv);
bool empty() const

View file

@ -162,8 +162,7 @@ namespace spot
std::ostream&
stat_printer::print(const const_twa_graph_ptr& aut,
const ltl::formula* f,
double run_time)
ltl::formula f, double run_time)
{
form_ = f;
run_time_ = run_time;

View file

@ -55,11 +55,11 @@ namespace spot
SPOT_API tgba_sub_statistics sub_stats_reachable(const const_twa_ptr& g);
class SPOT_API printable_formula: public printable_value<const ltl::formula*>
class SPOT_API printable_formula: public printable_value<ltl::formula>
{
public:
printable_formula&
operator=(const ltl::formula* new_val)
operator=(ltl::formula new_val)
{
val_ = new_val;
return *this;
@ -84,7 +84,7 @@ namespace spot
/// The \a f argument is not needed if the Formula does not need
/// to be output, and so is \a run_time).
std::ostream&
print(const const_twa_graph_ptr& aut, const ltl::formula* f = 0,
print(const const_twa_graph_ptr& aut, ltl::formula f = nullptr,
double run_time = -1.);
private:

View file

@ -24,8 +24,6 @@
#include "misc/hashfunc.hh"
#include "ltlvisit/apcollect.hh"
#include "translate.hh"
#include "ltlast/unop.hh"
#include "ltlast/binop.hh"
#include "ltlvisit/remove_x.hh"
#include "twaalgos/product.hh"
#include "twaalgos/ltl2tgba_fm.hh"
@ -542,9 +540,9 @@ namespace spot
}
bool
is_stutter_invariant(const ltl::formula* f)
is_stutter_invariant(ltl::formula f)
{
if (f->is_ltl_formula() && f->is_syntactic_stutter_invariant())
if (f.is_ltl_formula() && f.is_syntactic_stutter_invariant())
return true;
int algo = default_stutter_check_algorithm();
@ -552,35 +550,30 @@ namespace spot
if (algo == 0 || algo == 9)
// Etessami's check via syntactic transformation.
{
if (!f->is_ltl_formula())
if (!f.is_ltl_formula())
throw std::runtime_error("Cannot use the syntactic "
"stutter-invariance check "
"for non-LTL formulas");
const ltl::formula* g = remove_x(f);
ltl::formula g = remove_x(f);
bool res;
if (algo == 0) // Equivalence check
{
ltl::ltl_simplifier ls;
res = ls.are_equivalent(f, g);
g->destroy();
}
else
{
const ltl::formula* h = ltl::binop::instance(ltl::binop::Xor,
f->clone(), g);
ltl::formula h = ltl::formula::Xor(f, g);
res = ltl_to_tgba_fm(h, make_bdd_dict())->is_empty();
h->destroy();
}
return res;
}
// Prepare for an automata-based check.
const ltl::formula* nf = ltl::unop::instance(ltl::unop::Not, f->clone());
translator trans;
auto aut_f = trans.run(f);
auto aut_nf = trans.run(nf);
auto aut_nf = trans.run(ltl::formula::Not(f));
bdd aps = atomic_prop_collect_as_bdd(f, aut_f);
nf->destroy();
return is_stutter_invariant(std::move(aut_f), std::move(aut_nf), aps, algo);
}
@ -625,7 +618,7 @@ namespace spot
}
bool
check_stutter_invariance(const twa_graph_ptr& aut, const ltl::formula* f)
check_stutter_invariance(const twa_graph_ptr& aut, ltl::formula f)
{
bool is_stut = aut->is_stutter_invariant();
if (is_stut)
@ -634,9 +627,7 @@ namespace spot
twa_graph_ptr neg = nullptr;
if (f)
{
auto* nf = ltl::unop::instance(ltl::unop::Not, f->clone());
neg = translator(aut->get_dict()).run(nf);
nf->destroy();
neg = translator(aut->get_dict()).run(ltl::formula::Not(f));
}
else
{

View file

@ -51,7 +51,7 @@ namespace spot
/// \ingroup ltl_misc
/// \brief Check if a formula has the stutter invariance property.
SPOT_API bool
is_stutter_invariant(const ltl::formula* f);
is_stutter_invariant(ltl::formula f);
SPOT_API bool
is_stutter_invariant(twa_graph_ptr&& aut_f,
@ -65,5 +65,5 @@ namespace spot
/// of the automaton is updated and also returned.
SPOT_API bool
check_stutter_invariance(const twa_graph_ptr& aut,
const ltl::formula* f = nullptr);
ltl::formula f = nullptr);
}

View file

@ -61,7 +61,7 @@ namespace spot
simpl_owned_ = simpl_ = new ltl::ltl_simplifier(options, dict);
}
twa_graph_ptr translator::run(const ltl::formula** f)
twa_graph_ptr translator::run(ltl::formula* f)
{
bool unambiguous = (pref_ & postprocessor::Unambiguous);
if (unambiguous && type_ == postprocessor::Monitor)
@ -72,8 +72,7 @@ namespace spot
set_pref(pref_ | postprocessor::Deterministic);
}
const ltl::formula* r = simpl_->simplify(*f);
(*f)->destroy();
ltl::formula r = simpl_->simplify(*f);
*f = r;
// This helps ltl_to_tgba_fm() to order BDD variables in a more
@ -102,12 +101,9 @@ namespace spot
return aut;
}
twa_graph_ptr translator::run(const ltl::formula* f)
twa_graph_ptr translator::run(ltl::formula f)
{
f->clone();
auto aut = run(&f);
f->destroy();
return aut;
return run(&f);
}
}

View file

@ -100,16 +100,14 @@ namespace spot
/// \brief Convert \a f into an automaton.
///
/// The formula \a f is simplified internally, but it is not
/// not destroyed (this is the responsibility of the caller).
twa_graph_ptr run(const ltl::formula* f);
/// The formula \a f is simplified internally.
twa_graph_ptr run(ltl::formula f);
/// \brief Convert \a f into an automaton, and update f.
///
/// The formula <code>*f</code> is destroyed, and replaced
/// by the simplified version, which should be destroyed by
/// the caller.
twa_graph_ptr run(const ltl::formula** f);
/// The formula <code>*f</code> is replaced
/// by the simplified version.
twa_graph_ptr run(ltl::formula* f);
protected:
void setup_opt(const option_map* opt);