Commit 37bcb5d9 authored by Thibaud Michaud's avatar Thibaud Michaud Committed by Alexandre Duret-Lutz

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.
parent beafcf4e
......@@ -174,6 +174,7 @@ bench/ Benchmarks for ...
ltlclasses/ ... translation of more classes of LTL formulae,
spin13/ ... compositional suspension and other improvements,
wdba/ ... WDBA minimization (for obligation properties).
stutter/ ... stutter-invariance checking algorithms
wrap/ Wrappers for other languages.
python/ Python bindings for Spot and BuDDy
tests/ Tests for these bindings
......
......@@ -19,4 +19,4 @@
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
SUBDIRS = emptchk ltl2tgba ltlcounter ltlclasses wdba spin13 dtgbasat
SUBDIRS = emptchk ltl2tgba ltlcounter ltlclasses wdba spin13 dtgbasat stutter
## -*- coding: utf-8 -*-
## Copyright (C) 2014 Laboratoire de Recherche et Développement
## de l'Epita (LRDE).
##
## This file is part of Spot, a model checking library.
##
## Spot is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## Spot is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
## License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
SUBDIRS = .
AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src $(BUDDY_CPPFLAGS) \
-I$(top_builddir)/lib -I$(top_srcdir)/lib
AM_CXXFLAGS = $(WARNING_CXXFLAGS)
LDADD = $(top_builddir)/src/bin/libcommon.a ../../lib/libgnu.la ../../src/libspot.la
bin_PROGRAMS = stutter_invariance_randomgraph \
stutter_invariance_formulas
stutter_invariance_randomgraph_SOURCES = stutter_invariance_randomgraph.cc
stutter_invariance_formulas_SOURCES = stutter_invariance_formulas.cc
// -*- coding: utf-8 -*-
// Copyright (C) 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "bin/common_sys.hh"
#include "bin/common_setup.hh"
#include "bin/common_finput.hh"
#include "bin/common_output.hh"
#include "tgbaalgos/translate.hh"
#include "tgbaalgos/stutter_invariance.hh"
#include "ltlast/allnodes.hh"
#include "ltlvisit/apcollect.hh"
#include "ltlvisit/length.hh"
#include "misc/timer.hh"
#include <argp.h>
#include "error.h"
#include "tgbaalgos/closure.hh"
#include "tgbaalgos/stutterize.hh"
#include "tgbaalgos/dotty.hh"
#include "tgba/tgbaproduct.hh"
static unsigned n = 10;
const char argp_program_doc[] ="";
const struct argp_child children[] =
{
{ &finput_argp, 0, 0, 1 },
{ &output_argp, 0, 0, -20 },
{ &misc_argp, 0, 0, -1 },
{ 0, 0, 0, 0 }
};
namespace
{
class stut_processor: public job_processor
{
public:
spot::translator& trans;
std::string formula;
stut_processor(spot::translator& trans) : trans(trans)
{
}
int
process_string(const std::string& input,
const char* filename, int linenum)
{
formula = input;
return job_processor::process_string(input, filename, linenum);
}
int
process_formula(const spot::ltl::formula* f,
const char*, int)
{
const spot::ltl::formula* nf =
spot::ltl::unop::instance(spot::ltl::unop::Not,
f->clone());
spot::const_tgba_digraph_ptr a = trans.run(f);
spot::const_tgba_digraph_ptr na = trans.run(nf);
spot::ltl::atomic_prop_set* ap = spot::ltl::atomic_prop_collect(f);
bdd apdict = spot::ltl::atomic_prop_collect_as_bdd(f, a);
bool res;
bool prev = true;
for (char algo = '1'; algo <= '8'; ++algo)
{
// set SPOT_STUTTER_CHECK environment variable
char algostr[2] = { 0 };
algostr[0] = algo;
setenv("SPOT_STUTTER_CHECK", algostr, true);
spot::stopwatch sw;
sw.start();
for (unsigned i = 0; i < n; ++i)
res = spot::is_stutter_invariant(a, na, apdict);
const double time = sw.stop();
std::cout << formula << ", " << algo << ", " << ap->size() << ", "
<< a->num_states() << ", " << res << ", " << time << std::endl;
if (algo > '1')
assert(res == prev);
prev = res;
}
f->destroy();
nf->destroy();
delete(ap);
return 0;
}
};
}
int
main(int argc, char** argv)
{
setup(argv);
const argp ap = { 0, 0, "[FILENAME[/COL]...]",
argp_program_doc, children, 0, 0 };
if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, 0, 0))
exit(err);
spot::translator trans;
stut_processor processor(trans);
if (processor.run())
return 2;
return 0;
}
// -*- coding: utf-8 -*-
// Copyright (C) 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "misc/timer.hh"
#include "ltlast/atomic_prop.hh"
#include "tgbaalgos/dtgbacomp.hh"
#include "tgbaalgos/stutter_invariance.hh"
#include "tgbaalgos/randomgraph.hh"
#include "tgbaalgos/dotty.hh"
#include "tgbaalgos/product.hh"
#include "tgbaalgos/stutterize.hh"
#include "tgbaalgos/closure.hh"
#include "tgba/tgbagraph.hh"
#include "tgba/bdddict.hh"
#include <cstdio>
#include <cstring>
#include <vector>
int
main()
{
spot::bdd_dict_ptr dict = spot::make_bdd_dict();
spot::tgba_digraph_ptr a;
spot::tgba_digraph_ptr na;
unsigned n = 10;
for (unsigned states_n = 1; states_n <= 50; ++states_n)
for (float d = 0; d <= 1; d += 0.1)
{
for (unsigned props_n = 1; props_n <= 4; ++props_n)
{
// random ap set
auto ap = new spot::ltl::atomic_prop_set();
spot::ltl::default_environment& e =
spot::ltl::default_environment::instance();
for (unsigned i = 1; i < props_n; ++i)
{
std::ostringstream p;
p << 'p' << i;
ap->insert(static_cast<const spot::ltl::atomic_prop*>
(e.require(p.str())));
}
// ap set as bdd
bdd apdict = bddtrue;
for (auto& i: *ap)
apdict &= bdd_ithvar(dict->register_proposition(i, a));
// generate n random automata
typedef std::pair<spot::tgba_digraph_ptr, spot::tgba_digraph_ptr>
aut_pair_t;
std::vector<aut_pair_t> vec;
for (unsigned i = 0; i < n; ++i)
{
a = spot::random_graph(states_n, d, ap, dict, 2, 0.1, 0.5,
true);
na = spot::dtgba_complement(a);
vec.push_back(aut_pair_t(a, na));
}
for (char algo = '1'; algo <= '8'; ++algo)
{
// set SPOT_STUTTER_CHECK environment variable
char algostr[2] = { 0 };
algostr[0] = algo;
setenv("SPOT_STUTTER_CHECK", algostr, true);
spot::stopwatch sw;
sw.start();
bool res;
for (auto& a: vec)
res = spot::is_stutter_invariant(a.first, a.second, apdict);
const double time = sw.stop();
std::cout << algo << ", " << props_n << ", " << states_n
<< ", " << res << ", " << time << std::endl;
}
spot::ltl::destroy_atomic_prop_set(*ap);
delete(ap);
}
}
return 0;
}
......@@ -164,6 +164,7 @@ AC_CONFIG_FILES([
bench/ltl2tgba/defs
bench/spin13/Makefile
bench/wdba/Makefile
bench/stutter/Makefile
doc/Doxyfile
doc/Makefile
doc/tl/Makefile
......
......@@ -45,6 +45,7 @@
#include "tgbaalgos/ltl2tgba_fm.hh"
#include "tgbaalgos/minimize.hh"
#include "tgbaalgos/safety.hh"
#include "tgbaalgos/stutter_invariance.hh"
const char argp_program_doc[] ="\
Read a list of formulas and output them back after some optional processing.\v\
......@@ -550,8 +551,7 @@ namespace
matched &= !implied_by || simpl.implication(implied_by, f);
matched &= !imply || simpl.implication(f, imply);
matched &= !equivalent_to || simpl.are_equivalent(f, equivalent_to);
matched &= !stutter_insensitive || (f->is_ltl_formula()
&& is_stutter_insensitive(f));
matched &= !stutter_insensitive || spot::is_stutter_invariant(f);
// Match obligations and subclasses using WDBA minimization.
// Because this is costly, we compute it later, so that we don't
......@@ -609,8 +609,6 @@ main(int argc, char** argv)
if (jobs.empty())
jobs.emplace_back("-", 1);
// --stutter-insensitive implies --ltl
ltl |= stutter_insensitive;
if (boolean_to_isop && simplification_level == 0)
simplification_level = 1;
spot::ltl::ltl_simplifier_options opt = simplifier_options();
......
// Copyright (C) 2013 Laboratoire de Recherche et Developpement de
// Copyright (C) 2013, 2014 Laboratoire de Recherche et Developpement de
// l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -117,18 +117,5 @@ namespace spot
remove_x_visitor v(f);
return v.recurse(f);
}
bool is_stutter_insensitive(const formula* f)
{
assert(f->is_ltl_formula());
if (f->is_X_free())
return true;
const formula* g = remove_x(f);
ltl_simplifier ls;
bool res = ls.are_equivalent(f, g);
g->destroy();
return res;
}
}
}
......@@ -48,27 +48,6 @@ namespace spot
\endverbatim */
SPOT_API
const formula* remove_x(const formula* f);
/// \brief Whether an LTL formula \a f is stutter-insensitive.
///
/// This is simply achieved by checking whether the output of
/// <code>remove_x(f)</code> is equivalent to \a f. This only
/// works for LTL formulas, not PSL formulas.
///
/** \verbatim
@Article{ etessami.00.ipl,
author = {Kousha Etessami},
title = {A note on a question of {P}eled and {W}ilke regarding
stutter-invariant {LTL}},
journal = {Information Processing Letters},
volume = {75},
number = {6},
year = {2000},
pages = {261--263}
}
\endverbatim */
SPOT_API
bool is_stutter_insensitive(const formula* f);
}
}
......
......@@ -37,7 +37,8 @@ tgba_HEADERS = \
tgbamask.hh \
tgbaproxy.hh \
tgbaproduct.hh \
tgbasafracomplement.hh
tgbasafracomplement.hh \
tgbasl.hh
noinst_LTLIBRARIES = libtgba.la
libtgba_la_SOURCES = \
......@@ -50,4 +51,5 @@ libtgba_la_SOURCES = \
tgbaproduct.cc \
tgbamask.cc \
tgbaproxy.cc \
tgbasafracomplement.cc
tgbasafracomplement.cc \
tgbasl.cc
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2011, 2012, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "tgbasl.hh"
#include "bddprint.hh"
namespace spot
{
namespace
{
class state_tgbasl: public state
{
public:
state_tgbasl(state* s, bdd cond) : s_(s), cond_(cond)
{
}
virtual
~state_tgbasl()
{
s_->destroy();
}
virtual int
compare(const state* other) const
{
const state_tgbasl* o =
down_cast<const state_tgbasl*>(other);
assert(o);
int res = s_->compare(o->real_state());
if (res != 0)
return res;
return cond_.id() - o->cond_.id();
}
virtual size_t
hash() const
{
return wang32_hash(s_->hash()) ^ wang32_hash(cond_.id());
}
virtual
state_tgbasl* clone() const
{
return new state_tgbasl(*this);
}
state*
real_state() const
{
return s_;
}
bdd
cond() const
{
return cond_;
}
private:
state* s_;
bdd cond_;
};
class tgbasl_succ_iterator : public tgba_succ_iterator
{
public:
tgbasl_succ_iterator(tgba_succ_iterator* it, const state_tgbasl* state,
bdd_dict_ptr d, bdd atomic_propositions)
: it_(it), state_(state), aps_(atomic_propositions), d_(d)
{
}
virtual
~tgbasl_succ_iterator()
{
delete it_;
}
// iteration
bool
first()
{
loop_ = false;
done_ = false;
need_loop_ = true;
if (it_->first())
{
cond_ = it_->current_condition();
next_edge();
}
return true;
}
bool
next()
{
if (cond_ != bddfalse)
{
next_edge();
return true;
}
if (!it_->next())
{
if (loop_ || !need_loop_)
done_ = true;
loop_ = true;
return !done_;
}
else
{
cond_ = it_->current_condition();
next_edge();
return true;
}
}
bool
done() const
{
return it_->done() && done_;
}
// inspection
state_tgbasl*
current_state() const
{
if (loop_)
return new state_tgbasl(state_->real_state(), state_->cond());
return new state_tgbasl(it_->current_state(), one_);
}
bdd
current_condition() const
{
if (loop_)
return state_->cond();
return one_;
}
acc_cond::mark_t
current_acceptance_conditions() const
{
if (loop_)
return 0U;
return it_->current_acceptance_conditions();
}
private:
void
next_edge()
{
one_ = bdd_satoneset(cond_, aps_, bddtrue);
cond_ -= one_;
if (need_loop_ && (state_->cond() == one_)
&& (state_ == it_->current_state()))
need_loop_ = false;
}
tgba_succ_iterator* it_;
const state_tgbasl* state_;
bdd cond_;
bdd one_;
bdd aps_;
bdd_dict_ptr d_;
bool loop_;
bool need_loop_;
bool done_;
};
}
tgbasl::tgbasl(const const_tgba_ptr& a, bdd atomic_propositions)
: tgba(a->get_dict()), a_(a), aps_(atomic_propositions)
{
auto d = get_dict();
d->register_all_propositions_of(&a_, this);
assert(acc_.num_sets() == 0);
acc_.add_sets(a_->acc().num_sets());
}
tgbasl::~tgbasl()
{
get_dict()->unregister_all_my_variables(this);
}
state*
tgbasl::get_init_state() const
{
return new state_tgbasl(a_->get_init_state(), bddfalse);
}
tgba_succ_iterator*
tgbasl::succ_iter(const state* state) const
{
const state_tgbasl* s = down_cast<const state_tgbasl*>(state);
assert(s);
return new tgbasl_succ_iterator(a_->succ_iter(s->real_state()), s,
a_->get_dict(), aps_);
}
bdd
tgbasl::compute_support_conditions(const state*) const
{
return bddtrue;
}
std::string
tgbasl::format_state(const state* state) const
{
const state_tgbasl* s = down_cast<const state_tgbasl*>(state);
assert(s);
return (a_->format_state(s->real_state())
+ ", "
+ bdd_format_formula(a_->get_dict(), s->cond()));