Commit 7fbf4e0e authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

remove_fin: ignore more useless transitions

Do not clone transitions that are necessarily part of on accepting
cycle in the main copy of the automaton.

* spot/twaalgos/remfin.cc: Use propagate_marks_vector to ignore more
edges.
* tests/core/remfin.test, tests/python/remfin.py,
tests/python/automata.ipynb: Adjust.
* tests/sanity/style.test: Do not choke on C++17 if statements with
initializer.
parent 91db0e1e
......@@ -48,6 +48,9 @@ New in spot 2.9.3.dev (not yet released)
- Translations for formulas such as FGp1 & FGp2 &...& FGp32 which
used to take ages are now instantaneous. (See issue #412.)
- remove_fin() learned to remove more unnecessary edges by using
propagate_marks_vector().
Bugs fixed:
- Handle xor and <-> in a more natural way when translating
......
......@@ -26,6 +26,7 @@
#include <spot/twaalgos/isdet.hh>
#include <spot/twaalgos/mask.hh>
#include <spot/twaalgos/alternation.hh>
#include <spot/twaalgos/degen.hh>
// #define TRACE
#ifdef TRACE
......@@ -621,6 +622,17 @@ namespace spot
bool sbacc = res->prop_state_acc().is_true();
scc_info si(aut, scc_info_options::TRACK_STATES);
unsigned nscc = si.scc_count();
// Help remove more useless transition by propagating marks.
auto propmarks = propagate_marks_vector(aut, &si);
// Edges that are already satisfying the acceptance of the
// main copy do not need to be duplicated in the clones, so
// we fill allacc_edge to remember those. Of course this is
// only needed if the main copy can be accepting and if we
// will create clones.
std::vector<bool> allacc_edge(aut->edge_vector().size(), false);
std::vector<unsigned> state_map(nst);
for (unsigned n = 0; n < nscc; ++n)
{
......@@ -668,10 +680,11 @@ namespace spot
a = (t.acc & main_sets) | main_add;
res->new_edge(s, t.dst, t.cond, a);
// remember edges that are completely accepting
if (check_main_acc && main_acc.accepting(a))
allacc_edge[aut->edge_number(t)] = true;
if (check_main_acc)
if (unsigned en = aut->edge_number(t);
main_acc.accepting(a | (propmarks[en] & main_sets)))
allacc_edge[en] = true;
}
// We do not need any other copy if the SCC is non-accepting,
// of if it does not intersect any Fin.
if (!intersects_fin)
......@@ -693,12 +706,16 @@ namespace spot
auto ns = state_map[s];
for (auto& t: aut->out(s))
{
if ((t.acc & r) || si.scc_of(t.dst) != n
// edges that are already accepting in the
// main copy need not be copied in the
// clone, since cycles going through them
// are already accepted.
|| allacc_edge[aut->edge_number(t)])
if (unsigned en = aut->edge_number(t);
// Ignore edges have r, or that
// necessarily go through r.
((t.acc | propmarks[en]) & r)
// Ignore edges between SCCs.
|| si.scc_of(t.dst) != n
// Ignore edges that are already accepting
// in the main copy need not be copied in
// the clone.
|| allacc_edge[en])
continue;
auto nd = state_map[t.dst];
res->new_edge(ns, nd, t.cond, (t.acc & k) | a);
......
......@@ -877,14 +877,12 @@ State: 0
State: 1
[2] 0
[!2] 1
[0&2] 2
[0&!2] 3
[2] 4
[!2] 5
State: 2
[0] 2 {0 2}
State: 3
[0&2] 2 {0 2}
[0&!2] 3 {0}
State: 4
[1 | 2] 4 {1 2}
......@@ -1457,7 +1455,7 @@ State: 3
[1] 3
--END--
HOA: v1
States: 6
States: 5
Start: 0
AP: 3 "a" "b" "c"
acc-name: Buchi
......@@ -1468,25 +1466,20 @@ State: 0
[t] 0
[!1&!2] 1
[0] 2
[1 | 2] 4
[1 | 2] 3
State: 1
[2] 0
[!2] 1
[0&2] 2
[0&!2] 3
[2] 4
[!2] 5
[2] 3
[!2] 4
State: 2
[0] 2 {0}
State: 3
[0&2] 2
[0&!2] 3
[1 | 2] 3 {0}
[!1&!2] 4
State: 4
[1 | 2] 4 {0}
[!1&!2] 5
State: 5
[2] 4 {0}
[!2] 5
[2] 3 {0}
[!2] 4
--END--
EOF
......
This diff is collapsed.
......@@ -92,4 +92,4 @@ State: 2
""")
b = spot.remove_fin(a)
size = (b.num_states(), b.num_edges())
assert size == (5, 17);
assert size == (5, 15);
#! /bin/sh
# -*- coding: utf-8 -*-
# Copyright (C) 2009-2019 Laboratoire de Recherche et Développement de
# Copyright (C) 2009-2020 Laboratoire de Recherche et Développement de
# l'Epita (LRDE).
# Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6
# (LIP6), département Systèmes Répartis Coopératifs (SRC), Université
......@@ -158,7 +158,10 @@ for dir in "$TOP/spot" "$TOP/bin" "$TOP/tests"; do
$GREP '[ ]if ([^()]*).*{' $tmp &&
diag 'Opening { should be on its own line.'
$GREP '[ ]if (.*).*;' $tmp &&
$GREP '[ ]if ([^()]*).*;' $tmp &&
diag 'if body should be on another line.'
$GREP '[ ]if ([^()]*([^()]*)[^()]*).*;' $tmp &&
diag 'if body should be on another line.'
$GREP '[ ]else.*;' $tmp &&
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment