| |
|
|||||||
|
|
||||||||
|
libFAUDES Python ModulelibFAUDES can be build as a Python C extension; i.e., a module to be imported from within the Python scripting language and that provides access to relevant libFAUDES data types and functions as listed in the libFAUDES user reference. Technically, the libFAUDES Python module is implemented by the libFAUDES Plug-In PyBindings. InstallationIf you are using an official Python distribution (i.e., either dowloaded/installed from www.pytgon.org or, for Linux, via the default package manager), you can most likely install the faudes module via pip. On Linux and macOS, this is done via the command line by $ pip install faudes or, for Windows, > py -m pip install faudes Pip will search the index PyPI.org for a binary distribution of libFAUDES that fits your platform/archirecture; see also here. In the case that no such matching binary is found, please let us know. Instructions on how to compile your own binary are provided here. As a basic test, the below Python commands will report the libFAUDES version: >>> import faudes >>> faudes.Version() The libFAUDES Python Module exports the help system compiled from the runtime interaface specification; i.e., >>> faudes.Help()' will report:
Interface:
faudes.Help("EventSet") EventSet methods
faudes.Help("Generator") Generator methods
faudes.Help("System") System methods
faudes.Help("IndexSet") IndexSet methods
faudes.Help("TransSet") TransSet methods
faudes.Help("Synthesis") Synthesis PlugIn
Configuration:
faudes.StatenamesOn() enable automatic state names
faudes.StatenamesOff() disable automatic state names
faudes.DotExecPath("filename") path of dot executable
faudes.Version() report libFAUDES version string
Console Commands:
faudes.Print("message") print as faudes debugging message
faudes.Error("message") abort script with error message
faudes.Verbosity(int) set verbosity level
You may specify a keyword by calling faudes.Help("keyword") to obtain a list of relevant functions. Plug-ins that provide additional bindings will advertise themselves with their plug-in name as keyword; e.g., try
>>> faudes.Help("Synthesis")
for functions related to classical supervisory control theory. The EventSet Data TypeThe libFAUDES Python module maps most libFAUDES C++ classes to Python user-data pointers with corresponding access functions. The C++ class faudes::EventSet is used as the class to represent sets of events. You can create a variable of that type by using the default constructor: >>> alph1 = faudes.EventSet() Note: A consequence of mapping to user-data pointers is that within Python the assignment operator = does *not* create a copy of the object, but only passes on the reference. In order to create a copy of a libFAUDES object, you need to explicitly invoke the copy constructor or the copy method. >>> alph2 = alph1.Copy() # construct a copy of alph1 >>> alph3 = faudes.EventSet(alph1) # construct a copy of alph1 >>> alph4 = alph1 # have another reference to alph1 The available methods for EventSet objects are shown by the faudes.Help("EventSet") command. The first column shows the return type, the second the method name and arguments.
Help topic: "EventSet" [extract]
*** Constructors ***
EventSet EventSet()
EventSet EventSet(EventSet)
*** Maintenance ***
string Name()
Name(string)
int Size()
Lock()
Detach()
int Index(string)
string SymbolicName(int)
*** Element access ***
bool Empty()
bool Insert(string)
bool Erase(string)
bool Exists(string)
*** Set operations ***
InsertSet(EventSet)
EraseSet(EventSet)
EventSet SetIntersection(EventSet)
EventSet SetUnion(EventSet)
All(most all) methods directly correspond to their C++ counterpart. To invole a method for an EventSet, the method name is appended to the object:
>>> alph1.Insert("alpha")
>>> alph1.Insert("beta")
>>> alph1.Insert("gamma")
The integration with the native Python commands is seamless. E.g. the print(..) statement can be used to report the integer index of an individual event or the tokenized version of an event set:
>>> print(alph1.Index("beta"))
2
>>> print(alph1)
<NameSet> "alpha" "beta" "gamma" </NameSet>
The tutorial section of the pybindings plug-in provides a tutorial on containers to demonstrate basic access to events sets, state sets and transition relations. The Generator Data TypeThe libFAUDES class faudes::vGenerator is used to represent generators. A Generator object is created by the statement >>> gen1 = faudes.Generator() The available methods for Generator objects are shown by the faudes.Help("Generator") command. The first column shows the return type, the second the method name:
libFAUDES help topic: "Generator" [extract]
*** Constructors ***
Generator Generator()
Generator Generator(gen)
Generator Generator(filename)
*** Maintenance ***
Name(string)
string Name()
bool IsDeterministic()
*** Alphabet ***
EventSet Alphabet()
bool InsEvent(name)
bool DelEvent(name)
bool ExistsEvent(name)
*** State set ***
IndexSet States()
idx InsState(name)
bool DelState(name)
bool ExistsState(name)
SetInitState(name)
ClrInitState(idx)
SetMarkedState(name)
ClrMarkedState(idx)
*** Transitions ***
TransSet TransRel()
bool SetTransition(trans)
bool SetTransition(x1,ev,x2)
bool SetTransition(x1name,evname,x2name)
ClrTransition(trans)
ClrTransition(x1,ev,x2)
As with the EventSet, a method for a Generator object is called by appending the method to the object:
>>> gen1.InsEvent("alpha")
>>> gen1.InsEvent("beta")
>>> gen1.InsEvent("gamma")
>>> gen1.InsState("waiting")
>>> gen1.InsState("working")
>>> gen1.InsState("dump state")
>>> gen1.SetInitState("waiting")
>>> gen1.SetMarkedState("waiting")
>>> gen1.SetTransition("waiting", "alpha", "working")
>>> gen1.SetTransition("working", "beta", "waiting")
...
The tutorial section of the PyBindings plug-in provides a tutorial on generators to demonstrate access to generator class members. Calling libFAUDES FunctionsMost algorithms implemented in libFAUDES are also available in the Python module. To get a list of the available algorithms from the libFAUDES core, type faudes.Help("Functions"):
libFAUDES help topic: "Functions" [extract]
*** Regular expressions ***
bool LanguageEquality(gen1_arg, gen2_arg)
bool LanguageIncludion(gen1_arg, gen2_arg)
bool LanguageDisjoint(gen1_arg, gen2_arg)
LanguageComplement(gen)
LanguageConcatenate(gen1_arg, gen2_arg, gen_res)
LanguageConcatenateNonDet(gen1_arg, gen2_arg, gen_res)
LanguageUnion(gen1_arg, gen2_arg, gen_res)
LanguageIntersection(gen1_arg, gen2_arg, gen_res)
FullLanguage(alph_arg, gen_res)
AlphabetLanguage(alph_arg, gen_res)
KleeneClosure(gen)
KleeneClosureNonDet(gen)
*** Reachability ***
Accessible(gen)
bool IsAccessible(gen_arg)
CoAccessible(gen)
bool IsCoAccessible(gen_arg)
Trim(gen)
bool IsTrim(gen_arg)
*** Misc ***
bool IsDeterministic(gen_arg)
Deterministic(gen_arg, gen_res)
StateMin(gen_arg, gen_res
Project(gen, alph)
InvProject(gen, alph)
PrefixClosure(gen)
The tutorial section of the PyBindings plug-in provides a tutorial on regular expressions, to demonstrate access to libFAUDES functions. To test the installation, run an example script from the pybindings tutorial: $ cd ./libfaudes/plugins/pybindings/tutorial $ ls *.py 1_containers.py 2_generators.py 3_regular.py $ python3 3_regular.py By convention, the provided example scripts read input data from the data subdirectory, relative to the location of the script. Thus, it is mandatory to cd to the location of the script. Graphical OutputFor image output of generator graphs libFAUDES relies on the the tool dot from the Graphviz package. For most Linux distributions, dot can be installed by the package manager or is included anyway. For Mac OsX and MS Windows, installers are available from the Graphviz site. For all systems, the location of the binary dot must either be in the PATH environtment variable or specified within as follows:
>>> faudes.DotExecPath("/usr/bin/dot") # eg Linux
>>> faudes.DotExecPath("c:\\Programs\Graphviz\dot") # eg Windows
>>> faudes.DotExecPath("/Applications/Graphviz.app/Contents/MacOS/dot"); # eg MacOS
>>> gen=faudes.Generator("data/simplemachine.gen") # read generator
>>> gen.GraphWrite("tmp_simplemachine.jpg"); # write image
>>
libFAUDES 2.34e --- 2026.03.16 --- with "omegaaut-synthesis-observer-observability-diagnosis-hiosys-iosystem-multitasking-coordinationcontrol-timed-simulator-iodevice-priorities-luabindings-hybrid-example-pybindings" |