Implement is_safety_automaton().

* src/tgbaalgos/safety.hh, src/tgbaalgos/safety.cc: New
files.
* src/tgbaalgos/Makefile.am: Add them.
* src/tgbatests/ltl2tgba.cc: Add option "-O".
* src/tgbaalgos/scc.hh: Update documentation.
* src/tgbatest/Makefile.am (TESTS): Add safety.test.
* src/tgbatest/safety.test: New file.
This commit is contained in:
Alexandre Duret-Lutz 2010-03-20 12:57:36 +01:00
parent 99c1b607de
commit 0af8d03261
8 changed files with 264 additions and 6 deletions

View file

@ -1,7 +1,8 @@
## Copyright (C) 2003, 2004, 2005, 2008, 2009 Laboratoire
## d'Informatique de Paris 6 (LIP6),
## département Systèmes Répartis Coopératifs (SRC), Université Pierre
## et Marie Curie.
## Copyright (C) 2008, 2009, 2010 Laboratoire de Recherche et
## Développement de l'Epita (LRDE).
## Copyright (C) 2003, 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.
##
@ -51,6 +52,7 @@ tgbaalgos_HEADERS = \
reducerun.hh \
replayrun.hh \
rundotdec.hh \
safety.hh \
save.hh \
scc.hh \
sccfilter.hh \
@ -86,6 +88,7 @@ libtgbaalgos_la_SOURCES = \
reducerun.cc \
replayrun.cc \
rundotdec.cc \
safety.cc \
save.cc \
scc.cc \
sccfilter.cc \

75
src/tgbaalgos/safety.cc Normal file
View file

@ -0,0 +1,75 @@
// Copyright (C) 2010 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 2 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 Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include "safety.hh"
namespace spot
{
bool
is_safety_automaton(const tgba* aut, const scc_map* sm)
{
// Create an scc_map of the user did not give one to us.
bool need_sm = !sm;
if (need_sm)
{
scc_map* x = new scc_map(aut);
x->build_map();
sm = x;
}
bool result = true;
unsigned scc_count = sm->scc_count();
for (unsigned scc = 0; (scc < scc_count) && result; ++scc)
{
if (!sm->accepting(scc))
continue;
// Accepting SCCs should have only one state.
const std::list<const state*>& st = sm->states_of(scc);
if (st.size() != 1)
{
result = false;
break;
}
// The state should have only one transition that is a
// self-loop labelled by true.
const state* s = *st.begin();
tgba_succ_iterator* it = aut->succ_iter(s);
it->first();
assert(!it->done());
state* dest = it->current_state();
bdd cond = it->current_condition();
it->next();
result = (!dest->compare(s)) && it->done() && (cond == bddtrue);
delete dest;
delete it;
}
// Free the scc_map if we created it.
if (need_sm)
delete sm;
return result;
}
}

44
src/tgbaalgos/safety.hh Normal file
View file

@ -0,0 +1,44 @@
// Copyright (C) 2010 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 2 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 Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#ifndef SPOT_TGBAALGOS_SAFETY_HH
# define SPOT_TGBAALGOS_SAFETY_HH
#include "scc.hh"
namespace spot
{
/// \brief Whether an automaton is a safety property.
///
/// An automaton is an safety if any accepting path ends on an
/// accepting state with only one transition that is a self-loop
/// labelled by true. Note that this is only a sufficient
/// condition. Some safety automata might not be recognized with
/// this check because of some non-determinism in the automaton.
///
/// \param aut the automaton to check
///
/// \param sm an scc_map of the automaton if available (it will be
/// built otherwise. If you supply an scc_map you should call
/// build_map() before passing it to this function.
bool is_safety_automaton(const tgba* aut, const scc_map* sm = 0);
}
#endif // SPOT_TGBAALGOS_SAFETY_HH

View file

@ -1,5 +1,5 @@
// Copyright (C) 2008, 2009 Laboratoire de Recherche et Developpement de
// l'Epita.
// Copyright (C) 2008, 2009, 2010 Laboratoire de Recherche et
// Developpement de l'Epita.
//
// This file is part of Spot, a model checking library.
//
@ -90,6 +90,8 @@ namespace spot
/// \brief Get the number of SCC in the automaton.
///
/// SCCs are labelled from 0 to scc_count()-1.
///
/// \pre This should only be called once build_map() has run.
unsigned scc_count() const;