tgbadigraph: delegate useful graph methods

* src/tgba/tgbagraph.hh (new_state, new_states, new_transitions, out,
trans_data): Delegate these useful graph methods so we do not have to
call get_graph().
* src/graphtest/tgbagraph.cc, src/tgbaalgos/dtbasat.cc,
src/tgbaalgos/dtgbasat.cc, src/tgbaalgos/dupexp.cc,
src/tgbaalgos/emptiness.cc, src/tgbaalgos/lbtt.cc,
src/tgbaalgos/powerset.cc, src/tgbaalgos/randomgraph.cc,
src/tgbaalgos/sccfilter.cc,
src/tgbaalgos/sccinfo.cc,src/tgbaalgos/simulation.cc: Simplify.
This commit is contained in:
Alexandre Duret-Lutz 2014-07-10 10:23:48 +02:00
parent 18f6fe772b
commit 1a93166d15
12 changed files with 92 additions and 75 deletions

View file

@ -30,7 +30,6 @@ void f1()
auto& e = spot::ltl::default_environment::instance(); auto& e = spot::ltl::default_environment::instance();
spot::tgba_digraph tg(&d); spot::tgba_digraph tg(&d);
auto& g = tg.get_graph();
auto* f1 = e.require("p1"); auto* f1 = e.require("p1");
auto* f2 = e.require("p2"); auto* f2 = e.require("p2");
@ -41,21 +40,21 @@ void f1()
f1->destroy(); f1->destroy();
f2->destroy(); f2->destroy();
auto s1 = g.new_state(); auto s1 = tg.new_state();
auto s2 = g.new_state(); auto s2 = tg.new_state();
auto s3 = g.new_state(); auto s3 = tg.new_state();
g.new_transition(s1, s1, bddfalse, bddfalse); tg.new_transition(s1, s1, bddfalse, bddfalse);
g.new_transition(s1, s2, p1, bddfalse); tg.new_transition(s1, s2, p1, bddfalse);
g.new_transition(s1, s3, p2, !a1 & a2); tg.new_transition(s1, s3, p2, !a1 & a2);
g.new_transition(s2, s3, p1 & p2, a1 & !a2); tg.new_transition(s2, s3, p1 & p2, a1 & !a2);
g.new_transition(s3, s1, p1 | p2, (!a1 & a2) | (a1 & !a2)); tg.new_transition(s3, s1, p1 | p2, (!a1 & a2) | (a1 & !a2));
g.new_transition(s3, s2, p1 >> p2, bddfalse); tg.new_transition(s3, s2, p1 >> p2, bddfalse);
g.new_transition(s3, s3, bddtrue, (!a1 & a2) | (a1 & !a2)); tg.new_transition(s3, s3, bddtrue, (!a1 & a2) | (a1 & !a2));
spot::dotty_reachable(std::cout, &tg); spot::dotty_reachable(std::cout, &tg);
{ {
auto i = g.out_iteraser(s3); auto i = tg.get_graph().out_iteraser(s3);
++i; ++i;
i.erase(); i.erase();
i.erase(); i.erase();
@ -64,15 +63,15 @@ void f1()
} }
{ {
auto i = g.out_iteraser(s3); auto i = tg.get_graph().out_iteraser(s3);
i.erase(); i.erase();
assert(!i); assert(!i);
spot::dotty_reachable(std::cout, &tg); spot::dotty_reachable(std::cout, &tg);
} }
g.new_transition(s3, s1, p1 | p2, (!a1 & a2) | (a1 & !a2)); tg.new_transition(s3, s1, p1 | p2, (!a1 & a2) | (a1 & !a2));
g.new_transition(s3, s2, p1 >> p2, bddfalse); tg.new_transition(s3, s2, p1 >> p2, bddfalse);
g.new_transition(s3, s1, bddtrue, (!a1 & a2) | (a1 & !a2)); tg.new_transition(s3, s1, bddtrue, (!a1 & a2) | (a1 & !a2));
std::cerr << tg.num_transitions() << '\n'; std::cerr << tg.num_transitions() << '\n';
assert(tg.num_transitions() == 7); assert(tg.num_transitions() == 7);

View file

@ -221,7 +221,6 @@ namespace spot
return g_.num_transitions(); return g_.num_transitions();
} }
void set_init_state(graph_t::state s) void set_init_state(graph_t::state s)
{ {
init_ = &g_.state_data(s); init_ = &g_.state_data(s);
@ -296,6 +295,10 @@ namespace spot
return g_.trans_data(i->pos()); return g_.trans_data(i->pos());
} }
tgba_graph_trans_data& trans_data(unsigned t)
{
return g_.trans_data(t);
}
void set_acceptance_conditions(bdd all) void set_acceptance_conditions(bdd all)
{ {
@ -311,6 +314,34 @@ namespace spot
compute_all_acceptance_conditions(neg_acceptance_conditions_); compute_all_acceptance_conditions(neg_acceptance_conditions_);
} }
unsigned new_state()
{
return g_.new_state();
}
unsigned new_states(unsigned n)
{
return g_.new_states(n);
}
unsigned new_transition(unsigned src, unsigned dst,
bdd cond, bdd acc = bddfalse)
{
return g_.new_transition(src, dst, cond, acc);
}
internal::state_out<const graph_t>
out(unsigned src) const
{
return g_.out(src);
}
internal::state_out<graph_t>
out(unsigned src)
{
return g_.out(src);
}
/// \brief Copy the acceptance conditions of another tgba. /// \brief Copy the acceptance conditions of another tgba.
void copy_acceptance_conditions_of(const tgba *a) void copy_acceptance_conditions_of(const tgba *a)
{ {

View file

@ -678,8 +678,7 @@ namespace spot
bdd acc = bdd_ithvar(autdict->register_acceptance_variable(t, a)); bdd acc = bdd_ithvar(autdict->register_acceptance_variable(t, a));
a->set_acceptance_conditions(acc); a->set_acceptance_conditions(acc);
auto& g = a->get_graph(); a->new_states(satdict.cand_size);
g.new_states(satdict.cand_size);
unsigned last_aut_trans = -1U; unsigned last_aut_trans = -1U;
const transition* last_sat_trans = nullptr; const transition* last_sat_trans = nullptr;
@ -717,10 +716,10 @@ namespace spot
&& acc_states.find(t->second.src) != acc_states.end()) && acc_states.find(t->second.src) != acc_states.end())
accept = acc; accept = acc;
last_aut_trans = g.new_transition(t->second.src - 1, last_aut_trans = a->new_transition(t->second.src - 1,
t->second.dst -1, t->second.dst - 1,
t->second.cond, t->second.cond,
accept); accept);
last_sat_trans = &t->second; last_sat_trans = &t->second;
dout << v << '\t' << t->second << "δ\n"; dout << v << '\t' << t->second << "δ\n";
@ -737,7 +736,7 @@ namespace spot
assert(!state_based); assert(!state_based);
// This assumes that the SAT solvers output // This assumes that the SAT solvers output
// variables in increasing order. // variables in increasing order.
g.trans_data(last_aut_trans).acc = acc; a->trans_data(last_aut_trans).acc = acc;
} }
else if (state_based) else if (state_based)
{ {

View file

@ -851,8 +851,7 @@ namespace spot
autdict->unregister_all_typed_variables(bdd_dict::acc, aut); autdict->unregister_all_typed_variables(bdd_dict::acc, aut);
a->set_acceptance_conditions(satdict.all_cand_acc.back()); a->set_acceptance_conditions(satdict.all_cand_acc.back());
auto& g = a->get_graph(); a->new_states(satdict.cand_size);
g.new_states(satdict.cand_size);
// Last transition set in the automaton. // Last transition set in the automaton.
unsigned last_aut_trans = -1U; unsigned last_aut_trans = -1U;
@ -894,10 +893,10 @@ namespace spot
acc = i->second; acc = i->second;
} }
last_aut_trans = g.new_transition(t->second.src - 1, last_aut_trans = a->new_transition(t->second.src - 1,
t->second.dst - 1, t->second.dst - 1,
t->second.cond, t->second.cond,
acc); acc);
last_sat_trans = &t->second; last_sat_trans = &t->second;
dout << v << '\t' << t->second << "δ\n"; dout << v << '\t' << t->second << "δ\n";
@ -919,7 +918,7 @@ namespace spot
ta->second.dst == last_sat_trans->dst) ta->second.dst == last_sat_trans->dst)
{ {
assert(!state_based); assert(!state_based);
g.trans_data(last_aut_trans).acc |= ta->second.acc; a->trans_data(last_aut_trans).acc |= ta->second.acc;
} }
else if (state_based) else if (state_based)
{ {

View file

@ -50,7 +50,7 @@ namespace spot
virtual void virtual void
process_state(const state*, int n, tgba_succ_iterator*) process_state(const state*, int n, tgba_succ_iterator*)
{ {
unsigned ns = out_->get_graph().new_state(); unsigned ns = out_->new_state();
assert(ns == static_cast<unsigned>(n) - 1); assert(ns == static_cast<unsigned>(n) - 1);
(void)ns; (void)ns;
} }
@ -60,9 +60,9 @@ namespace spot
const state*, int out, const state*, int out,
const tgba_succ_iterator* si) const tgba_succ_iterator* si)
{ {
out_->get_graph().new_transition(in - 1, out - 1, out_->new_transition(in - 1, out - 1,
si->current_condition(), si->current_condition(),
si->current_acceptance_conditions()); si->current_acceptance_conditions());
} }
protected: protected:

View file

@ -287,7 +287,6 @@ namespace spot
{ {
auto d = a->get_dict(); auto d = a->get_dict();
auto res = new tgba_digraph(d); auto res = new tgba_digraph(d);
auto& g = res->get_graph();
d->register_all_variables_of(a, res); d->register_all_variables_of(a, res);
const state* s = a->get_init_state(); const state* s = a->get_init_state();
@ -308,7 +307,7 @@ namespace spot
tgba_run::steps::const_iterator i = l->begin(); tgba_run::steps::const_iterator i = l->begin();
assert(s->compare(i->s) == 0); assert(s->compare(i->s) == 0);
src = g.new_state(); src = res->new_state();
seen.insert(std::make_pair(i->s, src)); seen.insert(std::make_pair(i->s, src));
for (; i != l->end();) for (; i != l->end();)
@ -358,10 +357,10 @@ namespace spot
auto p = seen.insert(std::make_pair(next, 0)); auto p = seen.insert(std::make_pair(next, 0));
if (p.second) if (p.second)
p.first->second = g.new_state(); p.first->second = res->new_state();
dst = p.first->second; dst = p.first->second;
g.new_transition(src, dst, label, acc); res->new_transition(src, dst, label, acc);
src = dst; src = dst;
// Sum acceptance conditions. // Sum acceptance conditions.

View file

@ -177,8 +177,7 @@ namespace spot
{ {
auto aut = std::unique_ptr<tgba_digraph>(new tgba_digraph(dict)); auto aut = std::unique_ptr<tgba_digraph>(new tgba_digraph(dict));
acc_mapper_int acc_b(aut.get(), num_acc, envacc); acc_mapper_int acc_b(aut.get(), num_acc, envacc);
auto& g = aut->get_graph(); aut->new_states(num_states);
g.new_states(num_states);
for (unsigned n = 0; n < num_states; ++n) for (unsigned n = 0; n < num_states; ++n)
{ {
@ -229,7 +228,7 @@ namespace spot
} }
bdd cond = formula_to_bdd(f, dict, aut.get()); bdd cond = formula_to_bdd(f, dict, aut.get());
f->destroy(); f->destroy();
g.new_transition(src_state, dst_state, cond, acc); aut->new_transition(src_state, dst_state, cond, acc);
} }
} }
return aut.release(); return aut.release();
@ -243,8 +242,7 @@ namespace spot
{ {
auto aut = std::unique_ptr<tgba_digraph>(new tgba_digraph(dict)); auto aut = std::unique_ptr<tgba_digraph>(new tgba_digraph(dict));
acc_mapper_int acc_b(aut.get(), num_acc, envacc); acc_mapper_int acc_b(aut.get(), num_acc, envacc);
auto& g = aut->get_graph(); aut->new_states(num_states);
g.new_states(num_states);
for (unsigned n = 0; n < num_states; ++n) for (unsigned n = 0; n < num_states; ++n)
{ {
@ -295,7 +293,7 @@ namespace spot
} }
bdd cond = formula_to_bdd(f, dict, aut.get()); bdd cond = formula_to_bdd(f, dict, aut.get());
f->destroy(); f->destroy();
g.new_transition(src_state, dst_state, cond, acc); aut->new_transition(src_state, dst_state, cond, acc);
} }
} }
return aut.release(); return aut.release();

View file

