tgbagraph: add a merge_transitions() method.

* src/graph/graph.hh: Add some framework to erase transitions, and
defrag the resulting transitions_ vector on demand.  Also remove
the nb_states() and nb_transitions() because num_states() and
num_transitions() already exist.
* src/graphtest/graph.cc, src/graphtest/ngraph.cc: Adjust to
use num_states().
* src/tgba/tgbagraph.hh (merge_transitions): New method.
* src/misc/hash.hh: Add a pair_hash class, needed by
merge_transitions().
* src/graphtest/tgbagraph.cc, src/graphtest/tgbagraph.test: Add states
for transitions removal and merge_transitions().
This commit is contained in:
Alexandre Duret-Lutz 2014-05-21 19:16:50 +02:00
parent 9909699c63
commit 424de90385
7 changed files with 286 additions and 10 deletions

View file

@ -55,7 +55,7 @@ void
dot(std::ostream& out, spot::digraph<SL, TL>& g)
{
out << "digraph {\n";
unsigned c = g.nb_states();
unsigned c = g.num_states();
for (unsigned s = 0; s < c; ++s)
{
out << ' ' << s;

View file

@ -73,7 +73,7 @@ void
dot(std::ostream& out, const spot::digraph<SL, TL>& g)
{
out << "digraph {\n";
unsigned c = g.nb_states();
unsigned c = g.num_states();
for (unsigned s = 0; s < c; ++s)
{
out << ' ' << s;
@ -93,7 +93,7 @@ dot(std::ostream& out, const spot::named_graph<G1, G2, G3, G4>& g)
{
out << "digraph {\n";
auto& gg = g.graph();
unsigned c = gg.nb_states();
unsigned c = gg.num_states();
for (unsigned s = 0; s < c; ++s)
{
out << ' ' << s;

View file

@ -44,6 +44,7 @@ void f1()
auto s1 = g.new_state();
auto s2 = g.new_state();
auto s3 = g.new_state();
g.new_transition(s1, s1, bddfalse, bddfalse);
g.new_transition(s1, s2, p1, bddfalse);
g.new_transition(s1, s3, p2, !a1 & a2);
g.new_transition(s2, s3, p1 & p2, a1 & !a2);
@ -52,6 +53,36 @@ void f1()
g.new_transition(s3, s3, bddtrue, (!a1 & a2) | (a1 & !a2));
spot::dotty_reachable(std::cout, &tg);
{
auto i = g.out_iteraser(s3);
++i;
i.erase();
i.erase();
assert(!i);
spot::dotty_reachable(std::cout, &tg);
}
{
auto i = g.out_iteraser(s3);
i.erase();
assert(!i);
spot::dotty_reachable(std::cout, &tg);
}
g.new_transition(s3, s1, p1 | p2, (!a1 & a2) | (a1 & !a2));
g.new_transition(s3, s2, p1 >> p2, bddfalse);
g.new_transition(s3, s1, bddtrue, (!a1 & a2) | (a1 & !a2));
std::cerr << tg.num_transitions() << '\n';
assert(tg.num_transitions() == 7);
spot::dotty_reachable(std::cout, &tg);
tg.merge_transitions();
spot::dotty_reachable(std::cout, &tg);
std::cerr << tg.num_transitions() << '\n';
assert(tg.num_transitions() == 5);
}
int main()

View file

@ -37,6 +37,7 @@ digraph G {
0 [label="", style=invis, height=0]
0 -> 1
1 [label="0"]
1 -> 1 [label="0\n"]
1 -> 2 [label="p1\n"]
1 -> 3 [label="p2\n{Acc[p2]}"]
2 [label="1"]
@ -46,6 +47,55 @@ digraph G {
3 -> 2 [label="!p1 | p2\n"]
3 -> 3 [label="1\n{Acc[p2], Acc[p1]}"]
}
digraph G {
0 [label="", style=invis, height=0]
0 -> 1
1 [label="0"]
1 -> 1 [label="0\n"]
1 -> 2 [label="p1\n"]
1 -> 3 [label="p2\n{Acc[p2]}"]
2 [label="1"]
2 -> 3 [label="p1 & p2\n{Acc[p1]}"]
3 [label="2"]
3 -> 1 [label="p1 | p2\n{Acc[p2], Acc[p1]}"]
}
digraph G {
0 [label="", style=invis, height=0]
0 -> 1
1 [label="0"]
1 -> 1 [label="0\n"]
1 -> 2 [label="p1\n"]
1 -> 3 [label="p2\n{Acc[p2]}"]
2 [label="1"]
2 -> 3 [label="p1 & p2\n{Acc[p1]}"]
3 [label="2"]
}
digraph G {
0 [label="", style=invis, height=0]
0 -> 1
1 [label="0"]
1 -> 1 [label="0\n"]
1 -> 2 [label="p1\n"]
1 -> 3 [label="p2\n{Acc[p2]}"]
2 [label="1"]
2 -> 3 [label="p1 & p2\n{Acc[p1]}"]
3 [label="2"]
3 -> 1 [label="p1 | p2\n{Acc[p2], Acc[p1]}"]
3 -> 2 [label="!p1 | p2\n"]
3 -> 1 [label="1\n{Acc[p2], Acc[p1]}"]
}
digraph G {
0 [label="", style=invis, height=0]
0 -> 1
1 [label="0"]
1 -> 2 [label="p1\n"]
1 -> 3 [label="p2\n{Acc[p2]}"]
2 [label="1"]
2 -> 3 [label="p1 & p2\n{Acc[p1]}"]
3 [label="2"]
3 -> 1 [label="1\n{Acc[p2], Acc[p1]}"]
3 -> 2 [label="!p1 | p2\n"]
}
EOF
diff stdout expected