postproc: introduce --parity output

* spot/twaalgos/postproc.hh, spot/twaalgos/postproc.cc: Add parity
  options.
* bin/common_post.cc: Add support for --parity.
* NEWS: Mention it.
* tests/core/parity2.test: New file.
* tests/Makefile.am: Add it.
This commit is contained in:
Alexandre Duret-Lutz 2018-01-02 12:06:03 +01:00
parent 412c2059bf
commit 42ebf8b18c
6 changed files with 390 additions and 41 deletions

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2012-2017 Laboratoire de Recherche et Développement
// Copyright (C) 2012-2018 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
@ -35,6 +35,7 @@
#include <spot/twaalgos/sepsets.hh>
#include <spot/twaalgos/determinize.hh>
#include <spot/twaalgos/alternation.hh>
#include <spot/twaalgos/parity.hh>
namespace spot
{
@ -147,6 +148,15 @@ namespace spot
return do_sba_simul(d, ba_simul_);
}
twa_graph_ptr
postprocessor::do_degen_tba(const twa_graph_ptr& a)
{
return degeneralize_tba(a,
degen_reset_, degen_order_,
degen_cache_, degen_lskip_,
degen_lowinit_, degen_remscc_);
}
twa_graph_ptr
postprocessor::do_scc_filter(const twa_graph_ptr& a, bool arg)
{
@ -183,6 +193,33 @@ namespace spot
if (type_ == BA || SBACC_)
state_based_ = true;
bool want_parity = (type_ & Parity) == Parity;
auto finalize = [&](twa_graph_ptr tmp)
{
if (COMP_)
tmp = complete(tmp);
if (want_parity && tmp->acc().is_generalized_buchi())
tmp = SBACC_ ? do_degen(tmp) : do_degen_tba(tmp);
if (SBACC_)
tmp = sbacc(tmp);
if (want_parity)
{
parity_kind kind = parity_kind_any;
parity_style style = parity_style_any;
if ((type_ & ParityMin) == ParityMin)
kind = parity_kind_min;
else if ((type_ & ParityMax) == ParityMax)
kind = parity_kind_max;
if ((type_ & ParityOdd) == ParityOdd)
style = parity_style_odd;
else if ((type_ & ParityEven) == ParityEven)
style = parity_style_even;
change_parity_here(tmp, kind, style);
}
return tmp;
};
if (!a->is_existential() &&
// We will probably have to revisit this condition later.
// Currently, the intent is that postprocessor should never
@ -191,7 +228,8 @@ namespace spot
!(type_ == Generic && PREF_ == Any && level_ == Low))
a = remove_alternation(a);
if (type_ != Generic && !a->acc().is_generalized_buchi())
if ((type_ != Generic && !a->acc().is_generalized_buchi())
|| (want_parity && !a->acc().is_parity()))
{
a = to_generalized_buchi(a);
if (PREF_ == Any && level_ == Low)
@ -202,14 +240,9 @@ namespace spot
&& (type_ == Generic
|| type_ == TGBA
|| (type_ == BA && a->is_sba())
|| (type_ == Monitor && a->num_sets() == 0)))
{
if (COMP_)
a = complete(a);
if (SBACC_)
a = sbacc(a);
return a;
}
|| (type_ == Monitor && a->num_sets() == 0)
|| (want_parity && a->acc().is_parity())))
return finalize(a);
int original_acc = a->num_sets();
@ -244,20 +277,14 @@ namespace spot
}
a->remove_unused_ap();
}
if (COMP_)
a = complete(a);
return a;
return finalize(a);
}
if (PREF_ == Any)
{
if (type_ == BA)
a = do_degen(a);
if (COMP_)
a = complete(a);
if (SBACC_)
a = sbacc(a);
return a;
return finalize(a);
}
bool dba_is_wdba = false;
@ -305,6 +332,8 @@ namespace spot
// No need to do that if tba_determinisation_ will be used.
if (type_ == BA && !tba_determinisation_)
sim = do_degen(sim);
else if (want_parity && !sim->acc().is_parity())
sim = do_degen_tba(sim);
else if (SBACC_ && !tba_determinisation_)
sim = sbacc(sim);
}
@ -382,7 +411,7 @@ namespace spot
}
}
if (PREF_ == Deterministic && type_ == Generic && !dba)
if ((PREF_ == Deterministic && (type_ == Generic || want_parity)) && !dba)
{
dba = tgba_determinize(to_generalized_buchi(sim),
false, det_scc_, det_simul_, det_stutter_);
@ -517,12 +546,6 @@ namespace spot
sim = dba ? dba : sim;
sim->remove_unused_ap();
if (COMP_)
sim = complete(sim);
if (SBACC_)
sim = sbacc(sim);
return sim;
return finalize(sim);
}
}

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2012-2017 Laboratoire de Recherche et Développement
// Copyright (C) 2012-2018 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
@ -72,7 +72,20 @@ namespace spot
/// options used for debugging or benchmarking.
postprocessor(const option_map* opt = nullptr);
enum output_type { TGBA, BA, Monitor, Generic };
enum output_type { TGBA = 0,
BA = 1,
Monitor = 2,
Generic = 3,
Parity = 4,
ParityMin = Parity | 8,
ParityMax = Parity | 16,
ParityOdd = Parity | 32,
ParityEven = Parity | 64,
ParityMinOdd = ParityMin | ParityOdd,
ParityMaxOdd = ParityMax | ParityOdd,
ParityMinEven = ParityMin | ParityEven,
ParityMaxEven = ParityMax | ParityEven,
};
/// \brief Select the desired output type.
///
@ -96,11 +109,17 @@ namespace spot
/// SystemC" (Deian Tabakov and Moshe Y. Vardi, Proceedings of
/// RV10, LNCS 6418).
///
/// Finally \c Generic remove all constraints about the acceptance
/// condition. Using \c Generic can be needed to force the
/// determinization of some automata (e.g., not all TGBA can be
/// degeneralized, using \c Generic will allow parity acceptance
/// to be used instead).
/// \c Generic removes all constraints about the acceptance
/// condition. Using \c Generic (or \c Parity below) can be
/// needed to force the determinization of some automata (e.g.,
/// not all TGBA can be degeneralized, using \c Generic will allow
/// parity acceptance to be used instead).
///
/// \a Parity and its variants request the acceptance condition to
/// be of some parity type. Note that the determinization
/// algorithm used by Spot produces "parity min odd" acceptance,
/// but other parity types can be obtained from there by minor
/// adjustments.
///
/// If set_type() is not called, the default \c output_type is \c TGBA.
void
@ -195,6 +214,7 @@ namespace spot
twa_graph_ptr do_simul(const twa_graph_ptr& input, int opt);
twa_graph_ptr do_sba_simul(const twa_graph_ptr& input, int opt);
twa_graph_ptr do_degen(const twa_graph_ptr& input);
twa_graph_ptr do_degen_tba(const twa_graph_ptr& input);
twa_graph_ptr do_scc_filter(const twa_graph_ptr& a, bool arg);
twa_graph_ptr do_scc_filter(const twa_graph_ptr& a);