highlight: improve support for highlighted edges
* spot/twa/twa.cc, spot/twa/twa.hh: Add a way to remove named properties. * spot/twa/twagraph.cc: Clear highlight-edges on operations that reorder the edge vector. * spot/twaalgos/randomize.cc, spot/twaalgos/randomize.hh: Preserve highlighted state, but not highlighted edges. * spot/twaalgos/hoa.cc: Adjust output of highlight-edge when the edges are not stored in order. * tests/core/readsave.test, tests/core/tgbagraph.test, tests/core/twagraph.cc: More test cases.
This commit is contained in:
parent
e17a617bc2
commit
39332fb118
9 changed files with 128 additions and 23 deletions
|
|
@ -508,9 +508,24 @@ namespace spot
|
|||
if (auto hedges = aut->get_named_prop
|
||||
<std::map<unsigned, unsigned>>("highlight-edges"))
|
||||
{
|
||||
// Numbering edges is a delicate process. The
|
||||
// "highlight-edges" property uses edges numbers that are
|
||||
// indices in the "edges" vector. However these edges
|
||||
// need not be sorted. When edges are output in HOA, they
|
||||
// are output with increasing source state number, and the
|
||||
// edges number expected in the HOA file should use that
|
||||
// order. So we need to make a first pass on the
|
||||
// automaton to number all edges as they will be output.
|
||||
unsigned maxedge = aut->edge_vector().size();
|
||||
std::vector<unsigned> renum(maxedge);
|
||||
unsigned edge = 0;
|
||||
for (unsigned i = 0; i < num_states; ++i)
|
||||
for (auto& t: aut->out(i))
|
||||
renum[aut->get_graph().index_of_edge(t)] = ++edge;
|
||||
os << "spot.highlight.edges:";
|
||||
for (auto& p: *hedges)
|
||||
os << ' ' << p.first << ' ' << p.second;
|
||||
if (p.first < maxedge) // highlighted edges could come from user
|
||||
os << ' ' << renum[p.first] << ' ' << p.second;
|
||||
os << nl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2014, 2015 Laboratoire de Recherche et Développement
|
||||
// Copyright (C) 2014, 2015, 2016 Laboratoire de Recherche et Développement
|
||||
// de l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
|
|
@ -50,6 +50,14 @@ namespace spot
|
|||
(*nn)[nums[i]] = (*sn)[i];
|
||||
aut->set_named_prop("state-names", nn);
|
||||
}
|
||||
if (auto hs = aut->get_named_prop<std::map<unsigned, unsigned>>
|
||||
("highlight-states"))
|
||||
{
|
||||
std::map<unsigned, unsigned> hs2;
|
||||
for (auto p: *hs)
|
||||
hs2[nums[p.first]] = p.second;
|
||||
std::swap(*hs, hs2);
|
||||
}
|
||||
}
|
||||
if (randomize_edges)
|
||||
{
|
||||
|
|
@ -57,7 +65,7 @@ namespace spot
|
|||
auto& v = g.edge_vector();
|
||||
mrandom_shuffle(v.begin() + 1, v.end());
|
||||
}
|
||||
|
||||
aut->set_named_prop("highlight-edges", nullptr);
|
||||
typedef twa_graph::graph_t::edge_storage_t tr_t;
|
||||
g.sort_edges_([](const tr_t& lhs, const tr_t& rhs)
|
||||
{ return lhs.src < rhs.src; });
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2014, 2015 Laboratoire de Recherche et
|
||||
// Copyright (C) 2014, 2015, 2016 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
|
|
@ -27,6 +27,9 @@ namespace spot
|
|||
///
|
||||
/// Make a random permutation of the state, and of the edges
|
||||
/// leaving this state.
|
||||
///
|
||||
/// This function preserves state names, and highlighted states,
|
||||
/// but it does not preserve highlighted edges.
|
||||
SPOT_API void
|
||||
randomize(twa_graph_ptr& aut,
|
||||
bool randomize_states = true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue