Fault trees structure
Darrell
news at dorb.com
Mon Dec 11 22:49:50 EST 2000
Jumping right to code :)
Seemed more fun than reading too deeply about fault trees.
Looks like we need shift registers, flip-flops and ...
--Darrell
class NodeBase:
def name(self):
return self._name
def connectInput(self, name):
if not hasattr(self, "_input"):
self._input={}
self._input[name]=None
def connectOutput(self, otherNode, name):
if not hasattr(self, "_output"):
self._output={}
self._output[otherNode.name()]= name
otherNode.connectInput(name)
def signal(self, collection, name, value=1):
self._input[name]=value
self.logic(collection)
def propagate(self, collection, value):
for nodeName, inputName in self._output.items():
try:
node=getattr(collection, nodeName)
node.signal(collection, inputName, value)
except:
print self._name
print nodeName
print collection
raise
class AndNode(NodeBase):
def __init__(self, name):
self._name=name
def logic(self, collection):
cc= reduce(lambda x,y: x and y, self._input.values())
self.propagate(collection, cc)
class OrNode(NodeBase):
def __init__(self, name):
self._name=name
def logic(self, collection):
cc = reduce(lambda x,y: x or y, self._input.values())
self.propagate(collection, cc)
class AnnounceNode(NodeBase):
def __init__(self, name):
self._name=name
def logic(self, collection):
cc = reduce(lambda x,y: x or y, self._input.values())
if cc:
print self._name, self._input
else:
# Noise on the input, but nothing to report
print '.',
class SourceNode(NodeBase):
def __init__(self, name):
self._name=name
def __call__(self, collection, value):
self.propagate(collection, value)
class FaultTree:#(UserDict.UserDict): Not sure about this
def __init__(self, *nodes):
for n in nodes:
setattr(self, n.name(), n)
ft=FaultTree(AndNode("and1"), AndNode("and2"), AndNode("and3"),
AnnounceNode("fail"))
ft.and1.connectOutput(ft.and3,"one")
ft.and2.connectOutput(ft.and3,"two")
ft.and3.connectOutput(ft.fail,"who cares")
# Setup some signal sources
drivers=[]
for x in range(3):
s1=SourceNode(x)
drivers.append(s1)
s1.connectOutput(ft.and1, x)
# Setup some signal sources
for x in range(3):
s1=SourceNode(x)
drivers.append(s1)
s1.connectOutput(ft.and2, x)
# Make it go
for i in drivers:
i(ft, 1)
#### output
>faulttree.py
. . . . . fail {'who cares': 1}
Each "." is an input being propagated though the graph.
Unitl the output AnnounceNode fires with the "fail" message.
"who cares" is the name of the input connection of the AnnounceNode
"Arturo Pérez Mulas" wrote:
> Fault Tree are the following:
>
> - They have only ONE top node
>
> - Each node can have unlimited inputs (opposed to two allowed for binary
trees)
>
> - Nodes can be of any of the following different types:
>
> a) 'Gates' : are nodes that admit further inputs; there are different
types
> of gates, AND, OR, XOR, n/m, NOT but this is not important at this point,
> since from the tree structure they are all similar (except type n/m
> gates which must have exactly 'm' inputs)
>
> ....
More information about the Python-list
mailing list