* iface/gspn/ssp.cc (couvreur99_check_shy_ssp::find_state,

numbered_state_heap_ssp_semi): Implement a double hash_map using
greatspn's new container() function.
* iface/gspn/ssp.hh (gspn_ssp_interface): Add a doublehash option.
* iface/gspn/ltlgspn.cc: Add option -1 to disable this optimization.
This commit is contained in:
Alexandre Duret-Lutz 2006-02-14 17:07:23 +00:00
parent ea9ee5d5c7
commit 857f0ac54e
4 changed files with 285 additions and 144 deletions

View file

@ -1,3 +1,12 @@
2006-02-14 Alexandre Duret-Lutz <adl@src.lip6.fr>
Soheib Baarir <Souheib.Baarir@lip6.fr>
* iface/gspn/ssp.cc (couvreur99_check_shy_ssp::find_state,
numbered_state_heap_ssp_semi): Implement a double hash_map using
greatspn's new container() function.
* iface/gspn/ssp.hh (gspn_ssp_interface): Add a doublehash option.
* iface/gspn/ltlgspn.cc: Add option -1 to disable this optimization.
2006-02-11 Alexandre Duret-Lutz <adl@src.lip6.fr>
* src/tgbatest/ltl2tgba.cc: Pacify sanity.test.

View file

