introduce count_univbranch_states() and count_univbranch_edges()

Fixes #368, suggested by František Blahoudek.

* spot/twaalgos/isdet.cc, spot/twaalgos/isdet.hh
(count_univbranch_states(), count_univbranch_edges()): New functions.
* bin/common_aoutput.cc, bin/common_aoutput.hh: Add %u and variants.
* NEWS: Mention these.
* tests/core/alternating.test: Test them.
This commit is contained in:
Alexandre Duret-Lutz 2018-11-07 16:59:43 +01:00
parent 60296317c7
commit 29e08a1afb
6 changed files with 125 additions and 4 deletions

View file

@ -310,4 +310,33 @@ namespace spot
check_semi_determism(aut, true);
}
unsigned
count_univbranch_states(const const_twa_graph_ptr& aut)
{
if (aut->is_existential())
return 0;
unsigned res = 0;
unsigned ns = aut->num_states();
for (unsigned s = 0; s < ns; ++s)
for (auto& e: aut->out(s))
if (aut->is_univ_dest(e))
{
++res;
break;
}
return res;
}
unsigned
count_univbranch_edges(const const_twa_graph_ptr& aut)
{
if (aut->is_existential())
return 0;
unsigned res = aut->is_univ_dest(aut->get_init_state_number());
for (auto& e: aut->edges())
if (aut->is_univ_dest(e))
++res;
return res;
}
}

View file

@ -1,6 +1,6 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017 Laboratoire de Recherche
// et Développement de l'Epita (LRDE).
// Copyright (C) 2012-2018 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
@ -109,4 +109,33 @@ namespace spot
/// \brief Set the deterministic and semi-deterministic properties
/// appropriately.
SPOT_API void check_determinism(twa_graph_ptr aut);
// \brief Count states with some universal branching.
//
// This counts the number of states that have edges going to several
// destinations at once (as reported by aut->is_univ_dest(...)).
//
// Note that nondeterministic automata (which include deterministic
// automata) have 0 such state, but additionally they also have
// "singleton" initial state (which this function does not check).
//
// \see count_univbranch_edges()
SPOT_API unsigned
count_univbranch_states(const const_twa_graph_ptr& aut);
// \brief Count edges with universal branching.
//
// This counts the number of edges going to several destination at
// once (as reported by aut->is_univ_dest(...)).
//
// If the automaton starts in multiple initial states at once, this
// is considered as a universal "initial edge", and adds one to the
// total count.
//
// Nondeterministic automata (which include deterministic automata)
// have 0 edges with universal branching.
//
// \see count_univbranch_states()
SPOT_API unsigned
count_univbranch_edges(const const_twa_graph_ptr& aut);
}