Adding tgba-based stutter-invariance checking

* src/tgbaalgos/closure.cc, src/tgbaalgos/closure.hh:
Add closure function.
* src/tgbaalgos/stutterize.cc, src/tgbaalgos/stutterize.hh:
Add two implementations of "self-loopize" function.
* src/tgbaalgos/Makefile.am: Add them.
* src/tgba/tgbasl.cc, src/tgba/tgbasl.hh: On-the-fly implementation of
self-loopize.
* src/tgba/Makefile.am: Add it.
* src/tgbatest/ltl2tgba.cc, src/tgbatest/stutter_invariant.test: Test
closure and sl.
* src/tgbatest/Makefile.am: Adjust.
* src/bin/ltlfilt.cc: Modify stutter-invariant option to use
automaton-based checking rather than syntactic-based checking.
* src/ltlvisit/remove_x.cc, src/ltlvisit/remove_x.hh:
Remove is_stutter_insensitive function.
* src/tgbaalgos/stutter_invariance.cc,
src/tgbaalgos/stutter_invariance.hh: Check if a formula is
stutter-invariant using closure and sl.
* wrap/python/spot.i: Add closure and sl bindings.
* bench/stutter/stutter_invariance_formulas.cc: Generate benchmarks from
given formulas.
* bench/stutter/stutter_invariance_randomgraph.cc: Generate benchmarks
from random automata.
* bench/stutter/Makefile.am: Add them.
* configure.ac: Add bench/stutter/Makefile.
* bench/Makefile.am: Add stutter subdirectory.
* README: Document bench/stutter directory.
This commit is contained in:
Thibaud Michaud 2014-10-01 12:58:16 +02:00 committed by Alexandre Duret-Lutz
parent beafcf4e3d
commit 37bcb5d959
23 changed files with 1159 additions and 42 deletions

View file

@ -29,6 +29,7 @@ tgbaalgosdir = $(pkgincludedir)/tgbaalgos
tgbaalgos_HEADERS = \
bfssteps.hh \
closure.hh \
complete.hh \
compsusp.hh \
cycles.hh \
@ -69,6 +70,8 @@ tgbaalgos_HEADERS = \
simulation.hh \
stats.hh \
stripacc.hh \
stutter_invariance.hh \
stutterize.hh \
tau03.hh \
tau03opt.hh \
translate.hh \
@ -77,6 +80,7 @@ tgbaalgos_HEADERS = \
noinst_LTLIBRARIES = libtgbaalgos.la
libtgbaalgos_la_SOURCES = \
bfssteps.cc \
closure.cc \
complete.cc \
compsusp.cc \
cycles.cc \
@ -117,6 +121,8 @@ libtgbaalgos_la_SOURCES = \
simulation.cc \
stats.cc \
stripacc.cc \
stutter_invariance.cc \
stutterize.cc \
tau03.cc \
tau03opt.cc \
translate.cc \

121
src/tgbaalgos/closure.cc Normal file
View file

@ -0,0 +1,121 @@
// Copyright (C) 2014 Laboratoire de Recherche et Développement
// de l'Epita.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <unordered_set>
#include <deque>
#include "closure.hh"
#include "dupexp.hh"
namespace spot
{
namespace
{
struct transition
{
unsigned dst;
acc_cond::mark_t acc;
transition(unsigned dst, acc_cond::mark_t acc) :
dst(dst), acc(acc)
{
}
};
struct transition_hash
{
size_t
operator()(const transition& t) const
{
return wang32_hash(t.dst) ^ wang32_hash(t.acc);
}
};
struct transition_equal
{
bool
operator()(const transition& left, const transition& right) const
{
return left.dst == right.dst
&& left.acc == right.acc;
}
};
typedef std::unordered_map<transition, unsigned, transition_hash,
transition_equal> tmap_t;
typedef std::set<unsigned> tset_t;
}
tgba_digraph_ptr
closure(const const_tgba_digraph_ptr& a)
{
tgba_digraph_ptr res = tgba_dupexp_dfs(a);
unsigned n = res->num_states();
tset_t todo;
for (unsigned state = 0; state < n; ++state)
{
tmap_t uniq;
auto trans = res->out(state);
for (auto it = trans.begin(); it != trans.end(); ++it)
{
todo.insert(it.trans());
uniq.emplace(transition(it->dst, it->acc), it.trans());
}
while (!todo.empty())
{
unsigned t1 = *todo.begin();
todo.erase(t1);
tgba_graph_trans_data td = res->trans_data(t1);
unsigned dst = res->trans_storage(t1).dst;
for (auto& t2 : res->out(dst))
{
bdd cond = td.cond & t2.cond;
if (cond != bddfalse)
{
acc_cond::mark_t acc = td.acc | t2.acc;
transition jump(t2.dst, acc);
unsigned i;
auto u = uniq.find(jump);
if (u == uniq.end())
{
i = res->new_transition(state, t2.dst, cond, acc);
uniq.emplace(jump, i);
todo.insert(i);
}
else
{
bdd old_cond = res->trans_data(u->second).cond;
if (!bdd_implies(cond, old_cond))
{
res->trans_data(u->second).cond = cond | old_cond;
todo.insert(u->second);
}
}
}
}
}
uniq.clear();
}
return res;
}
}

31
src/tgbaalgos/closure.hh Normal file
View file

@ -0,0 +1,31 @@
// Copyright (C) 2014 Laboratoire de Recherche et Développement
// de l'Epita.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef SPOT_TGBAALGOS_CLOSURE_HH
# define SPOT_TGBAALGOS_CLOSURE_HH
#include "tgba/tgbagraph.hh"
namespace spot
{
SPOT_API tgba_digraph_ptr
closure(const const_tgba_digraph_ptr&);
}
#endif

View file

@ -0,0 +1,126 @@
// Copyright (C) 2014 Laboratoire de Recherche et Développement
// de l'Epita.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <iostream>
#include "tgba/tgbagraph.hh"
#include "closure.hh"
#include "stutterize.hh"
#include "ltlvisit/remove_x.hh"
#include "tgbaalgos/translate.hh"
#include "ltlast/allnodes.hh"
#include "ltlvisit/apcollect.hh"
#include "stutter_invariance.hh"
#include "tgba/tgbasl.hh"
#include "tgba/tgbaproduct.hh"
#include "tgbaalgos/dupexp.hh"
namespace spot
{
bool
is_stutter_invariant(const ltl::formula* f)
{
const char* stutter_check = getenv("SPOT_STUTTER_CHECK");
char algo = stutter_check ? stutter_check[0] : '1';
if (f->is_ltl_formula() && f->is_X_free())
return true;
if (algo == '0')
{
// Syntactic checking.
if (f->is_ltl_formula())
{
const ltl::formula* g = remove_x(f);
ltl::ltl_simplifier ls;
bool res = ls.are_equivalent(f, g);
g->destroy();
return res;
}
else
{
throw std::runtime_error("Cannot use the syntactic-based " \
"approach to stutter-invariance " \
"checking on non-ltl formula");
}
}
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);
bdd aps = atomic_prop_collect_as_bdd(f, aut_f);
nf->destroy();
return is_stutter_invariant(aut_f, aut_nf, aps);
}
bool
is_stutter_invariant(const const_tgba_digraph_ptr& aut_f,
const const_tgba_digraph_ptr& aut_nf, bdd aps)
{
const char* stutter_check = getenv("SPOT_STUTTER_CHECK");
char algo = stutter_check ? stutter_check[0] : '8';
switch (algo)
{
// sl(aut_f) x sl(aut_nf)
case '1':
{
return product(sl(aut_f, aps), sl(aut_nf, aps))->is_empty();
}
// sl(cl(aut_f)) x aut_nf
case '2':
{
return product(sl(closure(aut_f), aps), aut_nf)->is_empty();
}
// (cl(sl(aut_f)) x aut_nf
case '3':
{
return product(closure(sl(aut_f, aps)), aut_nf)->is_empty();
}
// sl2(aut_f) x sl2(aut_nf)
case '4':
{
return product(sl2(aut_f, aps), sl2(aut_nf, aps))->is_empty();
}
// sl2(cl(aut_f)) x aut_nf
case '5':
{
return product(sl2(closure(aut_f), aps), aut_nf)->is_empty();
}
// (cl(sl2(aut_f)) x aut_nf
case '6':
{
return product(closure(sl2(aut_f, aps)), aut_nf)->is_empty();
}
// on-the-fly sl(aut_f) x sl(aut_nf)
case '7':
{
auto slf = std::make_shared<tgbasl>(aut_f, aps);
auto slnf = std::make_shared<tgbasl>(aut_nf, aps);
return product(slf, slnf)->is_empty();
}
// cl(aut_f) x cl(aut_nf)
case '8':
{
return product(closure(aut_f), closure(aut_nf))->is_empty();
}
default:
throw std::runtime_error("invalid value for SPOT_STUTTER_CHECK.");
break;
}
}
}

View file

@ -0,0 +1,36 @@
// Copyright (C) 2014 Laboratoire de Recherche et Développement
// de l'Epita.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef SPOT_TGBAALGOS_STUTTER_INVARIANCE_HH
# define SPOT_TGBAALGOS_STUTTER_INVARIANCE_HH
#include "tgba/tgbagraph.hh"
namespace spot
{
// TODO doc
SPOT_API bool
is_stutter_invariant(const ltl::formula* f);
SPOT_API bool
is_stutter_invariant(const const_tgba_digraph_ptr& aut_f,
const const_tgba_digraph_ptr& aut_nf, bdd aps);
}
#endif

170
src/tgbaalgos/stutterize.cc Normal file
View file

@ -0,0 +1,170 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2014 Laboratoire de Recherche
// et Développement de l'Epita (LRDE).
// Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// 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/>.
#include "stutterize.hh"
#include "tgba/tgba.hh"
#include "dupexp.hh"
#include "misc/hash.hh"
#include "misc/hashfunc.hh"
#include "ltlvisit/apcollect.hh"
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <vector>
namespace spot
{
namespace
{
typedef std::pair<unsigned, bdd> stutter_state;
struct stutter_state_hash
{
size_t
operator()(const stutter_state& s) const
{
return wang32_hash(s.first) ^ wang32_hash(s.second.id());
}
};
// Associate the stutter state to its number.
typedef std::unordered_map<stutter_state, unsigned,
stutter_state_hash> ss2num_map;
// Queue of state to be processed.
typedef std::deque<stutter_state> queue_t;
}
tgba_digraph_ptr
sl(const const_tgba_digraph_ptr& a, const ltl::formula* f)
{
bdd aps = atomic_prop_collect_as_bdd(f, a);
return sl(a, aps);
}
tgba_digraph_ptr
sl2(const const_tgba_digraph_ptr& a, const ltl::formula* f)
{
bdd aps = atomic_prop_collect_as_bdd(f, a);
return sl2(a, aps);
}
tgba_digraph_ptr
sl(const const_tgba_digraph_ptr& a, bdd atomic_propositions)
{
// The result automaton uses numbered states.
tgba_digraph_ptr res = make_tgba_digraph(a->get_dict());
// We use the same BDD variables as the input.
res->copy_ap_of(a);
res->copy_acceptance_conditions_of(a);
// These maps make it possible to convert stutter_state to number
// and vice-versa.
ss2num_map ss2num;
queue_t todo;
unsigned s0 = a->get_init_state_number();
stutter_state s(s0, bddfalse);
ss2num[s] = 0;
res->new_state();
todo.push_back(s);
while (!todo.empty())
{
s = todo.front();
todo.pop_front();
unsigned src = ss2num[s];
bool self_loop_needed = true;
for (auto& t : a->out(s.first))
{
bdd all = t.cond;
while (all != bddfalse)
{
bdd one = bdd_satoneset(all, atomic_propositions, bddtrue);
all -= one;
stutter_state d(t.dst, one);
auto r = ss2num.emplace(d, ss2num.size());
unsigned dest = r.first->second;
if (r.second)
{
todo.push_back(d);
unsigned u = res->new_state();
assert(u == dest);
(void)u;
}
// Create the transition.
res->new_transition(src, dest, one, t.acc);
if (src == dest)
self_loop_needed = false;
}
}
if (self_loop_needed && s.second != bddfalse)
res->new_transition(src, src, s.second, 0U);
}
res->merge_transitions();
return res;
}
tgba_digraph_ptr
sl2(const const_tgba_digraph_ptr& a, bdd atomic_propositions)
{
tgba_digraph_ptr res = tgba_dupexp_dfs(a);
unsigned num_states = res->num_states();
for (unsigned state = 0; state < num_states; ++state)
{
std::vector<unsigned> out;
auto trans = res->out(state);
for (auto it = trans.begin(); it != trans.end(); ++it)
out.push_back(it.trans());
for (auto it: out)
{
if (res->trans_storage(it).dst != state)
{
bdd all = res->trans_storage(it).cond;
while (all != bddfalse)
{
unsigned dst = res->trans_storage(it).dst;
bdd one = bdd_satoneset(all, atomic_propositions, bddtrue);
unsigned tmp = res->new_state();
res->new_transition(state, tmp, one,
res->trans_storage(it).acc);
res->new_transition(tmp, tmp, one, 0U);
res->new_transition(tmp, dst, one,
res->trans_storage(it).acc);
all -= one;
}
}
}
}
res->merge_transitions();
return res;
}
}

View file

@ -0,0 +1,43 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2014 Laboratoire de Recherche
// et Développement de l'Epita (LRDE).
// Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef SPOT_TGBAALGOS_STUTTERIZE_HH
# define SPOT_TGBAALGOS_STUTTERIZE_HH
#include "tgba/tgbagraph.hh"
namespace spot
{
SPOT_API tgba_digraph_ptr
sl(const const_tgba_digraph_ptr&, const ltl::formula*);
SPOT_API tgba_digraph_ptr
sl(const const_tgba_digraph_ptr&, bdd);
SPOT_API tgba_digraph_ptr
sl2(const const_tgba_digraph_ptr&, const ltl::formula*);
SPOT_API tgba_digraph_ptr
sl2(const const_tgba_digraph_ptr&, bdd);
}
#endif