safra: Iterate on APs to compute successors

* spot/twaalgos/safra.cc, spot/twaalgos/safra.hh: Here.
This commit is contained in:
Alexandre Lewkowicz 2016-02-04 16:03:47 +01:00 committed by Alexandre Duret-Lutz
parent 8068cfad93
commit dbd7740874
2 changed files with 32 additions and 34 deletions

View file

@ -184,28 +184,28 @@ safra_state::find_scc_brace_id(unsigned scc_id, const scc_info& scc)
void void
safra_state::compute_succs(const const_twa_graph_ptr& aut, safra_state::compute_succs(const const_twa_graph_ptr& aut,
const std::vector<bdd_id_t>& bddnums, succs_t& res,
std::unordered_map<bdd, const scc_info& scc,
std::pair<unsigned, unsigned>, const std::map<int, bdd>& implications,
bdd_hash>& deltas, const std::vector<bool>& is_connected,
succs_t& res, std::unordered_map<bdd, unsigned, bdd_hash>& bdd2num,
const scc_info& scc, std::vector<bdd>& all_bdds,
const std::map<int, bdd>& implications, bool scc_opt,
const std::vector<bool>& is_connected, bool use_bisimulation) const
bool scc_opt,
bool use_bisimulation) const
{ {
// Given a bdd returns index of associated safra_state in res // Given a bdd returns index of associated safra_state in res
std::map<unsigned, unsigned> bdd2num; std::map<unsigned, unsigned> bdd_idx2node_idx;
for (auto& node: nodes_) for (auto& ap: all_bdds)
{ {
for (auto& t: aut->out(node.first)) for (auto& node: nodes_)
{ {
// deltas precalculate all transitions in edge t for (auto& t: aut->out(node.first))
auto p = deltas[t.cond];
for (unsigned j = p.first; j < p.second; ++j)
{ {
auto i = bdd2num.insert(std::make_pair(bddnums[j], res.size())); if (!bdd_implies(ap, t.cond))
continue;
unsigned bdd_idx = bdd2num[ap];
auto i = bdd_idx2node_idx.insert(std::make_pair(bdd_idx,
res.size()));
unsigned idx; unsigned idx;
if (!i.second) if (!i.second)
// No new state added, so get pre-existing state whichi is an // No new state added, so get pre-existing state whichi is an
@ -215,8 +215,7 @@ safra_state::compute_succs(const const_twa_graph_ptr& aut,
{ {
// Each new node starts out with same number of nodes as src // Each new node starts out with same number of nodes as src
idx = res.size(); idx = res.size();
res.emplace_back(safra_state(nb_braces_.size()), res.emplace_back(safra_state(nb_braces_.size()), bdd_idx);
bddnums[j]);
} }
safra_state& ss = res[idx].first; safra_state& ss = res[idx].first;
// Check if we are leaving the SCC, if so we delete all the // Check if we are leaving the SCC, if so we delete all the
@ -245,7 +244,7 @@ safra_state::compute_succs(const const_twa_graph_ptr& aut,
assert(ss.nb_braces_.size() == ss.is_green_.size()); assert(ss.nb_braces_.size() == ss.is_green_.size());
} }
} }
} }
for (auto& s: res) for (auto& s: res)
{ {
safra_state& tmp = s.first; safra_state& tmp = s.first;
@ -254,7 +253,7 @@ safra_state::compute_succs(const const_twa_graph_ptr& aut,
tmp.ungreenify_last_brace(); tmp.ungreenify_last_brace();
s.first.color_ = tmp.finalize_construction(); s.first.color_ = tmp.finalize_construction();
} }
} }
void void
safra_state::merge_redundant_states(const std::map<int, bdd>& implications, safra_state::merge_redundant_states(const std::map<int, bdd>& implications,
@ -572,8 +571,8 @@ safra_state::compute_succs(const const_twa_graph_ptr& aut,
safra_state curr = todo.front(); safra_state curr = todo.front();
unsigned src_num = seen.find(curr)->second; unsigned src_num = seen.find(curr)->second;
todo.pop_front(); todo.pop_front();
curr.compute_succs(aut, bddnums, deltas, succs, scc, implications, curr.compute_succs(aut, succs, scc, implications, is_connected,
is_connected, scc_opt, use_bisimulation); bdd2num, num2bdd, scc_opt, use_bisimulation);
for (auto s: succs) for (auto s: succs)
{ {
auto i = seen.find(s.first); auto i = seen.find(s.first);

View file

@ -54,17 +54,16 @@ namespace spot
bool acceptance_scc = false); bool acceptance_scc = false);
// Given a certain transition_label, compute all the successors of that // Given a certain transition_label, compute all the successors of that
// label, and return that new node. // label, and return that new node.
void compute_succs(const const_twa_graph_ptr& aut, void
const std::vector<bdd_id_t>& bddnums, compute_succs(const const_twa_graph_ptr& aut,
std::unordered_map<bdd, succs_t& res,
std::pair<unsigned, unsigned>, const scc_info& scc,
bdd_hash>& deltas, const std::map<int, bdd>& implications,
succs_t& res, const std::vector<bool>& is_connected,
const scc_info& scc, std::unordered_map<bdd, unsigned, bdd_hash>& bdd2num,
const std::map<int, bdd>& implications, std::vector<bdd>& all_bdds,
const std::vector<bool>& is_connected, bool scc_opt,
bool scc_opt = false, bool use_bisimulation) const;
bool use_bisimulation = false) const;
// scc_id has to be an accepting SCC. This function tries to find a node // scc_id has to be an accepting SCC. This function tries to find a node
// who lives in that SCC and if it does, we return the brace_id of that SCC. // who lives in that SCC and if it does, we return the brace_id of that SCC.
unsigned find_scc_brace_id(unsigned scc_id, const scc_info& scc); unsigned find_scc_brace_id(unsigned scc_id, const scc_info& scc);