* src/tgbaalgos/magic.cc: rewrite to externalize the heap and

prepare it to a bit state hashing version.
* src/tgbaalgos/magic.hh: adapt to the new interface of
magic_search and se05_search.
* src/tgbaalgos/se05.cc: new file.
* src/tgbaalgos/Makefile.am: Add it.
* src/tgbatest/ltl2tgba.cc: Add new emptiness check.
* src/tgbatest/emptchk.test: more tests.
* src/tgbatest/dfs.test: new file.
* src/tgbatest/Makefile.am: Add it.
This commit is contained in:
Denis Poitrenaud 2004-11-09 17:22:58 +00:00
parent 908b6129f4
commit f52082bcfb
9 changed files with 1226 additions and 254 deletions

View file

@ -1,3 +1,16 @@
2004-11-09 Poitrenaud Denis <denis@src.lip6.fr>
* src/tgbaalgos/magic.cc: rewrite to externalize the heap and
prepare it to a bit state hashing version.
* src/tgbaalgos/magic.hh: adapt to the new interface of
magic_search and se05_search.
* src/tgbaalgos/se05.cc: new file.
* src/tgbaalgos/Makefile.am: Add it.
* src/tgbatest/ltl2tgba.cc: Add new emptiness check.
* src/tgbatest/emptchk.test: more tests.
* src/tgbatest/dfs.test: new file.
* src/tgbatest/Makefile.am: Add it.
2004-11-09 Alexandre Duret-Lutz <adl@src.lip6.fr> 2004-11-09 Alexandre Duret-Lutz <adl@src.lip6.fr>
* src/tgbaalgos/emptiness.cc (print_tgba_run): Output the * src/tgbaalgos/emptiness.cc (print_tgba_run): Output the

View file

@ -62,6 +62,7 @@ libtgbaalgos_la_SOURCES = \
replayrun.cc \ replayrun.cc \
rundotdec.cc \ rundotdec.cc \
save.cc \ save.cc \
se05.cc \
stats.cc \ stats.cc \
reductgba_sim.cc \ reductgba_sim.cc \
reductgba_sim_del.cc reductgba_sim_del.cc

View file

@ -19,163 +19,397 @@
// 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.
#include <iostream>
#include "misc/hash.hh"
#include <list>
#include <iterator> #include <iterator>
#include <cassert> #include <cassert>
#include "magic.hh" #include "magic.hh"
#include "tgba/bddprint.hh"
namespace spot namespace spot
{ {
magic_search::result::result(magic_search& ms) namespace
: ms_(ms)
{ {
} enum color {WHITE, BLUE, RED};
tgba_run* /// \brief Emptiness checker on spot::tgba automata having at most one
magic_search::result::accepting_run() /// accepting condition (i.e. a TBA).
{ template <typename heap>
tgba_run* run = new tgba_run; class magic_search : public emptiness_check
{
stack_type::const_reverse_iterator i, e = ms_.stack.rend(); public:
tstack_type::const_reverse_iterator ti; /// \brief Initialize the Magic Search algorithm on the automaton \a a
tgba_run::steps* l = &run->prefix; ///
/// \pre The automaton \a a must have at most one accepting
for (i = ms_.stack.rbegin(), ti = ms_.tstack.rbegin(); i != e; ++i, ++ti) /// condition (i.e. it is a TBA).
magic_search(const tgba *a)
: a(a), all_cond(a->all_acceptance_conditions())
{ {
if (i->first.s->compare(ms_.x) == 0) assert(a->number_of_acceptance_conditions() <= 1);
l = &run->cycle;
tgba_run::step s = { i->first.s->clone(), ti->first, ti->second };
l->push_back(s);
} }
return run; virtual ~magic_search()
}
magic_search::magic_search(const tgba_tba_proxy* a)
: a(a), x(0)
{
}
magic_search::~magic_search()
{
hash_type::const_iterator s = h.begin();
while (s != h.end())
{ {
// Advance the iterator before deleting the "key" pointer. // Release all iterators on the stacks.
const state* ptr = s->first; while (!st_blue.empty())
++s; {
delete ptr; h.pop_notify(st_blue.front().s);
} delete st_blue.front().it;
delete x; st_blue.pop_front();
// Release all iterators on the stack. }
while (!stack.empty()) while (!st_red.empty())
{ {
delete stack.front().second; h.pop_notify(st_red.front().s);
stack.pop_front(); delete st_red.front().it;
} st_red.pop_front();
} }
void
magic_search::push(const state* s, bool m)
{
tgba_succ_iterator* i = a->succ_iter(s);
i->first();
hash_type::iterator hi = h.find(s);
if (hi == h.end())
{
magic d = { !m, m };
h[s] = d;
}
else
{
hi->second.seen_without |= !m;
hi->second.seen_with |= m;
if (hi->first != s)
delete s;
s = hi->first;
} }
magic_state ms = { s, m }; /// \brief Perform a Magic Search.
stack.push_front(state_iter_pair(ms, i)); ///
} /// \return non null pointer iff the algorithm has found a
/// new accepting path.
bool ///
magic_search::has(const state* s, bool m) const /// check() can be called several times (until it returns a null
{ /// pointer) to enumerate all the visited accepting paths. The method
hash_type::const_iterator i = h.find(s); /// visits only a finite set of accepting paths.
if (i == h.end()) virtual emptiness_check_result* check()
return false;
if (!m && i->second.seen_without)
return true;
if (m && i->second.seen_with)
return true;
return false;
}
emptiness_check_result*
magic_search::check()
{
if (stack.empty())
// It's a new search.
push(a->get_init_state(), false);
else
// Remove the transition to the cycle root.
tstack.pop_front();
assert(stack.size() == 1 + tstack.size());
while (!stack.empty())
{ {
recurse: nbn = nbt = 0;
magic_search::state_iter_pair& p = stack.front(); sts = mdp = st_blue.size() + st_red.size();
tgba_succ_iterator* i = p.second; if (st_red.empty())
const bool magic = p.first.m; {
assert(st_blue.empty());
while (!i->done()) const state* s0 = a->get_init_state();
{ ++nbn;
const state* s_prime = i->current_state(); h.add_new_state(s0, BLUE);
bdd c = i->current_condition(); push(st_blue, s0, bddfalse, bddfalse);
bdd acc = i->current_acceptance_conditions(); if (dfs_blue())
i->next(); return new result(*this);
if (magic && 0 == s_prime->compare(x)) }
{ else
delete s_prime; {
tstack.push_front (tstack_item(c, acc)); h.pop_notify(st_red.front().s);
assert(stack.size() == tstack.size()); delete st_red.front().it;
return new result(*this); st_red.pop_front();
} if (!st_red.empty() && dfs_red())
if (!has(s_prime, magic)) return new result(*this);
{ else
push(s_prime, magic); if (dfs_blue())
tstack.push_front (tstack_item(c, acc)); return new result(*this);
goto recurse; }
} return 0;
delete s_prime;
}
const state* s = p.first.s;
delete i;
stack.pop_front();
if (!magic && a->state_is_accepting(s))
{
if (!has(s, true))
{
delete x;
x = s->clone();
push(s, true);
continue;
}
}
if (!stack.empty())
tstack.pop_front();
} }
assert(tstack.empty()); virtual std::ostream& print_stats(std::ostream &os) const
return 0; {
os << nbn << " distinct nodes visited" << std::endl;
os << nbt << " transitions explored" << std::endl;
os << mdp << " nodes for the maximal stack depth" << std::endl;
if (!st_red.empty())
{
assert(!st_blue.empty());
os << st_blue.size() + st_red.size() - 1
<< " nodes for the counter example" << 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 followed to reach \a s
/// (false for the first one).
bdd label;
/// The acc set of the transition followed 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;
/// State targeted by the red dfs.
const state* target;
/// The automata to check.
const tgba* a;
/// The automata to check.
bdd all_cond;
bool dfs_blue()
{
while (!st_blue.empty())
{
stack_item& f = st_blue.front();
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();
f.it->next();
typename heap::color_ref c = h.get_color_ref(s_prime);
if (c.is_null())
// Go down the edge (f.s, <label, acc>, s_prime)
{
++nbn;
h.add_new_state(s_prime, BLUE);
push(st_blue, s_prime, label, acc);
}
else // Backtrack the edge (f.s, <label, acc>, s_prime)
{
if (c.get() == BLUE && acc == all_cond)
// the test 'c.get() == BLUE' is added to limit
// the number of runs reported by successive
// calls to the check method. Without this
// functionnality, the test can be ommited.
{
target = f.s;
c.set(RED);
push(st_red, s_prime, label, acc);
if (dfs_red())
return true;
}
}
}
else
// Backtrack the edge
// (predecessor of f.s in st_blue, <f.label, f.acc>, f.s)
{
--sts;
stack_item f_dest(f);
delete f.it;
st_blue.pop_front();
typename heap::color_ref c = h.get_color_ref(f_dest.s);
assert(!c.is_null());
if (c.get() == BLUE && f_dest.acc == all_cond
&& !st_blue.empty())
// the test 'c.get() == BLUE' is added to limit
// the number of runs reported by successive
// calls to the check method. Without this
// functionnality, the test can be ommited.
{
target = st_blue.front().s;
c.set(RED);
push(st_red, f_dest.s, f_dest.label, f_dest.acc);
if (dfs_red())
return true;
}
else
h.pop_notify(f_dest.s);
}
}
return false;
}
bool dfs_red()
{
assert(!st_red.empty());
if (target->compare(st_red.front().s) == 0)
return true;
while (!st_red.empty())
{
stack_item& f = st_red.front();
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();
f.it->next();
typename heap::color_ref c = h.get_color_ref(s_prime);
if (c.is_null())
// Notice that this case is taken into account only to
// support successive calls to the check method. Without
// this functionnality, one can check assert(c.is_null()).
// Go down the edge (f.s, <label, acc>, s_prime)
{
++nbn;
h.add_new_state(s_prime, RED);
push(st_red, s_prime, label, acc);
}
else // Go down the edge (f.s, <label, acc>, s_prime)
{
if (c.get() != RED)
{
c.set(RED);
push(st_red, s_prime, label, acc);
if (target->compare(s_prime) == 0)
return true;
}
}
}
else // Backtrack
{
--sts;
h.pop_notify(f.s);
delete f.it;
st_red.pop_front();
}
}
return false;
}
class result: public emptiness_check_result
{
public:
result(magic_search& ms)
: ms_(ms)
{
}
virtual tgba_run* accepting_run()
{
assert(!ms_.st_blue.empty());
assert(!ms_.st_red.empty());
tgba_run* run = new tgba_run;
typename stack_type::const_reverse_iterator i, j, end;
tgba_run::steps* l;
l = &run->prefix;
i = ms_.st_blue.rbegin();
end = ms_.st_blue.rend(); --end;
j = i; ++j;
for (; i != end; ++i, ++j)
{
tgba_run::step s = { i->s->clone(), j->label, j->acc };
l->push_back(s);
}
l = &run->cycle;
j = ms_.st_red.rbegin();
tgba_run::step s = { i->s->clone(), j->label, j->acc };
l->push_back(s);
i = j; ++j;
end = ms_.st_red.rend(); --end;
for (; i != end; ++i, ++j)
{
tgba_run::step s = { i->s->clone(), j->label, j->acc };
l->push_back(s);
}
return run;
}
private:
magic_search& ms_;
};
};
class explicit_magic_search_heap
{
public:
class color_ref
{
public:
color_ref(color* c) :p(c)
{
}
int get() const
{
return *p;
}
void set(color c)
{
assert(!is_null());
*p=c;
}
bool is_null() const
{
return p==0;
}
private:
color *p;
};
explicit_magic_search_heap()
{
}
~explicit_magic_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);
if (s!=it->first)
{
delete s;
s = it->first;
}
return color_ref(&(it->second));
}
void add_new_state(const state* s, color c)
{
assert(h.find(s)==h.end());
h.insert(std::make_pair(s, c));
}
void pop_notify(const state*)
{
}
private:
typedef Sgi::hash_map<const state*, color,
state_ptr_hash, state_ptr_equal> hash_type;
hash_type h;
};
} // anonymous
emptiness_check* explicit_magic_search(const tgba *a)
{
return new magic_search<explicit_magic_search_heap>(a);
} }
} }

View file

@ -22,107 +22,148 @@
#ifndef SPOT_TGBAALGOS_MAGIC_HH #ifndef SPOT_TGBAALGOS_MAGIC_HH
# define SPOT_TGBAALGOS_MAGIC_HH # define SPOT_TGBAALGOS_MAGIC_HH
#include "misc/hash.hh" #include "tgba/tgba.hh"
#include <list>
#include <utility>
#include <ostream>
#include "tgba/tgbatba.hh"
#include "emptiness.hh" #include "emptiness.hh"
namespace spot namespace spot
{ {
/// \brief Emptiness check on spot::tgba_tba_proxy automata using /// \brief Returns an emptiness check on the spot::tgba automaton \a a.
/// the Magic Search algorithm. ///
/// \pre The automaton \a a must have at most one accepting condition (i.e.
/// it is a TBA).
///
/// The method \a check() of the returned checker can be called several times
/// (until it returns a null pointer) to enumerate all the visited accepting
/// paths. The method visits only a finite set of accepting paths.
///
/// The implemented algorithm is the following.
/// ///
/// This algorithm comes from
/// \verbatim /// \verbatim
/// @InProceedings{ godefroid.93.pstv, /// procedure nested_dfs ()
/// author = {Patrice Godefroid and Gerard .J. Holzmann}, /// begin
/// title = {On the verification of temporal properties}, /// call dfs_blue(s0);
/// booktitle = {Proceedings of the 13th IFIP TC6/WG6.1 International /// end;
/// Symposium on Protocol Specification, Testing, and ///
/// Verification (PSTV'93)}, /// procedure dfs_blue (s)
/// month = {May}, /// begin
/// editor = {Andr{\'e} A. S. Danthine and Guy Leduc /// s.color = blue;
/// and Pierre Wolper}, /// for all t in post(s) do
/// address = {Liege, Belgium}, /// if t.color == white then
/// pages = {109--124}, /// call dfs_blue(t);
/// publisher = {North-Holland}, /// end if;
/// year = {1993}, /// if (the edge (s,t) is accepting) then
/// series = {IFIP Transactions}, /// target = s;
/// volume = {C-16}, /// call dfs_red(t);
/// isbn = {0-444-81648-8} /// end if;
/// } /// end for;
/// end;
///
/// procedure dfs_red(s)
/// begin
/// s.color = red;
/// if s == target then
/// report cycle
/// end if;
/// for all t in post(s) do
/// if t.color != red then
/// call dfs_red(t);
/// end if;
/// end for;
/// end;
/// \endverbatim /// \endverbatim
struct magic_search : public emptiness_check ///
{ /// It is an adaptation to TBA of the Magic Search algorithm
/// Initialize the Magic Search algorithm on the automaton \a a. /// which deals with accepting states and is presented in
magic_search(const tgba_tba_proxy *a); ///
virtual ~magic_search(); /// \verbatim
/// Article{ courcoubertis.92.fmsd,
/// author = {Costas Courcoubetis and Moshe Y. Vardi and Pierre
/// Wolper and Mihalis Yannakakis},
/// title = {Memory-Efficient Algorithm for the Verification of
/// Temporal Properties},
/// journal = {Formal Methods in System Design},
/// pages = {275--288},
/// year = {1992},
/// volume = {1}
/// }
/// \endverbatim
emptiness_check* explicit_magic_search(const tgba *a);
/// \brief Perform a Magic Search. /// \brief Returns an emptiness check on the spot::tgba automaton \a a.
/// ///
/// \return true iff the algorithm has found a new accepting /// \pre The automaton \a a must have at most one accepting condition (i.e.
/// path. /// it is a TBA).
/// ///
/// check() can be called several times until it return false, /// The method \a check() of the returned checker can be called several times
/// to enumerate all accepting paths. /// (until it returns a null pointer) to enumerate all the visited accepting
virtual emptiness_check_result* check(); /// paths. The method visits only a finite set of accepting paths.
///
private: /// The implemented algorithm is the following:
///
// The names "stack", "h", and "x", are those used in the paper. /// procedure nested_dfs ()
/// begin
/// \brief Records whether a state has be seen with the magic bit /// weight = 0;
/// on or off. /// call dfs_blue(s0);
struct magic /// end;
{ ///
bool seen_without : 1; /// procedure dfs_blue (s)
bool seen_with : 1; /// begin
}; /// s.color = cyan;
/// s.weight = weight;
/// \brief A state for the spot::magic_search algorithm. /// for all t in post(s) do
struct magic_state /// if t.color == white then
{ /// if the edge (s,t) is accepting then
const state* s; /// weight = weight + 1;
bool m; ///< The state of the magic demon. /// end if;
}; /// call dfs_blue(t);
/// if the edge (s,t) is accepting then
typedef std::pair<magic_state, tgba_succ_iterator*> state_iter_pair; /// weight = weight - 1;
typedef std::list<state_iter_pair> stack_type; /// end if;
stack_type stack; ///< Stack of visited states on the path. /// else if t.color == cyan and
/// (the edge (s,t) is accepting or
typedef std::pair<bdd, bdd> tstack_item; /// weight > t.weight) then
typedef std::list<tstack_item> tstack_type; /// report cycle;
/// \brief Stack of transitions. /// end if;
/// /// if the edge (s,t) is accepting then
/// This is an addition to the data from the paper. /// call dfs_red(t);
tstack_type tstack; /// end if;
/// end for;
typedef Sgi::hash_map<const state*, magic, /// s.color = blue;
state_ptr_hash, state_ptr_equal> hash_type; /// end;
hash_type h; ///< Map of visited states. ///
/// procedure dfs_red(s)
/// Append a new state to the current path. /// begin
void push(const state* s, bool m); /// if s.color == cyan then
/// Check whether we already visited \a s with the Magic bit set to \a m. /// report cycle;
bool has(const state* s, bool m) const; /// end if;
/// s.color = red;
const tgba_tba_proxy* a; ///< The automata to check. /// for all t in post(s) do
/// The state for which we are currently seeking an SCC. /// if t.color != red then
const state* x; /// call dfs_red(t);
/// end if;
#ifndef SWIG /// end for;
class result: public emptiness_check_result /// end;
{ ///
public: /// It is an adaptation to TBA and an extension of the one
result(magic_search& ms); /// presented in
virtual tgba_run* accepting_run(); /// \verbatim
private: /// InProceedings{ schwoon.05.tacas,
magic_search& ms_; /// author = {Stephan Schwoon and Javier Esparza},
}; /// title = {A Note on On-The-Fly Verification Algorithms},
#endif // SWIG /// booktitle = {TACAS'05},
}; /// pages = {},
/// year = {2005},
/// volume = {},
/// series = {LNCS},
/// publisher = {Springer-Verlag}
/// }
/// \endverbatim
///
/// the extention consists in the introduction of a weight associated
/// to each state in the blue stack. The weight represents the number of
/// accepting arcs traversed to reach it from the initial state.
///
emptiness_check* explicit_se05_search(const tgba *a);
} }

483
src/tgbaalgos/se05.cc Normal file
View file

@ -0,0 +1,483 @@
// 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.
#include <iostream>
#include "misc/hash.hh"
#include <list>
#include <iterator>
#include <cassert>
#include "magic.hh"
namespace spot
{
namespace
{
enum color {WHITE, CYAN, BLUE, RED};
/// \brief Emptiness checker on spot::tgba automata having at most one
/// accepting condition (i.e. a TBA).
template <typename heap>
class se05_search : public emptiness_check
{
public:
/// \brief Initialize the Magic Search algorithm on the automaton \a a
///
/// \pre The automaton \a a must have at most one accepting
/// condition (i.e. it is a TBA).
se05_search(const tgba *a)
: current_weight(0), a(a), all_cond(a->all_acceptance_conditions())
{
assert(a->number_of_acceptance_conditions() <= 1);
}
virtual ~se05_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 a
/// new accepting path.
///
/// check() can be called several times (until it returns a null
/// pointer) to enumerate all the visited accepting paths. The method
/// visits only a finite set of accepting paths.
virtual emptiness_check_result* check()
{
nbn = nbt = 0;
sts = mdp = st_blue.size() + st_red.size();
if (st_red.empty())
{
assert(st_blue.empty());
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 result(*this);
}
else
{
h.pop_notify(st_red.front().s);
delete st_red.front().it;
st_red.pop_front();
if (!st_red.empty() && dfs_red())
return new result(*this);
else
if (dfs_blue())
return new result(*this);
}
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;
if (!st_red.empty())
{
assert(!st_blue.empty());
os << st_blue.size() + st_red.size() - 1
<< " nodes for the counter example" << 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 followed to reach \a s
/// (false for the first one).
bdd label;
/// The acc set of the transition followed 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 number of visited accepting arcs
/// in the blue stack.
int current_weight;
/// \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 automata to check.
bdd all_cond;
bool dfs_blue()
{
while (!st_blue.empty())
{
stack_item& f = st_blue.front();
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();
f.it->next();
typename heap::color_ref c = h.get_color_ref(s_prime);
if (c.is_null())
// Go down the edge (f.s, <label, acc>, s_prime)
{
if (acc == all_cond)
++current_weight;
++nbn;
h.add_new_state(s_prime, CYAN, current_weight);
push(st_blue, s_prime, label, acc);
}
else // Backtrack the edge (f.s, <label, acc>, s_prime)
{
if (c.get() == CYAN &&
(acc == all_cond || current_weight > c.get_weight()))
{
c.set(RED);
push(st_red, s_prime, label, acc);
return true;
}
else if (c.get() == BLUE && acc == all_cond)
{
// the test 'c.get() == BLUE' is added to limit
// the number of runs reported by successive
// calls to the check method. Without this
// functionnality, the test can be ommited.
c.set(RED);
push(st_red, s_prime, label, acc);
if (dfs_red())
return true;
}
}
}
else
// Backtrack the edge
// (predecessor of f.s in st_blue, <f.label, f.acc>, f.s)
{
--sts;
stack_item f_dest(f);
delete f.it;
st_blue.pop_front();
if (f_dest.acc == all_cond)
--current_weight;
typename heap::color_ref c = h.get_color_ref(f_dest.s);
assert(!c.is_null());
if (c.get() == BLUE && f_dest.acc == all_cond
&& !st_blue.empty())
// the test 'c.get() == BLUE' is added to limit
// the number of runs reported by successive
// calls to the check method. Without this
// functionnality, the test can be ommited.
{
c.set(RED);
push(st_red, f_dest.s, f_dest.label, f_dest.acc);
if (dfs_red())
return true;
}
else
{
c.set(BLUE);
h.pop_notify(f_dest.s);
}
}
}
return false;
}
bool dfs_red()
{
assert(!st_red.empty());
while (!st_red.empty())
{
stack_item& f = st_red.front();
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();
f.it->next();
typename heap::color_ref c = h.get_color_ref(s_prime);
if (c.is_null())
// Notice that this case is taken into account only to
// support successive calls to the check method. Without
// this functionnality => assert(c.is_null())
// Go down the edge (f.s, <label, acc>, s_prime)
{
++nbn;
h.add_new_state(s_prime, RED);
push(st_red, s_prime, label, acc);
}
else // Go down the edge (f.s, <label, acc>, s_prime)
{
if (c.get() == CYAN)
{
c.set(RED);
push(st_red, s_prime, label, acc);
return true;
}
if (c.get() == BLUE)
{
c.set(RED);
push(st_red, s_prime, label, acc);
}
}
}
else // Backtrack
{
--sts;
h.pop_notify(f.s);
delete f.it;
st_red.pop_front();
}
}
return false;
}
class result: public emptiness_check_result
{
public:
result(se05_search& ms)
: ms_(ms)
{
}
virtual tgba_run* accepting_run()
{
assert(!ms_.st_blue.empty());
assert(!ms_.st_red.empty());
tgba_run* run = new tgba_run;
typename stack_type::const_reverse_iterator i, j, end;
tgba_run::steps* l;
const state* target = ms_.st_red.front().s;
l = &run->prefix;
i = ms_.st_blue.rbegin();
end = ms_.st_blue.rend(); --end;
j = i; ++j;
for (; i != end; ++i, ++j)
{
if (l == &run->prefix && i->s->compare(target) == 0)
l = &run->cycle;
tgba_run::step s = { i->s->clone(), j->label, j->acc };
l->push_back(s);
}
if (l == &run->prefix && i->s->compare(target) == 0)
l = &run->cycle;
assert(l == &run->cycle);
j = ms_.st_red.rbegin();
tgba_run::step s = { i->s->clone(), j->label, j->acc };
l->push_back(s);
i = j; ++j;
end = ms_.st_red.rend(); --end;
for (; i != end; ++i, ++j)
{
tgba_run::step s = { i->s->clone(), j->label, j->acc };
l->push_back(s);
}
return run;
}
private:
se05_search& ms_;
};
};
class explicit_se05_search_heap
{
typedef Sgi::hash_map<const state*, int,
state_ptr_hash, state_ptr_equal> hcyan_type;
typedef Sgi::hash_map<const state*, color,
state_ptr_hash, state_ptr_equal> hash_type;
public:
class color_ref
{
public:
color_ref(hash_type* h, hcyan_type* hc, const state* s, int w)
: is_cyan(true), weight(w), ph(h), phc(hc), ps(s), pc(0)
{
}
color_ref(color* c)
: is_cyan(false), weight(0), ph(0), phc(0), ps(0), pc(c)
{
}
int get() const
{
if (is_cyan)
return CYAN; // the color cyan is fixed to 0
return *pc;
}
int get_weight() const
{
assert(is_cyan);
return weight;
}
void set(color c)
{
assert(!is_null());
if (is_cyan)
{
phc->erase(ps);
ph->insert(std::make_pair(ps, c));
}
else
{
*pc=c;
}
}
bool is_null() const
{
return !is_cyan && pc==0;
}
private:
bool is_cyan;
int weight; // weight of a cyan node
hash_type* ph; //point to the main hash table
hcyan_type* phc; // point to the hash table hcyan
const state* ps; // point to the state in hcyan
color *pc; // point to the color of a state stored in main hash table
};
explicit_se05_search_heap()
{
}
~explicit_se05_search_heap()
{
hcyan_type::const_iterator sc = hc.begin();
while (sc != hc.end())
{
const state* ptr = sc->first;
++sc;
delete ptr;
}
hash_type::const_iterator s = h.begin();
while (s != h.end())
{
const state* ptr = s->first;
++s;
delete ptr;
}
}
color_ref get_color_ref(const state*& s)
{
hcyan_type::iterator ic = hc.find(s);
if (ic==hc.end())
{
hash_type::iterator it = h.find(s);
if (it==h.end())
return color_ref(0); // unknown state
if (s!=it->first)
{
delete s;
s = it->first;
}
return color_ref(&(it->second)); // blue or red state
}
if (s!=ic->first)
{
delete s;
s = ic->first;
}
return color_ref(&h, &hc, ic->first, ic->second); // cyan state
}
void add_new_state(const state* s, color c, int w=0)
{
assert(hc.find(s)==hc.end() && h.find(s)==h.end());
if (c == CYAN)
hc.insert(std::make_pair(s, w));
else
h.insert(std::make_pair(s, c));
}
void pop_notify(const state*)
{
}
private:
hash_type h;
hcyan_type hc;
};
} // anonymous
emptiness_check* explicit_se05_search(const tgba *a)
{
return new se05_search<explicit_se05_search_heap>(a);
}
}

View file

@ -80,9 +80,14 @@ TESTS = \
reduccmp.test \ reduccmp.test \
reductgba.test \ reductgba.test \
emptchk.test \ emptchk.test \
magic.test \
se05.test \
emptchke.test \ emptchke.test \
dfs.test \
spotlbtt.test spotlbtt.test
EXTRA_DIST = $(TESTS) ltl2baw.pl EXTRA_DIST = $(TESTS) ltl2baw.pl
CLEANFILES = input input1 input2 input3 stdout expected config output1 output2 CLEANFILES = input input1 input2 input3 stdout expected config output1 output2 \
red blue_counter blue_last

170
src/tgbatest/dfs.test Executable file
View file

@ -0,0 +1,170 @@
#!/bin/sh
# 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.
. ./defs
set -e
cat >blue_counter <<'EOF'
acc = a;
s1, s2,, a;
s2, s3,,;
s3, s1,,;
s3, s4,,;
s4, s4,,;
s4, s5,,;
s4, s6,,;
s4, s7,,;
s4, s8,,;
s4, s9,,;
s5, s4,,;
s5, s5,,;
s5, s6,,;
s5, s7,,;
s5, s8,,;
s5, s9,,;
s6, s4,,;
s6, s5,,;
s6, s6,,;
s6, s7,,;
s6, s8,,;
s6, s9,,;
s7, s4,,;
s7, s5,,;
s7, s6,,;
s7, s7,,;
s7, s8,,;
s7, s9,,;
s8, s4,,;
s8, s5,,;
s8, s6,,;
s8, s7,,;
s8, s8,,;
s8, s9,,;
s9, s4,,;
s9, s5,,;
s9, s6,,;
s9, s7,,;
s9, s8,,;
s9, s9,,;
EOF
run 0 ./ltl2tgba -emagic_search -X blue_counter
run 0 ./ltl2tgba -ese05_search -X blue_counter
cat >blue_last <<'EOF'
acc = a;
s1, s2,,;
s2, s3,,;
s3, s1,, a;
s3, s4,,;
s4, s4,,;
s4, s5,,;
s4, s6,,;
s4, s7,,;
s4, s8,,;
s4, s9,,;
s5, s4,,;
s5, s5,,;
s5, s6,,;
s5, s7,,;
s5, s8,,;
s5, s9,,;
s6, s4,,;
s6, s5,,;
s6, s6,,;
s6, s7,,;
s6, s8,,;
s6, s9,,;
s7, s4,,;
s7, s5,,;
s7, s6,,;
s7, s7,,;
s7, s8,,;
s7, s9,,;
s8, s4,,;
s8, s5,,;
s8, s6,,;
s8, s7,,;
s8, s8,,;
s8, s9,,;
s9, s4,,;
s9, s5,,;
s9, s6,,;
s9, s7,,;
s9, s8,,;
s9, s9,,;
EOF
run 0 ./ltl2tgba -emagic_search -X blue_last
run 0 ./ltl2tgba -ese05_search -X blue_last
cat >red <<'EOF'
acc = a;
s1, s2,,;
s1, s3,, a;
s2, s3,,;
s3, s1,,;
s3, s4,,;
s4, s4,,;
s4, s5,,;
s4, s6,,;
s4, s7,,;
s4, s8,,;
s4, s9,,;
s5, s4,,;
s5, s5,,;
s5, s6,,;
s5, s7,,;
s5, s8,,;
s5, s9,,;
s6, s4,,;
s6, s5,,;
s6, s6,,;
s6, s7,,;
s6, s8,,;
s6, s9,,;
s7, s4,,;
s7, s5,,;
s7, s6,,;
s7, s7,,;
s7, s8,,;
s7, s9,,;
s8, s4,,;
s8, s5,,;
s8, s6,,;
s8, s7,,;
s8, s8,,;
s8, s9,,;
s9, s4,,;
s9, s5,,;
s9, s6,,;
s9, s7,,;
s9, s8,,;
s9, s9,,;
EOF
run 0 ./ltl2tgba -emagic_search -X red
run 0 ./ltl2tgba -ese05_search -X red
rm -f red blue_counter blue_last

View file

@ -43,6 +43,11 @@ expect_ce()
expect_ce_do -ecouvreur99_shy -f -D "$1" expect_ce_do -ecouvreur99_shy -f -D "$1"
expect_ce_do -emagic_search "$1" expect_ce_do -emagic_search "$1"
expect_ce_do -emagic_search -f "$1" expect_ce_do -emagic_search -f "$1"
run 0 ./ltl2tgba -ese05_search "$1"
run 0 ./ltl2tgba -ese05_search -f "$1"
# Expect multiple accepting runs
test `./ltl2tgba -emagic_search_repeated "$1" | grep Prefix: | wc -l` -ge $2
test `./ltl2tgba -ese05_search_repeated "$1" | grep Prefix: | wc -l` -ge $2
} }
expect_no() expect_no()
@ -57,22 +62,24 @@ expect_no()
run 0 ./ltl2tgba -Ecouvreur99_shy -f -D "$1" run 0 ./ltl2tgba -Ecouvreur99_shy -f -D "$1"
run 0 ./ltl2tgba -Emagic_search "$1" run 0 ./ltl2tgba -Emagic_search "$1"
run 0 ./ltl2tgba -Emagic_search -f "$1" run 0 ./ltl2tgba -Emagic_search -f "$1"
run 0 ./ltl2tgba -Ese05_search "$1"
run 0 ./ltl2tgba -Ese05_search -f "$1"
test `./ltl2tgba -emagic_search_repeated "!($1)" |
grep Prefix: | wc -l` -ge $2
test `./ltl2tgba -ese05_search_repeated "!($1)" |
grep Prefix: | wc -l` -ge $2
} }
expect_ce 'a' expect_ce 'a' 1
expect_ce 'a U b' expect_ce 'a U b' 2
expect_ce 'X a' expect_ce 'X a' 1
expect_ce 'a & b & c' expect_ce 'a & b & c' 1
expect_ce 'a | b | (c U (d & (g U (h ^ i))))' expect_ce 'a | b | (c U (d & (g U (h ^ i))))' 2
expect_ce 'Xa & (b U !a) & (b U !a)' expect_ce 'Xa & (b U !a) & (b U !a)' 1
expect_ce 'Fa & Xb & GFc & Gd' expect_ce 'Fa & Xb & GFc & Gd' 1
expect_ce 'Fa & Xa & GFc & Gc' expect_ce 'Fa & Xa & GFc & Gc' 2
expect_ce 'Fc & X(a | Xb) & GF(a | Xb) & Gc' expect_ce 'Fc & X(a | Xb) & GF(a | Xb) & Gc' 1
expect_ce '!((FF a) <=> (F x))' expect_ce '!((FF a) <=> (F x))' 3
expect_no '!((FF a) <=> (F a))' expect_no '!((FF a) <=> (F a))' 4
expect_no 'Xa && (!a U b) && !b && X!b' expect_no 'Xa && (!a U b) && !b && X!b' 5
expect_no '(a U !b) && Gb' expect_no '(a U !b) && Gb' 4
# Expect at least four accepting runs
test `./ltl2tgba -emagic_search_repeated 'FFx <=> Fx' |
grep Prefix: | wc -l` -ge 4

View file

@ -119,7 +119,9 @@ syntax(char* prog)
<< " couvreur99 (the default)" << std::endl << " couvreur99 (the default)" << std::endl
<< " couvreur99_shy" << std::endl << " couvreur99_shy" << std::endl
<< " magic_search" << std::endl << " magic_search" << std::endl
<< " magic_search_repeated" << std::endl; << " magic_search_repeated" << std::endl
<< " se05_search" << std::endl
<< " se05_search_repeated" << std::endl;
exit(2); exit(2);
} }
@ -137,7 +139,7 @@ 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 } echeck = None; enum { None, Couvreur, Couvreur2, MagicSearch, Se04Search } echeck = None;
enum { NoneDup, BFS, DFS } dupexp = NoneDup; enum { NoneDup, BFS, DFS } dupexp = NoneDup;
bool magic_many = false; bool magic_many = false;
bool expect_counter_example = false; bool expect_counter_example = false;
@ -347,6 +349,17 @@ main(int argc, char** argv)
degeneralize_opt = true; degeneralize_opt = true;
magic_many = true; magic_many = true;
} }
else if (echeck_algo == "se05_search")
{
echeck = Se04Search;
degeneralize_opt = true;
}
else if (echeck_algo == "se05_search_repeated")
{
echeck = Se04Search;
degeneralize_opt = true;
magic_many = true;
}
else else
{ {
std::cerr << "unknown emptiness-check: " << echeck_algo << std::endl; std::cerr << "unknown emptiness-check: " << echeck_algo << std::endl;
@ -569,7 +582,12 @@ main(int argc, char** argv)
case MagicSearch: case MagicSearch:
ec_a = degeneralized; ec_a = degeneralized;
ec = new spot::magic_search(degeneralized); ec = spot::explicit_magic_search(degeneralized);
break;
case Se04Search:
ec_a = degeneralized;
ec = spot::explicit_se05_search(degeneralized);
break; break;
} }