twaalgos: introduce match_states(a,b)
This is a useful part for issue #591. * spot/twaalgos/matchstates.cc, spot/twaalgos/matchstates.hh: New files. * spot/twaalgos/Makefile.am: Add them. * python/spot/impl.i: Add python bindings. * tests/python/matchstates.py: New file. * tests/Makefile.am: Add it. * NEWS: Mention this new function.
This commit is contained in:
parent
b549e8e8c1
commit
5f1d00b858
7 changed files with 164 additions and 0 deletions
|
|
@ -64,6 +64,7 @@ twaalgos_HEADERS = \
|
|||
ltl2tgba_fm.hh \
|
||||
magic.hh \
|
||||
mask.hh \
|
||||
matchstates.hh \
|
||||
minimize.hh \
|
||||
mealy_machine.hh \
|
||||
couvreurnew.hh \
|
||||
|
|
@ -139,6 +140,7 @@ libtwaalgos_la_SOURCES = \
|
|||
ltl2tgba_fm.cc \
|
||||
magic.cc \
|
||||
mask.cc \
|
||||
matchstates.cc \
|
||||
minimize.cc \
|
||||
mealy_machine.cc \
|
||||
couvreurnew.cc \
|
||||
|
|
|
|||
50
spot/twaalgos/matchstates.cc
Normal file
50
spot/twaalgos/matchstates.cc
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) by the Spot authors, see the AUTHORS file for details.
|
||||
//
|
||||
// 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/matchstates.hh>
|
||||
#include <spot/twaalgos/sccinfo.hh>
|
||||
#include <spot/twaalgos/product.hh>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
std::vector<std::vector<unsigned>>
|
||||
match_states(const const_twa_graph_ptr& aut1,
|
||||
const const_twa_graph_ptr& aut2)
|
||||
{
|
||||
twa_graph_ptr prod = product(aut1, aut2);
|
||||
product_states* ps = prod->get_named_prop<product_states>("product-states");
|
||||
if (!ps)
|
||||
return {};
|
||||
scc_info si(prod, scc_info_options::TRACK_SUCCS);
|
||||
|
||||
std::vector<std::vector<unsigned>> v(aut1->num_states());
|
||||
unsigned sz = ps->size();
|
||||
assert(sz == prod->num_states());
|
||||
for (unsigned sp = 0; sp < sz; ++sp)
|
||||
if (si.is_useful_state(sp))
|
||||
{
|
||||
auto [sl, sr] = (*ps)[sp];
|
||||
v[sl].push_back(sr);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
40
spot/twaalgos/matchstates.hh
Normal file
40
spot/twaalgos/matchstates.hh
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) by the Spot authors, see the AUTHORS file for details.
|
||||
//
|
||||
// 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/misc/common.hh>
|
||||
#include <spot/twa/fwd.hh>
|
||||
#include <vector>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
/// \ingroup twa_algorithms
|
||||
/// \brief match the state of \a aut1 with the states of \a aut2.
|
||||
///
|
||||
/// Return a vector `V` such that for each state `x` of
|
||||
/// \a aut1, `V[x]` contains the set of states `y` such that
|
||||
/// `(x,y)` is a useful state of `product(aut1,aut2)`.
|
||||
///
|
||||
/// In particular, if the language of \a aut2 includes the language
|
||||
/// of \a aut1, then any word accepted from state `x` in \a aut1
|
||||
/// is also accepted from one of the states in `V[x]`.
|
||||
SPOT_API std::vector<std::vector<unsigned>>
|
||||
match_states(const const_twa_graph_ptr& aut1,
|
||||
const const_twa_graph_ptr& aut2);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue