From 85f6e0e158c581a4cb5278a7a433b24ce3bdb25b Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Fri, 11 Nov 2016 15:17:34 +0100 Subject: [PATCH] scc_filter: preserve state names and highlighted states Suggested by Juraj Major. * spot/twaalgos/sccfilter.cc: Here. * tests/python/sccfilter.py: New file. * tests/Makefile.am: Add it. * NEWS: Mention the news. --- NEWS | 2 ++ spot/twaalgos/sccfilter.cc | 31 ++++++++++++++++++-- tests/Makefile.am | 1 + tests/python/sccfilter.py | 60 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 tests/python/sccfilter.py diff --git a/NEWS b/NEWS index a23c3589e..1578a53ac 100644 --- a/NEWS +++ b/NEWS @@ -40,6 +40,8 @@ New in spot 2.1.2.dev (not yet released) this halves the run time of genltl --rv-counter=10 | ltl2tgba + * scc_filter() learned to preserve state names and highlighted states. + Bugs: * ltl2tgba was alway using the highest settings for the LTL diff --git a/spot/twaalgos/sccfilter.cc b/spot/twaalgos/sccfilter.cc index 569987d41..5eabfbc98 100644 --- a/spot/twaalgos/sccfilter.cc +++ b/spot/twaalgos/sccfilter.cc @@ -330,10 +330,37 @@ namespace spot // has one initial state). auto init = inout[aut->get_init_state_number()]; filtered->set_init_state(init < out_n ? init : filtered->new_state()); + + if (auto* names = + aut->get_named_prop>("state-names")) + { + std::cerr << "names\n"; + unsigned size = names->size(); + if (size > in_n) + size = in_n; + auto* new_names = new std::vector(out_n); + filtered->set_named_prop("state-names", new_names); + for (unsigned s = 0; s < size; ++s) + { + unsigned new_s = inout[s]; + if (new_s != -1U) + (*new_names)[new_s] = (*names)[s]; + } + } + if (auto hs = + aut->get_named_prop>("highlight-states")) + { + auto* new_hs = new std::map; + filtered->set_named_prop("highlight-states", new_hs); + for (auto p: *hs) + { + unsigned new_s = inout[p.first]; + if (new_s != -1U) + new_hs->emplace(new_s, p.second); + } + } return filtered; } - - } twa_graph_ptr diff --git a/tests/Makefile.am b/tests/Makefile.am index bf8dd110d..682be915c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -342,6 +342,7 @@ TESTS_python = \ python/remfin.py \ python/satmin.py \ python/setacc.py \ + python/sccfilter.py \ python/setxor.py \ python/trival.py \ $(TESTS_ipython) diff --git a/tests/python/sccfilter.py b/tests/python/sccfilter.py new file mode 100644 index 000000000..6edd33e9f --- /dev/null +++ b/tests/python/sccfilter.py @@ -0,0 +1,60 @@ +#!/usr/bin/python3 +# -*- mode: python; coding: utf-8 -*- +# Copyright (C) 2016 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 . + +# Make sure scc_filter preserves state-names (suggested by Juraj +# Major) + +import spot + +a = spot.automaton(""" +HOA: v1.1 +States: 3 +Start: 1 +AP: 1 "a" +acc-name: Buchi +Acceptance: 1 Inf(0) +spot.highlight.states: 0 0 2 3 +--BODY-- +State: 0 "baz" +[t] 0 +State: 2 "foo" {0} +[0] 0 +[0] 2 +[!0] 2 +State: 1 "bar" +[0] 2 +--END-- +""") + +assert (spot.scc_filter(a, True).to_str('hoa', '1.1') == """HOA: v1.1 +States: 2 +Start: 0 +AP: 1 "a" +acc-name: Buchi +Acceptance: 1 Inf(0) +properties: trans-labels explicit-labels state-acc !complete +properties: deterministic +spot.highlight.states: 1 3 +--BODY-- +State: 0 "bar" +[0] 1 +State: 1 "foo" {0} +[t] 1 +--END--""")