Commit 7e7c2575 authored by Thomas Medioni's avatar Thomas Medioni
Browse files

spot::sbacc() works on alternating automata, fix dualize

Fixes #273.

* NEWS: Mention this.
* spot/twaalgos/dualize.cc, tests/python/dualize.py: Adapt dualize.
* spot/twaalgos/sbacc.cc, tests/core/sbacc.test: sbacc support
  alternating automata
parent c8889e65
...@@ -148,6 +148,8 @@ New in spot 2.3.5.dev (not yet released) ...@@ -148,6 +148,8 @@ New in spot 2.3.5.dev (not yet released)
input automaton with generalized Büchi/co-Büchi acceptance and input automaton with generalized Büchi/co-Büchi acceptance and
convert it to a weak alternating automaton. convert it to a weak alternating automaton.
- spot::sbacc() is now able to work on alternating automata.
Python: Python:
- The 'spot.gen' package exports the functions from libspotgen. - The 'spot.gen' package exports the functions from libspotgen.
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
#include <spot/twaalgos/complete.hh> #include <spot/twaalgos/complete.hh>
#include <spot/twaalgos/dualize.hh> #include <spot/twaalgos/dualize.hh>
#include <spot/twaalgos/isdet.hh> #include <spot/twaalgos/isdet.hh>
#include <spot/twaalgos/sbacc.hh>
#include <memory>
namespace spot namespace spot
{ {
...@@ -272,7 +275,9 @@ namespace spot ...@@ -272,7 +275,9 @@ namespace spot
public: public:
dualizer(const const_twa_graph_ptr& aut) dualizer(const const_twa_graph_ptr& aut)
: aut_(aut), : aut_(is_universal(aut)
? aut
: sbacc(std::const_pointer_cast<spot::twa_graph>(aut))),
state_to_var_(aut_->num_states(), bddfalse), state_to_var_(aut_->num_states(), bddfalse),
true_state_(-1U), true_state_(-1U),
acc_(0U), acc_(0U),
......
...@@ -30,9 +30,6 @@ namespace spot ...@@ -30,9 +30,6 @@ namespace spot
{ {
if (old->prop_state_acc()) if (old->prop_state_acc())
return old; return old;
if (!old->is_existential())
throw std::runtime_error
("sbacc() does not support alternation");
// We will need a mark that is rejecting to mark rejecting states. // We will need a mark that is rejecting to mark rejecting states.
// If no such mark exist, our work is actually quite simple: we // If no such mark exist, our work is actually quite simple: we
...@@ -56,16 +53,18 @@ namespace spot ...@@ -56,16 +53,18 @@ namespace spot
// Marks that label one incoming transition from the same SCC. // Marks that label one incoming transition from the same SCC.
std::vector<acc_cond::mark_t> one_in(ns, 0U); std::vector<acc_cond::mark_t> one_in(ns, 0U);
for (auto& e: old->edges()) for (auto& e: old->edges())
if (si.scc_of(e.src) == si.scc_of(e.dst)) for (unsigned d: old->univ_dests(e.dst))
{ if (si.scc_of(e.src) == si.scc_of(d))
common_in[e.dst] &= e.acc; {
common_out[e.src] &= e.acc; common_in[d] &= e.acc;
} common_out[e.src] &= e.acc;
}
for (unsigned s = 0; s < ns; ++s) for (unsigned s = 0; s < ns; ++s)
common_out[s] |= common_in[s]; common_out[s] |= common_in[s];
for (auto& e: old->edges()) for (auto& e: old->edges())
if (si.scc_of(e.src) == si.scc_of(e.dst)) for (unsigned d: old->univ_dests(e.dst))
one_in[e.dst] = e.acc - common_out[e.src]; if (si.scc_of(e.src) == si.scc_of(d))
one_in[d] = e.acc - common_out[e.src];
auto res = make_twa_graph(old->get_dict()); auto res = make_twa_graph(old->get_dict());
res->copy_ap_of(old); res->copy_ap_of(old);
...@@ -92,14 +91,24 @@ namespace spot ...@@ -92,14 +91,24 @@ namespace spot
return p.first->second; return p.first->second;
}; };
unsigned old_init = old->get_init_state_number(); std::vector<unsigned> old_init;
acc_cond::mark_t init_acc = 0U; for (unsigned d: old->univ_dests(old->get_init_state_number()))
if (!si.is_rejecting_scc(si.scc_of(old_init))) old_init.push_back(d);
// Use any edge going into the initial state to set the first
// acceptance mark. std::vector<unsigned> old_st;
init_acc = one_in[old_init] | common_out[old_init]; internal::univ_dest_mapper<twa_graph::graph_t> uniq(res->get_graph());
for (unsigned s: old_init)
{
acc_cond::mark_t init_acc = 0U;
if (!si.is_rejecting_scc(si.scc_of(s)))
// Use any edge going into the initial state to set the first
// acceptance mark.
init_acc = one_in[s] | common_out[s];
old_st.push_back(new_state(s, init_acc));
}
res->set_init_state(uniq.new_univ_dests(old_st.begin(), old_st.end()));
res->set_init_state(new_state(old_init, init_acc));
while (!todo.empty()) while (!todo.empty())
{ {
auto one = todo.back(); auto one = todo.back();
...@@ -108,20 +117,27 @@ namespace spot ...@@ -108,20 +117,27 @@ namespace spot
bool maybe_accepting = !si.is_rejecting_scc(scc_src); bool maybe_accepting = !si.is_rejecting_scc(scc_src);
for (auto& t: old->out(one.first.first)) for (auto& t: old->out(one.first.first))
{ {
unsigned scc_dst = si.scc_of(t.dst); std::vector<unsigned> dests;
acc_cond::mark_t acc = 0U; for (unsigned d: old->univ_dests(t.dst))
bool dst_acc = !si.is_rejecting_scc(scc_dst); {
if (maybe_accepting && scc_src == scc_dst) unsigned scc_dst = si.scc_of(d);
acc = t.acc - common_out[t.src]; acc_cond::mark_t acc = 0U;
else if (dst_acc) bool dst_acc = !si.is_rejecting_scc(scc_dst);
// We enter a new accepting SCC. Use any edge going into if (maybe_accepting && scc_src == scc_dst)
// t.dst from this SCC to set the initial acceptance mark. acc = t.acc - common_out[t.src];
acc = one_in[t.dst]; else if (dst_acc)
if (dst_acc) // We enter a new accepting SCC. Use any edge going into
acc |= common_out[t.dst]; // t.dst from this SCC to set the initial acceptance mark.
else acc = one_in[d];
acc = unsat_mark.second; if (dst_acc)
res->new_edge(one.second, new_state(t.dst, acc), acc |= common_out[d];
else
acc = unsat_mark.second;
dests.push_back(new_state(d, acc));
}
res->new_edge(one.second,
uniq.new_univ_dests(dests.begin(), dests.end()),
t.cond, one.first.second); t.cond, one.first.second);
} }
} }
......
...@@ -224,3 +224,46 @@ State: 1 ...@@ -224,3 +224,46 @@ State: 1
EOF EOF
autfilt --sbacc taut.hoa > out.hoa autfilt --sbacc taut.hoa > out.hoa
diff out.hoa expect.hoa diff out.hoa expect.hoa
cat >alt.hoa <<EOF
HOA: v1
States: 4
Start: 0
AP: 1 "a"
Acceptance: 2 Inf(0) & Inf(1)
--BODY--
State: 0
[0] 1&2 {0}
[0] 3 {0}
State: 1
[0] 0 {1}
State: 2
[t] 2
State: 3
[!0] 0
--END--
EOF
cat >expect.hoa <<EOF
HOA: v1
States: 4
Start: 0
AP: 1 "a"
acc-name: generalized-Buchi 2
Acceptance: 2 Inf(0)&Inf(1)
properties: univ-branch trans-labels explicit-labels state-acc
--BODY--
State: 0 {0}
[0] 3
[0] 1&2
State: 1 {0 1}
[0] 0
State: 2
[t] 2
State: 3 {0}
[!0] 0
--END--
EOF
autfilt --sbacc alt.hoa > out.hoa
diff out.hoa expect.hoa
...@@ -394,12 +394,11 @@ State: 2 ...@@ -394,12 +394,11 @@ State: 2
[0] 2 [0] 2
--END--""") --END--""")
dual = spot.dualize(aut) dual = spot.dualize(aut)
h = dual.to_str('hoa') h = dual.to_str('hoa')
assert h == """HOA: v1 assert h == """HOA: v1
States: 2 States: 3
Start: 0 Start: 0
AP: 2 "a" "b" AP: 2 "a" "b"
acc-name: all acc-name: all
...@@ -407,9 +406,11 @@ Acceptance: 0 t ...@@ -407,9 +406,11 @@ Acceptance: 0 t
properties: trans-labels explicit-labels state-acc deterministic properties: trans-labels explicit-labels state-acc deterministic
--BODY-- --BODY--
State: 0 State: 0
[!0 | !1] 1 [0&1] 1
[!0 | !1] 2
State: 1 State: 1
[t] 1 State: 2
[t] 2
--END--""" --END--"""
aut = spot.automaton(""" aut = spot.automaton("""
...@@ -492,6 +493,45 @@ State: 2 {0} ...@@ -492,6 +493,45 @@ State: 2 {0}
[t] 2 [t] 2
--END--""" --END--"""
aut = spot.automaton("""
HOA: v1
States: 3
Start: 0
AP: 1 "a"
Acceptance: 2 Fin(0) & Inf(1)
properties: trans-labels explicit-labels
--BODY--
State: 0
[!0] 0
[0] 1 {0}
[0] 2 {1}
State: 1
[t] 0
State: 2
[t] 0
--END--""")
dual = spot.dualize(aut)
assert dualtype(aut, dual)
h = dual.to_str('hoa')
assert h == """HOA: v1
States: 3
Start: 0
AP: 1 "a"
acc-name: parity min even 2
Acceptance: 2 Inf(0) | Fin(1)
properties: univ-branch trans-labels explicit-labels state-acc complete
properties: deterministic
--BODY--
State: 0
[!0] 0
[0] 1&2
State: 1 {0}
[t] 0
State: 2 {1}
[t] 0
--END--"""
aut = spot.translate('G!a R XFb') aut = spot.translate('G!a R XFb')
test_assert(aut) test_assert(aut)
...@@ -499,12 +539,12 @@ dual = spot.dualize(aut) ...@@ -499,12 +539,12 @@ dual = spot.dualize(aut)
h = dual.to_str('hoa') h = dual.to_str('hoa')
assert h == """HOA: v1 assert h == """HOA: v1
States: 5 States: 6
Start: 0 Start: 0
AP: 2 "a" "b" AP: 2 "a" "b"
acc-name: co-Buchi acc-name: co-Buchi
Acceptance: 1 Fin(0) Acceptance: 1 Fin(0)
properties: univ-branch trans-labels explicit-labels trans-acc complete properties: univ-branch trans-labels explicit-labels state-acc complete
properties: deterministic properties: deterministic
--BODY-- --BODY--
State: 0 State: 0
...@@ -512,17 +552,22 @@ State: 0 ...@@ -512,17 +552,22 @@ State: 0
[!0] 1&2 [!0] 1&2
State: 1 State: 1
[0&!1] 1 [0&!1] 1
[0&1] 1 {0} [0&1] 4
[!0&1] 2&4
[!0&!1] 1&2 [!0&!1] 1&2
[!0&1] 1&2 {0}
State: 2 State: 2
[!0&1] 3 [!0&1] 3
[0 | !1] 4 [0 | !1] 5
State: 3 State: 3 {0}
[!0] 3 {0} [!0] 3
[0] 4 [0] 5
State: 4 State: 4 {0}
[t] 4 [0&!1] 1
[0&1] 4
[!0&1] 2&4
[!0&!1] 1&2
State: 5
[t] 5
--END--""" --END--"""
......
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