parity game: various improvements

Zielonka algorithm has been fixed and optimized.
It also now computes the strategy for both players.

* bin/ltlsynt.cc: Update calls to parity_game::solve()
* spot/misc/game.cc, spot/misc/game.hh: Implement the changes
This commit is contained in:
Maximilien Colange 2018-01-24 18:05:46 +01:00
parent 0e29d30d1b
commit 9698363ef5
3 changed files with 131 additions and 94 deletions

View file

@ -35,47 +35,40 @@ namespace spot
class SPOT_API parity_game
{
private:
const const_twa_graph_ptr dpa_;
const const_twa_graph_ptr arena_;
const std::vector<bool> owner_;
public:
/// \a parity_game provides an interface to manipulate a deterministic parity
/// \a parity_game provides an interface to manipulate a colorized parity
/// automaton as a parity game, including methods to solve the game.
/// The input automaton (arena) should be colorized and have a max-odd parity
/// acceptance condition.
///
/// \param dpa the underlying deterministic parity automaton
/// \param owner a vector of Booleans indicating the owner of each state,
/// with the convention that true represents player 1 and false represents
/// player 0.
parity_game(const twa_graph_ptr dpa, std::vector<bool> owner)
: dpa_(dpa), owner_(owner)
{
bool max;
bool odd;
dpa_->acc().is_parity(max, odd, true);
SPOT_ASSERT(max && odd);
SPOT_ASSERT(owner_.size() == dpa_->num_states());
}
/// \param arena the underlying parity automaton
/// \param owner a vector of Booleans indicating the owner of each state:
/// true stands for Player 1, false stands for Player 0.
parity_game(const twa_graph_ptr& arena, const std::vector<bool>& owner);
unsigned num_states() const
{
return dpa_->num_states();
return arena_->num_states();
}
unsigned get_init_state_number() const
{
return dpa_->get_init_state_number();
return arena_->get_init_state_number();
}
internal::state_out<const twa_graph::graph_t>
out(unsigned src) const
{
return dpa_->out(src);
return arena_->out(src);
}
internal::state_out<const twa_graph::graph_t>
out(unsigned src)
{
return dpa_->out(src);
return arena_->out(src);
}
bool owner(unsigned src) const
@ -86,7 +79,7 @@ public:
unsigned max_parity() const
{
unsigned max_parity = 0;
for (auto& e: dpa_->edges())
for (const auto& e: arena_->edges())
max_parity = std::max(max_parity, e.acc.max_set());
SPOT_ASSERT(max_parity);
return max_parity - 1;
@ -113,7 +106,7 @@ public:
author = "Wieslaw Zielonka",
}
\endverbatim */
std::pair<region_t, strategy_t> solve() const;
void solve(region_t (&w)[2], strategy_t (&s)[2]) const;
/// Whether player 1 has a winning strategy from the initial state.
/// Implements Calude et al.'s quasipolynomial time algorithm.
@ -148,12 +141,12 @@ private:
// if attr_max is true, states that can force a visit through an edge with
// max parity are also counted in.
strategy_t attractor(const region_t& subgame, region_t& set,
unsigned max_parity, bool odd,
unsigned max_parity, int odd,
bool attr_max = false) const;
// Compute the winning strategy and winning region for player 1.
std::pair<region_t, strategy_t>
solve_rec(region_t& subgame, unsigned max_parity) const;
// Compute the winning strategy and winning region for both players.
void solve_rec(region_t& subgame, unsigned max_parity,
region_t (&w)[2], strategy_t (&s)[2]) const;
};