some more work
This commit is contained in:
41
mason.py
41
mason.py
@@ -7,7 +7,18 @@ class System:
|
||||
self.nodes.append(Node(self, self.nextname()))
|
||||
|
||||
def findtransfer(self, source, sink):
|
||||
def findpaths():
|
||||
def concat(*args):
|
||||
res = []
|
||||
map(res.extend, args)
|
||||
|
||||
|
||||
def findpaths(crnt, path, target):
|
||||
if crnt is target:
|
||||
return Path(path + [crnt])
|
||||
nxt = [i.target for i in crnt.connections if i.target not in deadnodes]
|
||||
newpath = path + [crnt]
|
||||
return [findpaths(i, newpath, sink) for i in nxt]
|
||||
|
||||
|
||||
virtual = False
|
||||
if not source.issource():
|
||||
@@ -19,19 +30,19 @@ class System:
|
||||
paths = []
|
||||
loops = []
|
||||
|
||||
|
||||
#create automatic node names
|
||||
def nextname(self):
|
||||
pass
|
||||
|
||||
#returns True if there are no connections pointing to the node#returns True if there are no connections pointing to the node
|
||||
def issource(self, node):
|
||||
if not isinstance(node, Node):
|
||||
raise TypeError('argument must be a Node')
|
||||
for i in self.nodes:
|
||||
if not isinstance(node, (Node, Connection)):
|
||||
elif for i in self.nodes:
|
||||
for j in i.connections:
|
||||
if node is j[1]:
|
||||
return False
|
||||
return True
|
||||
raise TypeError('argument must be a Node or Connection')
|
||||
|
||||
#returns True if there are no connections starting from the node
|
||||
def issink(self, node):
|
||||
@@ -46,7 +57,7 @@ class Node:
|
||||
self.connections = []
|
||||
|
||||
def connect(target, transfer):
|
||||
self.connections.append((taget, transfer))
|
||||
self.connections.append((target, transfer))
|
||||
|
||||
#returns True if there are no connections pointing to the node
|
||||
def issource(self):
|
||||
@@ -56,10 +67,22 @@ class Node:
|
||||
def issink(self):
|
||||
return self.connections == []
|
||||
|
||||
#I'm still not sure whether I want to use this or just tuples
|
||||
class Connection:
|
||||
def __init__(self, target, gain):
|
||||
def __init__(self, origin, target, gain):
|
||||
self.origin = origin
|
||||
self.target = target
|
||||
self.gain = gain
|
||||
|
||||
class NodeLink:
|
||||
def __init__(self, nodes):
|
||||
self.nodes = nodes
|
||||
|
||||
class Loop:
|
||||
def __init__(self):
|
||||
def contains(self, node):
|
||||
return node in self.nodes
|
||||
|
||||
class Path(NodeLink):
|
||||
pass
|
||||
|
||||
class Loop(NodeLink):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user