sbacc: define original-states

* spot/twaalgos/sbacc.cc (sbacc): Define the original-states
property on the created automaton.
* spot/twaalgos/sbacc.hh: Improve documentation.
* tests/python/sbacc.py: Update test cases.
This commit is contained in:
Alexandre Duret-Lutz 2021-11-18 13:56:28 +01:00
parent afdd38277d
commit 58b349d3ca
3 changed files with 48 additions and 8 deletions

View file

@ -64,6 +64,10 @@ namespace spot
{ {
common_in[d] &= e.acc; common_in[d] &= e.acc;
common_out[e.src] &= e.acc; common_out[e.src] &= e.acc;
// Any state with an accepting edge labeled by true is a
// "true state". We will merge all true states, and
// ignore other outgoing edges. See issue #276 for an
// example.
if (e.src == e.dst && e.cond == bddtrue if (e.src == e.dst && e.cond == bddtrue
&& old->acc().accepting(e.acc)) && old->acc().accepting(e.acc))
{ {
@ -89,6 +93,9 @@ namespace spot
std::map<pair_t, unsigned> s2n; std::map<pair_t, unsigned> s2n;
std::vector<std::pair<pair_t, unsigned>> todo; std::vector<std::pair<pair_t, unsigned>> todo;
auto* origin = new std::vector<unsigned>;
origin->reserve(ns);
res->set_named_prop("original-states", origin);
auto new_state = auto new_state =
[&](unsigned state, acc_cond::mark_t m) -> unsigned [&](unsigned state, acc_cond::mark_t m) -> unsigned
@ -107,6 +114,8 @@ namespace spot
if (p.second) // This is a new state if (p.second) // This is a new state
{ {
unsigned s = res->new_state(); unsigned s = res->new_state();
assert(origin->size() == s);
origin->push_back(state);
p.first->second = s; p.first->second = s;
if (ts) if (ts)
{ {
@ -175,6 +184,12 @@ namespace spot
} }
res->merge_edges(); res->merge_edges();
// Compose original-states with the any previously existing one.
if (auto old_orig_states =
old->get_named_prop<std::vector<unsigned>>("original-states"))
for (auto& s: *origin)
s = (*old_orig_states)[s];
// If the automaton was marked as not complete or not universal, // If the automaton was marked as not complete or not universal,
// and we have ignored some unreachable state, then it is possible // and we have ignored some unreachable state, then it is possible
// that the result becomes complete or universal. // that the result becomes complete or universal.

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2015 Laboratoire de Recherche et Développement // Copyright (C) 2015, 2021 Laboratoire de Recherche et Développement
// de l'Epita. // de l'Epita.
// //
// This file is part of Spot, a model checking library. // This file is part of Spot, a model checking library.
@ -23,8 +23,31 @@
namespace spot namespace spot
{ {
/// \ingroup twa_algorithms
/// \brief Transform an automaton to use state-based acceptance /// \brief Transform an automaton to use state-based acceptance
/// ///
/// This is independent on the acceptance condition used. /// This transformation is independent on the acceptance condition
/// used. The implementation supports alternating automata.
///
/// It works by creating an automaton whose states correspond to
/// pairs (s,colors) for each edge entering state s with colors. In
/// other words, we are pushing colors from the edges to their
/// outgoing states. The implementation is also able to pull colors
/// on incoming states in cases where that helps.
///
/// When called on automata that are already known to have
/// state-based acceptance, this function returns the input
/// unmodified, not a copy.
///
/// Trues states (any state with an accepting self-loop labeled by
/// true) are merged in the process.
///
/// The output will have a named property called "original-states"
/// that is a vector indexed by the produced states, and giving the
/// corresponding state in the input automaton. If the input
/// automaton also had an "original-states" property, the two
/// vectors will be composed, so the `original-states[s]` in the
/// output will contains the value of `original-states[y] if state s
/// was created from state y.
SPOT_API twa_graph_ptr sbacc(twa_graph_ptr aut); SPOT_API twa_graph_ptr sbacc(twa_graph_ptr aut);
} }

View file

@ -1,6 +1,6 @@
# -*- mode: python; coding: utf-8 -*- # -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017, 2018 Laboratoire de Recherche et Développement de l'Epita # Copyright (C) 2017-2018, 2021 Laboratoire de Recherche et
# (LRDE). # Développement de l'Epita (LRDE).
# #
# This file is part of Spot, a model checking library. # This file is part of Spot, a model checking library.
# #
@ -45,6 +45,7 @@ State: 2
--END--""") --END--""")
s = spot.sbacc(aut) s = spot.sbacc(aut)
s.copy_state_names_from(aut)
h = s.to_str('hoa') h = s.to_str('hoa')
assert h == """HOA: v1 assert h == """HOA: v1
@ -54,9 +55,9 @@ AP: 2 "a" "b"
Acceptance: 2 Inf(0) | Inf(1) Acceptance: 2 Inf(0) | Inf(1)
properties: trans-labels explicit-labels state-acc deterministic properties: trans-labels explicit-labels state-acc deterministic
--BODY-- --BODY--
State: 0 State: 0 "0"
[0] 1 [0] 1
State: 1 {1} State: 1 "2" {1}
[t] 1 [t] 1
--END--""" --END--"""
@ -79,6 +80,7 @@ State: 2
--END--""") --END--""")
d = spot.degeneralize(aut) d = spot.degeneralize(aut)
d.copy_state_names_from(aut)
h = d.to_str('hoa') h = d.to_str('hoa')
assert h == """HOA: v1 assert h == """HOA: v1
@ -89,8 +91,8 @@ acc-name: Buchi
Acceptance: 1 Inf(0) Acceptance: 1 Inf(0)
properties: trans-labels explicit-labels state-acc deterministic properties: trans-labels explicit-labels state-acc deterministic
--BODY-- --BODY--
State: 0 State: 0 "0#0"
[0] 1 [0] 1
State: 1 {0} State: 1 "2#0" {0}
[t] 1 [t] 1
--END--""" --END--"""