lbtt: build an explicit automaton on input.

* src/priv/accmap.hh (acc_mapper): Rename into...
(acc_mapper_string): ... this, and add
(acc_mapper_int): ... this variant.
* src/tgbaparse/tgbaparse.yy: Adjust to renaming.
* src/tgbaalgos/lbtt.cc: Use acc_mapper_int and build an explicit
automaton.
* src/tgbaalgos/lbtt.hh: Adjust return type.
* src/tgbatest/ltl2tgba.cc: Adjust to new return type.
This commit is contained in:
Alexandre Duret-Lutz 2014-07-02 18:54:20 +02:00
parent 1d28714c3a
commit 120ce7d8e6
5 changed files with 218 additions and 188 deletions

View file

@ -28,33 +28,51 @@
namespace spot
{
class acc_mapper
class acc_mapper_common
{
protected:
bdd_dict* dict_;
tgba_digraph* aut_;
ltl::environment& env_;
std::unordered_map<std::string, int> map_;
bdd neg_;
public:
acc_mapper(tgba_digraph *aut,
ltl::environment& env = ltl::default_environment::instance())
acc_mapper_common(tgba_digraph *aut, ltl::environment& env)
: dict_(aut->get_dict()), aut_(aut), env_(env), neg_(bddtrue)
{
}
public:
const ltl::environment& get_env() const
{
return env_;
}
// Commit all acceptance set to the automaton.
void commit()
{
aut_->set_acceptance_conditions(neg_);
}
};
class acc_mapper_string: public acc_mapper_common
{
std::unordered_map<std::string, int> map_;
public:
acc_mapper_string(tgba_digraph *aut,
ltl::environment& env
= ltl::default_environment::instance())
: acc_mapper_common(aut, env)
{
}
// Declare an acceptance name.
bool declare(const std::string& name)
{
auto i = map_.find(name);
if (i != map_.end())
return true;
const ltl::formula* f = env_.require(name);
auto f = env_.require(name);
if (!f)
return false;
int v = dict_->register_acceptance_variable(f, aut_);
@ -64,12 +82,6 @@ namespace spot
return true;
}
// Commit all acceptance set to the automaton.
void commit()
{
aut_->set_acceptance_conditions(neg_);
}
std::pair<bool, bdd> lookup(std::string name) const
{
auto p = map_.find(name);
@ -79,7 +91,54 @@ namespace spot
bdd_nithvar(p->second),
p->second));
}
};
// The acceptance sets are named using count integers, but we do not
// assume the numbers are necessarily consecutive.
class acc_mapper_int: public acc_mapper_common
{
std::vector<bdd> usable_;
unsigned used_;
std::map<int, bdd> map_;
public:
acc_mapper_int(tgba_digraph *aut,
unsigned count,
ltl::environment& env = ltl::default_environment::instance())
: acc_mapper_common(aut, env), usable_(count), used_(0)
{
std::vector<int> vmap(count);
for (unsigned n = 0; n < count; ++n)
{
std::ostringstream s;
s << n;
auto f = env.require(s.str());
int v = dict_->register_acceptance_variable(f, aut_);
f->destroy();
vmap[n] = v;
neg_ &= bdd_nithvar(v);
}
for (unsigned n = 0; n < count; ++n)
{
int v = vmap[n];
usable_[n] = bdd_compose(neg_, bdd_nithvar(v), v);
}
commit();
}
std::pair<bool, bdd> lookup(unsigned n)
{
auto p = map_.find(n);
if (p != map_.end())
return std::make_pair(true, p->second);
if (used_ < usable_.size())
{
bdd res = usable_[used_++];
map_[n] = res;
return std::make_pair(true, res);
}
return std::make_pair(false, bddfalse);
}
};
}