game: fix handling of useless SCCs

This is a bug I introduced while merging Philipp's patch.

* spot/misc/game.cc (parity_game::solve): Set the strategy for player
0 in useless SCCs.
(parity_game::fix_scc): Do not use sub_game_ to detect edges exiting
the SCC.
* tests/python/game.py: New file.
* tests/Makefile.am: Add it.
This commit is contained in:
Alexandre Duret-Lutz 2020-09-24 12:18:14 +02:00
parent 2f819e5034
commit 392c1a0ec3
3 changed files with 77 additions and 13 deletions

View file

@ -159,8 +159,6 @@ namespace spot
bool solve(const twa_graph_ptr &arena) bool solve(const twa_graph_ptr &arena)
{ {
ensure_parity_game(arena, "solve_parity_game()");
// todo check if reordering states according to scc is worth it // todo check if reordering states according to scc is worth it
set_up(arena); set_up(arena);
// Start recursive zielonka in a bottom-up fashion on each scc // Start recursive zielonka in a bottom-up fashion on each scc
@ -171,7 +169,17 @@ namespace spot
if (!info_->is_useful_scc(c_scc_idx_)) if (!info_->is_useful_scc(c_scc_idx_))
{ {
for (unsigned v: c_states()) for (unsigned v: c_states())
w_.set(v, false); {
w_.set(v, false);
// The strategy for player 0 is to take the first
// available edge.
if ((*owner_ptr_)[v] == false)
for (const auto &e : arena_->out(v))
{
s_[v] = arena_->edge_number(e);
break;
}
}
continue; continue;
} }
// Convert transitions leaving edges to self-loops // Convert transitions leaving edges to self-loops
@ -195,14 +203,6 @@ namespace spot
// All done -> restore graph, i.e. undo self-looping // All done -> restore graph, i.e. undo self-looping
restore(); restore();
if (!std::all_of(w_.has_winner_.cbegin(), w_.has_winner_.cend(),
[](bool b)
{ return b; }))
{
for (unsigned n = 0; n < w_.has_winner_.size(); ++n)
std::cerr << "hw[" << n << "]=" << w_.has_winner_[n] << '\n';
}
assert(std::all_of(w_.has_winner_.cbegin(), w_.has_winner_.cend(), assert(std::all_of(w_.has_winner_.cbegin(), w_.has_winner_.cend(),
[](bool b) [](bool b)
{ return b; })); { return b; }));
@ -234,7 +234,7 @@ namespace spot
void set_up(const twa_graph_ptr &arena) void set_up(const twa_graph_ptr &arena)
{ {
owner_ptr_ = arena->get_named_prop<std::vector<bool>>("state-player"); owner_ptr_ = ensure_parity_game(arena, "solve_parity_game()");
arena_ = arena; arena_ = arena;
unsigned n_states = arena_->num_states(); unsigned n_states = arena_->num_states();
// Resize data structures // Resize data structures
@ -333,7 +333,7 @@ namespace spot
{ {
// The outgoing edges are taken finitely often // The outgoing edges are taken finitely often
// -> disregard parity // -> disregard parity
if (subgame_[e.dst] != unseen_mark) if (info_->scc_of(e.dst) != c_scc_idx_)
{ {
// Edge leaving the scc // Edge leaving the scc
change_stash_.emplace_back(arena_->edge_number(e), change_stash_.emplace_back(arena_->edge_number(e),

View file

@ -393,6 +393,7 @@ TESTS_python = \
python/dualize.py \ python/dualize.py \
python/ecfalse.py \ python/ecfalse.py \
python/except.py \ python/except.py \
python/game.py \
python/gen.py \ python/gen.py \
python/genem.py \ python/genem.py \
python/implies.py \ python/implies.py \

63
tests/python/game.py Normal file
View file

@ -0,0 +1,63 @@
#!/usr/bin/python3
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2020 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/>.
import spot
g = spot.automaton("""HOA: v1 States: 9 Start: 0 AP: 2 "a" "b"
acc-name: Streett 1 Acceptance: 2 Fin(0) | Inf(1) properties:
trans-labels explicit-labels state-acc spot-state-player: 0 1 0 1 0 1
0 1 1 --BODY-- State: 0 {1} [1] 1 [1] 3 State: 1 {1} [1] 2 State: 2
{1} [0] 8 State: 3 {1} [1] 4 State: 4 {1} [0] 5 State: 5 {1} [0] 6
State: 6 {1} [1] 7 State: 7 State: 8 {1} [0] 2 --END--""")
assert spot.solve_parity_game(g) == False
s = spot.highlight_strategy(g).to_str("HOA", "1.1")
assert s == """HOA: v1.1
States: 9
Start: 0
AP: 2 "a" "b"
acc-name: Streett 1
Acceptance: 2 Fin(0) | Inf(1)
properties: trans-labels explicit-labels state-acc !complete
properties: !deterministic exist-branch
spot.highlight.states: 0 5 1 4 2 4 3 5 4 5 5 5 6 5 7 5 8 4
spot.highlight.edges: 2 5 3 4 6 5 8 5 9 4
spot.state-player: 0 1 0 1 0 1 0 1 1
--BODY--
State: 0 {1}
[1] 1
[1] 3
State: 1 {1}
[1] 2
State: 2 {1}
[0] 8
State: 3 {1}
[1] 4
State: 4 {1}
[0] 5
State: 5 {1}
[0] 6
State: 6 {1}
[1] 7
State: 7
State: 8 {1}
[0] 2
--END--"""