tl: mp_class() and --format=%[vw]h

Tools for deciding the class of a formula.

* spot/tl/hierarchy.cc, spot/tl/hierarchy.hh: New files.
* spot/tl/Makefile.am: Add them.
* bin/common_output.cc, bin/common_output.hh: Implement --format=%h.
* tests/core/hierarchy.test: More tests.
* NEWS: Update.
This commit is contained in:
Alexandre Duret-Lutz 2017-01-10 21:34:56 +01:00
parent de8a248fb2
commit 7d9ce0d6fc
7 changed files with 276 additions and 11 deletions

View file

@ -1,6 +1,6 @@
## -*- coding: utf-8 -*-
## Copyright (C) 2015, 2016 Laboratoire de Recherche et Développement de
## l'Epita (LRDE).
## Copyright (C) 2015, 2016, 2017 Laboratoire de Recherche et
## Développement de l'Epita (LRDE).
##
## This file is part of Spot, a model checking library.
##
@ -31,6 +31,7 @@ tl_HEADERS = \
environment.hh \
exclusive.hh \
formula.hh \
hierarchy.hh \
length.hh \
ltlf.hh \
mutation.hh \
@ -53,6 +54,7 @@ libtl_la_SOURCES = \
dot.cc \
exclusive.cc \
formula.cc \
hierarchy.cc \
length.cc \
ltlf.cc \
mark.cc \

85
spot/tl/hierarchy.cc Normal file
View file

@ -0,0 +1,85 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2017 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 <spot/tl/hierarchy.hh>
#include <spot/twaalgos/isdet.hh>
#include <spot/twaalgos/ltl2tgba_fm.hh>
#include <spot/twaalgos/minimize.hh>
#include <spot/twaalgos/postproc.hh>
#include <spot/twaalgos/remfin.hh>
#include <spot/twaalgos/strength.hh>
#include <spot/twaalgos/totgba.hh>
namespace spot
{
namespace
{
static bool is_recurrence(formula f, const twa_graph_ptr& aut)
{
if (f.is_syntactic_recurrence() || is_deterministic(aut))
return true;
// If aut is a non-deterministic TGBA, we do
// TGBA->DPA->DRA->(D?)BA. The conversion from DRA to
// BA will preserve determinism if possible.
spot::postprocessor p;
p.set_type(spot::postprocessor::Generic);
p.set_pref(spot::postprocessor::Deterministic
| spot::postprocessor::SBAcc);
p.set_level(spot::postprocessor::Low);
auto dra = p.run(aut);
if (dra->acc().is_generalized_buchi())
{
return true;
}
else
{
auto ba = rabin_to_buchi_maybe(to_generalized_rabin(dra));
assert(ba);
return is_deterministic(ba);
}
}
}
char mp_class(formula f)
{
if (f.is_syntactic_safety() && f.is_syntactic_guarantee())
return 'B';
auto dict = make_bdd_dict();
auto aut = ltl_to_tgba_fm(f, dict, true);
auto min = minimize_obligation(aut, f);
if (aut != min) // An obligation.
{
bool g = is_terminal_automaton(min);
bool s = is_safety_mwdba(min);
if (g)
return s ? 'B' : 'G';
else
return s ? 'S' : 'O';
}
// Not an obligation. Could by 'P', 'R', or 'T'.
if (is_recurrence(f, aut))
return 'R';
f = formula::Not(f);
aut = ltl_to_tgba_fm(f, dict, true);
if (is_recurrence(f, aut))
return 'P';
return 'T';
}
}

40
spot/tl/hierarchy.hh Normal file
View file

@ -0,0 +1,40 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2017 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/>.
#pragma once
#include <spot/tl/formula.hh>
namespace spot
{
/// \brief Return the class of \a f in the temporal hierarchy of Manna
/// and Pnueli (PODC'90).
///
/// The class is indicated using a character among:
/// - 'B' (bottom) safety properties that are also guarantee properties
/// - 'G' guarantee properties that are not also safety properties
/// - 'S' safety properties that are not also guarantee properties
/// - 'O' obligation properties that are not safety or guarantee
/// properties
/// - 'P' persistence properties that are not obligations
/// - 'R' recurrence properties that are not obligations
/// - 'T' (top) properties that are not persistence or recurrence
/// properties
SPOT_API char mp_class(formula f);
}