* src/tgbaalgos/se05.hh, src/tgbaalgos/tau03.hh: Typo.
* src/tgbaalgos/tau03.cc: Suppress optimisations, the algorithm is now the original one. * src/tgbaalgos/tau03opt.hh, src/tgbaalgos/tau03opt.cc: New files implementing most of all the optimisations of tau03. * src/tgbaalgos/Makefile.am: Add them. * src/tgbatest/ltl2tgba.cc, src/tgbatest/randtgba.cc: Make them public. * src/tgbatest/tba_samples_from_spin.test: Test them.
This commit is contained in:
parent
321177331d
commit
121d582480
10 changed files with 635 additions and 77 deletions
11
ChangeLog
11
ChangeLog
|
|
@ -1,3 +1,14 @@
|
||||||
|
2004-11-17 Poitrenaud Denis <denis@src.lip6.fr>
|
||||||
|
|
||||||
|
* src/tgbaalgos/se05.hh, src/tgbaalgos/tau03.hh: Typo.
|
||||||
|
* src/tgbaalgos/tau03.cc: Suppress optimisations, the algorithm is now
|
||||||
|
the original one.
|
||||||
|
* src/tgbaalgos/tau03opt.hh, src/tgbaalgos/tau03opt.cc: New files
|
||||||
|
implementing most of all the optimisations of tau03.
|
||||||
|
* src/tgbaalgos/Makefile.am: Add them.
|
||||||
|
* src/tgbatest/ltl2tgba.cc, src/tgbatest/randtgba.cc: Make them public.
|
||||||
|
* src/tgbatest/tba_samples_from_spin.test: Test them.
|
||||||
|
|
||||||
2004-11-17 Alexandre Duret-Lutz <adl@src.lip6.fr>
|
2004-11-17 Alexandre Duret-Lutz <adl@src.lip6.fr>
|
||||||
|
|
||||||
* src/tgba/tgba.hh, src/tgbaalgos/ltl2tgba_fm.hh,
|
* src/tgba/tgba.hh, src/tgbaalgos/ltl2tgba_fm.hh,
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ tgbaalgos_HEADERS = \
|
||||||
se05.hh \
|
se05.hh \
|
||||||
stats.hh \
|
stats.hh \
|
||||||
tau03.hh \
|
tau03.hh \
|
||||||
|
tau03opt.hh \
|
||||||
reductgba_sim.hh
|
reductgba_sim.hh
|
||||||
|
|
||||||
noinst_LTLIBRARIES = libtgbaalgos.la
|
noinst_LTLIBRARIES = libtgbaalgos.la
|
||||||
|
|
@ -69,6 +70,7 @@ libtgbaalgos_la_SOURCES = \
|
||||||
se05.cc \
|
se05.cc \
|
||||||
stats.cc \
|
stats.cc \
|
||||||
tau03.cc \
|
tau03.cc \
|
||||||
|
tau03opt.cc \
|
||||||
reductgba_sim.cc \
|
reductgba_sim.cc \
|
||||||
reductgba_sim_del.cc
|
reductgba_sim_del.cc
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,4 +145,4 @@ namespace spot
|
||||||
/// @}
|
/// @}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // SPOT_TGBAALGOS_MAGIC_HH
|
#endif // SPOT_TGBAALGOS_SE05_HH
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@
|
||||||
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||||
// 02111-1307, USA.
|
// 02111-1307, USA.
|
||||||
|
|
||||||
|
/// FIXME: Add
|
||||||
|
/// - the computation of a counter example if detected.
|
||||||
|
/// - a bit-state hashing version.
|
||||||
|
|
||||||
//#define TRACE
|
//#define TRACE
|
||||||
|
|
||||||
#ifdef TRACE
|
#ifdef TRACE
|
||||||
|
|
@ -39,7 +43,7 @@ namespace spot
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
enum color {WHITE, CYAN, BLUE};
|
enum color {WHITE, BLUE};
|
||||||
|
|
||||||
/// \brief Emptiness checker on spot::tgba automata having at most one
|
/// \brief Emptiness checker on spot::tgba automata having at most one
|
||||||
/// accepting condition (i.e. a TBA).
|
/// accepting condition (i.e. a TBA).
|
||||||
|
|
@ -77,17 +81,16 @@ namespace spot
|
||||||
/// accepting path.
|
/// accepting path.
|
||||||
virtual emptiness_check_result* check()
|
virtual emptiness_check_result* check()
|
||||||
{
|
{
|
||||||
if (!st_red.empty())
|
if (!st_blue.empty())
|
||||||
{
|
{
|
||||||
assert(!st_blue.empty());
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
assert(st_blue.empty());
|
assert(st_red.empty());
|
||||||
nbn = nbt = 0;
|
nbn = nbt = 0;
|
||||||
sts = mdp = 0;
|
sts = mdp = 0;
|
||||||
const state* s0 = a->get_init_state();
|
const state* s0 = a->get_init_state();
|
||||||
++nbn;
|
++nbn;
|
||||||
h.add_new_state(s0, CYAN);
|
h.add_new_state(s0, BLUE);
|
||||||
push(st_blue, s0, bddfalse, bddfalse);
|
push(st_blue, s0, bddfalse, bddfalse);
|
||||||
if (dfs_blue())
|
if (dfs_blue())
|
||||||
return new emptiness_check_result;
|
return new emptiness_check_result;
|
||||||
|
|
@ -146,9 +149,6 @@ namespace spot
|
||||||
/// by the last dfs visiting it.
|
/// by the last dfs visiting it.
|
||||||
heap h;
|
heap h;
|
||||||
|
|
||||||
/// State targeted by the red dfs.
|
|
||||||
const state* target;
|
|
||||||
|
|
||||||
/// The automata to check.
|
/// The automata to check.
|
||||||
const tgba* a;
|
const tgba* a;
|
||||||
|
|
||||||
|
|
@ -175,24 +175,23 @@ namespace spot
|
||||||
<< a->format_state(s_prime) << std::endl;
|
<< a->format_state(s_prime) << std::endl;
|
||||||
#endif
|
#endif
|
||||||
f.it->next();
|
f.it->next();
|
||||||
typename heap::color_ref c = h.get_color_ref(s_prime);
|
typename heap::color_ref c_prime = h.get_color_ref(s_prime);
|
||||||
if (c.is_white())
|
if (c_prime.is_white())
|
||||||
// Go down the edge (f.s, <label, acc>, s_prime)
|
// Go down the edge (f.s, <label, acc>, s_prime)
|
||||||
{
|
{
|
||||||
++nbn;
|
++nbn;
|
||||||
#ifdef TRACE
|
#ifdef TRACE
|
||||||
std::cout << " It is white, go down" << std::endl;
|
std::cout << " It is white, go down" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
h.add_new_state(s_prime, CYAN);
|
h.add_new_state(s_prime, BLUE);
|
||||||
push(st_blue, s_prime, label, acc);
|
push(st_blue, s_prime, label, acc);
|
||||||
}
|
}
|
||||||
else // Backtrack the edge (f.s, <label, acc>, s_prime)
|
else // Backtrack the edge (f.s, <label, acc>, s_prime)
|
||||||
{
|
{
|
||||||
#ifdef TRACE
|
#ifdef TRACE
|
||||||
std::cout << " It is cyan or blue, pop it"
|
std::cout << " It is blue, pop it" << std::endl;
|
||||||
<< std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
h.pop_notify(s_prime);
|
h.pop_notify(s_prime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -217,44 +216,35 @@ namespace spot
|
||||||
assert(!c_prime.is_white());
|
assert(!c_prime.is_white());
|
||||||
bdd acu = acc | c.get_acc();
|
bdd acu = acc | c.get_acc();
|
||||||
#ifdef TRACE
|
#ifdef TRACE
|
||||||
std::cout << "DFS_BLUE rescanning from: "
|
std::cout << "DFS_BLUE rescanning the arc from "
|
||||||
<< a->format_state(f.s) << std::endl;
|
<< a->format_state(f.s) << " to "
|
||||||
std::cout << " tests "
|
|
||||||
<< a->format_state(s_prime) << std::endl;
|
<< a->format_state(s_prime) << std::endl;
|
||||||
std::cout << " if ";
|
|
||||||
bdd_print_acc(std::cout, a->get_dict(), acu);
|
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << " is not included in ";
|
|
||||||
bdd_print_acc(std::cout, a->get_dict(), c_prime.get_acc());
|
|
||||||
std::cout << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
if ((c_prime.get_acc() & acu) != acu)
|
if ((c_prime.get_acc() & acu) != acu)
|
||||||
{
|
{
|
||||||
#ifdef TRACE
|
#ifdef TRACE
|
||||||
std::cout << " that is true, starts a red dfs with "
|
std::cout << " ";
|
||||||
|
bdd_print_acc(std::cout, a->get_dict(), acu);
|
||||||
|
std::cout << " is not included in ";
|
||||||
|
bdd_print_acc(std::cout, a->get_dict(),
|
||||||
|
c_prime.get_acc());
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << " Start a red dfs from "
|
||||||
<< a->format_state(s_prime)
|
<< a->format_state(s_prime)
|
||||||
<< " propagating: ";
|
<< " propagating: ";
|
||||||
bdd_print_acc(std::cout, a->get_dict(), acu);
|
bdd_print_acc(std::cout, a->get_dict(), acu);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
target = f.s;
|
|
||||||
c_prime.cumulate_acc(acu);
|
c_prime.cumulate_acc(acu);
|
||||||
push(st_red, s_prime, label, acc);
|
push(st_red, s_prime, label, acc);
|
||||||
if (target->compare(s_prime) == 0 &&
|
dfs_red(acu);
|
||||||
c_prime.get_acc() == all_cond)
|
|
||||||
{
|
|
||||||
delete i;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (dfs_red(acu) || c.get_acc() == all_cond)
|
|
||||||
{
|
|
||||||
delete i;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete i;
|
delete i;
|
||||||
c.set_color(BLUE);
|
if (c.get_acc() == all_cond)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
delete f.it;
|
delete f.it;
|
||||||
--sts;
|
--sts;
|
||||||
h.pop_notify(f.s);
|
h.pop_notify(f.s);
|
||||||
|
|
@ -264,7 +254,7 @@ namespace spot
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dfs_red(const bdd& acu)
|
void dfs_red(const bdd& acu)
|
||||||
{
|
{
|
||||||
assert(!st_red.empty());
|
assert(!st_red.empty());
|
||||||
|
|
||||||
|
|
@ -287,31 +277,33 @@ namespace spot
|
||||||
#endif
|
#endif
|
||||||
f.it->next();
|
f.it->next();
|
||||||
typename heap::color_ref c_prime = h.get_color_ref(s_prime);
|
typename heap::color_ref c_prime = h.get_color_ref(s_prime);
|
||||||
if (!c_prime.is_white() &&
|
if (!c_prime.is_white())
|
||||||
(c_prime.get_acc() & acu) != acu)
|
{
|
||||||
|
if ((c_prime.get_acc() & acu) != acu)
|
||||||
|
{
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " It is blue and propagation "
|
||||||
|
<< "is needed, go down" << std::endl;
|
||||||
|
#endif
|
||||||
|
c_prime.cumulate_acc(acu);
|
||||||
|
push(st_red, s_prime, label, acc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " It is blue and no propagation "
|
||||||
|
<< "is needed, pop it" << std::endl;
|
||||||
|
#endif
|
||||||
|
h.pop_notify(s_prime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
#ifdef TRACE
|
#ifdef TRACE
|
||||||
std::cout << " It is cyan or blue and propagation "
|
std::cout << " It is white, pop it" << std::endl;
|
||||||
<< "is nedded, go down"
|
|
||||||
<< std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
c_prime.cumulate_acc(acu);
|
delete s_prime;
|
||||||
push(st_red, s_prime, label, acc);
|
|
||||||
if (target->compare(s_prime) == 0 &&
|
|
||||||
c_prime.get_acc() == all_cond)
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef TRACE
|
|
||||||
std::cout << " It is white or no propagation is needed "
|
|
||||||
<< ", pop it"
|
|
||||||
<< std::endl;
|
|
||||||
#endif
|
|
||||||
if (c_prime.is_white())
|
|
||||||
delete s_prime;
|
|
||||||
h.pop_notify(s_prime);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else // Backtrack
|
else // Backtrack
|
||||||
{
|
{
|
||||||
|
|
@ -325,7 +317,6 @@ namespace spot
|
||||||
st_red.pop_front();
|
st_red.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ namespace spot
|
||||||
///
|
///
|
||||||
/// procedure dfs_blue (s)
|
/// procedure dfs_blue (s)
|
||||||
/// begin
|
/// begin
|
||||||
/// s.color = cyan;
|
/// s.color = blue;
|
||||||
/// s.acc = emptyset;
|
/// s.acc = emptyset;
|
||||||
/// for all t in post(s) do
|
/// for all t in post(s) do
|
||||||
/// if t.color == white then
|
/// if t.color == white then
|
||||||
|
|
@ -54,28 +54,19 @@ namespace spot
|
||||||
/// end for;
|
/// end for;
|
||||||
/// for all t in post(s) do
|
/// for all t in post(s) do
|
||||||
/// let (s, l, a, t) be the edge from s to t;
|
/// let (s, l, a, t) be the edge from s to t;
|
||||||
/// if a U s.acc not included in t.acc then
|
/// if s.acc U a not included in t.acc then
|
||||||
/// target = s;
|
|
||||||
/// call dfs_red(t, a U s.acc);
|
/// call dfs_red(t, a U s.acc);
|
||||||
/// end if;
|
/// end if;
|
||||||
/// end for;
|
/// end for;
|
||||||
/// if s.acc == all_acc then
|
/// if s.acc == all_acc then
|
||||||
/// report a cycle;
|
/// report a cycle;
|
||||||
/// end if;
|
/// end if;
|
||||||
/// s.color = blue;
|
|
||||||
/// end;
|
/// end;
|
||||||
///
|
///
|
||||||
/// procedure dfs_red(s, A)
|
/// procedure dfs_red(s, A)
|
||||||
/// begin
|
/// begin
|
||||||
/// s.acc = s.acc U A;
|
/// s.acc = s.acc U A;
|
||||||
/// // The following test has been added to the origiginal algorithm to
|
|
||||||
/// // report a cycle as soon as possible (and to mimic the classic magic
|
|
||||||
/// // search.
|
|
||||||
/// if s == target and s.acc == all_acc then
|
|
||||||
/// report a cycle;
|
|
||||||
/// end if;
|
|
||||||
/// for all t in post(s) do
|
/// for all t in post(s) do
|
||||||
/// let (s, l, a, t) be the edge from s to t;
|
|
||||||
/// if t.color != white and A not included in t.acc then
|
/// if t.color != white and A not included in t.acc then
|
||||||
/// call dfs_red(t, A);
|
/// call dfs_red(t, A);
|
||||||
/// end if;
|
/// end if;
|
||||||
|
|
@ -107,4 +98,4 @@ namespace spot
|
||||||
/// @}
|
/// @}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // SPOT_TGBAALGOS_MAGIC_HH
|
#endif // SPOT_TGBAALGOS_TAU03_HH
|
||||||
|
|
|
||||||
447
src/tgbaalgos/tau03opt.cc
Normal file
447
src/tgbaalgos/tau03opt.cc
Normal file
|
|
@ -0,0 +1,447 @@
|
||||||
|
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||||
|
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||||
|
// et Marie Curie.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
/// FIXME: Add
|
||||||
|
/// - the optimisation based on weights (a weight by accepting conditions),
|
||||||
|
/// - the computation of a counter example if detected.
|
||||||
|
/// - a bit-state hashing version.
|
||||||
|
|
||||||
|
//#define TRACE
|
||||||
|
|
||||||
|
#ifdef TRACE
|
||||||
|
#include <iostream>
|
||||||
|
#include "tgba/bddprint.hh"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <list>
|
||||||
|
#include <iterator>
|
||||||
|
#include "misc/hash.hh"
|
||||||
|
#include "tgba/tgba.hh"
|
||||||
|
#include "emptiness.hh"
|
||||||
|
#include "magic.hh"
|
||||||
|
#include "tau03opt.hh"
|
||||||
|
|
||||||
|
namespace spot
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
enum color {WHITE, CYAN, BLUE};
|
||||||
|
|
||||||
|
/// \brief Emptiness checker on spot::tgba automata having at most one
|
||||||
|
/// accepting condition (i.e. a TBA).
|
||||||
|
template <typename heap>
|
||||||
|
class tau03_opt_search : public emptiness_check
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// \brief Initialize the search algorithm on the automaton \a a
|
||||||
|
tau03_opt_search(const tgba *a, size_t size)
|
||||||
|
: h(size), a(a), all_acc(a->all_acceptance_conditions())
|
||||||
|
{
|
||||||
|
assert(a->number_of_acceptance_conditions() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~tau03_opt_search()
|
||||||
|
{
|
||||||
|
// Release all iterators on the stacks.
|
||||||
|
while (!st_blue.empty())
|
||||||
|
{
|
||||||
|
h.pop_notify(st_blue.front().s);
|
||||||
|
delete st_blue.front().it;
|
||||||
|
st_blue.pop_front();
|
||||||
|
}
|
||||||
|
while (!st_red.empty())
|
||||||
|
{
|
||||||
|
h.pop_notify(st_red.front().s);
|
||||||
|
delete st_red.front().it;
|
||||||
|
st_red.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Perform a Magic Search.
|
||||||
|
///
|
||||||
|
/// \return non null pointer iff the algorithm has found an
|
||||||
|
/// accepting path.
|
||||||
|
virtual emptiness_check_result* check()
|
||||||
|
{
|
||||||
|
if (!st_red.empty())
|
||||||
|
{
|
||||||
|
assert(!st_blue.empty());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
assert(st_blue.empty());
|
||||||
|
nbn = nbt = 0;
|
||||||
|
sts = mdp = 0;
|
||||||
|
const state* s0 = a->get_init_state();
|
||||||
|
++nbn;
|
||||||
|
h.add_new_state(s0, CYAN);
|
||||||
|
push(st_blue, s0, bddfalse, bddfalse);
|
||||||
|
if (dfs_blue())
|
||||||
|
return new emptiness_check_result;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::ostream& print_stats(std::ostream &os) const
|
||||||
|
{
|
||||||
|
os << nbn << " distinct nodes visited" << std::endl;
|
||||||
|
os << nbt << " transitions explored" << std::endl;
|
||||||
|
os << mdp << " nodes for the maximal stack depth" << std::endl;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \brief counters for statistics (number of distinct nodes, of
|
||||||
|
/// transitions and maximal stacks size.
|
||||||
|
int nbn, nbt, mdp, sts;
|
||||||
|
|
||||||
|
struct stack_item
|
||||||
|
{
|
||||||
|
stack_item(const state* n, tgba_succ_iterator* i, bdd l, bdd a)
|
||||||
|
: s(n), it(i), label(l), acc(a) {};
|
||||||
|
/// The visited state.
|
||||||
|
const state* s;
|
||||||
|
/// Design the next successor of \a s which has to be visited.
|
||||||
|
tgba_succ_iterator* it;
|
||||||
|
/// The label of the transition traversed to reach \a s
|
||||||
|
/// (false for the first one).
|
||||||
|
bdd label;
|
||||||
|
/// The acceptance set of the transition traversed to reach \a s
|
||||||
|
/// (false for the first one).
|
||||||
|
bdd acc;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::list<stack_item> stack_type;
|
||||||
|
|
||||||
|
void push(stack_type& st, const state* s,
|
||||||
|
const bdd& label, const bdd& acc)
|
||||||
|
{
|
||||||
|
++sts;
|
||||||
|
if (sts>mdp)
|
||||||
|
mdp = sts;
|
||||||
|
tgba_succ_iterator* i = a->succ_iter(s);
|
||||||
|
i->first();
|
||||||
|
st.push_front(stack_item(s, i, label, acc));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Stack of the blue dfs.
|
||||||
|
stack_type st_blue;
|
||||||
|
|
||||||
|
/// \brief Stack of the red dfs.
|
||||||
|
stack_type st_red;
|
||||||
|
|
||||||
|
/// \brief Map where each visited state is colored
|
||||||
|
/// by the last dfs visiting it.
|
||||||
|
heap h;
|
||||||
|
|
||||||
|
/// The automata to check.
|
||||||
|
const tgba* a;
|
||||||
|
|
||||||
|
/// The unique accepting condition of the automaton \a a.
|
||||||
|
bdd all_acc;
|
||||||
|
|
||||||
|
bool dfs_blue()
|
||||||
|
{
|
||||||
|
while (!st_blue.empty())
|
||||||
|
{
|
||||||
|
stack_item& f = st_blue.front();
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << "DFS_BLUE treats: "
|
||||||
|
<< a->format_state(f.s) << std::endl;
|
||||||
|
#endif
|
||||||
|
if (!f.it->done())
|
||||||
|
{
|
||||||
|
++nbt;
|
||||||
|
const state *s_prime = f.it->current_state();
|
||||||
|
bdd label = f.it->current_condition();
|
||||||
|
bdd acc = f.it->current_acceptance_conditions();
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " Visit the successor: "
|
||||||
|
<< a->format_state(s_prime) << std::endl;
|
||||||
|
#endif
|
||||||
|
f.it->next();
|
||||||
|
typename heap::color_ref c_prime = h.get_color_ref(s_prime);
|
||||||
|
if (c_prime.is_white())
|
||||||
|
// Go down the edge (f.s, <label, acc>, s_prime)
|
||||||
|
{
|
||||||
|
++nbn;
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " It is white, go down" << std::endl;
|
||||||
|
#endif
|
||||||
|
h.add_new_state(s_prime, CYAN);
|
||||||
|
push(st_blue, s_prime, label, acc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
typename heap::color_ref c = h.get_color_ref(f.s);
|
||||||
|
assert(!c.is_white());
|
||||||
|
if (c_prime.get_color() == CYAN &&
|
||||||
|
(c.get_acc() | acc | c_prime.get_acc()) == all_acc)
|
||||||
|
{
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " It is cyan and acceptance condition "
|
||||||
|
<< "is reached, report cycle" << std::endl;
|
||||||
|
#endif
|
||||||
|
c_prime.cumulate_acc(c.get_acc() | acc);
|
||||||
|
push(st_red, s_prime, label, acc);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else // Backtrack the edge (f.s, <label, acc>, s_prime)
|
||||||
|
{
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " It is cyan or blue, pop it"
|
||||||
|
<< std::endl;
|
||||||
|
#endif
|
||||||
|
h.pop_notify(s_prime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// Backtrack the edge
|
||||||
|
// (predecessor of f.s in st_blue, <f.label, f.acc>, f.s)
|
||||||
|
{
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " All the successors have been visited"
|
||||||
|
<< ", rescan this successors"
|
||||||
|
<< std::endl;
|
||||||
|
#endif
|
||||||
|
typename heap::color_ref c = h.get_color_ref(f.s);
|
||||||
|
assert(!c.is_white());
|
||||||
|
tgba_succ_iterator* i = a->succ_iter(f.s);
|
||||||
|
for (i->first(); !i->done(); i->next())
|
||||||
|
{
|
||||||
|
++nbt;
|
||||||
|
const state *s_prime = i->current_state();
|
||||||
|
bdd label = i->current_condition();
|
||||||
|
bdd acc = i->current_acceptance_conditions();
|
||||||
|
typename heap::color_ref c_prime = h.get_color_ref(s_prime);
|
||||||
|
assert(!c_prime.is_white());
|
||||||
|
bdd acu = acc | c.get_acc();
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << "DFS_BLUE rescanning the arc from "
|
||||||
|
<< a->format_state(f.s) << " to "
|
||||||
|
<< a->format_state(s_prime) << std::endl;
|
||||||
|
#endif
|
||||||
|
if ((c_prime.get_acc() & acu) != acu)
|
||||||
|
{
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " ";
|
||||||
|
bdd_print_acc(std::cout, a->get_dict(), acu);
|
||||||
|
std::cout << " is not included in ";
|
||||||
|
bdd_print_acc(std::cout, a->get_dict(),
|
||||||
|
c_prime.get_acc());
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << " Start a red dfs from "
|
||||||
|
<< a->format_state(s_prime)
|
||||||
|
<< " propagating: ";
|
||||||
|
bdd_print_acc(std::cout, a->get_dict(), acu);
|
||||||
|
std::cout << std::endl;
|
||||||
|
#endif
|
||||||
|
c_prime.cumulate_acc(acu);
|
||||||
|
push(st_red, s_prime, label, acc);
|
||||||
|
if (dfs_red(acu))
|
||||||
|
{
|
||||||
|
delete i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete i;
|
||||||
|
c.set_color(BLUE);
|
||||||
|
delete f.it;
|
||||||
|
--sts;
|
||||||
|
h.pop_notify(f.s);
|
||||||
|
st_blue.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dfs_red(const bdd& acu)
|
||||||
|
{
|
||||||
|
assert(!st_red.empty());
|
||||||
|
|
||||||
|
while (!st_red.empty())
|
||||||
|
{
|
||||||
|
stack_item& f = st_red.front();
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << "DFS_RED treats: "
|
||||||
|
<< a->format_state(f.s) << std::endl;
|
||||||
|
#endif
|
||||||
|
if (!f.it->done()) // Go down
|
||||||
|
{
|
||||||
|
++nbt;
|
||||||
|
const state *s_prime = f.it->current_state();
|
||||||
|
bdd label = f.it->current_condition();
|
||||||
|
bdd acc = f.it->current_acceptance_conditions();
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " Visit the successor: "
|
||||||
|
<< a->format_state(s_prime) << std::endl;
|
||||||
|
#endif
|
||||||
|
f.it->next();
|
||||||
|
typename heap::color_ref c_prime = h.get_color_ref(s_prime);
|
||||||
|
if (!c_prime.is_white())
|
||||||
|
{
|
||||||
|
if (c_prime.get_color() == CYAN &&
|
||||||
|
(c_prime.get_acc() | acu) == all_acc)
|
||||||
|
{
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " It is cyan and acceptance condition "
|
||||||
|
<< "is reached, report cycle" << std::endl;
|
||||||
|
#endif
|
||||||
|
c_prime.cumulate_acc(acu);
|
||||||
|
push(st_red, s_prime, label, acc);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if ((c_prime.get_acc() & acu) != acu)
|
||||||
|
{
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " It is cyan or blue and propagation "
|
||||||
|
<< "is needed, go down"
|
||||||
|
<< std::endl;
|
||||||
|
#endif
|
||||||
|
c_prime.cumulate_acc(acu);
|
||||||
|
push(st_red, s_prime, label, acc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " It is cyan or blue and no propagation "
|
||||||
|
<< "is needed , pop it" << std::endl;
|
||||||
|
#endif
|
||||||
|
h.pop_notify(s_prime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " It is white, pop it" << std::endl;
|
||||||
|
#endif
|
||||||
|
delete s_prime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // Backtrack
|
||||||
|
{
|
||||||
|
#ifdef TRACE
|
||||||
|
std::cout << " All the successors have been visited"
|
||||||
|
<< ", pop it" << std::endl;
|
||||||
|
#endif
|
||||||
|
--sts;
|
||||||
|
h.pop_notify(f.s);
|
||||||
|
delete f.it;
|
||||||
|
st_red.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class explicit_tau03_opt_search_heap
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
class color_ref
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
color_ref(color* c, bdd* a) :p(c), acc(a)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
color get_color() const
|
||||||
|
{
|
||||||
|
return *p;
|
||||||
|
}
|
||||||
|
void set_color(color c)
|
||||||
|
{
|
||||||
|
assert(!is_white());
|
||||||
|
*p = c;
|
||||||
|
}
|
||||||
|
const bdd& get_acc() const
|
||||||
|
{
|
||||||
|
assert(!is_white());
|
||||||
|
return *acc;
|
||||||
|
}
|
||||||
|
void cumulate_acc(const bdd& a)
|
||||||
|
{
|
||||||
|
assert(!is_white());
|
||||||
|
*acc |= a;
|
||||||
|
}
|
||||||
|
bool is_white() const
|
||||||
|
{
|
||||||
|
return p == 0;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
color *p;
|
||||||
|
bdd* acc;
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit_tau03_opt_search_heap(size_t)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~explicit_tau03_opt_search_heap()
|
||||||
|
{
|
||||||
|
hash_type::const_iterator s = h.begin();
|
||||||
|
while (s != h.end())
|
||||||
|
{
|
||||||
|
// Advance the iterator before deleting the "key" pointer.
|
||||||
|
const state* ptr = s->first;
|
||||||
|
++s;
|
||||||
|
delete ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
color_ref get_color_ref(const state*& s)
|
||||||
|
{
|
||||||
|
hash_type::iterator it = h.find(s);
|
||||||
|
if (it==h.end())
|
||||||
|
return color_ref(0, 0);
|
||||||
|
if (s!=it->first)
|
||||||
|
{
|
||||||
|
delete s;
|
||||||
|
s = it->first;
|
||||||
|
}
|
||||||
|
return color_ref(&(it->second.first), &(it->second.second));
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_new_state(const state* s, color c)
|
||||||
|
{
|
||||||
|
assert(h.find(s)==h.end());
|
||||||
|
h.insert(std::make_pair(s, std::make_pair(c, bddfalse)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void pop_notify(const state*)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
typedef Sgi::hash_map<const state*, std::pair<color, bdd>,
|
||||||
|
state_ptr_hash, state_ptr_equal> hash_type;
|
||||||
|
hash_type h;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous
|
||||||
|
|
||||||
|
emptiness_check* explicit_tau03_opt_search(const tgba *a)
|
||||||
|
{
|
||||||
|
return new tau03_opt_search<explicit_tau03_opt_search_heap>(a, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
91
src/tgbaalgos/tau03opt.hh
Normal file
91
src/tgbaalgos/tau03opt.hh
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||||
|
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||||
|
// et Marie Curie.
|
||||||
|
//
|
||||||
|
// 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_TAU03_OPT_HH
|
||||||
|
# define SPOT_TGBAALGOS_TAU03_OPT_HH
|
||||||
|
|
||||||
|
namespace spot
|
||||||
|
{
|
||||||
|
class tgba;
|
||||||
|
class emptiness_check;
|
||||||
|
|
||||||
|
/// \addtogroup emptiness_check_algorithms
|
||||||
|
/// @{
|
||||||
|
|
||||||
|
/// \brief Returns an emptiness checker on the spot::tgba automaton \a a.
|
||||||
|
///
|
||||||
|
/// \pre The automaton \a a must have at least one accepting condition.
|
||||||
|
///
|
||||||
|
/// During the visit of \a a, the returned checker stores explicitely all
|
||||||
|
/// the traversed states. The implemented algorithm is the following:
|
||||||
|
///
|
||||||
|
/// \verbatim
|
||||||
|
/// procedure check ()
|
||||||
|
/// begin
|
||||||
|
/// call dfs_blue(s0);
|
||||||
|
/// end;
|
||||||
|
///
|
||||||
|
/// procedure dfs_blue (s)
|
||||||
|
/// begin
|
||||||
|
/// s.color = cyan;
|
||||||
|
/// s.acc = emptyset;
|
||||||
|
/// for all t in post(s) do
|
||||||
|
/// let (s, l, a, t) be the edge from s to t;
|
||||||
|
/// if t.color == white then
|
||||||
|
/// call dfs_blue(t);
|
||||||
|
/// else if t.color == cyan && s.acc U a U t.acc == all_acc then
|
||||||
|
/// report a cycle;
|
||||||
|
/// end if;
|
||||||
|
/// end for;
|
||||||
|
/// for all t in post(s) do
|
||||||
|
/// let (s, l, a, t) be the edge from s to t;
|
||||||
|
/// if s.acc U a not included in t.acc then
|
||||||
|
/// call dfs_red(t, a U s.acc);
|
||||||
|
/// end if;
|
||||||
|
/// end for;
|
||||||
|
/// s.color = blue;
|
||||||
|
/// end;
|
||||||
|
///
|
||||||
|
/// procedure dfs_red(s, A)
|
||||||
|
/// begin
|
||||||
|
/// s.acc = s.acc U A;
|
||||||
|
/// for all t in post(s) do
|
||||||
|
/// let (s, l, a, t) be the edge from s to t;
|
||||||
|
/// if t.color != white then
|
||||||
|
/// if t.color == cyan && A U t.acc == all_acc then
|
||||||
|
/// report a cycle;
|
||||||
|
/// else if A not included in t.acc then
|
||||||
|
/// call dfs_red(t, A);
|
||||||
|
/// end if;
|
||||||
|
/// end if;
|
||||||
|
/// end for;
|
||||||
|
/// end;
|
||||||
|
/// \endverbatim
|
||||||
|
///
|
||||||
|
/// This algorithm is an optimisation of the one implemented in
|
||||||
|
/// spot::explicit_tau03_search.
|
||||||
|
///
|
||||||
|
emptiness_check* explicit_tau03_opt_search(const tgba *a);
|
||||||
|
|
||||||
|
/// @}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SPOT_TGBAALGOS_TAU03_OPT_HH
|
||||||
|
|
@ -38,6 +38,7 @@
|
||||||
#include "tgbaalgos/magic.hh"
|
#include "tgbaalgos/magic.hh"
|
||||||
#include "tgbaalgos/se05.hh"
|
#include "tgbaalgos/se05.hh"
|
||||||
#include "tgbaalgos/tau03.hh"
|
#include "tgbaalgos/tau03.hh"
|
||||||
|
#include "tgbaalgos/tau03opt.hh"
|
||||||
#include "tgbaalgos/gtec/gtec.hh"
|
#include "tgbaalgos/gtec/gtec.hh"
|
||||||
#include "tgbaalgos/gtec/ce.hh"
|
#include "tgbaalgos/gtec/ce.hh"
|
||||||
#include "tgbaparse/public.hh"
|
#include "tgbaparse/public.hh"
|
||||||
|
|
@ -128,7 +129,8 @@ syntax(char* prog)
|
||||||
<< std::endl
|
<< std::endl
|
||||||
<< " bsh_se05_search_repeated[(heap size in MB - 10MB"
|
<< " bsh_se05_search_repeated[(heap size in MB - 10MB"
|
||||||
<< " by default)]" << std::endl
|
<< " by default)]" << std::endl
|
||||||
<< " tau03_search" << std::endl;
|
<< " tau03_search" << std::endl
|
||||||
|
<< " tau03_opt_search" << std::endl;
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -147,8 +149,8 @@ main(int argc, char** argv)
|
||||||
int output = 0;
|
int output = 0;
|
||||||
int formula_index = 0;
|
int formula_index = 0;
|
||||||
std::string echeck_algo;
|
std::string echeck_algo;
|
||||||
enum { None, Couvreur, Couvreur2, MagicSearch, Se05Search, Tau03Search }
|
enum { None, Couvreur, Couvreur2, MagicSearch, Se05Search,
|
||||||
echeck = None;
|
Tau03Search, Tau03OptSearch } echeck = None;
|
||||||
enum { NoneDup, BFS, DFS } dupexp = NoneDup;
|
enum { NoneDup, BFS, DFS } dupexp = NoneDup;
|
||||||
bool search_many = false;
|
bool search_many = false;
|
||||||
bool bit_state_hashing = false;
|
bool bit_state_hashing = false;
|
||||||
|
|
@ -415,6 +417,10 @@ main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
echeck = Tau03Search;
|
echeck = Tau03Search;
|
||||||
}
|
}
|
||||||
|
else if (echeck_algo == "tau03_opt_search")
|
||||||
|
{
|
||||||
|
echeck = Tau03OptSearch;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "unknown emptiness-check: " << echeck_algo << std::endl;
|
std::cerr << "unknown emptiness-check: " << echeck_algo << std::endl;
|
||||||
|
|
@ -669,6 +675,18 @@ main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
ec = spot::explicit_tau03_search(a);
|
ec = spot::explicit_tau03_search(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case Tau03OptSearch:
|
||||||
|
if (a->number_of_acceptance_conditions() == 0)
|
||||||
|
{
|
||||||
|
std::cout << "To apply tau03_opt_search, the automaton must "
|
||||||
|
<< "have at least on accepting condition. "
|
||||||
|
<< "Try with another algorithm." << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ec = spot::explicit_tau03_opt_search(a);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@
|
||||||
#include "tgbaalgos/magic.hh"
|
#include "tgbaalgos/magic.hh"
|
||||||
#include "tgbaalgos/se05.hh"
|
#include "tgbaalgos/se05.hh"
|
||||||
#include "tgbaalgos/tau03.hh"
|
#include "tgbaalgos/tau03.hh"
|
||||||
|
#include "tgbaalgos/tau03opt.hh"
|
||||||
#include "tgbaalgos/replayrun.hh"
|
#include "tgbaalgos/replayrun.hh"
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -212,6 +213,10 @@ main(int argc, char** argv)
|
||||||
ec_obj.push_back(spot::explicit_tau03_search(a));
|
ec_obj.push_back(spot::explicit_tau03_search(a));
|
||||||
ec_name.push_back("explicit_tau03_search");
|
ec_name.push_back("explicit_tau03_search");
|
||||||
ec_safe.push_back(true);
|
ec_safe.push_back(true);
|
||||||
|
|
||||||
|
ec_obj.push_back(spot::explicit_tau03_opt_search(a));
|
||||||
|
ec_name.push_back("explicit_tau03_opt_search");
|
||||||
|
ec_safe.push_back(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt_n_acc <= 1)
|
if (opt_n_acc <= 1)
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ expect_ce()
|
||||||
./ltl2tgba -X -ese05_search "$1"
|
./ltl2tgba -X -ese05_search "$1"
|
||||||
./ltl2tgba -X -ebsh_se05_search "$1"
|
./ltl2tgba -X -ebsh_se05_search "$1"
|
||||||
./ltl2tgba -X -etau03_search "$1"
|
./ltl2tgba -X -etau03_search "$1"
|
||||||
|
./ltl2tgba -X -etau03_opt_search "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
expect_no()
|
expect_no()
|
||||||
|
|
@ -44,6 +45,7 @@ expect_no()
|
||||||
./ltl2tgba -X -Ese05_search "$1"
|
./ltl2tgba -X -Ese05_search "$1"
|
||||||
./ltl2tgba -X -Ebsh_se05_search "$1"
|
./ltl2tgba -X -Ebsh_se05_search "$1"
|
||||||
./ltl2tgba -X -Etau03_search "$1"
|
./ltl2tgba -X -Etau03_search "$1"
|
||||||
|
./ltl2tgba -X -Etau03_opt_search "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
dir=$srcdir/tba_samples_from_spin
|
dir=$srcdir/tba_samples_from_spin
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue