spot/doc/org/tut22.org
Alexandre Duret-Lutz 2402d721a9 modernize the logo
* doc/org/spot2.svg: New file.
* doc/Makefile.am: Distribute it.
* doc/org/.gitignore: Adjust.
* doc/org/setup.org: Display it.
* doc/org/autcross.org, doc/org/autfilt.org, doc/org/citing.org,
doc/org/compile.org, doc/org/concepts.org, doc/org/csv.org,
doc/org/dstar2tgba.org, doc/org/genaut.org, doc/org/genltl.org,
doc/org/hierarchy.org, doc/org/hoa.org, doc/org/index.org,
doc/org/install.org, doc/org/ioltl.org, doc/org/ltl2tgba.org,
doc/org/ltl2tgta.org, doc/org/ltlcross.org, doc/org/ltldo.org,
doc/org/ltlfilt.org, doc/org/ltlgrind.org, doc/org/ltlsynt.org,
doc/org/oaut.org, doc/org/randaut.org, doc/org/randltl.org,
doc/org/satmin.org, doc/org/tools.org, doc/org/tut.org,
doc/org/tut01.org, doc/org/tut02.org, doc/org/tut03.org,
doc/org/tut04.org, doc/org/tut10.org, doc/org/tut11.org,
doc/org/tut20.org, doc/org/tut21.org, doc/org/tut22.org,
doc/org/tut23.org, doc/org/tut24.org, doc/org/tut30.org,
doc/org/tut31.org, doc/org/tut50.org, doc/org/tut51.org,
doc/org/upgrade2.org: Include setup.org instead of declaring it as
SETUPFILE.
* doc/org/spot.css: Add entries for the logo.
* python/ajax/trans.html: Use the new logo.
* python/ajax/logos/mail.png, python/ajax/logos/spot64s.png: Delete.
* python/ajax/Makefile.am: Adjust.
2018-06-27 16:18:15 +02:00

3.8 KiB

Creating an automaton by adding states and transitions

This example demonstrates how to create an automaton and then print it.

C++

  #include <iostream>
  #include <spot/twaalgos/hoa.hh>
  #include <spot/twa/twagraph.hh>

  int main(void)
  {
    // The bdd_dict is used to maintain the correspondence between the
    // atomic propositions and the BDD variables that label the edges of
    // the automaton.
    spot::bdd_dict_ptr dict = spot::make_bdd_dict();
    // This creates an empty automaton that we have yet to fill.
    spot::twa_graph_ptr aut = make_twa_graph(dict);

    // Since a BDD is associated to every atomic proposition, the
    // register_ap() function returns a BDD variable number
    // that can be converted into a BDD using bdd_ithvar().
    bdd p1 = bdd_ithvar(aut->register_ap("p1"));
    bdd p2 = bdd_ithvar(aut->register_ap("p2"));

    // Set the acceptance condition of the automaton to Inf(0)&Inf(1)
    aut->set_generalized_buchi(2);

    // States are numbered from 0.
    aut->new_states(3);
    // The default initial state is 0, but it is always better to
    // specify it explicitely.
    aut->set_init_state(0U);

    // new_edge() takes 3 mandatory parameters: source state,
    // destination state, and label.  A last optional parameter can be
    // used to specify membership to acceptance sets.
    aut->new_edge(0, 1, p1);
    aut->new_edge(1, 1, p1 & p2, {0});
    aut->new_edge(1, 2, p2, {1});
    aut->new_edge(2, 1, p1 | p2, {0, 1});

    // Print the resulting automaton.
    print_hoa(std::cout, aut);
    return 0;
  }
HOA: v1
States: 3
Start: 0
AP: 2 "p1" "p2"
acc-name: generalized-Buchi 2
Acceptance: 2 Inf(0)&Inf(1)
properties: trans-labels explicit-labels trans-acc
--BODY--
State: 0
[0] 1
State: 1
[0&1] 1 {0}
[1] 2 {1}
State: 2
[0 | 1] 1 {0 1}
--END--

Python

  import spot
  import buddy

  # The bdd_dict is used to maintain the correspondence between the
  # atomic propositions and the BDD variables that label the edges of
  # the automaton.
  bdict = spot.make_bdd_dict();
  # This creates an empty automaton that we have yet to fill.
  aut = spot.make_twa_graph(bdict)

  # Since a BDD is associated to every atomic proposition, the register_ap()
  # function returns a BDD variable number that can be converted into a BDD using
  # bdd_ithvar() from the BuDDy library.
  p1 = buddy.bdd_ithvar(aut.register_ap("p1"))
  p2 = buddy.bdd_ithvar(aut.register_ap("p2"))

  # Set the acceptance condition of the automaton to Inf(0)&Inf(1)
  aut.set_generalized_buchi(2)

  # States are numbered from 0.
  aut.new_states(3)
  # The default initial state is 0, but it is always better to
  # specify it explicitely.
  aut.set_init_state(0)

  # new_edge() takes 3 mandatory parameters: source state, destination state, and
  # label.  A last optional parameter can be used to specify membership to
  # acceptance sets.  In the Python version, the list of acceptance sets the
  # transition belongs to should be specified as a list.
  aut.new_edge(0, 1, p1)
  aut.new_edge(1, 1, p1 & p2, [0])
  aut.new_edge(1, 2, p2, [1]);
  aut.new_edge(2, 1, p1 | p2, [0, 1]);

  # Print the resulting automaton.
  print(aut.to_str('hoa'))
HOA: v1
States: 3
Start: 0
AP: 2 "p1" "p2"
acc-name: generalized-Buchi 2
Acceptance: 2 Inf(0)&Inf(1)
properties: trans-labels explicit-labels trans-acc
--BODY--
State: 0
[0] 1
State: 1
[0&1] 1 {0}
[1] 2 {1}
State: 2
[0 | 1] 1 {0 1}
--END--