langmap: adjust to only color non-unique languages
Fixes #203. * spot/twaalgos/langmap.hh (highlight_languages): Simplify the interface by only taking the automaton to color. * spot/twaalgos/langmap.cc (highlight_languages): Only introduce color for states that have a non-unique language. * tests/core/highlightstate.test: Update and add more tests. * tests/python/langmap.py: Keep the tests simple. * bin/autfilt.cc: Adjust usage and help string.
This commit is contained in:
parent
aa457a204d
commit
0ad62cb97b
5 changed files with 131 additions and 104 deletions
|
|
@ -1,5 +1,6 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2016 Laboratoire de Recherche et Développement de l'Epita.
|
||||
// Copyright (C) 2016, 2017 Laboratoire de Recherche et Développement
|
||||
// de l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
|
|
@ -26,18 +27,6 @@
|
|||
|
||||
namespace spot
|
||||
{
|
||||
void highlight_languages(twa_graph_ptr& aut,
|
||||
const std::vector<unsigned>& v)
|
||||
{
|
||||
auto hs = new std::map<unsigned, unsigned>;
|
||||
aut->set_named_prop("highlight-states", hs);
|
||||
|
||||
unsigned n_states = aut->num_states();
|
||||
for (unsigned i = 0; i < n_states; ++i)
|
||||
(*hs)[i] = v[i];
|
||||
}
|
||||
|
||||
|
||||
std::vector<unsigned>
|
||||
language_map(const const_twa_graph_ptr& aut)
|
||||
{
|
||||
|
|
@ -80,4 +69,38 @@ namespace spot
|
|||
|
||||
return res;
|
||||
}
|
||||
|
||||
void highlight_languages(twa_graph_ptr& aut)
|
||||
{
|
||||
std::vector<unsigned> lang = language_map(aut);
|
||||
unsigned lang_sz = lang.size();
|
||||
std::vector<unsigned> cnt(lang_sz, 0);
|
||||
for (unsigned v: lang)
|
||||
{
|
||||
assert(v < lang_sz);
|
||||
++cnt[v];
|
||||
}
|
||||
|
||||
unsigned color = 0;
|
||||
auto hs = new std::map<unsigned, unsigned>;
|
||||
aut->set_named_prop("highlight-states", hs);
|
||||
|
||||
assert(lang_sz == aut->num_states());
|
||||
|
||||
// Give a unique color number to each state that has not a unique
|
||||
// language. This assumes that lang[i] <= i, as guaranteed by
|
||||
// language_map.
|
||||
for (unsigned i = 0; i < lang_sz; ++i)
|
||||
{
|
||||
unsigned v = lang[i];
|
||||
if (cnt[v] > 1)
|
||||
{
|
||||
if (v == i)
|
||||
lang[i] = color++;
|
||||
else
|
||||
assert(v < i);
|
||||
(*hs)[i] = lang[v];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue