maskkeep: Add a tgba_digraph version

* src/bin/autfilt.cc: Add option --keep-states.
* src/tgbaalgos/mask.cc, src/tgbaalgos/mask.hh: Keep the selected states
and update the initial state.
* src/tgbatest/Makefile.am: Adjust.
* src/tgbatest/maskkeep.test: New file.
This commit is contained in:
Alexandre Lewkowicz 2015-02-12 14:49:37 +01:00 committed by Alexandre Duret-Lutz
parent 727c351657
commit dcad10fc68
5 changed files with 182 additions and 11 deletions

View file

@ -44,4 +44,25 @@ namespace spot
return res;
}
tgba_digraph_ptr mask_keep_states(const const_tgba_digraph_ptr& in,
std::vector<bool>& to_keep,
unsigned int init)
{
if (to_keep.size() < in->num_states())
to_keep.resize(in->num_states(), false);
auto res = make_tgba_digraph(in->get_dict());
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)
{
if (!to_keep[dst])
cond = bddfalse;
}, init);
return res;
}
}

View file

@ -36,11 +36,12 @@ namespace spot
/// the transitions. Set the condition to bddfalse to remove it
/// (this will also remove the destination state and its descendants
/// if they are not reachable by another transition).
/// \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)
Trans trans, unsigned int init)
{
std::vector<unsigned> todo;
std::vector<unsigned> seen(old->num_states(), -1U);
@ -58,7 +59,7 @@ namespace spot
return tmp;
};
new_state(old->get_init_state_number());
cpy->set_init_state(new_state(init));
while (!todo.empty())
{
unsigned old_src = todo.back();
@ -81,11 +82,28 @@ namespace spot
}
}
template<typename Trans>
void transform_mask(const const_tgba_digraph_ptr& old,
tgba_digraph_ptr& cpy,
Trans trans)
{
transform_mask(old, cpy, trans, old->get_init_state_number());
}
/// \brief Remove all transitions that are in some given acceptance sets.
SPOT_API
tgba_digraph_ptr mask_acc_sets(const const_tgba_digraph_ptr& in,
acc_cond::mark_t to_remove);
/// \brief Keep only the states as specified by \a to_keep.
///
/// Each index in the vector \a to_keep specifies wether or not to keep that
/// state. The initial state will be set to \a init.
SPOT_API
tgba_digraph_ptr mask_keep_states(const const_tgba_digraph_ptr& in,
std::vector<bool>& to_keep,
unsigned int init);
}