maskacc: Add a tgba_digraph version

* src/tgbaalgos/mask.cc, src/tgbaalgos/mask.hh: New files.
* src/tgbaalgos/Makefile.am: Adjust.
* src/tgba/acc.hh (mark_t::set): New method.
* src/bin/autfilt.cc: Add option --mask-acc.
* src/tgbatest/maskacc.test: Rewrite.
* src/tgbatest/maskacc.cc: Delete.
* src/tgbatest/Makefile.am: Adjust.
This commit is contained in:
Alexandre Duret-Lutz 2015-01-31 20:28:47 +01:00
parent a0a035e0e1
commit d0f0be234d
8 changed files with 264 additions and 90 deletions

View file

@ -50,6 +50,7 @@ tgbaalgos_HEADERS = \
ltl2taa.hh \
ltl2tgba_fm.hh \
magic.hh \
mask.hh \
minimize.hh \
neverclaim.hh \
postproc.hh \
@ -100,6 +101,7 @@ libtgbaalgos_la_SOURCES = \
ltl2taa.cc \
ltl2tgba_fm.cc \
magic.cc \
mask.cc \
minimize.cc \
ndfs_result.hxx \
neverclaim.cc \

47
src/tgbaalgos/mask.cc Normal file
View file

@ -0,0 +1,47 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2015 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "mask.hh"
namespace spot
{
tgba_digraph_ptr mask_acc_sets(const const_tgba_digraph_ptr& in,
acc_cond::mark_t to_remove)
{
auto& inacc = in->acc();
auto res = make_tgba_digraph(in->get_dict());
res->copy_ap_of(in);
res->prop_copy(in, { true, false, true, true });
unsigned na = inacc.num_sets();
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);
});
return res;
}
}

93
src/tgbaalgos/mask.hh Normal file
View file

@ -0,0 +1,93 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2015 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef SPOT_TGBAALGOS_MASK_HH
# define SPOT_TGBAALGOS_MASK_HH
#include "tgba/tgbagraph.hh"
namespace spot
{
/// \brief Clone and mask an automaton.
///
/// 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:
/// <code>
/// void (*trans) (bdd& 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
/// (this will also remove the destination state and its descendants
/// if they are not reachable by another transition).
template<typename Trans>
void transform_mask(const const_tgba_digraph_ptr& old,
tgba_digraph_ptr& cpy,
Trans trans)
{
std::vector<unsigned> todo;
std::vector<unsigned> seen(old->num_states(), -1U);
auto new_state =
[&](unsigned old_state) -> unsigned
{
unsigned tmp = seen[old_state];
if (tmp == -1U)
{
tmp = cpy->new_state();
seen[old_state] = tmp;
todo.push_back(old_state);
}
return tmp;
};
new_state(old->get_init_state_number());
while (!todo.empty())
{
unsigned old_src = todo.back();
todo.pop_back();
unsigned new_src = seen[old_src];
assert(new_src != -1U);
for (auto& t: old->out(old_src))
{
bdd cond = t.cond;
acc_cond::mark_t acc = t.acc;
trans(cond, acc, t.dst);
if (cond != bddfalse)
cpy->new_transition(new_src,
new_state(t.dst),
cond, acc);
}
}
}
/// \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);
}
#endif // SPOT_TGBAALGOS_MASK_HH