Home | Trees | Indices | Help |
|
---|
|
Mealy machine.
Traffic Light: Fig. 3.14, p.72 [LS11]
>>> m = MealyMachine() >>> pure_signal = {'present', 'absent'} >>> m.add_inputs([('tick', pure_signal) ]) >>> m.add_outputs([('go', pure_signal), ('stop', pure_signal) ]) >>> m.states.add_from(['red', 'green', 'yellow']) >>> m.states.initial.add('red')
For brevity:
>>> p = 'present' >>> a = 'absent'
The transitions can equivalently be defined with dict(). So instead
of the previous m.transitions.add
, we can use:
>>> label = {'tick':p, 'go':p, 'stop':a} >>> m.transitions.add('red', 'green', **label) >>> label = {'tick':p, 'go':a, 'stop':p} >>> m.transitions.add('green', 'yellow', **label) >>> label = {'tick':p, 'go':a, 'stop':p} >>> m.transitions.add('yellow', 'red', **label)
This avoids any ordering issues, i.e., changing the order of the sublabels does not matter:
>>> label = {'go':p, 'tick':p, 'stop':a} >>> m.transitions.add('red', 'green', **label)
A Mealy machine implements the discrete dynamics:
x[k+1] = f(x[k], u[k] ) y[k] = g(x[k], u[k] )
where:
Observe that the output is defined when a reaction occurs to an input.
valuation: assignment of values to each port
Instance Methods | |||
|
|||
|
|||
|
|||
(outputs, next_state) where outputs :
{'port_name':port_value, ...}
|
|
||
|
|||
Inherited from Inherited from Inherited from Inherited from Inherited from Inherited from Inherited from |
Properties | |
Inherited from Inherited from |
Method Details |
Initialize the types of labelings on states and edges. Label types by exampleUse a >>> types = [ {'name': 'drink', 'values': {'tea', 'coffee'}, 'setter': True, 'default': 'tea'}, ] This will create a label type named Assuming this label type applies to nodes, you can now label a new node as: >>> g = LabeledDiGraph(types) >>> g.add_node(1, drink='coffee') If you omit the label when adding a new node, it gets the default value: >>> g.add_node(2) >>> g.node[2] {'drink': 'tea'} The main difference with vanilla >>> type(g.node[2]) tulip.transys.mathset.TypedDict The This allows us to add more values after creating the graph: >>> g.drink {'coffee', 'tea'} >>> g.drink.add('water') {'coffee', 'tea', 'water'} Finally, the graph will prevent us from accidentally using an
untyped label name, by raising an >>> g.add_node(3, day='Jan') AttributeError: ... To add untyped labels, do so explicitly: >>> g.add_node(3, day='Jan', check=False) >>> g.node[3] {'day': 'Jan', 'drink': 'tea'} Details on label typesEach label type is defined by a
and optionally the keys:
|
Get informal string representation.
|
Add new outputs.
|
Return next state and output, when reacting to given inputs. The machine must be deterministic. (for each state and input at most a single transition enabled, this notion does not coincide with output-determinism) Not exactly a wrapper of
|
Guided or interactive run.
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue May 12 18:21:43 2015 | http://epydoc.sourceforge.net |