From fdad1d0e85daf5824fa5450730484a444f313149 Mon Sep 17 00:00:00 2001 From: Cameron Neville Date: Wed, 28 Feb 2018 22:01:52 -0500 Subject: [PATCH] first commit --- mason.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 mason.py diff --git a/mason.py b/mason.py new file mode 100644 index 0000000..471cf0e --- /dev/null +++ b/mason.py @@ -0,0 +1,65 @@ +class System: + def __init__(self): + self.nodes = [] + + def create(*args): + if len(args) == 0: + self.nodes.append(Node(self, self.nextname())) + + def findtransfer(self, source, sink): + def findpaths(): + + virtual = False + if not source.issource(): + raise ValueError('first node must be a source') + if not sink.issink(): + virtual = True + self.nodes.append(Node(self, 'virtual')) + sink = self.nodes[-1] + paths = [] + loops = [] + + + 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: + for j in i.connections: + if node is j[1]: + return False + return True + + #returns True if there are no connections starting from the node + def issink(self, node): + if not isinstance(node, Node): + raise TypeError('argument must be a Node') + return node.issink() + +class Node: + def __init__(self, system, name): + self.system = system + self.name = name + self.connections = [] + + def connect(target, transfer): + self.connections.append((taget, transfer)) + + #returns True if there are no connections pointing to the node + def issource(self): + return self.system.issource(self) + + #returns True if there are no connections starting from the node + def issink(self): + return self.connections == [] + +class Connection: + def __init__(self, target, gain): + + +class Loop: + def __init__(self): + pass