Add count_nondet_states(aut) and is_deterministic(aut).

* src/tgbaalgos/isdet.cc, src/tgbaalgos/isdet.hh: New files.
* src/tgbaalgos/Makefile.am: Add them.
* wrap/python/spot.i: Wrap them.
* wrap/python/ajax/spot.in: Display count of nondeterministic
states.
* src/tgbatest/ltl2tgba.cc (-kt): Likewise.
* NEWS: Upadte.
This commit is contained in:
Alexandre Duret-Lutz 2012-09-11 15:10:49 +02:00
parent 45e93ea16c
commit 04b5e37055
7 changed files with 183 additions and 6 deletions

View file

@ -40,6 +40,7 @@ tgbaalgos_HEADERS = \
emptiness.hh \
emptiness_stats.hh \
gv04.hh \
isdet.hh \
lbtt.hh \
ltl2taa.hh \
ltl2tgba_fm.hh \
@ -77,6 +78,7 @@ libtgbaalgos_la_SOURCES = \
eltl2tgba_lacim.cc \
emptiness.cc \
gv04.cc \
isdet.cc \
lbtt.cc \
ltl2taa.cc \
ltl2tgba_fm.cc \

111
src/tgbaalgos/isdet.cc Normal file
View file

@ -0,0 +1,111 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2012 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 2 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 Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include "tgbaalgos/isdet.hh"
#include <set>
#include <deque>
namespace spot
{
namespace
{
static
unsigned
count_nondet_states_aux(const tgba* aut, bool count = true)
{
unsigned res = 0;
typedef std::set<const state*, state_ptr_less_than> seen_set;
typedef std::deque<const state*> todo_list;
seen_set seen;
todo_list todo;
{
const state* s = aut->get_init_state();
seen.insert(s);
todo.push_back(s);
}
while (!todo.empty())
{
const state* src = todo.front();
todo.pop_front();
tgba_succ_iterator* i = aut->succ_iter(src);
tgba_succ_iterator* j = aut->succ_iter(src);
unsigned in = 0;
bool nondeterministic = false;
for (i->first(); !i->done(); i->next())
{
// If we know the state is nondeterministic, just skip the
// test for the remaining transitions. But don't break
// the loop, because we still have to record the
// destination states.
if (!nondeterministic)
{
++in;
// Move j to the transition that follows i.
j->first();
for (unsigned jn = 0; jn < in; ++jn)
j->next();
// Make sure transitions after i are not conflicting.
while (!j->done())
{
if ((i->current_condition() & j->current_condition())
!= bddfalse)
{
nondeterministic = true;
break;
}
j->next();
}
}
const state* dst = i->current_state();
if (seen.insert(dst).second)
todo.push_back(dst);
else
dst->destroy();
}
delete j;
delete i;
res += nondeterministic;
if (!count && nondeterministic)
break;
}
for (seen_set::const_iterator i = seen.begin(); i != seen.end();)
{
const state* s = *i++;
s->destroy();
}
return res;
}
}
unsigned
count_nondet_states(const tgba* aut)
{
return count_nondet_states_aux(aut);
}
bool
is_deterministic(const tgba* aut)
{
return !!count_nondet_states_aux(aut, false);
}
}

49
src/tgbaalgos/isdet.hh Normal file
View file

@ -0,0 +1,49 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2012 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 2 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 Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#ifndef SPOT_TGBAALGOS_ISDET_HH
# define SPOT_TGBAALGOS_ISDET_HH
# include "tgba/tgba.hh"
namespace spot
{
/// \addtogroup tgba_misc
/// @{
/// \brief Count the number of non-deterministic states in \a aut.
///
/// The automaton is deterministic if it has 0 nondeterministic states,
/// but it is more efficient to call is_deterministic() if you do not
/// care about the number of nondeterministic states.
unsigned count_nondet_states(const tgba* aut);
/// \brief Return true iff \a aut is deterministic.
///
/// This function is more efficient than count_nondet_states() when
/// the automaton is nondeterministic, because it can return before
/// the entire automaton has been explored.
bool is_deterministic(const tgba* aut);
/// @}
}
#endif // SPOT_TGBAALGOS_ISDET_HH

View file

@ -63,6 +63,7 @@
#include "tgbaalgos/scc.hh"
#include "tgbaalgos/emptiness_stats.hh"
#include "tgbaalgos/scc.hh"
#include "tgbaalgos/isdet.hh"
#include "kripkeparse/public.hh"
#include "tgbaalgos/simulation.hh"
@ -1367,6 +1368,8 @@ main(int argc, char** argv)
break;
case 13:
sub_stats_reachable(a).dump(std::cout);
std::cout << "nondeterministic states: "
<< count_nondet_states(a) << std::endl;
break;
case 14:
if (minimized == 0)