spot/doc/org/tut30.org
Alexandre Duret-Lutz f120dd3206 rename src/ as spot/ and use include <spot/...>
* NEWS: Mention the change.
* src/: Rename as ...
* spot/: ... this, adjust all headers to include <spot/...> instead of
"...", and adjust all Makefile.am to search headers from the top-level
directory.
* HACKING: Add conventions about #include.
* spot/sanity/style.test: Add a few more grep to catch cases
that do not follow these conventions.
* .gitignore, Makefile.am, README, bench/stutter/Makefile.am,
bench/stutter/stutter_invariance_formulas.cc,
bench/stutter/stutter_invariance_randomgraph.cc, configure.ac,
debian/rules, doc/Doxyfile.in, doc/Makefile.am,
doc/org/.dir-locals.el.in, doc/org/g++wrap.in, doc/org/init.el.in,
doc/org/tut01.org, doc/org/tut02.org, doc/org/tut03.org,
doc/org/tut10.org, doc/org/tut20.org, doc/org/tut21.org,
doc/org/tut22.org, doc/org/tut30.org, iface/ltsmin/Makefile.am,
iface/ltsmin/kripke.test, iface/ltsmin/ltsmin.cc,
iface/ltsmin/ltsmin.hh, iface/ltsmin/modelcheck.cc,
wrap/python/Makefile.am, wrap/python/ajax/spotcgi.in,
wrap/python/spot_impl.i, wrap/python/tests/ltl2tgba.py,
wrap/python/tests/randgen.py, wrap/python/tests/run.in: Adjust.
2015-12-04 20:13:59 +01:00

7.1 KiB

Converting Rabin (or Other) to Büchi, and simplifying it

Consider the following Rabin automaton, generated by ltl2dstar:

ltldo ltl2dstar -f 'F(Xp1 xor XXp1)' -H > tut30.hoa

/alarsyo/spot/media/commit/34c3c1cedc8b5b3a5f30f6acb3f91a9687cc6e4d/doc/org/tut30in.png

Our goal is to generate an equivalent Büchi automaton, preserving determinism if possible. However nothing of what we will write is specific to Rabin acceptance: the same code will convert automata with any acceptance to Büchi acceptance.

Shell

We use autfilt with option -B to request Büchi acceptance and state-based output, -D to express a preference for deterministic output, and -H for output in the HOA format. Using option -D/--deterministic (or --small) actually activates the "postprocessing" routines of Spot: the acceptance will not only be changed to Büchi, but simplification routines (useless SCCs removal, simulation-based reductions, acceptance sets simplifications, WDBA-minimization, …) will also be applied.

autfilt -B -D -H tut30.hoa
HOA: v1
States: 5
Start: 1
AP: 1 "p1"
acc-name: Buchi
Acceptance: 1 Inf(0)
properties: trans-labels explicit-labels state-acc complete
properties: deterministic weak
--BODY--
State: 0 {0}
[t] 0
State: 1
[t] 2
State: 2
[!0] 3
[0] 4
State: 3
[0] 0
[!0] 3
State: 4
[!0] 0
[0] 4
--END--

/alarsyo/spot/media/commit/34c3c1cedc8b5b3a5f30f6acb3f91a9687cc6e4d/doc/org/tut30out.png

In the general case transforming an automaton with a complex acceptance condition into a Büchi automaton can make the output bigger. However the postprocessing routines may manage to simplify the result further.

Python

The Python version uses the postprocess() routine:

import spot
aut = spot.automaton('tut30.hoa').postprocess('BA', 'deterministic')
print(aut.to_str('hoa'))
HOA: v1
States: 5
Start: 1
AP: 1 "p1"
acc-name: Buchi
Acceptance: 1 Inf(0)
properties: trans-labels explicit-labels state-acc complete
properties: deterministic weak
--BODY--
State: 0 {0}
[t] 0
State: 1
[t] 2
State: 2
[!0] 3
[0] 4
State: 3
[0] 0
[!0] 3
State: 4
[!0] 0
[0] 4
--END--

The postprocess() function has an interface similar to the translate() function discussed previously:

import spot
help(spot.postprocess)
Help on function postprocess in module spot:

postprocess(automaton, *args)
    Post process an automaton.

    This applies a number of simlification algorithms, depending on
    the options supplied. Keep in mind that 'Deterministic' expresses
    just a preference that may not be satisfied if the input is
    not already 'Deterministic'.

    The optional arguments should be strings among the following:
    - at most one in 'Generic', 'TGBA', 'BA', or 'Monitor'
      (type of automaton to build)
    - at most one in 'Small', 'Deterministic', 'Any'
      (preferred characteristics of the produced automaton)
    - at most one in 'Low', 'Medium', 'High'
      (optimization level)
    - any combination of 'Complete' and 'StateBasedAcceptance'
      (or 'SBAcc' for short)

    The default corresponds to 'generic', 'small' and 'high'.

C++

The C++ version of this code is a bit more verbose, because the postprocess() function does not exist. You have to instantiate a postprocessor object, configure it, and then call it for each automaton to process.

  #include <iostream>
  #include <spot/parseaut/public.hh>
  #include <spot/twaalgos/postproc.hh>
  #include <spot/twaalgos/hoa.hh>

  int main()
  {
    spot::parsed_aut_ptr pa = parse_aut("tut30.hoa", spot::make_bdd_dict());
    if (pa->format_errors(std::cerr))
      return 1;
    if (pa->aborted)
      {
        std::cerr << "--ABORT-- read\n";
        return 1;
      }
    spot::postprocessor post;
    post.set_type(spot::postprocessor::BA);
    post.set_pref(spot::postprocessor::Deterministic);
    post.set_level(spot::postprocessor::High);
    auto aut = post.run(pa->aut);
    spot::print_hoa(std::cout, aut) << '\n';
    return 0;
  }
HOA: v1
States: 5
Start: 1
AP: 1 "p1"
acc-name: Buchi
Acceptance: 1 Inf(0)
properties: trans-labels explicit-labels state-acc complete
properties: deterministic weak
--BODY--
State: 0 {0}
[t] 0
State: 1
[t] 2
State: 2
[!0] 3
[0] 4
State: 3
[0] 0
[!0] 3
State: 4
[!0] 0
[0] 4
--END--