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

Make sure we can multiply two tgba_explicit.

* tgba/state.hh (state::translate, state::clone, state::as_bdd):
New virtual methods.
* tgba/stataebdd.cc (state::translate, state::clone): New methods.
* tgba/stataebdd.hh (state::translate, state::clone): New methods.
* tgba/tgbabddprod.cc (state_bdd_product::clone,
tgba_bdd_product_succ_iterator::~tgba_bdd_product_succ_iterator):
New methods.
(tgba_bdd_product_succ_iterator::first): Reset right_
if any of left_ or right_ is already done (i.e., is empty).
(tgba_bdd_product_succ_iterator::done): Return true
if right_ is NULL.
(tgba_bdd_product_succ_iterator::current_state,
tgba_bdd_product::get_init_state): Work	directory with `state's.
* tgba/tgbabddprod.hh (state_bdd_product::clone,
tgba_bdd_product_succ_iterator::~tgba_bdd_product_succ_iterator):
New methods.
* tgba/tgbabddtranslateproxy.cc
(tgba_bdd_translate_proxy_succ_iterator::
tgba_bdd_translate_proxy_succ_iterator): Work on any kind of iteraator.
(tgba_bdd_translate_proxy_succ_iterator::
~tgba_bdd_translate_proxy_succ_iterator): New method.
(tgba_bdd_translate_proxy_succ_iterator::current_state,
tgba_bdd_translate_proxy::get_init_state,
tgba_bdd_translate_proxy::succ_iter): Work on `state's and
`tgba_succ_iterator's directlry.
(tgba_bdd_translate_proxy::format_state): Delegate formating
to the proxied automata.
* tgba/tgbaexplicit.cc (state_explicit::clone): New method.
* src/tgba/tgbaexplicit.cc (tgba_explicit::get_condition,
tgba_explicit::get_promise): Call ltl::destroy on existing formulae.
* tgbatest/Makefile.am (check_PROGRAMS): Add explprod.
(explprod_SOURCES): New variable.
(TESTS): Add explprod.test.
(CLEANFILES): Add input1 and input2.
parent 5d2e0a42
2003-06-16 Alexandre Duret-Lutz <aduret@src.lip6.fr>
Make sure we can multiply two tgba_explicit.
* tgba/state.hh (state::translate, state::clone, state::as_bdd):
New virtual methods.
* tgba/stataebdd.cc (state::translate, state::clone): New methods.
* tgba/stataebdd.hh (state::translate, state::clone): New methods.
* tgba/tgbabddprod.cc (state_bdd_product::clone,
tgba_bdd_product_succ_iterator::~tgba_bdd_product_succ_iterator):
New methods.
(tgba_bdd_product_succ_iterator::first): Reset right_
if any of left_ or right_ is already done (i.e., is empty).
(tgba_bdd_product_succ_iterator::done): Return true
if right_ is NULL.
(tgba_bdd_product_succ_iterator::current_state,
tgba_bdd_product::get_init_state): Work directory with `state's.
* tgba/tgbabddprod.hh (state_bdd_product::clone,
tgba_bdd_product_succ_iterator::~tgba_bdd_product_succ_iterator):
New methods.
* tgba/tgbabddtranslateproxy.cc
(tgba_bdd_translate_proxy_succ_iterator::
tgba_bdd_translate_proxy_succ_iterator): Work on any kind of iteraator.
(tgba_bdd_translate_proxy_succ_iterator::
~tgba_bdd_translate_proxy_succ_iterator): New method.
(tgba_bdd_translate_proxy_succ_iterator::current_state,
tgba_bdd_translate_proxy::get_init_state,
tgba_bdd_translate_proxy::succ_iter): Work on `state's and
`tgba_succ_iterator's directlry.
(tgba_bdd_translate_proxy::format_state): Delegate formating
to the proxied automata.
* tgba/tgbaexplicit.cc (state_explicit::clone): New method.
* src/tgba/tgbaexplicit.cc (tgba_explicit::get_condition,
tgba_explicit::get_promise): Call ltl::destroy on existing formulae.
* tgbatest/Makefile.am (check_PROGRAMS): Add explprod.
(explprod_SOURCES): New variable.
(TESTS): Add explprod.test.
(CLEANFILES): Add input1 and input2.
2003-06-12 Alexandre Duret-Lutz <aduret@src.lip6.fr> 2003-06-12 Alexandre Duret-Lutz <aduret@src.lip6.fr>
* src/tgba/tgbabddconcrete.cc (set_init_state, succ_iter): Make * src/tgba/tgbabddconcrete.cc (set_init_state, succ_iter): Make
......
...@@ -22,6 +22,28 @@ namespace spot ...@@ -22,6 +22,28 @@ namespace spot
/// \sa spot::state_ptr_less_than /// \sa spot::state_ptr_less_than
virtual int compare(const state* other) const = 0; virtual int compare(const state* other) const = 0;
/// \brief Translate a state.
///
/// If this state uses any BDD variable. This function
/// should rewrite the variables according to \a rewrite.
/// This used by spot::tgbabddtranslateproxy.
virtual void translate(bddPair* rewrite)
{
// This does nothing by default and is
// overridden in spot::state_bdd.
(void) rewrite;
}
/// Duplicate a state.
virtual state* clone() const = 0;
/// Return the BDD part of the state.
virtual bdd
as_bdd() const
{
return bddtrue;
}
virtual ~state() virtual ~state()
{ {
} }
......
#include "statebdd.hh" #include "statebdd.hh"
#include "bddprint.hh" #include <bdd.h>
#include <cassert> #include <cassert>
namespace spot namespace spot
{ {
int int
state_bdd::compare(const state* other) const state_bdd::compare(const state* other) const
{ {
...@@ -14,4 +15,18 @@ namespace spot ...@@ -14,4 +15,18 @@ namespace spot
assert(o); assert(o);
return o->as_bdd().id() - state_.id(); return o->as_bdd().id() - state_.id();
} }
void
state_bdd::translate(bddPair* rewrite)
{
state_ = bdd_replace(state_, rewrite);
}
/// Duplicate a state.
state_bdd*
state_bdd::clone() const
{
return new state_bdd(*this);
}
} }
...@@ -16,20 +16,15 @@ namespace spot ...@@ -16,20 +16,15 @@ namespace spot
} }
/// Return the BDD part of the state. /// Return the BDD part of the state.
bdd virtual bdd
as_bdd() const as_bdd() const
{ {
return state_; return state_;
} }
/// Return the BDD part of the state.
bdd&
as_bdd()
{
return state_;
}
virtual int compare(const state* other) const; virtual int compare(const state* other) const;
virtual void translate(bddPair* rewrite);
virtual state_bdd* clone() const;
protected: protected:
bdd state_; ///< BDD representation of the state. bdd state_; ///< BDD representation of the state.
......
...@@ -26,6 +26,12 @@ namespace spot ...@@ -26,6 +26,12 @@ namespace spot
return right_->compare(o->right()); return right_->compare(o->right());
} }
state_bdd_product*
state_bdd_product::clone() const
{
return new state_bdd_product(*this);
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// tgba_bdd_product_succ_iterator // tgba_bdd_product_succ_iterator
...@@ -35,6 +41,13 @@ namespace spot ...@@ -35,6 +41,13 @@ namespace spot
{ {
} }
tgba_bdd_product_succ_iterator::~tgba_bdd_product_succ_iterator()
{
delete left_;
if (right_)
delete right_;
}
void void
tgba_bdd_product_succ_iterator::step_() tgba_bdd_product_succ_iterator::step_()
{ {
...@@ -67,8 +80,20 @@ namespace spot ...@@ -67,8 +80,20 @@ namespace spot
void void
tgba_bdd_product_succ_iterator::first() tgba_bdd_product_succ_iterator::first()
{ {
if (!right_)
return;
left_->first(); left_->first();
right_->first(); right_->first();
// If one of the two successor set is empty initially, we reset
// right_, so that done() can detect this situation easily. (We
// choose to reset right_ because this variable is already used by
// done().)
if (left_->done() || right_->done())
{
delete right_;
right_ = 0;
}
next_non_false_(); next_non_false_();
} }
...@@ -82,18 +107,15 @@ namespace spot ...@@ -82,18 +107,15 @@ namespace spot
bool bool
tgba_bdd_product_succ_iterator::done() tgba_bdd_product_succ_iterator::done()
{ {
return right_->done(); return !right_ || right_->done();
} }
state_bdd* state_bdd_product*
tgba_bdd_product_succ_iterator::current_state() tgba_bdd_product_succ_iterator::current_state()
{ {
state_bdd* ls = dynamic_cast<state_bdd*>(left_->current_state()); return new state_bdd_product(left_->current_state(),
state_bdd* rs = dynamic_cast<state_bdd*>(right_->current_state()); right_->current_state());
assert(ls);
assert(rs);
return new state_bdd_product(ls, rs);
} }
bdd bdd
...@@ -149,11 +171,8 @@ namespace spot ...@@ -149,11 +171,8 @@ namespace spot
state* state*
tgba_bdd_product::get_init_state() const tgba_bdd_product::get_init_state() const
{ {
state_bdd* ls = dynamic_cast<state_bdd*>(left_->get_init_state()); return new state_bdd_product(left_->get_init_state(),
state_bdd* rs = dynamic_cast<state_bdd*>(right_->get_init_state()); right_->get_init_state());
assert(ls);
assert(rs);
return new state_bdd_product(ls, rs);
} }
tgba_bdd_product_succ_iterator* tgba_bdd_product_succ_iterator*
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace spot namespace spot
{ {
/// \brief A state for spot::tgba_bdd_product. /// \brief A state for spot::tgba_bdd_product.
/// ///
/// This state is in fact a pair of state: the state from the left /// This state is in fact a pair of state: the state from the left
/// automaton and that of the right. /// automaton and that of the right.
...@@ -19,32 +19,33 @@ namespace spot ...@@ -19,32 +19,33 @@ namespace spot
/// \param right The state from the right automaton. /// \param right The state from the right automaton.
/// These state are acquired by spot::state_bdd_product, and will /// These state are acquired by spot::state_bdd_product, and will
/// be deleted on destruction. /// be deleted on destruction.
state_bdd_product(state_bdd* left, state_bdd* right) state_bdd_product(state* left, state* right)
: state_bdd(left->as_bdd() & right->as_bdd()), : state_bdd(left->as_bdd() & right->as_bdd()),
left_(left), left_(left),
right_(right) right_(right)
{ {
} }
virtual ~state_bdd_product(); virtual ~state_bdd_product();
state_bdd* state*
left() const left() const
{ {
return left_; return left_;
} }
state_bdd* state*
right() const right() const
{ {
return right_; return right_;
} }
virtual int compare(const state* other) const; virtual int compare(const state* other) const;
virtual state_bdd_product* clone() const;
private: private:
state_bdd* left_; ///< State from the left automaton. state* left_; ///< State from the left automaton.
state_bdd* right_; ///< State from the right automaton. state* right_; ///< State from the right automaton.
}; };
...@@ -52,16 +53,18 @@ namespace spot ...@@ -52,16 +53,18 @@ namespace spot
class tgba_bdd_product_succ_iterator: public tgba_succ_iterator class tgba_bdd_product_succ_iterator: public tgba_succ_iterator
{ {
public: public:
tgba_bdd_product_succ_iterator(tgba_succ_iterator* left, tgba_bdd_product_succ_iterator(tgba_succ_iterator* left,
tgba_succ_iterator* right); tgba_succ_iterator* right);
virtual ~tgba_bdd_product_succ_iterator();
// iteration // iteration
void first(); void first();
void next(); void next();
bool done(); bool done();
// inspection // inspection
state_bdd* current_state(); state_bdd_product* current_state();
bdd current_condition(); bdd current_condition();
bdd current_promise(); bdd current_promise();
...@@ -77,7 +80,7 @@ namespace spot ...@@ -77,7 +80,7 @@ namespace spot
tgba_succ_iterator* right_; tgba_succ_iterator* right_;
bdd current_cond_; bdd current_cond_;
}; };
/// \brief A lazy product. (States are computed on the fly.) /// \brief A lazy product. (States are computed on the fly.)
class tgba_bdd_product : public tgba class tgba_bdd_product : public tgba
{ {
...@@ -87,12 +90,12 @@ namespace spot ...@@ -87,12 +90,12 @@ namespace spot
/// \param right The right automata in the product. /// \param right The right automata in the product.
/// Do not be fooled by these arguments: a product \emph is commutative. /// Do not be fooled by these arguments: a product \emph is commutative.
tgba_bdd_product(const tgba& left, const tgba& right); tgba_bdd_product(const tgba& left, const tgba& right);
virtual ~tgba_bdd_product(); virtual ~tgba_bdd_product();
virtual state* get_init_state() const; virtual state* get_init_state() const;
virtual tgba_bdd_product_succ_iterator* virtual tgba_bdd_product_succ_iterator*
succ_iter(const state* state) const; succ_iter(const state* state) const;
virtual const tgba_bdd_dict& get_dict() const; virtual const tgba_bdd_dict& get_dict() const;
......
...@@ -9,12 +9,18 @@ namespace spot ...@@ -9,12 +9,18 @@ namespace spot
// -------------------------------------- // --------------------------------------
tgba_bdd_translate_proxy_succ_iterator:: tgba_bdd_translate_proxy_succ_iterator::
tgba_bdd_translate_proxy_succ_iterator(tgba_succ_iterator_concrete* it, tgba_bdd_translate_proxy_succ_iterator(tgba_succ_iterator* it,
bddPair* rewrite) bddPair* rewrite)
: iter_(it), rewrite_(rewrite) : iter_(it), rewrite_(rewrite)
{ {
} }
tgba_bdd_translate_proxy_succ_iterator::
~tgba_bdd_translate_proxy_succ_iterator()
{
delete iter_;
}
void void
tgba_bdd_translate_proxy_succ_iterator::first() tgba_bdd_translate_proxy_succ_iterator::first()
{ {
...@@ -33,11 +39,11 @@ namespace spot ...@@ -33,11 +39,11 @@ namespace spot
return iter_->done(); return iter_->done();
} }
state_bdd* state*
tgba_bdd_translate_proxy_succ_iterator::current_state() tgba_bdd_translate_proxy_succ_iterator::current_state()
{ {
state_bdd* s = iter_->current_state(); state* s = iter_->current_state();
s->as_bdd() = bdd_replace(s->as_bdd(), rewrite_); s->translate(rewrite_);
return s; return s;
} }
...@@ -99,25 +105,24 @@ namespace spot ...@@ -99,25 +105,24 @@ namespace spot
bdd_freepair(rewrite_to_); bdd_freepair(rewrite_to_);
} }
state_bdd* state*
tgba_bdd_translate_proxy::get_init_state() const tgba_bdd_translate_proxy::get_init_state() const
{ {
state_bdd* s = dynamic_cast<state_bdd*>(from_.get_init_state()); state* s = from_.get_init_state();
assert(s); s->translate(rewrite_to_);
s->as_bdd() = bdd_replace(s->as_bdd(), rewrite_to_);
return s; return s;
} }
tgba_bdd_translate_proxy_succ_iterator* tgba_bdd_translate_proxy_succ_iterator*
tgba_bdd_translate_proxy::succ_iter(const state* state) const tgba_bdd_translate_proxy::succ_iter(const state* s) const
{ {
const state_bdd* s = dynamic_cast<const state_bdd*>(state); state* s2 = s->clone();
assert(s); s2->translate(rewrite_from_);
state_bdd s2(bdd_replace(s->as_bdd(), rewrite_from_)); tgba_bdd_translate_proxy_succ_iterator *res =
tgba_succ_iterator_concrete* it = new tgba_bdd_translate_proxy_succ_iterator(from_.succ_iter(s2),
dynamic_cast<tgba_succ_iterator_concrete*>(from_.succ_iter(&s2)); rewrite_to_);
assert(it); delete s2;
return new tgba_bdd_translate_proxy_succ_iterator(it, rewrite_to_); return res;
} }
const tgba_bdd_dict& const tgba_bdd_dict&
...@@ -127,12 +132,13 @@ namespace spot ...@@ -127,12 +132,13 @@ namespace spot
} }
std::string std::string
tgba_bdd_translate_proxy::format_state(const state* state) const tgba_bdd_translate_proxy::format_state(const state* s) const
{ {
const state_bdd* s = dynamic_cast<const state_bdd*>(state); state* s2 = s->clone();
assert(s); s2->translate(rewrite_from_);
return bdd_format_set(to_, s->as_bdd()); std::string res = from_.format_state(s2);
delete s2;
return res;
} }
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
# define SPOT_TGBA_TGBABDDTRANSLATEPROXY_HH # define SPOT_TGBA_TGBABDDTRANSLATEPROXY_HH
#include "tgba.hh" #include "tgba.hh"
#include "succiterconcrete.hh"
namespace spot namespace spot
{ {
...@@ -11,8 +10,9 @@ namespace spot ...@@ -11,8 +10,9 @@ namespace spot
class tgba_bdd_translate_proxy_succ_iterator: public tgba_succ_iterator class tgba_bdd_translate_proxy_succ_iterator: public tgba_succ_iterator
{ {
public: public:
tgba_bdd_translate_proxy_succ_iterator tgba_bdd_translate_proxy_succ_iterator(tgba_succ_iterator* it,
(tgba_succ_iterator_concrete* it, bddPair* rewrite); bddPair* rewrite);
virtual ~tgba_bdd_translate_proxy_succ_iterator();
// iteration // iteration
void first(); void first();
...@@ -20,11 +20,11 @@ namespace spot ...@@ -20,11 +20,11 @@ namespace spot
bool done(); bool done();
// inspection // inspection
state_bdd* current_state(); state* current_state();
bdd current_condition(); bdd current_condition();
bdd current_promise(); bdd current_promise();
protected: protected:
tgba_succ_iterator_concrete* iter_; tgba_succ_iterator* iter_;
bddPair* rewrite_; bddPair* rewrite_;
}; };
...@@ -42,7 +42,7 @@ namespace spot ...@@ -42,7 +42,7 @@ namespace spot
virtual ~tgba_bdd_translate_proxy(); virtual ~tgba_bdd_translate_proxy();
virtual state_bdd* get_init_state() const; virtual state* get_init_state() const;
virtual tgba_bdd_translate_proxy_succ_iterator* virtual tgba_bdd_translate_proxy_succ_iterator*
succ_iter(const state* state) const; succ_iter(const state* state) const;
......
#include "ltlast/atomic_prop.hh" #include "ltlast/atomic_prop.hh"
#include "ltlvisit/destroy.hh"
#include "tgbaexplicit.hh" #include "tgbaexplicit.hh"
#include <cassert> #include <cassert>
...@@ -14,37 +15,37 @@ namespace spot ...@@ -14,37 +15,37 @@ namespace spot
{ {
} }
void void
tgba_explicit_succ_iterator::first() tgba_explicit_succ_iterator::first()
{ {
i_ = s_->begin(); i_ = s_->begin();
} }
void void
tgba_explicit_succ_iterator::next() tgba_explicit_succ_iterator::next()
{ {
++i_; ++i_;
} }
bool bool
tgba_explicit_succ_iterator::done() tgba_explicit_succ_iterator::done()
{ {
return i_ == s_->end(); return i_ == s_->end();
} }