some more work

This commit is contained in:
Cameron Neville
2018-03-03 22:51:40 -05:00
parent fdad1d0e85
commit 1e806da4e6

View File

@@ -7,7 +7,18 @@ class System:
self.nodes.append(Node(self, self.nextname())) self.nodes.append(Node(self, self.nextname()))
def findtransfer(self, source, sink): 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 virtual = False
if not source.issource(): if not source.issource():
@@ -19,19 +30,19 @@ class System:
paths = [] paths = []
loops = [] loops = []
#create automatic node names
def nextname(self): def nextname(self):
pass pass
#returns True if there are no connections pointing to the node#returns True if there are no connections pointing to the node #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): def issource(self, node):
if not isinstance(node, Node): if not isinstance(node, (Node, Connection)):
raise TypeError('argument must be a Node') elif for i in self.nodes:
for i in self.nodes:
for j in i.connections: for j in i.connections:
if node is j[1]: if node is j[1]:
return False return False
return True return True
raise TypeError('argument must be a Node or Connection')
#returns True if there are no connections starting from the node #returns True if there are no connections starting from the node
def issink(self, node): def issink(self, node):
@@ -46,7 +57,7 @@ class Node:
self.connections = [] self.connections = []
def connect(target, transfer): 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 #returns True if there are no connections pointing to the node
def issource(self): def issource(self):
@@ -56,10 +67,22 @@ class Node:
def issink(self): def issink(self):
return self.connections == [] return self.connections == []
#I'm still not sure whether I want to use this or just tuples
class Connection: class Connection:
def __init__(self, target, gain): def __init__(self, origin, target, gain):
self.origin = origin
self.target = target
self.gain = gain
class Loop: class NodeLink:
def __init__(self): def __init__(self, nodes):
pass self.nodes = nodes
def contains(self, node):
return node in self.nodes
class Path(NodeLink):
pass
class Loop(NodeLink):
pass