transform: copy and accessible versions

* src/tgbaalgos/mask.cc, src/tgbaalgos/mask.hh: Rename transform_mask
to accessible_mask. Add Copy version and use it in mask_keep_states().
* src/tgbatest/maskkeep.test: Update.
This commit is contained in:
Alexandre Lewkowicz 2015-02-19 16:23:59 +01:00 committed by Alexandre Duret-Lutz
parent 223d41d26b
commit c61f053e2d
3 changed files with 101 additions and 31 deletions

View file

@ -32,15 +32,16 @@ namespace spot
unsigned tr = to_remove.count();
assert(tr <= na);
res->set_acceptance_conditions(na - tr);
transform_mask(in, res, [&](bdd& cond,
acc_cond::mark_t& acc,
unsigned)
{
if (acc & to_remove)
cond = bddfalse;
else
acc = inacc.strip(acc, to_remove);
});
transform_accessible(in, res, [&](unsigned,
bdd& cond,
acc_cond::mark_t& acc,
unsigned)
{
if (acc & to_remove)
cond = bddfalse;
else
acc = inacc.strip(acc, to_remove);
});
return res;
}
@ -55,11 +56,12 @@ namespace spot
res->copy_ap_of(in);
res->prop_copy(in, { true, true, true, true });
res->copy_acceptance_conditions_of(in);
transform_mask(in, res, [&](bdd& cond,
acc_cond::mark_t&,
unsigned dst)
transform_copy(in, res, [&](unsigned src,
bdd& cond,
acc_cond::mark_t&,
unsigned dst)
{
if (!to_keep[dst])
if (!to_keep[src] || !to_keep[dst])
cond = bddfalse;
}, init);
return res;

View file

@ -28,9 +28,10 @@ namespace spot
///
/// Copy the transition of the automaton \a old, into the automaton
/// \a cpy, creating new states at the same time. The argument \a
/// trans should behave as a fonction with the following prototype:
/// trans should behave as a function with the following prototype:
/// <code>
/// void (*trans) (bdd& cond, acc_cond::mark_t& acc, unsigned dst)
/// void (*trans) (unsigned srcbdd& cond, acc_cond::mark_t& acc,
/// unsigned dst)
/// </code>
/// It can modify either the condition or the acceptance sets of
/// the transitions. Set the condition to bddfalse to remove it
@ -39,9 +40,9 @@ namespace spot
/// \param init The optional new initial state.
template<typename Trans>
void transform_mask(const const_tgba_digraph_ptr& old,
tgba_digraph_ptr& cpy,
Trans trans, unsigned int init)
void transform_accessible(const const_tgba_digraph_ptr& old,
tgba_digraph_ptr& cpy,
Trans trans, unsigned int init)
{
std::vector<unsigned> todo;
std::vector<unsigned> seen(old->num_states(), -1U);
@ -72,7 +73,7 @@ namespace spot
{
bdd cond = t.cond;
acc_cond::mark_t acc = t.acc;
trans(cond, acc, t.dst);
trans(t.src, cond, acc, t.dst);
if (cond != bddfalse)
cpy->new_transition(new_src,
@ -82,12 +83,55 @@ namespace spot
}
}
/// \brief Copy an automaton and update each transitions.
///
/// Copy the states of the automaton \a old, into the automaton
/// \a cpy. Each state in \a cpy will have the same id as the ones in \a old.
/// The argument \a trans
/// should behave as a function with the following prototype:
/// <code>
/// void (*trans) (unsigned srcbdd& cond, acc_cond::mark_t& acc,
/// unsigned dst)
/// </code>
/// It can modify either the condition or the acceptance sets of
/// the transitions. Set the condition to bddfalse to remove it. Note that
/// all transtions will be processed.
/// \param init The optional new initial state.
template<typename Trans>
void transform_mask(const const_tgba_digraph_ptr& old,
tgba_digraph_ptr& cpy,
Trans trans)
void transform_copy(const const_tgba_digraph_ptr& old,
tgba_digraph_ptr& cpy,
Trans trans, unsigned int init)
{
transform_mask(old, cpy, trans, old->get_init_state_number());
// Each state in cpy corresponds to a unique state in old.
cpy->new_states(old->num_states());
cpy->set_init_state(init);
for (auto& t: old->transitions())
{
bdd cond = t.cond;
acc_cond::mark_t acc = t.acc;
trans(t.src, cond, acc, t.dst);
// Having the same number of states should assure that state ids are
// equivilent in old and cpy.
assert(t.src < cpy->num_states() && t.dst < cpy->num_states());
if (cond != bddfalse)
cpy->new_transition(t.src, t.dst, cond, acc);
}
}
template<typename Trans>
void transform_accessible(const const_tgba_digraph_ptr& old,
tgba_digraph_ptr& cpy,
Trans trans)
{
transform_accessible(old, cpy, trans, old->get_init_state_number());
}
template<typename Trans>
void transform_copy(const const_tgba_digraph_ptr& old,
tgba_digraph_ptr& cpy,
Trans trans)
{
transform_copy(old, cpy, trans, old->get_init_state_number());
}
/// \brief Remove all transitions that are in some given acceptance sets.