@ -55,14 +55,13 @@ namespace spot
auto res = new tgba_digraph(d); auto res = new tgba_digraph(d);
d->register_all_variables_of(aut, res); d->register_all_variables_of(aut, res);
d->unregister_all_typed_variables(bdd_dict::acc, res); d->unregister_all_typed_variables(bdd_dict::acc, res);
auto& g = res->get_graph();
{ {
power_state ps; power_state ps;
const state* s = pm.canonicalize(aut->get_init_state()); const state* s = pm.canonicalize(aut->get_init_state());
ps.insert(s); ps.insert(s);
todo.push_back(ps); todo.push_back(ps);
unsigned num = g.new_state(); unsigned num = res->new_state();
seen[ps] = num; seen[ps] = num;
pm.map_[num] = ps; pm.map_[num] = ps;
} }
@ -101,12 +100,12 @@ namespace spot
} }
else else
{ {
dest_num = g.new_state(); dest_num = res->new_state();
seen[dest] = dest_num; seen[dest] = dest_num;
pm.map_[dest_num] = dest; pm.map_[dest_num] = dest;
todo.push_back(dest); todo.push_back(dest);
} }
g.new_transition(seen[src], dest_num, cond); res->new_transition(seen[src], dest_num, cond);
} }
} }
if (merge) if (merge)
@ -180,15 +179,14 @@ namespace spot
// Build an automaton representing this loop. // Build an automaton representing this loop.
tgba_digraph loop_a(aut_->get_dict()); tgba_digraph loop_a(aut_->get_dict());
auto& g = loop_a.get_graph();
int loop_size = std::distance(begin, dfs_.end()); int loop_size = std::distance(begin, dfs_.end());
g.new_states(loop_size); loop_a.new_states(loop_size);
int n; int n;
cycle_iter i; cycle_iter i;
for (n = 1, i = begin; n <= loop_size; ++n, ++i) for (n = 1, i = begin; n <= loop_size; ++n, ++i)
{ {
trans* t = &a->trans_data(i->succ); trans* t = &a->trans_data(i->succ);
g.new_transition(n - 1, n % loop_size, t->cond); loop_a.new_transition(n - 1, n % loop_size, t->cond);
if (reject_.find(t) == reject_.end()) if (reject_.find(t) == reject_.end())
ts.insert(t); ts.insert(t);
} }

View file

@ -76,7 +76,7 @@ namespace spot
if (drand() < a) if (drand() < a)
ac |= *i; ac |= *i;
aut->get_graph().new_transition(src, dest, p, ac); aut->new_transition(src, dest, p, ac);
} }
} }
@ -117,7 +117,7 @@ namespace spot
node_set nodes_to_process; node_set nodes_to_process;
node_set unreachable_nodes; node_set unreachable_nodes;
res->get_graph().new_states(n); res->new_states(n);
std::vector<unsigned> state_randomizer(n); std::vector<unsigned> state_randomizer(n);
state_randomizer[0] = 0; state_randomizer[0] = 0;

View file

@ -1023,15 +1023,13 @@ namespace spot
bdd neg = aut->neg_acceptance_conditions(); bdd neg = aut->neg_acceptance_conditions();
filtered->set_acceptance_conditions(filter.accsets(all, neg).first); filtered->set_acceptance_conditions(filter.accsets(all, neg).first);
} }
const tgba_digraph::graph_t& ing = aut->get_graph(); filtered->new_states(out_n);
tgba_digraph::graph_t& outg = filtered->get_graph();
outg.new_states(out_n);
for (unsigned isrc = 0; isrc < in_n; ++isrc) for (unsigned isrc = 0; isrc < in_n; ++isrc)
{ {
unsigned osrc = inout[isrc]; unsigned osrc = inout[isrc];
if (osrc >= out_n) if (osrc >= out_n)
continue; continue;
for (auto& t: ing.out(isrc)) for (auto& t: aut->out(isrc))
{ {
unsigned odst = inout[t.dst]; unsigned odst = inout[t.dst];
if (odst >= out_n) if (odst >= out_n)
@ -1042,7 +1040,7 @@ namespace spot
std::tie(want, cond, acc) = std::tie(want, cond, acc) =
filter.trans(isrc, t.dst, t.cond, t.acc); filter.trans(isrc, t.dst, t.cond, t.acc);
if (want) if (want)
outg.new_transition(osrc, odst, cond, acc); filtered->new_transition(osrc, odst, cond, acc);
} }
} }
if (!given_si) if (!given_si)

View file

@ -81,7 +81,7 @@ namespace spot
num_ = -1; num_ = -1;
h_[init] = num_; h_[init] = num_;
root_.emplace_front(num_, bddfalse, bddfalse); root_.emplace_front(num_, bddfalse, bddfalse);
todo_.emplace(init, aut->get_graph().out(init).begin()); todo_.emplace(init, aut->out(init).begin());
} }
while (!todo_.empty()) while (!todo_.empty())
@ -148,7 +148,7 @@ namespace spot
// for later processing. // for later processing.
h_[dest] = --num_; h_[dest] = --num_;
root_.emplace_front(num_, cond, acc); root_.emplace_front(num_, cond, acc);
todo_.emplace(dest, aut->get_graph().out(dest).begin()); todo_.emplace(dest, aut->out(dest).begin());
continue; continue;
} }
@ -230,8 +230,7 @@ namespace spot
std::vector<bdd> scc_info::used_acc() const std::vector<bdd> scc_info::used_acc() const
{ {
auto& g = aut_->get_graph(); unsigned n = aut_->num_states();
unsigned n = g.num_states();
std::vector<bdd> result(scc_count()); std::vector<bdd> result(scc_count());
acceptance_convertor conv(aut_->neg_acceptance_conditions()); acceptance_convertor conv(aut_->neg_acceptance_conditions());
@ -240,7 +239,7 @@ namespace spot
unsigned src_scc = scc_of(src); unsigned src_scc = scc_of(src);
if (!is_accepting_scc(src_scc)) if (!is_accepting_scc(src_scc))
continue; continue;
for (auto& t: g.out(src)) for (auto& t: aut_->out(src))
{ {
if (scc_of(t.dst) != src_scc) if (scc_of(t.dst) != src_scc)
continue; continue;

View file

@ -236,14 +236,12 @@ namespace spot
bd->register_all_variables_of(old_a_, a_); bd->register_all_variables_of(old_a_, a_);
a_->copy_acceptance_conditions_of(old_a_); a_->copy_acceptance_conditions_of(old_a_);
} }
tgba_digraph::graph_t& gout = a_->get_graph(); unsigned ns = old_a_->num_states();
tgba_digraph::graph_t& gin = old_a_->get_graph();
unsigned ns = gin.num_states();
if (Cosimulation) if (Cosimulation)
gout.new_states(ns); a_->new_states(ns);
for (unsigned s = 0; s < ns; ++s) for (unsigned s = 0; s < ns; ++s)
{ {
for (auto& t: gin.out(s)) for (auto& t: old_a_->out(s))
{ {
bdd acc; bdd acc;
if (Sba && Cosimulation) if (Sba && Cosimulation)
@ -255,7 +253,7 @@ namespace spot
// (which now become outgoing arcs after // (which now become outgoing arcs after
// transposition). // transposition).
acc = bddfalse; acc = bddfalse;
for (auto& td: gin.out(t.dst)) for (auto& td: old_a_->out(t.dst))
{ {
acc = ac.complement(td.acc); acc = ac.complement(td.acc);
break; break;
@ -266,7 +264,7 @@ namespace spot
acc = ac.complement(t.acc); acc = ac.complement(t.acc);
} }
if (Cosimulation) if (Cosimulation)
gout.new_transition(t.dst, s, t.cond, acc); a_->new_transition(t.dst, s, t.cond, acc);
else else
t.acc = acc; t.acc = acc;
} }
@ -378,7 +376,7 @@ namespace spot
{ {
bdd res = bddfalse; bdd res = bddfalse;
for (auto& t: a_->get_graph().out(src)) for (auto& t: a_->out(src))
{ {
bdd acc = bddtrue; bdd acc = bddtrue;
@ -681,14 +679,13 @@ namespace spot
// dealing with SBA in cosimulation. // dealing with SBA in cosimulation.
if (Sba && Cosimulation) if (Sba && Cosimulation)
{ {
tgba_digraph::graph_t& g = res->get_graph();
unsigned ns = res->num_states(); unsigned ns = res->num_states();
for (unsigned s = 0; s < ns; ++s) for (unsigned s = 0; s < ns; ++s)
{ {
bdd acc = accst[s]; bdd acc = accst[s];
if (acc == bddfalse) if (acc == bddfalse)
continue; continue;
for (auto& t: g.out(s)) for (auto& t: res->out(s))
t.acc = acc; t.acc = acc;
} }
} }
@ -831,7 +828,7 @@ namespace spot
unsigned scc = scc_map_->scc_of_state(old_a_->state_from_number(src)); unsigned scc = scc_map_->scc_of_state(old_a_->state_from_number(src));
bool sccacc = scc_map_->accepting(scc); bool sccacc = scc_map_->accepting(scc);
for (auto& t: a_->get_graph().out(src)) for (auto& t: a_->out(src))
{ {
bdd cl = previous_class_[t.dst]; bdd cl = previous_class_[t.dst];
bdd acc; bdd acc;