From 1e806da4e6f9fd9fa7d2b2da1606131ce75150b9 Mon Sep 17 00:00:00 2001 From: Cameron Neville Date: Sat, 3 Mar 2018 22:51:40 -0500 Subject: [PATCH] some more work --- mason.py | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/mason.py b/mason.py index 471cf0e..d492cde 100644 --- a/mason.py +++ b/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 Loop: - def __init__(self): - pass +class NodeLink: + def __init__(self, nodes): + self.nodes = nodes + + def contains(self, node): + return node in self.nodes + +class Path(NodeLink): + pass + +class Loop(NodeLink): + pass