Commit 5069a565 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

* src/ltlast/formula.hh (hash, dump, dump_, hash_key_): New members.

(formula_ptr_less_than, formula_ptr_hash): New class.
* src/ltlast/atomic_prop.cc, src/ltlast/binop.cc,
src/ltlast/constant.cc, src/ltlast/formula.cc,
src/ltlast/multop.cc, src/ltlast/unop.cc: Adjust to handle dump_.
* src/ltlvisit/apcollect.cc, src/ltlvisit/apcollect.hh:
Sort the set using formula_ptr_less_than.
* src/ltlvisit/dump.cc: Simplify using ->dump().
* src/tgbaalgos/ltl2tgba_fm.cc: Sort all maps to get deterministic
results.
parent 8a5e31f0
2005-01-20 Alexandre Duret-Lutz <adl@src.lip6.fr>
* src/ltlast/formula.hh (hash, dump, dump_, hash_key_): New members.
(formula_ptr_less_than, formula_ptr_hash): New class.
* src/ltlast/atomic_prop.cc, src/ltlast/binop.cc,
src/ltlast/constant.cc, src/ltlast/formula.cc,
src/ltlast/multop.cc, src/ltlast/unop.cc: Adjust to handle dump_.
* src/ltlvisit/apcollect.cc, src/ltlvisit/apcollect.hh:
Sort the set using formula_ptr_less_than.
* src/ltlvisit/dump.cc: Simplify using ->dump().
* src/tgbaalgos/ltl2tgba_fm.cc: Sort all maps to get deterministic
results.
2005-01-18 Alexandre Duret-Lutz <adl@src.lip6.fr>
* src/tgbaalgos/tau03opt.hh (explicit_tau03_opt_search): Doco.
......
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
......@@ -32,6 +32,8 @@ namespace spot
atomic_prop::atomic_prop(const std::string& name, environment& env)
: name_(name), env_(&env)
{
dump_ = "AP(" + name + ")";
set_key_();
}
atomic_prop::~atomic_prop()
......
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
......@@ -31,6 +31,10 @@ namespace spot
binop::binop(type op, formula* first, formula* second)
: op_(op), first_(first), second_(second)
{
dump_ = "binop(";
dump_ += op_name();
dump_ += ", " + first->dump() + ", " + second->dump() + ")";
set_key_();
}
binop::~binop()
......
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
......@@ -30,6 +30,19 @@ namespace spot
constant::constant(type val)
: val_(val)
{
switch (val)
{
case True:
dump_ = "constant(1)";
set_key_();
return;
case False:
dump_ = "constant(0)";
set_key_();
return;
}
// Unreachable code.
assert(0);
}
constant::~constant()
......
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
......@@ -20,6 +20,7 @@
// 02111-1307, USA.
#include "formula.hh"
#include "misc/hash.hh"
namespace spot
{
......@@ -55,5 +56,19 @@ namespace spot
// Not reference counted by default.
return false;
}
const std::string&
formula::dump() const
{
return dump_;
}
void
formula::set_key_()
{
string_hash sh;
hash_key_ = sh(dump_);
}
}
}
......@@ -24,6 +24,8 @@
#ifndef SPOT_LTLAST_FORMULA_HH
# define SPOT_LTLAST_FORMULA_HH
#include <string>
#include <cassert>
#include "predecl.hh"
namespace spot
......@@ -89,6 +91,15 @@ namespace spot
/// want to release a whole formula, use spot::ltl::destroy() instead.
static void unref(formula* f);
/// Return a canonic representation of the formula
const std::string& dump() const;
/// Return a hash_key for the formula.
const size_t
hash() const
{
return hash_key_;
}
protected:
virtual ~formula();
......@@ -97,8 +108,70 @@ namespace spot
/// \brief decrement reference counter if any, return true when
/// the instance must be deleted (usually when the counter hits 0).
virtual bool unref_();
/// \brief Compute key_ from dump_.
///
/// Should be called once in each object, after dump_ has been set.
void set_key_();
/// The canonic representation of the formula
std::string dump_;
/// \brief The hash key of this formula.
///
/// Initialized by set_key_().
size_t hash_key_;
};
/// \brief Strict Weak Ordering for <code>const formula*</code>.
/// \ingroup ltl_essentials
///
/// This is meant to be used as a comparison functor for
/// STL \c map whose key are of type <code>const formula*</code>.
///
/// For instance here is how one could declare
/// a map of \c const::formula*.
/// \code
/// // Remember how many times each formula has been seen.
/// std::map<const spot::ltl::formula*, int,
/// spot::formula_ptr_less_than> seen;
/// \endcode
struct formula_ptr_less_than:
public std::binary_function<const formula*, const formula*, bool>
{
bool
operator()(const formula* left, const formula* right) const
{
assert(left);
assert(right);
return left->hash() < right->hash();
}
};
/// \brief Hash Function for <code>const formula*</code>.
/// \ingroup ltl_essentials
/// \ingroup hash_funcs
///
/// This is meant to be used as a hash functor for
/// Sgi's \c hash_map whose key are of type <code>const formula*</code>.
///
/// For instance here is how one could declare
/// a map of \c const::formula*.
/// \code
/// // Remember how many times each formula has been seen.
/// Sgi::hash_map<const spot::ltl::formula*, int,
/// const spot::ltl::formula_ptr_hash> seen;
/// \endcode
struct formula_ptr_hash:
public std::unary_function<const formula*, size_t>
{
size_t
operator()(const formula* that) const
{
assert(that);
return that->hash();
}
};
}
}
......
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
......@@ -34,6 +34,15 @@ namespace spot
multop::multop(type op, vec* v)
: op_(op), children_(v)
{
dump_ = "multop(";
dump_ += op_name();
unsigned max = v->size();
for (unsigned n = 0; n < max; ++n)
{
dump_ += ", " + (*v)[n]->dump();
}
dump_ += ")";
set_key_();
}
multop::~multop()
......@@ -131,7 +140,7 @@ namespace spot
v->insert(v->end(), inlined.begin(), inlined.end());
}
std::sort(v->begin(), v->end());
std::sort(v->begin(), v->end(), formula_ptr_less_than());
// Remove duplicates. We can't use std::unique(), because we
// must destroy() any formula we drop.
......
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
......@@ -30,6 +30,10 @@ namespace spot
unop::unop(type op, formula* child)
: op_(op), child_(child)
{
dump_ = "unop(";
dump_ += op_name();
dump_ += ", " + child->dump() + ")";
set_key_();
}
unop::~unop()
......
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
......@@ -20,6 +20,7 @@
// 02111-1307, USA.
#include "apcollect.hh"
#include "ltlvisit/postfix.hh"
namespace spot
{
......
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
......@@ -23,7 +23,7 @@
# define SPOT_LTLVISIT_APCOLLECT_HH
#include <set>
#include "ltlvisit/postfix.hh"
#include "ltlast/atomic_prop.hh"
namespace spot
{
......@@ -33,7 +33,7 @@ namespace spot
/// @{
/// Set of atomic propositions.
typedef std::set<spot::ltl::atomic_prop*> atomic_prop_set;
typedef std::set<atomic_prop*, formula_ptr_less_than> atomic_prop_set;
/// \brief Return the set of atomic propositions occurring in a formula.
///
......
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
......@@ -28,74 +28,10 @@ namespace spot
{
namespace ltl
{
namespace
{
class dump_visitor: public const_visitor
{
public:
dump_visitor(std::ostream& os)
: os_(os)
{
}
virtual
~dump_visitor()
{
}
void
visit(const atomic_prop* ap)
{
os_ << "AP(" << ap->name() << ")";
}
void
visit(const constant* c)
{
os_ << "constant(" << c->val_name() << ")";
}
void
visit(const binop* bo)
{
os_ << "binop(" << bo->op_name() << ", ";
bo->first()->accept(*this);
os_ << ", ";
bo->second()->accept(*this);
os_ << ")";
}
void
visit(const unop* uo)
{
os_ << "unop(" << uo->op_name() << ", ";
uo->child()->accept(*this);
os_ << ")";
}
void
visit(const multop* mo)
{
os_ << "multop(" << mo->op_name() << ", ";
unsigned max = mo->size();
mo->nth(0)->accept(*this);
for (unsigned n = 1; n < max; ++n)
{
os_ << ", ";
mo->nth(n)->accept(*this);
}
os_ << ")";
}
private:
std::ostream& os_;
};
}
std::ostream&
dump(std::ostream& os, const formula* f)
{
dump_visitor v(os);
f->accept(v);
os << f->dump();
return os;
}
......
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
......@@ -533,7 +533,7 @@ namespace spot
}
private:
typedef Sgi::hash_map<const formula*, bool, ptr_hash<formula> > pfl_map;
typedef Sgi::hash_map<const formula*, bool, formula_ptr_hash> pfl_map;
pfl_map pfl_;
};
......@@ -613,7 +613,7 @@ namespace spot
}
typedef std::map<bdd, bdd, bdd_less_than> prom_map;
typedef Sgi::hash_map<const formula*, prom_map, ptr_hash<formula> > dest_map;
typedef Sgi::hash_map<const formula*, prom_map, formula_ptr_hash> dest_map;
static void
fill_dests(translate_dict& d, dest_map& dests, bdd label, const formula* dest)
......@@ -649,8 +649,9 @@ namespace spot
formula* f2 = negative_normal_form(f1);
destroy(f1);
std::set<const formula*> formulae_seen;
std::set<const formula*> formulae_to_translate;
typedef std::set<const formula*, formula_ptr_less_than> set_type;
set_type formulae_seen;
set_type formulae_to_translate;
translate_dict d(dict);
formula_canonizer fc(d);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment