Commit 0f15d28f authored by Denis Poitrenaud's avatar Denis Poitrenaud
Browse files

* src/tgbaalgos/emptiness_stats.hh, src/tgbaalgos/weight.cc,

src/tgbaalgos/weight.hh: New files.
* src/tgbaalgos/Makefile.am: Add them.
* src/tgbaalgos/magic.cc, src/tgbaalgos/se05.cc,
src/tgbaalgos/tau03.cc, src/tgbaalgos/tau03opt.cc,
src/tgbaalgos/gtec/gtec.cc, src/tgbaalgos/gtec/status.cc,
src/tgbaalgos/gtec/status.hh, : Add emptiness check statistics
capability.
* src/tgbatest/randtgba.cc: Print these statistics.
* src/tgbatest/ltl2tgba.cc: tau03opt search can deal without acceptance
condition.
* src/tgbatest/emptchk.test: Test tau03opt search.
parent fc775a8b
2004-11-22 Poitrenaud Denis <denis@src.lip6.fr>
* src/tgbaalgos/emptiness_stats.hh, src/tgbaalgos/weight.cc,
src/tgbaalgos/weight.hh: New files.
* src/tgbaalgos/Makefile.am: Add them.
* src/tgbaalgos/magic.cc, src/tgbaalgos/se05.cc,
src/tgbaalgos/tau03.cc, src/tgbaalgos/tau03opt.cc,
src/tgbaalgos/gtec/gtec.cc, src/tgbaalgos/gtec/status.cc,
src/tgbaalgos/gtec/status.hh, : Add emptiness check statistics
capability.
* src/tgbatest/randtgba.cc: Print these statistics.
* src/tgbatest/ltl2tgba.cc: tau03opt search can deal without acceptance
condition.
* src/tgbatest/emptchk.test: Test tau03opt search.
2004-11-19 Alexandre Duret-Lutz <adl@src.lip6.fr>
* src/tgbaalgos/magic.hh, src/tgbaalgos/magic.cc,
......
......@@ -31,6 +31,7 @@ tgbaalgos_HEADERS = \
dottydec.hh \
dupexp.hh \
emptiness.hh \
emptiness_stats.hh \
lbtt.hh \
ltl2tgba_fm.hh \
ltl2tgba_lacim.hh \
......@@ -47,7 +48,8 @@ tgbaalgos_HEADERS = \
stats.hh \
tau03.hh \
tau03opt.hh \
reductgba_sim.hh
reductgba_sim.hh \
weight.hh
noinst_LTLIBRARIES = libtgbaalgos.la
libtgbaalgos_la_SOURCES = \
......@@ -72,6 +74,7 @@ libtgbaalgos_la_SOURCES = \
tau03.cc \
tau03opt.cc \
reductgba_sim.cc \
reductgba_sim_del.cc
reductgba_sim_del.cc \
weight.cc
libtgbaalgos_la_LIBADD = gtec/libgtec.la
// Copyright (C) 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_EC_STATS_HH
# define SPOT_TGBAALGOS_EC_STATS_HH
namespace spot
{
/// \addtogroup ec_misc
/// @{
class ec_statistics
{
public :
ec_statistics()
: states_(0), transitions_(0), depth_(0), max_depth_(0)
{
}
void set_states(int n)
{
states_ = n;
}
void inc_states()
{
++states_;
}
void inc_transitions()
{
++transitions_;
}
void inc_depth()
{
++depth_;
if (depth_ > max_depth_)
max_depth_ = depth_;
}
void dec_depth()
{
--depth_;
}
int states() const
{
return states_;
}
int transitions() const
{
return transitions_;
}
int max_depth() const
{
return max_depth_;
}
private :
unsigned states_; /// number of disctint visited states
unsigned transitions_; /// number of visited transitions
unsigned depth_; /// maximal depth of the stack(s)
unsigned max_depth_; /// maximal depth of the stack(s)
};
/// @}
}
#endif // SPOT_TGBAALGOS_EC_STATS_HH
......@@ -221,6 +221,7 @@ namespace spot
delete todo.top().second;
todo.pop();
}
set_states(ecs_->states());
return new couvreur99_check_result(ecs_);
}
}
......@@ -344,6 +345,7 @@ namespace spot
}
todo.pop();
}
set_states(ecs_->states());
return new couvreur99_check_result(ecs_);
}
}
......
......@@ -24,6 +24,7 @@
#include "status.hh"
#include "tgbaalgos/emptiness.hh"
#include "tgbaalgos/emptiness_stats.hh"
namespace spot
{
......@@ -71,7 +72,7 @@ namespace spot
/// tgba_succ_iterators: it must compute all successors of a state
/// at once in order to decide which to explore first, and must keep
/// a list of all unexplored successors in its DFS stack.
class couvreur99_check: public emptiness_check
class couvreur99_check: public emptiness_check, public ec_statistics
{
public:
couvreur99_check(const tgba* a,
......
......@@ -45,4 +45,10 @@ namespace spot
<< " strongly connected components in search stack"
<< std::endl;
}
int
couvreur99_check_status::states() const
{
return h->size();
}
}
......@@ -47,6 +47,9 @@ namespace spot
/// Output statistics about this object.
void print_stats(std::ostream& os) const;
/// Return the number of states visited by the search
int states() const;
};
}
......
......@@ -19,11 +19,18 @@
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//#define TRACE
#ifdef TRACE
#include <iostream>
#endif
#include <cassert>
#include <list>
#include "misc/hash.hh"
#include "tgba/tgba.hh"
#include "emptiness.hh"
#include "emptiness_stats.hh"
#include "magic.hh"
namespace spot
......@@ -35,7 +42,7 @@ namespace spot
/// \brief Emptiness checker on spot::tgba automata having at most one
/// accepting condition (i.e. a TBA).
template <typename heap>
class magic_search : public emptiness_check
class magic_search : public emptiness_check, public ec_statistics
{
public:
/// \brief Initialize the Magic Search algorithm on the automaton \a a
......@@ -43,7 +50,10 @@ namespace spot
/// \pre The automaton \a a must have at most one accepting
/// condition (i.e. it is a TBA).
magic_search(const tgba *a, size_t size)
: h(size), a(a), all_cond(a->all_acceptance_conditions())
: ec_statistics(),
h(size),
a(a),
all_cond(a->all_acceptance_conditions())
{
assert(a->number_of_acceptance_conditions() <= 1);
}
......@@ -75,13 +85,11 @@ namespace spot
/// 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;
inc_states();
h.add_new_state(s0, BLUE);
push(st_blue, s0, bddfalse, bddfalse);
if (dfs_blue())
......@@ -90,8 +98,7 @@ namespace spot
else
{
h.pop_notify(st_red.front().s);
delete st_red.front().it;
st_red.pop_front();
pop(st_red);
if (!st_red.empty() && dfs_red())
return new result(*this);
else
......@@ -103,9 +110,9 @@ namespace spot
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;
os << states() << " distinct nodes visited" << std::endl;
os << transitions() << " transitions explored" << std::endl;
os << max_depth() << " nodes for the maximal stack depth" << std::endl;
if (!st_red.empty())
{
assert(!st_blue.empty());
......@@ -116,9 +123,6 @@ namespace spot
}
private:
/// \brief counters for statistics (number of distinct nodes, of
/// transitions and maximal stacks size.
int nbn, nbt, mdp, sts;
struct stack_item
{
......@@ -141,14 +145,19 @@ namespace spot
void push(stack_type& st, const state* s,
const bdd& label, const bdd& acc)
{
++sts;
if (sts>mdp)
mdp = sts;
inc_depth();
tgba_succ_iterator* i = a->succ_iter(s);
i->first();
st.push_front(stack_item(s, i, label, acc));
}
void pop(stack_type& st)
{
dec_depth();
delete st.front().it;
st.pop_front();
}
/// \brief Stack of the blue dfs.
stack_type st_blue;
......@@ -173,66 +182,100 @@ namespace spot
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();
# ifdef TRACE
std::cout << " Visit the successor: "
<< a->format_state(s_prime) << std::endl;
# endif
bdd label = f.it->current_condition();
bdd acc = f.it->current_acceptance_conditions();
// Go down the edge (f.s, <label, acc>, s_prime)
f.it->next();
inc_transitions();
typename heap::color_ref c = h.get_color_ref(s_prime);
if (c.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
inc_states();
h.add_new_state(s_prime, BLUE);
push(st_blue, s_prime, label, acc);
}
else // Backtrack the edge (f.s, <label, acc>, s_prime)
else
{
if (acc == all_cond && c.get_color() != RED)
{
if (c.get() != RED && acc == all_cond)
// the test 'c.get() != RED' is added to limit
// the test 'c.get_color() != RED' is added to limit
// the number of runs reported by successive
// calls to the check method. Without this
// functionnality, the test can be ommited.
{
# ifdef TRACE
std::cout << " It is blue and the arc is "
<< "accepting, start a red dfs" << std::endl;
# endif
target = f.s;
c.set(RED);
c.set_color(RED);
push(st_red, s_prime, label, acc);
if (dfs_red())
return true;
}
else
{
# ifdef TRACE
std::cout << " It is blue or red, 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)
{
--sts;
# ifdef TRACE
std::cout << " All the successors have been visited"
<< std::endl;
# endif
stack_item f_dest(f);
delete f.it;
st_blue.pop_front();
pop(st_blue);
typename heap::color_ref c = h.get_color_ref(f_dest.s);
assert(!c.is_white());
if (c.get() != RED && f_dest.acc == all_cond
&& !st_blue.empty())
// the test 'c.get() != RED' is added to limit
if (!st_blue.empty() &&
f_dest.acc == all_cond && c.get_color() != RED)
{
// the test 'c.get_color() != RED' is added to limit
// the number of runs reported by successive
// calls to the check method. Without this
// functionnality, the test can be ommited.
{
# ifdef TRACE
std::cout << " It is blue and the arc from "
<< a->format_state(st_blue.front().s)
<< " to it is accepting, start a red dfs"
<< std::endl;
# endif
target = st_blue.front().s;
c.set(RED);
c.set_color(RED);
push(st_red, f_dest.s, f_dest.label, f_dest.acc);
if (dfs_red())
return true;
}
else
{
# ifdef TRACE
std::cout << " Pop it"
<< std::endl;
# endif
h.pop_notify(f_dest.s);
}
}
}
return false;
}
......@@ -245,40 +288,63 @@ namespace spot
while (!st_red.empty())
{
stack_item& f = st_red.front();
if (!f.it->done()) // Go down
# ifdef TRACE
std::cout << "DFS_RED treats: "
<< a->format_state(f.s) << std::endl;
# endif
if (!f.it->done())
{
++nbt;
const state *s_prime = f.it->current_state();
# ifdef TRACE
std::cout << " Visit the successor: "
<< a->format_state(s_prime) << std::endl;
# endif
bdd label = f.it->current_condition();
bdd acc = f.it->current_acceptance_conditions();
// Go down the edge (f.s, <label, acc>, s_prime)
f.it->next();
inc_transitions();
typename heap::color_ref c = h.get_color_ref(s_prime);
if (c.is_white())
// 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);
// If the red dfs find a white here, it must have crossed
// the blue stack and the target must be reached soon.
// Notice that this property holds only for explicit search.
// Collisions in bit-state hashing search can also lead
// to the visit of white state. Anyway, it is not necessary
// to visit white states either if a cycle can be missed
// with bit-state hashing search.
# ifdef TRACE
std::cout << " It is white, pop it" << std::endl;
# endif
delete s_prime;
}
else if (c.get_color() == BLUE)
{
# ifdef TRACE
std::cout << " It is blue, go down" << std::endl;
# endif
c.set_color(RED);
push(st_red, s_prime, label, acc);
if (target->compare(s_prime) == 0)
return true;
}
else
{
# ifdef TRACE
std::cout << " It is red, pop it" << std::endl;
# endif
h.pop_notify(s_prime);
}
}
else // Backtrack
{
--sts;
# ifdef TRACE
std::cout << " All the successors have been visited, pop it"
<< std::endl;
# endif
h.pop_notify(f.s);
delete f.it;
st_red.pop_front();
pop(st_red);
}
}
return false;
......@@ -343,11 +409,11 @@ namespace spot
color_ref(color* c) :p(c)
{
}
color get() const
color get_color() const
{
return *p;
}
void set(color c)
void set_color(color c)
{
assert(!is_white());
*p=c;
......@@ -415,17 +481,17 @@ namespace spot
color_ref(unsigned char *b, unsigned char o): base(b), offset(o*2)
{
}
color get() const
color get_color() const
{
return color(((*base) >> offset) & 3U);
}
void set(color c)
void set_color(color c)
{
*base = (*base & ~(3U << offset)) | (c << offset);
}
bool is_white() const
{
return get()==WHITE;
return get_color()==WHITE;
}
private:
unsigned char *base;
......@@ -454,7 +520,7 @@ namespace spot
{
color_ref cr(get_color_ref(s));
assert(cr.is_white());
cr.set(c);
cr.set_color(c);
}
void pop_notify(const state* s)
......
......@@ -30,8 +30,11 @@
#include "misc/hash.hh"
#include "tgba/tgba.hh"
#include "emptiness.hh"
#include "emptiness_stats.hh"
#include "se05.hh"
/// FIXME: make compiling depedent the taking into account of weights.
namespace spot
{
namespace
......@@ -41,7 +44,7 @@ namespace spot
/// \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
class se05_search : public emptiness_check, public ec_statistics
{
public:
/// \brief Initialize the Magic Search algorithm on the automaton \a a
......@@ -49,8 +52,11 @@ namespace spot
/// \pre The automaton \a a must have at most one accepting
/// condition (i.e. it is a TBA).
se05_search(const tgba *a, size_t size)
: current_weight(0), h(size),
a(a), all_cond(a->all_acceptance_conditions())
: ec_statistics(),
current_weight(0),
h(size),
a(a),
all_cond(a->all_acceptance_conditions())
{
assert(a->number_of_acceptance_conditions() <= 1);
}
......@@ -82,13 +88,11 @@ namespace spot
/// 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;
inc_states();
h.add_new_state(s0, CYAN, current_weight);
push(st_blue, s0, bddfalse, bddfalse);
if (dfs_blue())
......@@ -97,8 +101,7 @@ namespace spot
else
{
h.pop_notify(st_red.front().s);
delete st_red.front().it;
st_red.pop_front();
pop(st_red);
if (!st_red.empty() && dfs_red())
return new result(*this);
else
......@@ -110,9 +113,9 @@ namespace spot
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;
os << states() << " distinct nodes visited" << std::endl;
os << transitions() << " transitions explored" << std::endl;
os << max_depth() << " nodes for the maximal stack depth" << std::endl;
if (!st_red.empty())
{
assert(!st_blue.empty());
......@@ -123,9 +126,6 @@ namespace spot
}
private:
/// \brief counters for statistics (number of distinct nodes, of
/// transitions and maximal stacks size.
int nbn, nbt, mdp, sts;
struct stack_item
{
......@@ -148,21 +148,26 @@ namespace spot
void push(stack_type& st, const state* s,
const bdd& label, const bdd& acc)
{
++sts;
if (sts>mdp)
mdp = sts;
inc_depth();
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;
void pop(stack_type& st)
{
dec_depth();
delete st.front().it;