spot/doc/org/tut22.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

67 lines
1.8 KiB
Org Mode

# -*- coding: utf-8 -*-
#+TITLE: Creating an automaton in C++
#+SETUPFILE: setup.org
#+HTML_LINK_UP: tut.html
This example demonstrates how to create an automaton in C++, and then print it.
#+BEGIN_SRC C++ :results verbatim :exports both :wrap SRC hoa
#include <iostream>
#include <spot/twaalgos/hoa.hh>
#include <spot/twa/twagraph.hh>
int main(void)
{
// The dict is used to maintain the correspondence between the
// atomic propositions and the BDD variables to 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);
// new_edge() takes 3 mandatory parameters:
// source state, destination state, label
// and 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;
}
#+END_SRC
#+RESULTS:
#+BEGIN_SRC 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--
#+END_SRC