ignore false edges in emptiness checks and scc_info

Based on reports by Florian Renkin and Jens Kreber.

* spot/twaalgos/bfssteps.cc, spot/twaalgos/couvreurnew.cc,
spot/twaalgos/gtec/gtec.cc, spot/twaalgos/gv04.cc,
spot/twaalgos/magic.cc, spot/twaalgos/sccinfo.cc
spot/twaalgos/se05.cc, spot/twaalgos/tau03.cc: Ignore bddfalse edges.
* spot/twaalgos/gtec/gtec.hh: Remove debugging function.
* tests/core/neverclaimread.test: Adjust.
* tests/python/ecfalse.py: New test file.
* tests/Makefile.am: Add it.
* NEWS: Mention the bug.
This commit is contained in:
Alexandre Duret-Lutz 2020-04-11 11:09:10 +02:00
parent 67fa19cb08
commit 0b25820211
13 changed files with 206 additions and 61 deletions

3
NEWS
View file

@ -119,6 +119,9 @@ New in spot 2.8.7.dev (not yet released)
- Relabeling automata could introduce false edges. Those are now - Relabeling automata could introduce false edges. Those are now
removed. removed.
- Emptiness checks, and scc_info should now ignore edges labeled
with false.
New in spot 2.8.7 (2020-03-13) New in spot 2.8.7 (2020-03-13)
Bugs fixed: Bugs fixed:

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2014, 2015, 2018 Laboratoire de Recherche et // Copyright (C) 2014, 2015, 2018, 2020 Laboratoire de Recherche et
// Développement de l'Epita (LRDE) // Développement de l'Epita (LRDE)
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre // département Systèmes Répartis Coopératifs (SRC), Université Pierre
@ -78,6 +78,10 @@ namespace spot
todo.pop_front(); todo.pop_front();
for (auto i: a_->succ(src)) for (auto i: a_->succ(src))
{ {
// skip false transitions
if (SPOT_UNLIKELY(i->cond() == bddfalse))
continue;
const state* dest = filter(i->dst()); const state* dest = filter(i->dst());
if (!dest) if (!dest)

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2016-2019 Laboratoire de Recherche et Développement // Copyright (C) 2016-2020 Laboratoire de Recherche et Développement
// de l'Epita (LRDE). // de l'Epita (LRDE).
// //
// This file is part of Spot, a model checking library. // This file is part of Spot, a model checking library.
@ -41,7 +41,8 @@ namespace spot
public: public:
explicitproxy(explicit_iterator it) explicitproxy(explicit_iterator it)
: it_(it) : it_(it)
{} {
}
const explicitproxy* const explicitproxy*
operator->() const operator->() const
@ -73,6 +74,12 @@ namespace spot
return it_->acc; return it_->acc;
} }
bdd
cond() const
{
return it_->cond;
}
void void
next() next()
{ {
@ -704,7 +711,7 @@ namespace spot
assert(ecs_->root.size() == arc.size()); assert(ecs_->root.size() == arc.size());
// We are looking at the next successor in SUCC. // We are looking at the next successor in SUCC.
auto succ = todo.top().second; auto& succ = todo.top().second;
// If there are no more successors, backtrack. // If there are no more successors, backtrack.
if (succ->done()) if (succ->done())
@ -744,6 +751,14 @@ namespace spot
// We have a successor to look at. // We have a successor to look at.
inc_transitions(); inc_transitions();
// Ignore false edges
if (SPOT_UNLIKELY(succ->cond() == bddfalse))
{
succ->next();
continue;
}
// Fetch the values we are interested in... // Fetch the values we are interested in...
auto acc = succ->acc(); auto acc = succ->acc();
if (!need_accepting_run) if (!need_accepting_run)
@ -763,7 +778,7 @@ namespace spot
state_t dest = succ->dst(); state_t dest = succ->dst();
// ... and point the iterator to the next successor, for // ... and point the iterator to the next successor, for
// the next iteration. // the next iteration.
todo.top().second->next(); succ->next();
// We do not need succ from now on. // We do not need succ from now on.

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2008, 2011, 2014-2016, 2018-2019 Laboratoire de // Copyright (C) 2008, 2011, 2014-2016, 2018-2020 Laboratoire de
// Recherche et Développement de l'Epita (LRDE). // Recherche et Développement de l'Epita (LRDE).
// Copyright (C) 2003, 2004, 2005, 2006 Laboratoire d'Informatique de // Copyright (C) 2003, 2004, 2005, 2006 Laboratoire d'Informatique de
// Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC), // Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
@ -109,6 +109,8 @@ namespace spot
do do
{ {
inc_transitions(); inc_transitions();
if (SPOT_UNLIKELY(i->cond() == bddfalse))
continue;
const state* s = i->dst(); const state* s = i->dst();
auto j = ecs_->h.find(s); auto j = ecs_->h.find(s);
@ -219,9 +221,15 @@ namespace spot
// of the arc) we are interested in... // of the arc) we are interested in...
const state* dest = succ->dst(); const state* dest = succ->dst();
acc_cond::mark_t acc = succ->acc(); acc_cond::mark_t acc = succ->acc();
trace << "-> " << dest << ' ' << acc << ' ' << succ->cond();
// ... and point the iterator to the next successor, for // ... and point the iterator to the next successor, for
// the next iteration. // the next iteration.
succ->next(); {
bdd cond = succ->cond();
succ->next();
if (SPOT_UNLIKELY(cond == bddfalse))
continue;
}
// We do not need SUCC from now on. // We do not need SUCC from now on.
// Are we going to a new state? // Are we going to a new state?
@ -321,10 +329,12 @@ namespace spot
{ {
for (auto iter: shy->ecs_->aut->succ(s)) for (auto iter: shy->ecs_->aut->succ(s))
{ {
shy->inc_transitions();
if (SPOT_UNLIKELY(iter->cond() == bddfalse))
continue;
q.emplace_back(iter->acc(), q.emplace_back(iter->acc(),
iter->dst()); iter->dst());
shy->inc_depth(); shy->inc_depth();
shy->inc_transitions();
} }
} }
@ -372,24 +382,28 @@ namespace spot
} }
#ifdef TRACE #ifdef TRACE
couvreur99_check_shy::dump_queue(std::ostream& os) namespace
{ {
os << "--- TODO ---\n"; template<class T>
unsigned lvl = 0; void dump_queue(const T& todo)
for (auto& ti: todo) {
{ trace << "--- TODO ---\n";
++lvl; unsigned lvl = 0;
os << '#' << lvl << " s:" << ti.s << " n:" << ti.n for (auto& ti: todo)
<< " q:{"; {
for (auto qi = ti.q.begin(); qi != ti.q.end();) ++lvl;
{ trace << '#' << lvl << " s:" << ti.s << " n:" << ti.n
os << qi->s; << " q:{";
++qi; for (auto qi = ti.q.begin(); qi != ti.q.end();)
if (qi != ti.q.end()) {
os << ", "; trace << qi->s;
} ++qi;
os << "}\n"; if (qi != ti.q.end())
} trace << ", ";
}
trace << "}\n";
}
}
} }
#endif #endif
@ -410,7 +424,7 @@ namespace spot
for (;;) for (;;)
{ {
#ifdef TRACE #ifdef TRACE
dump_queue(); dump_queue(todo);
#endif #endif
assert(ecs_->root.size() == 1 + arc.size()); assert(ecs_->root.size() == 1 + arc.size());

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2008, 2013-2016, 2018-2019 Laboratoire de Recherche // Copyright (C) 2008, 2013-2016, 2018-2020 Laboratoire de Recherche
// et Développement de l'Epita (LRDE). // et Développement de l'Epita (LRDE).
// Copyright (C) 2003, 2004, 2005, 2006 Laboratoire d'Informatique de // Copyright (C) 2003, 2004, 2005, 2006 Laboratoire d'Informatique de
// Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC), // Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
@ -218,11 +218,6 @@ namespace spot
void clear_todo(); void clear_todo();
#ifdef SPOT_TRACE
/// Dump the queue for debugging.
void dump_queue(std::ostream& os = std::cerr);
#endif
/// Whether successors should be grouped for states in the same SCC. /// Whether successors should be grouped for states in the same SCC.
bool group_; bool group_;
// If the "group2" option is set (it implies "group"), we // If the "group2" option is set (it implies "group"), we

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2008, 2010, 2011, 2013-2019 Laboratoire de // Copyright (C) 2008, 2010, 2011, 2013-2020 Laboratoire de
// recherche et développement de l'Epita (LRDE). // recherche et développement de l'Epita (LRDE).
// Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6
// (LIP6), département Systèmes Répartis Coopératifs (SRC), Université // (LIP6), département Systèmes Répartis Coopératifs (SRC), Université
@ -120,6 +120,10 @@ namespace spot
trace << " No more successors" << std::endl; trace << " No more successors" << std::endl;
pop(); pop();
} }
else if (SPOT_UNLIKELY(iter->cond() == bddfalse))
{
continue;
}
else else
{ {
const state* s_prime = iter->dst(); const state* s_prime = iter->dst();

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2011, 2013-2019 Laboratoire de recherche et // Copyright (C) 2011, 2013-2020 Laboratoire de recherche et
// développement de l'Epita (LRDE). // développement de l'Epita (LRDE).
// Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre // département Systèmes Répartis Coopératifs (SRC), Université Pierre
@ -199,6 +199,8 @@ namespace spot
// Go down the edge (f.s, <label, acc>, s_prime) // Go down the edge (f.s, <label, acc>, s_prime)
f.it->next(); f.it->next();
inc_transitions(); inc_transitions();
if (SPOT_UNLIKELY(label == bddfalse))
continue;
typename heap::color_ref c = h.get_color_ref(s_prime); typename heap::color_ref c = h.get_color_ref(s_prime);
if (c.is_white()) if (c.is_white())
{ {
@ -286,6 +288,8 @@ namespace spot
// Go down the edge (f.s, <label, acc>, s_prime) // Go down the edge (f.s, <label, acc>, s_prime)
f.it->next(); f.it->next();
inc_transitions(); inc_transitions();
if (SPOT_UNLIKELY(label == bddfalse))
continue;
typename heap::color_ref c = h.get_color_ref(s_prime); typename heap::color_ref c = h.get_color_ref(s_prime);
if (c.is_white()) if (c.is_white())
{ {

View file

@ -158,24 +158,25 @@ namespace spot
// Gather all successor SCCs // Gather all successor SCCs
if (track_succs) if (track_succs)
for (auto& t: aut->out(*s)) for (auto& t: aut->out(*s))
for (unsigned d: aut->univ_dests(t)) if (SPOT_LIKELY(t.cond != bddfalse))
{ for (unsigned d: aut->univ_dests(t))
unsigned n = sccof_[d]; {
if (n == num || n == -1U) unsigned n = sccof_[d];
continue; if (n == num || n == -1U)
// If edges are cut, we are not able to continue;
// maintain proper successor information. // If edges are cut, we are not able to
if (filter_) // maintain proper successor information.
switch (filter_(t, d, filter_data_)) if (filter_)
{ switch (filter_(t, d, filter_data_))
case edge_filter_choice::keep: {
break; case edge_filter_choice::keep:
case edge_filter_choice::ignore: break;
case edge_filter_choice::cut: case edge_filter_choice::ignore:
continue; case edge_filter_choice::cut:
} continue;
succ.emplace_back(n); }
} succ.emplace_back(n);
}
} }
while (*s++ != curr); while (*s++ != curr);
@ -251,6 +252,13 @@ namespace spot
// Fetch the values we are interested in... // Fetch the values we are interested in...
auto& e = gr.edge_storage(tr_succ); auto& e = gr.edge_storage(tr_succ);
// Skip false edges.
if (SPOT_UNLIKELY(e.cond == bddfalse))
{
todo_.top().out_edge = e.next_succ;
continue;
}
unsigned dest = e.dst; unsigned dest = e.dst;
if ((int) dest < 0) if ((int) dest < 0)
{ {
@ -412,7 +420,7 @@ namespace spot
auto& s = result[src_scc]; auto& s = result[src_scc];
for (auto& t: aut_->out(src)) for (auto& t: aut_->out(src))
{ {
if (scc_of(t.dst) != src_scc) if (scc_of(t.dst) != src_scc || SPOT_UNLIKELY(t.cond == bddfalse))
continue; continue;
s.insert(t.acc); s.insert(t.acc);
} }
@ -502,7 +510,7 @@ namespace spot
bfs_queue.pop_front(); bfs_queue.pop_front();
for (auto& t: aut->out(src)) for (auto& t: aut->out(src))
{ {
if (filter(t)) if (SPOT_UNLIKELY(t.cond == bddfalse) || filter(t))
continue; continue;
if (match(t)) if (match(t))
@ -573,7 +581,8 @@ namespace spot
if (scc_of(s) != scc) if (scc_of(s) != scc)
continue; continue;
for (auto& e: aut_->out(s)) for (auto& e: aut_->out(s))
if (e.src == e.dst && !filter(e) && acccond.accepting(e.acc)) if (e.src == e.dst && SPOT_LIKELY(e.cond != bddfalse)
&& !filter(e) && acccond.accepting(e.acc))
{ {
// We have found an accepting self-loop. That's the cycle // We have found an accepting self-loop. That's the cycle
// part of our accepting run. // part of our accepting run.

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2011, 2013-2019 Laboratoire de Recherche et // Copyright (C) 2011, 2013-2020 Laboratoire de Recherche et
// Développement de l'Epita (LRDE). // Développement de l'Epita (LRDE).
// Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre // département Systèmes Répartis Coopératifs (SRC), Université Pierre
@ -195,6 +195,8 @@ namespace spot
// Go down the edge (f.s, <label, acc>, s_prime) // Go down the edge (f.s, <label, acc>, s_prime)
f.it->next(); f.it->next();
inc_transitions(); inc_transitions();
if (SPOT_UNLIKELY(label == bddfalse))
continue;
typename heap::color_ref c = h.get_color_ref(s_prime); typename heap::color_ref c = h.get_color_ref(s_prime);
if (c.is_white()) if (c.is_white())
{ {
@ -286,6 +288,8 @@ namespace spot
// Go down the edge (f.s, <label, acc>, s_prime) // Go down the edge (f.s, <label, acc>, s_prime)
f.it->next(); f.it->next();
inc_transitions(); inc_transitions();
if (SPOT_UNLIKELY(label == bddfalse))
continue;
typename heap::color_ref c = h.get_color_ref(s_prime); typename heap::color_ref c = h.get_color_ref(s_prime);
if (c.is_white()) if (c.is_white())
{ {

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2011, 2013-2019 Laboratoire de Recherche et // Copyright (C) 2011, 2013-2020 Laboratoire de Recherche et
// Developpement de l'Epita (LRDE). // Developpement de l'Epita (LRDE).
// Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre // département Systèmes Répartis Coopératifs (SRC), Université Pierre
@ -167,6 +167,8 @@ namespace spot
// Go down the edge (f.s, <label, acc>, s_prime) // Go down the edge (f.s, <label, acc>, s_prime)
f.it->next(); f.it->next();
inc_transitions(); inc_transitions();
if (SPOT_UNLIKELY(label == bddfalse))
continue;
typename heap::color_ref c_prime = h.get_color_ref(s_prime); typename heap::color_ref c_prime = h.get_color_ref(s_prime);
if (c_prime.is_white()) if (c_prime.is_white())
{ {
@ -194,11 +196,13 @@ namespace spot
{ {
inc_transitions(); inc_transitions();
const state *s_prime = i->dst(); const state *s_prime = i->dst();
bdd label = i->cond();
auto acc = i->acc();
if (SPOT_UNLIKELY(label == bddfalse))
continue;
trace << "DFS_BLUE rescanning the arc from " trace << "DFS_BLUE rescanning the arc from "
<< a_->format_state(f.s) << " to " << a_->format_state(f.s) << " to "
<< a_->format_state(s_prime) << std::endl; << a_->format_state(s_prime) << std::endl;
bdd label = i->cond();
auto acc = i->acc();
typename heap::color_ref c_prime = h.get_color_ref(s_prime); typename heap::color_ref c_prime = h.get_color_ref(s_prime);
assert(!c_prime.is_white()); assert(!c_prime.is_white());
auto acu = acc | c.get_acc(); auto acu = acc | c.get_acc();
@ -247,6 +251,8 @@ namespace spot
// Go down the edge (f.s, <label, acc>, s_prime) // Go down the edge (f.s, <label, acc>, s_prime)
f.it->next(); f.it->next();
inc_transitions(); inc_transitions();
if (SPOT_UNLIKELY(label == bddfalse))
continue;
typename heap::color_ref c_prime = h.get_color_ref(s_prime); typename heap::color_ref c_prime = h.get_color_ref(s_prime);
if (c_prime.is_white()) if (c_prime.is_white())
{ {

View file

@ -377,6 +377,7 @@ TESTS_python = \
python/declenv.py \ python/declenv.py \
python/decompose_scc.py \ python/decompose_scc.py \
python/dualize.py \ python/dualize.py \
python/ecfalse.py \
python/except.py \ python/except.py \
python/gen.py \ python/gen.py \
python/genem.py \ python/genem.py \

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2010-2015, 2017-2018 Laboratoire # Copyright (C) 2010-2015, 2017-2018, 2020 Laboratoire
# de Recherche et Développement de l'Epita (LRDE). # de Recherche et 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.
@ -340,7 +340,7 @@ digraph "-" {
1 [label="1", peripheries=2] 1 [label="1", peripheries=2]
} }
subgraph cluster_1 { subgraph cluster_1 {
color=red color=black
label="" label=""
0 [label="0"] 0 [label="0"]
} }

86
tests/python/ecfalse.py Normal file
View file

@ -0,0 +1,86 @@
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2020 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/>.
import spot
from buddy import bddfalse, bddtrue
a = spot.automaton("""
HOA: v1
States: 2
Start: 1
AP: 2 "p0" "p1"
acc-name: Buchi
Acceptance: 1 Inf(0)
--BODY--
State: 0
[!0 | 1] 0 {0}
[0&!1] 1
State: 1
/* we want this edge to be false, but the parser
would ignore it if we wrote it here */
[0] 0 {0}
[!1] 1
--END--
""")
# Make the false edge.
for e in a.out(1):
if e.dst == 0:
e.cond = bddfalse
assert a.accepting_run() is None
assert a.is_empty()
for name in ['SE05', 'CVWY90', 'GV04', 'Cou99(shy)', 'Cou99', 'Tau03']:
print(name)
ec = spot.make_emptiness_check_instantiator(name)[0].instantiate(a)
res = ec.check()
if res is not None:
print(res.accepting_run())
assert res is None
si = spot.scc_info(a)
assert si.scc_count() == 1 # only one accessible SCC
a.set_init_state(0)
si = spot.scc_info(a)
assert si.scc_count() == 2
a = spot.automaton("""HOA: v1 States: 11 Start: 0 AP: 2 "a" "b" Acceptance: 8
(Fin(0) | Inf(1)) & (Fin(2) | Inf(3)) & ((Fin(4) & Inf(5)) | (Fin(6) & Inf(7)))
properties: trans-labels explicit-labels trans-acc --BODY-- State: 0 [!0&!1] 1
{0 4 6 7} [!0&!1] 2 {0 5 6} [!0&!1] 3 {3 4 6 7} [!0&!1] 4 {3 5 6} State: 1
[0&1] 5 {2 5 7} [0&1] 6 {2 7} [0&1] 7 {2 3 5 7} [0&1] 8 {2 3 7} [0&1] 0 {2 5 7}
[0&1] 9 {2 7} State: 2 [0&1] 1 {2} [0&1] 3 {2 3} [0&1] 10 {2} State: 3 [0&1] 0
{3 5 7} [0&1] 9 {3 7} State: 4 [!0&!1] 5 {4 6} [!0&!1] 6 {7} [0&1] 10 {3}
State: 5 State: 6 State: 7 [!0&!1] 1 {4 6 7} [!0&!1] 2 {5 6} State: 8 [!0&!1] 2
{4} State: 9 [!0&!1] 2 {0 4} [!0&!1] 4 {3 4} State: 10 --END-- """)
r = a.accepting_run()
assert r is not None
assert r.replay(spot.get_cout())
for e in a.out(7):
if e.dst == 2:
e.cond = bddfalse
s = a.accepting_run()
assert s is not None
assert s.replay(spot.get_cout())
for e in a.out(2):
if e.dst == 1:
e.cond = bddfalse
s = a.accepting_run()
assert s is None