@ -50,6 +50,10 @@ syntax(char* prog)
<< " [OPTIONS...] model formula automata props..." << std::endl
#endif
<< std::endl
#ifdef SSP
<< " -1 do not use a double hash (for inclusion check)"
<< std::endl
#endif
<< " -c compute an example" << std::endl
<< " (instead of just checking for emptiness)" << std::endl
<< std::endl
@ -99,12 +103,22 @@ main(int argc, char **argv)
enum { Lacim, Fm } trans = Lacim;
bool compute_counter_example = false;
bool proj = true;
#ifdef SSP
bool doublehash = true;
#endif
std::string dead = "true";
spot::ltl::declarative_environment env;
while (formula_index < argc && *argv[formula_index] == '-')
{
#ifdef SSP
if (!strcmp(argv[formula_index], "-1"))
{
doublehash = false;
}
else
#endif
if (!strcmp(argv[formula_index], "-c"))
{
compute_counter_example = true;
@ -187,7 +201,7 @@ main(int argc, char **argv)
#if SSP
bool inclusion = (check != Couvreur && check != Couvreur2);
spot::gspn_ssp_interface gspn(2, argv, dict, env, inclusion);
spot::gspn_ssp_interface gspn(2, argv, dict, env, inclusion, doublehash);
spot::tgba_parse_error_list pel1;
spot::tgba_explicit* control = spot::tgba_parse(argv[formula_index + 2],

View file

@ -25,6 +25,7 @@
#include <gspnlib.h>
#include "ssp.hh"
#include "misc/bddlt.hh"
#include "misc/hash.hh"
#include <bdd.h>
#include "tgbaalgos/gtec/explscc.hh"
#include "tgbaalgos/gtec/nsheap.hh"
@ -46,6 +47,8 @@ namespace spot
delete[] t;
return tmp;
}
static bool doublehash;
}
// state_gspn_ssp
@ -380,7 +383,8 @@ namespace spot
props_[nb_arc_props].arc->curr_acc_conds = size_bdd;
++size_bdd;
state_array = (state**) realloc(state_array,
state_array =
(state**) realloc(state_array,
(size_states + 1) * sizeof(state*));
state_array[size_states] = i->current_state();
props_[nb_arc_props].arc->curr_state = size_states;
@ -534,9 +538,11 @@ namespace spot
bdd_dict* dict,
const
ltl::declarative_environment& env,
bool inclusion)
bool inclusion,
bool doublehash_)
: dict_(dict), env_(env)
{
doublehash = doublehash_;
if (inclusion)
inclusion_version();
@ -635,6 +641,14 @@ namespace spot
//////////////////////////////////////////////////////////////////////
namespace
{
inline void*
container_(const State s)
{
return doublehash ? container(s) : 0;
}
}
class numbered_state_heap_ssp_semi : public numbered_state_heap
{
@ -656,13 +670,18 @@ namespace spot
virtual numbered_state_heap::state_index
find(const state* s) const
{
state_index res;
const void* cont =
container_(dynamic_cast<const state_gspn_ssp*>(s)->left());
contained_map::const_iterator i = contained.find(cont);
if (i != contained.end())
{
const state_list& l = i->second;
hash_type::const_iterator i;
for (i = h.begin(); i != h.end(); ++i)
state_list::const_iterator j;
for (j = l.begin(); j != l.end(); ++j)
{
const state_gspn_ssp* old_state =
dynamic_cast<const state_gspn_ssp*>(i->first);
dynamic_cast<const state_gspn_ssp*>(*j);
const state_gspn_ssp* new_state =
dynamic_cast<const state_gspn_ssp*>(s);
assert(old_state);
@ -679,19 +698,38 @@ namespace spot
break;
}
}
if (j != l.end())
{
if (s != *j)
{
delete s;
s = *j;
}
}
else
{
s = 0;
}
}
else
{
s = 0;
}
if (i == h.end())
state_index res;
if (s == 0)
{
res.first = 0;
res.second = 0;
}
else
{
hash_type::const_iterator i = h.find(s);
assert(i != h.end());
assert(s == i->first);
res.first = i->first;
res.second = i->second;
if (s != i->first)
delete s;
}
return res;
}
@ -699,13 +737,18 @@ namespace spot
virtual numbered_state_heap::state_index_p
find(const state* s)
{
state_index_p res;
const void* cont =
container_(dynamic_cast<const state_gspn_ssp*>(s)->left());
contained_map::const_iterator i = contained.find(cont);
if (i != contained.end())
{
const state_list& l = i->second;
hash_type::iterator i;
for (i = h.begin(); i != h.end(); ++i)
state_list::const_iterator j;
for (j = l.begin(); j != l.end(); ++j)
{
const state_gspn_ssp* old_state =
dynamic_cast<const state_gspn_ssp*>(i->first);
dynamic_cast<const state_gspn_ssp*>(*j);
const state_gspn_ssp* new_state =
dynamic_cast<const state_gspn_ssp*>(s);
assert(old_state);
@ -722,19 +765,38 @@ namespace spot
break;
}
}
if (j != l.end())
{
if (s != *j)
{
delete s;
s = *j;
}
}
else
{
s = 0;
}
}
else
{
s = 0;
}
if (i == h.end())
state_index_p res;
if (s == 0)
{
res.first = 0;
res.second = 0;
}
else
{
hash_type::iterator i = h.find(s);
assert(i != h.end());
assert(s == i->first);
res.first = i->first;
res.second = &i->second;
if (s != i->first)
delete s;
}
return res;
}
@ -781,23 +843,17 @@ namespace spot
return res;
}
virtual int&
index_and_insert(const state*& s)
{
std::pair<hash_type::iterator, bool> r
= h.insert(hash_type::value_type(s, 0));
if (!r.second)
{
delete s;
s = r.first->first;
}
return r.first->second;
}
virtual void
insert(const state* s, int index)
{
h[s] = index;
State sg = dynamic_cast<const state_gspn_ssp*>(s)->left();
if (sg)
{
const void* cont = container_(sg);
contained[cont].push_front(s);
}
}
virtual int
@ -813,8 +869,14 @@ namespace spot
state_ptr_hash, state_ptr_equal> hash_type;
hash_type h; ///< Map of visited states.
typedef std::list<const state*> state_list;
typedef Sgi::hash_map<const void*, state_list,
ptr_hash<void> > contained_map;
contained_map contained;
friend class numbered_state_heap_ssp_const_iterator;
friend class couvreur99_check_shy_ssp;
friend class couvreur99_check_shy_semi_ssp;
};
@ -924,6 +986,9 @@ namespace spot
stats["inclusion count stack"] =
static_cast<spot::unsigned_statistics::unsigned_fun>
(&couvreur99_check_shy_ssp::get_inclusion_count_stack);
stats["contained map size"] =
static_cast<spot::unsigned_statistics::unsigned_fun>
(&couvreur99_check_shy_ssp::get_contained_map_size);
}
private:
@ -941,6 +1006,12 @@ namespace spot
{
return inclusion_count_stack;
};
unsigned
get_contained_map_size() const
{
return
dynamic_cast<numbered_state_heap_ssp_semi*>(ecs_->h)->contained.size();
}
// If a new state includes an older state, we may have to add new
// children to the list of children of that older state. We cannot
@ -951,12 +1022,23 @@ namespace spot
{
typedef numbered_state_heap_ssp_semi::hash_type hash_type;
hash_type& h = dynamic_cast<numbered_state_heap_ssp_semi*>(ecs_->h)->h;
typedef numbered_state_heap_ssp_semi::contained_map contained_map;
typedef numbered_state_heap_ssp_semi::state_list state_list;
const contained_map& contained =
dynamic_cast<numbered_state_heap_ssp_semi*>(ecs_->h)->contained;
hash_type::iterator i;
for (i = h.begin(); i != h.end(); ++i)
const void* cont =
container_(dynamic_cast<const state_gspn_ssp*>(s)->left());
contained_map::const_iterator i = contained.find(cont);
if (i != contained.end())
{
const state_list& l = i->second;
state_list::const_iterator j;
for (j = l.begin(); j != l.end(); ++j)
{
const state_gspn_ssp* old_state =
dynamic_cast<const state_gspn_ssp*>(i->first);
dynamic_cast<const state_gspn_ssp*>(*j);
const state_gspn_ssp* new_state =
dynamic_cast<const state_gspn_ssp*>(s);
assert(old_state);
@ -969,9 +1051,12 @@ namespace spot
if (old_state->left() && new_state->left())
{
hash_type::const_iterator i = h.find(*j);
assert(i != h.end());
if (i->second == -1)
{
if (spot_inclusion(new_state->left(), old_state->left()))
if (spot_inclusion(new_state->left(),
old_state->left()))
{
++inclusion_count_heap;
break;
@ -979,7 +1064,8 @@ namespace spot
}
else
{
if (spot_inclusion(old_state->left(), new_state->left()))
if (spot_inclusion(old_state->left(),
new_state->left()))
{
++inclusion_count_stack;
@ -996,7 +1082,8 @@ namespace spot
new state_gspn_ssp
(succ_tgba_[i],
old_state->right()->clone());
queue.push_back(successor(queue.begin()->acc, s));
queue.push_back(successor(queue.begin()->acc,
s));
inc_depth();
}
if (size_tgba_ != 0)
@ -1008,19 +1095,40 @@ namespace spot
}
}
if (j != l.end())
{
if (s != *j)
{
delete s;
s = *j;
}
}
else
{
s = 0;
}
}
else
{
s = 0;
}
// s points to the resulting state, or to 0 if we didn't find
// the state in the list.
numbered_state_heap::state_index_p res;
if (i == h.end())
if (s == 0)
{
res.first = 0;
res.second = 0;
}
else
{
res.first = i->first;
res.second = &i->second;
if (s != i->first)
delete s;
hash_type::iterator k = h.find(s);
assert(k != h.end());
assert(s == k->first);
res.first = k->first;
res.second = &k->second;
}
return res;
}
@ -1037,9 +1145,12 @@ namespace spot
numbered_state_heap_ssp_factory_semi::instance()),
inclusion_count(0)
{
stats["inclusion count"] =
stats["find_state count"] =
static_cast<spot::unsigned_statistics::unsigned_fun>
(&couvreur99_check_shy_semi_ssp::get_inclusion_count);
stats["contained map size"] =
static_cast<spot::unsigned_statistics::unsigned_fun>
(&couvreur99_check_shy_semi_ssp::get_contained_map_size);
}
private:
@ -1051,6 +1162,12 @@ namespace spot
{
return inclusion_count;
};
unsigned
get_contained_map_size() const
{
return
dynamic_cast<numbered_state_heap_ssp_semi*>(ecs_->h)->contained.size();
}
virtual numbered_state_heap::state_index_p
find_state(const state* s)

View file

@ -1,6 +1,6 @@
// 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.
// Copyright (C) 2003, 2004, 2006 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.
//
@ -40,7 +40,8 @@ namespace spot
public:
gspn_ssp_interface(int argc, char **argv,
bdd_dict* dict, const ltl::declarative_environment& env,
bool inclusion = false);
bool inclusion = false,
bool doublehash = true);
~gspn_ssp_interface();
tgba* automaton(const tgba* operand) const;
private: