Move language containment into ltl_simplifier.
* src/ltlvisit/simplify.cc: Integrate the tau03 containment rules. * src/ltlvisit/simplify.hh: Add options to select simplifications. * src/ltlvisit/reduce.cc (reduce): Do not call reduce_tau03(). * src/ltlvisit/contain.cc (reduce_tau03_visitor): Remove. (reduce_tau03): Implement it using ltl_simplifier.
This commit is contained in:
parent
82b42494db
commit
1087c62356
4 changed files with 442 additions and 539 deletions
|
|
@ -22,6 +22,7 @@
|
|||
// 02111-1307, USA.
|
||||
|
||||
#include "contain.hh"
|
||||
#include "simplify.hh"
|
||||
#include "tunabbrev.hh"
|
||||
#include "ltlast/unop.hh"
|
||||
#include "ltlast/binop.hh"
|
||||
|
|
@ -144,271 +145,16 @@ namespace spot
|
|||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
struct reduce_tau03_visitor : public clone_visitor {
|
||||
bool stronger;
|
||||
language_containment_checker* lcc;
|
||||
|
||||
reduce_tau03_visitor(bool stronger,
|
||||
language_containment_checker* lcc)
|
||||
: stronger(stronger), lcc(lcc)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
visit(unop* uo)
|
||||
{
|
||||
formula* a = recurse(uo->child());
|
||||
switch (uo->op())
|
||||
{
|
||||
case unop::X:
|
||||
// if X(a) = a, then keep only a !
|
||||
if (stronger && lcc->equal(a, uo))
|
||||
{
|
||||
result_ = a;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
result_ = unop::instance(uo->op(), a);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
visit(binop* bo)
|
||||
{
|
||||
formula* a = recurse(bo->first());
|
||||
formula* b = recurse(bo->second());
|
||||
switch (bo->op())
|
||||
{
|
||||
case binop::U:
|
||||
// if (a U b) => b, then keep b !
|
||||
if (stronger && lcc->contained(bo, b))
|
||||
{
|
||||
a->destroy();
|
||||
result_ = b;
|
||||
}
|
||||
// if a => b, then a U b = b.
|
||||
else if ((!stronger) && lcc->contained(a, b))
|
||||
{
|
||||
a->destroy();
|
||||
result_ = b;
|
||||
}
|
||||
// if !a => b, then a U b = Fb
|
||||
else if (lcc->neg_contained(a, b))
|
||||
{
|
||||
a->destroy();
|
||||
result_ = unop::instance(unop::F, b);
|
||||
}
|
||||
else
|
||||
{
|
||||
result_ = binop::instance(binop::U, a, b);
|
||||
}
|
||||
break;
|
||||
case binop::W:
|
||||
// if (a W b) => b, then keep b !
|
||||
if (stronger && lcc->contained(bo, b))
|
||||
{
|
||||
a->destroy();
|
||||
result_ = b;
|
||||
}
|
||||
// if a => b, then a W b = b.
|
||||
else if ((!stronger) && lcc->contained(a, b))
|
||||
{
|
||||
a->destroy();
|
||||
result_ = b;
|
||||
}
|
||||
// if !a => b, then a W b = 1
|
||||
else if (lcc->neg_contained(a, b))
|
||||
{
|
||||
a->destroy();
|
||||
b->destroy();
|
||||
result_ = constant::true_instance();
|
||||
}
|
||||
else
|
||||
{
|
||||
result_ = binop::instance(binop::W, a, b);
|
||||
}
|
||||
break;
|
||||
case binop::R:
|
||||
// if b => a, then a R b = b.
|
||||
if (lcc->contained(b, a))
|
||||
{
|
||||
a->destroy();
|
||||
result_ = b;
|
||||
}
|
||||
// if a => !b, then a R b = Gb
|
||||
else if (lcc->contained_neg(a, b))
|
||||
{
|
||||
a->destroy();
|
||||
result_ = unop::instance(unop::G, b);
|
||||
}
|
||||
else
|
||||
{
|
||||
result_ = binop::instance(binop::R, a, b);
|
||||
}
|
||||
break;
|
||||
case binop::M:
|
||||
// if b => a, then a M b = b.
|
||||
if (lcc->contained(b, a))
|
||||
{
|
||||
a->destroy();
|
||||
result_ = b;
|
||||
}
|
||||
// if a => !b, then a M b = 0
|
||||
else if (lcc->contained_neg(a, b))
|
||||
{
|
||||
a->destroy();
|
||||
b->destroy();
|
||||
result_ = constant::false_instance();
|
||||
}
|
||||
else
|
||||
{
|
||||
result_ = binop::instance(binop::M, a, b);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
result_ = binop::instance(bo->op(), a, b);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
visit(automatop*)
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
void
|
||||
visit(multop* mo)
|
||||
{
|
||||
multop::vec* res = new multop::vec;
|
||||
unsigned mos = mo->size();
|
||||
for (unsigned i = 0; i < mos; ++i)
|
||||
res->push_back(recurse(mo->nth(i)));
|
||||
result_ = 0;
|
||||
bool changed = false;
|
||||
|
||||
switch (mo->op())
|
||||
{
|
||||
case multop::Or:
|
||||
for (unsigned i = 0; i < mos; ++i)
|
||||
{
|
||||
if (!(*res)[i])
|
||||
continue;
|
||||
for (unsigned j = i + 1; j < mos; ++j)
|
||||
{
|
||||
if (!(*res)[j])
|
||||
continue;
|
||||
// if !i => j, then i|j = true
|
||||
if (lcc->neg_contained((*res)[i], (*res)[j]))
|
||||
{
|
||||
result_ = constant::true_instance();
|
||||
goto constant_;
|
||||
}
|
||||
// if i => j, then i|j = j
|
||||
else if (lcc->contained((*res)[i], (*res)[j]))
|
||||
{
|
||||
(*res)[i]->destroy();
|
||||
(*res)[i] = 0;
|
||||
changed = true;
|
||||
break;
|
||||
}
|
||||
// if j => i, then i|j = i
|
||||
else if (lcc->contained((*res)[j], (*res)[i]))
|
||||
{
|
||||
(*res)[j]->destroy();
|
||||
(*res)[j] = 0;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case multop::And:
|
||||
for (unsigned i = 0; i < mos; ++i)
|
||||
{
|
||||
if (!(*res)[i])
|
||||
continue;
|
||||
for (unsigned j = i + 1; j < mos; ++j)
|
||||
{
|
||||
if (!(*res)[j])
|
||||
continue;
|
||||
// if i => !j, then i&j = false
|
||||
if (lcc->contained_neg((*res)[i], (*res)[j]))
|
||||
{
|
||||
result_ = constant::false_instance();
|
||||
goto constant_;
|
||||
}
|
||||
// if i => j, then i&j = i
|
||||
else if (lcc->contained((*res)[i], (*res)[j]))
|
||||
{
|
||||
(*res)[j]->destroy();
|
||||
(*res)[j] = 0;
|
||||
changed = true;
|
||||
}
|
||||
// if j => i, then i&j = j
|
||||
else if (lcc->contained((*res)[j], (*res)[i]))
|
||||
{
|
||||
(*res)[i]->destroy();
|
||||
(*res)[i] = 0;
|
||||
changed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case multop::Concat:
|
||||
case multop::Fusion:
|
||||
case multop::AndNLM:
|
||||
break;
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
multop::vec* nres = new multop::vec;
|
||||
for (unsigned i = 0; i < mos; ++i)
|
||||
if ((*res)[i])
|
||||
nres->push_back((*res)[i]);
|
||||
delete res;
|
||||
res = nres;
|
||||
}
|
||||
result_ = multop::instance(mo->op(), res);
|
||||
return;
|
||||
constant_:
|
||||
for (unsigned i = 0; i < mos; ++i)
|
||||
if ((*res)[i])
|
||||
(*res)[i]->destroy();
|
||||
delete res;
|
||||
}
|
||||
|
||||
formula*
|
||||
recurse(formula* f)
|
||||
{
|
||||
if (!f->is_psl_formula())
|
||||
return f->clone();
|
||||
|
||||
reduce_tau03_visitor v(stronger, lcc);
|
||||
const_cast<formula*>(f)->accept(v);
|
||||
return v.result();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
formula*
|
||||
reduce_tau03(const formula* f, bool stronger)
|
||||
{
|
||||
if (!f->is_psl_formula())
|
||||
return f->clone();
|
||||
|
||||
bdd_dict b;
|
||||
reduce_tau03_visitor v(stronger,
|
||||
new language_containment_checker(&b,
|
||||
true, true,
|
||||
false, false));
|
||||
// reduce_tau03_visitor does not handle Xor, Implies, and Equiv.
|
||||
f = unabbreviate_ltl(f);
|
||||
const_cast<formula*>(f)->accept(v);
|
||||
f->destroy();
|
||||
delete v.lcc;
|
||||
return v.result();
|
||||
ltl_simplifier_options opt(false, false, false,
|
||||
true, stronger);
|
||||
ltl_simplifier simpl(opt);
|
||||
return simpl.simplify(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
#include "lunabbrev.hh"
|
||||
#include "simpfg.hh"
|
||||
#include "nenoform.hh"
|
||||
#include "contain.hh"
|
||||
#include "simplify.hh"
|
||||
|
||||
namespace spot
|
||||
|
|
@ -73,20 +72,8 @@ namespace spot
|
|||
f2->destroy();
|
||||
f2 = f1;
|
||||
|
||||
f1 = simplifier.simplify(f2);
|
||||
f = simplifier.simplify(f2);
|
||||
f2->destroy();
|
||||
f2 = f1;
|
||||
|
||||
if (opt & (Reduce_Containment_Checks
|
||||
| Reduce_Containment_Checks_Stronger))
|
||||
{
|
||||
formula* f1 =
|
||||
reduce_tau03(f2,
|
||||
opt & Reduce_Containment_Checks_Stronger);
|
||||
f2->destroy();
|
||||
f2 = f1;
|
||||
}
|
||||
f = f2;
|
||||
}
|
||||
prev->destroy();
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -31,15 +31,20 @@ namespace spot
|
|||
class ltl_simplifier_options
|
||||
{
|
||||
public:
|
||||
ltl_simplifier_options()
|
||||
: reduce_basics(true),
|
||||
synt_impl(true),
|
||||
event_univ(true),
|
||||
containment_checks(false),
|
||||
containment_checks_stronger(false),
|
||||
ltl_simplifier_options(bool basics = true,
|
||||
bool synt_impl = true,
|
||||
bool event_univ = true,
|
||||
bool containment_checks = false,
|
||||
bool containment_checks_stronger = false,
|
||||
bool nenoform_stop_on_boolean = false)
|
||||
: reduce_basics(basics),
|
||||
synt_impl(synt_impl),
|
||||
event_univ(event_univ),
|
||||
containment_checks(containment_checks),
|
||||
containment_checks_stronger(containment_checks_stronger),
|
||||
// If true, Boolean subformulae will not be put into
|
||||
// negative normal form.
|
||||
nenoform_stop_on_boolean(false)
|
||||
nenoform_stop_on_boolean(nenoform_stop_on_boolean)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -48,6 +53,8 @@ namespace spot
|
|||
bool event_univ;
|
||||
bool containment_checks;
|
||||
bool containment_checks_stronger;
|
||||
// If true, Boolean subformulae will not be put into
|
||||
// negative normal form.
|
||||
bool nenoform_stop_on_boolean;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue