introduce containement checks functions

* spot/twaalgos/contains.hh, spot/twaalgos/contains.cc: New files.
* spot/twaalgos/Makefile.am, python/spot/impl.i: Add them.
* python/spot/__init__.py: Also attach these functions as methods,
and support string arguments.
* tests/python/contains.ipynb: New file.
* tests/Makefile.am, doc/org/tut.org: Add it.
* bin/autfilt.cc, tests/python/streett_totgba.py, tests/python/sum.py,
tests/python/toweak.py: Use the new function.
This commit is contained in:
Alexandre Duret-Lutz 2018-05-04 17:00:38 +02:00
parent 58d9a12495
commit d6f9618172
13 changed files with 547 additions and 60 deletions

View file

@ -39,6 +39,7 @@ twaalgos_HEADERS = \
complete.hh \
complement.hh \
compsusp.hh \
contains.hh \
copy.hh \
cycles.hh \
degen.hh \
@ -107,6 +108,7 @@ libtwaalgos_la_SOURCES = \
complete.cc \
complement.cc \
compsusp.cc \
contains.cc \
cycles.cc \
degen.cc \
determinize.cc \

101
spot/twaalgos/contains.cc Normal file
View file

@ -0,0 +1,101 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2018 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 "config.h"
#include <spot/twaalgos/contains.hh>
#include <spot/twaalgos/postproc.hh>
#include <spot/twaalgos/ltl2tgba_fm.hh>
#include <spot/twaalgos/isdet.hh>
#include <spot/twaalgos/dualize.hh>
namespace spot
{
namespace
{
static spot::const_twa_graph_ptr
ensure_deterministic(const spot::const_twa_graph_ptr& aut)
{
if (spot::is_deterministic(aut))
return aut;
spot::postprocessor p;
p.set_type(spot::postprocessor::Generic);
p.set_pref(spot::postprocessor::Deterministic);
p.set_level(spot::postprocessor::Low);
return p.run(std::const_pointer_cast<twa_graph>(aut));
}
static spot::const_twa_graph_ptr
translate(formula f, const bdd_dict_ptr& dict)
{
return ltl_to_tgba_fm(f, dict);
}
}
bool contains(const_twa_graph_ptr left, const_twa_graph_ptr right)
{
return !left->intersects(dualize(ensure_deterministic(right)));
}
bool contains(const_twa_graph_ptr left, formula right)
{
return !left->intersects(translate(formula::Not(right), left->get_dict()));
}
bool contains(formula left, const_twa_graph_ptr right)
{
auto left_aut = translate(left, right->get_dict());
return !left_aut->intersects(dualize(ensure_deterministic(right)));
}
bool contains(formula left, formula right)
{
auto dict = make_bdd_dict();
auto left_aut = translate(left, dict);
return !left_aut->intersects(translate(formula::Not(right), dict));
}
bool are_equivalent(const_twa_graph_ptr left, const_twa_graph_ptr right)
{
// Start with a deterministic automaton at right if possible to
// avoid a determinization (in case the first containment check
// fails).
if (!is_deterministic(right))
std::swap(left, right);
return contains(left, right) && contains(right, left);
}
bool are_equivalent(const_twa_graph_ptr left, formula right)
{
// The first containement check does not involve a
// complementation, the second might.
return contains(left, right) && contains(right, left);
}
bool are_equivalent(formula left, const_twa_graph_ptr right)
{
// The first containement check does not involve a
// complementation, the second might.
return contains(right, left) && contains(left, right);
}
bool are_equivalent(formula left, formula right)
{
return contains(right, left) && contains(left, right);
}
}

60
spot/twaalgos/contains.hh Normal file
View file

@ -0,0 +1,60 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2018 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/>.
#pragma once
#include <spot/twa/twagraph.hh>
#include <spot/tl/formula.hh>
/// \defgroup containment Language containment checks
/// \ingroup twa_algorithms
namespace spot
{
/// \ingroup containment
/// \brief Test if the language of \a left is included in that of \a right.
///
/// Both arguments can be either formulas or automata. Formulas
/// will be converted into automata.
///
/// The inclusion check if performed by ensuring that the automaton
/// associated to \a left does not intersect the automaton
/// associated to the complement of \a right. It helps if \a right
/// is a deterministic automaton or a formula (because in both cases
/// complementation is easier).
/// @{
SPOT_API bool contains(const_twa_graph_ptr left, const_twa_graph_ptr right);
SPOT_API bool contains(const_twa_graph_ptr left, formula right);
SPOT_API bool contains(formula left, const_twa_graph_ptr right);
SPOT_API bool contains(formula left, formula right);
/// @}
/// \ingroup containment
/// \brief Test if the language of \a left is equivalent to that of \a right.
///
/// Both arguments can be either formulas or automata. Formulas
/// will be converted into automata.
/// @{
SPOT_API bool are_equivalent(const_twa_graph_ptr left,
const_twa_graph_ptr right);
SPOT_API bool are_equivalent(const_twa_graph_ptr left, formula right);
SPOT_API bool are_equivalent(formula left, const_twa_graph_ptr right);
SPOT_API bool are_equivalent(formula left, formula right);
/// @}
}