| |
|
|||||||
|
|
||||||||
|
Python Module faudes: TypesThe Python module faudes maps most relevant libFAUDES C++ classes to Python classes via a proxy which in turn provides a sensible subset of the C++ member methods. libFAUDES types register with the Python help system as well as with the libFAUDES help systen; i.e., you may run help(my_object or Help('my_class_name') from within Python to obtain a list of member methods. Further technical details are provided via the libFAUDES C++ API documentation. In this section, we outline features common to all libFAUDES classes by example of faudes::EventSet, i.e., a set of symbolic events, and faudes::Generator, i.e., a finite state machine. The EventSet Data TypeAll relevant libFAUDES classes come with three constructors. Demo for faudes::EventSet:
>>> n1=EventSet() # default constructor (empty set)
>>> n2=EventSet(n2) # copy constructor from specified set
>>> n3=EventSet('filename.fts') # constructor from .fts file
The latter file format is documented with the respectice C++ class. libFAUDES classes support additionally initialisation from a string in the same .fts format, or, in the case of containers, from a Python list:
>>> n1.FromString('<N> alpha beta </N>') # set data from string
>>> n2.FromList(['lambda', 'mue']) # set data from string
Note that in the above example, n1 and n2 habe allready been instantiated; e.g., FromString(...) is a class member method. For new instantiation from string (or list) use the static variant
>>> n3=EventSet.NewFromString('<N> alpha beta </N>') # set data from string
>>> n4=EventSet.NewFromList(['lambda', 'mue']) # set data from string
Reading from a string and constructing from file are particular instances of libFAUDES serialisation. Other available methods in this regard by example for the class faudes::EventSet include:
>>> n1.Write() # write to console in .fts format
>>> n1.Write('filename.fts') # ... to file in .fts format
>>> n1.XWrite('filename.xml') # ... to file in strict XML format
>>> n1.DWrite() # write with more details to console
>>> n1.SWrite() # write statistical summary to console
>>> n1.Read('filename.fts/xml') # read back from file (fts or xml)
A list of those methods we believe are most relevant is provided via the libFAUDES help system by Help('ClassName'). E.g., Help("EventSet") reports along the line of
Help topic: "EventSet" [extract]
*** Maintenance ***
string Name()
Name(string)
int Size()
int Index(string)
string SymbolicName(int)
*** Element access ***
bool Empty()
bool Insert(string)
bool Erase(string)
bool Exists(string)
This shows the general pattern that libFAUDES container classes provide an STL like interface. A complete list of methods exported via the proxy class can be accessed via the Python help system using help(ClassName) (lower case help and no quotes). Specifically, you will observe extra methods for the iter/next protocol for Python style iteraion and support of the Python print function:
>>> print(f'May events are: {n2}'))
My events are: [EventSet]{ lambda#3, mue#4 }
>>> for e in n2:
>>> print(f'Event: at index {e} is {n2.SymbolicName(e)}')
Event: at index 3 is lambda
Event: at index 4 is mue
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. Note: The way libFAUDES interacts with Python implies that 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. >>> n5 = n1.Copy() # construct a copy of n1 >>> n6 = faudes.EventSet(n1) # construct a copy of n1 >>> n7 = n1 # have another reference to n1 >>> n7.Clear() # clear the set referenced by n1 and n7 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]
*** 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(x1,ev,x2)
ClrTransition(x1,ev,x2)
Example to instatiate a very simple machine:
>>> g1=Generator() # instantiate generator
>>> g1.InsEvent("alpha") # add events
>>> g1.InsEvent("beta")
>>> g1.InsState("waiting") # add states
>>> g1.InsState("working")
>>> g1.SetInitState("waiting") # indicate init/marked states
>>> g1.SetMarkedState("waiting")
>>> g1.SetTransition("waiting", "alpha", "working") # set transitions
>>> g1.SetTransition("working", "beta", "waiting")
Likewise using initialisation from string:
>>> g2=Generator() # instantiate generator
>>> g2.FromString("""
>>> <G>
>>> <T> waiting alpha working working beta waiting </T>
>>> <I> waiting </I>
>>> <M> waiting </M>
>>> </G>""")
The tutorial section of the PyBindings plug-in provides a tutorial on generators to demonstrate access to generator class members. >>
libFAUDES 2.34g --- 2026.03.30 --- with "omegaaut-synthesis-observer-observability-diagnosis-hiosys-iosystem-multitasking-coordinationcontrol-timed-simulator-iodevice-priorities-luabindings-hybrid-example-pybindings" |