Adding selective edge sorting and state merging

The merging is (possibly) more expensive but also
merges more states when applied to all states.

* spot/graph/graph.hh: edge sorting
* spot/twa/twagraph.cc,
spot/twa/twagraph.hh: selective state merging
* tests/core/twagraph.cc: Adjusting tests
This commit is contained in:
philipp 2021-08-12 00:04:29 +02:00 committed by Florian Renkin
parent 2c267dd894
commit 786599ed20
4 changed files with 280 additions and 1 deletions

View file

@ -88,7 +88,9 @@ static void f1()
// Test purge with named and highlighted states.
static void f2()
{
auto d = spot::make_bdd_dict();
auto
d = spot::make_bdd_dict();
auto tg = make_twa_graph(d);
auto s1 = tg->new_state();
@ -186,6 +188,76 @@ static void f5()
spot::print_hoa(std::cout, tg) << '\n';
}
// Test merge_states_of()
static void f6()
{
auto d = spot::make_bdd_dict();
auto tg = make_twa_graph(d);
auto s1 = tg->new_state();
auto s2 = tg->new_state();
auto s3 = tg->new_state();
auto s4 = tg->new_state();
auto s5 = tg->new_state();
tg->set_init_state(s5);
tg->new_edge(s1, s2, bddtrue);
tg->new_edge(s2, s2, bddtrue);
tg->new_edge(s3, s2, bddtrue);
tg->new_edge(s4, s4, bddtrue);
tg->new_edge(s5, s1, bddtrue);
tg->new_edge(s5, s2, bddtrue);
tg->new_edge(s5, s3, bddtrue);
tg->new_edge(s5, s4, bddtrue);
unsigned out = tg->merge_states_of();
assert(out == 3);
}
// Compare merge_states() and merge_states_of()
// when faced with a more involved problem
static void f7()
{
// The current mege_states implementation of "next"
// needs two successive calls to obtain an automaton with only 3 states
// This is especially annoying as this depends on the numbering.
// By renumbering 2->1 3->2 1->3 the current version only needs one call too
auto get_aut = []()
{
auto d = spot::make_bdd_dict();
auto aut = make_twa_graph(d);
aut->new_states(5);
aut->new_edge(0, 1, bddtrue);
aut->new_edge(0, 2, bddtrue);
aut->new_edge(1, 1, bddtrue);
aut->new_edge(1, 4, bddtrue);
aut->new_edge(2, 3, bddtrue);
aut->new_edge(2, 4, bddtrue);
aut->new_edge(3, 3, bddtrue);
aut->new_edge(3, 4, bddtrue);
return aut;
};
auto aut = get_aut();
// Basic merge_states needs 2 iterations
// Merging only one step each
assert(aut->merge_states() == 1u);
assert(aut->merge_states() == 1u);
assert(aut->num_states() == 3u);
// merge_states_of can do it in one iteration
// when used on all states
aut = get_aut();
assert(aut->merge_states_of() == 2u);
assert(aut->num_states() == 3u);
}
int main()
{
f1();
@ -193,4 +265,6 @@ int main()
f3();
f4();
f5();
f6();
f7();
}