Loading model/levelBinaryTreeToPlanarTree.py +0 −4 Original line number Diff line number Diff line Loading @@ -8,7 +8,6 @@ class LevelBinaryTreeToPlanarTree: self.index = index self.answer = getTree(index) self.planarAnswer = Tree(binaryTreeToPlanarTree(self.answer.root)) self.answer = self.planarAnswer self.tree = None self.score = None self.initialize() Loading @@ -30,9 +29,6 @@ class LevelBinaryTreeToPlanarTree: def checkTree(self, index: int, nodeType: str): copy = self.tree.copyTree() copy.completeNode(index, nodeType) """print("-----------------------") print(self.planarAnswer.root) print(copy.root)""" if self.planarAnswer.root.checkNode(copy.root): self.tree.completeNode(index, nodeType) return True Loading model/levelEnum.py +20 −1 Original line number Diff line number Diff line import math from enum import Enum from model.node import BinaryNode, Leaf, randomTree from model.node import BinaryNode, Leaf, randomTree, PlanarNode, planarTreeToBinaryTree from model.tree import Tree n = PlanarNode([ PlanarNode([]), PlanarNode([ PlanarNode([ PlanarNode([]), PlanarNode([]), PlanarNode([]), PlanarNode([]) ]) ]), PlanarNode([ PlanarNode([]), PlanarNode([ PlanarNode([]) ]), PlanarNode([]), ]) ]) bn = planarTreeToBinaryTree(n) Levels = Enum("Levels", [ ("Lvl1", Tree(BinaryNode(Leaf(), BinaryNode(Leaf(), Leaf())))), ("Lvl2", Tree(BinaryNode(BinaryNode(Leaf(), Leaf()), BinaryNode(Leaf(), Leaf())))), Loading model/node.py +24 −13 Original line number Diff line number Diff line Loading @@ -345,32 +345,33 @@ class PlanarNode(Node): child.completeNode(index, nodeType, tree) def checkNode(self, node, nodeBrothers=None, brothers=None): print("node: ") print(node) print(self) if brothers is None: brothers = [] if nodeBrothers is None: nodeBrothers = [] if not isinstance(node, IncompleteNode): if len(self.children) != len(node.children): print("AAAAAAAAAAA") # the node can't have more children than the model if isinstance(node, IncompleteNode): if len(self.children) < len(node.children): return False # moreover, if the node is completed, it should have exactly the same number of children than the model else: if len(self.children) < len(node.children): print("BBBBBBBBBB") if len(self.children) != len(node.children): return False if not self.children: # if they have not children, call this funtion with the brother of the current nodes if brothers: if not nodeBrothers: """if len(nodeBrothers) != len(brothers): print("Z") return True else: else:""" return brothers.pop(0).checkNode(nodeBrothers.pop(0), nodeBrothers, brothers) else: # if they have no children and no brothers, they are exactly the same trees return True else: # if the model has children but the node has not, we call the funtion with the brothers if not node.children: if brothers: if not nodeBrothers: Loading @@ -380,8 +381,20 @@ class PlanarNode(Node): else: return True else: newBrothers = self.children[1:] + brothers # we add the brothers of the model and the node in the lists, for the models, we only add the brothers # which are represented in the node newNodeBrothers = node.children[1:] + nodeBrothers if len(self.children) == len(node.children): newBrothers = self.children[1:] + brothers else: tmp = [] if len(node.children) > 2: for i in range(1, len(node.children[1:])): print(self.children[i]) tmp.append(self.children[i]) elif len(node.children) == 2: tmp.append(self.children[1]) newBrothers = tmp + brothers return self.children[0].checkNode(node.children[0], newNodeBrothers, newBrothers) def isEqual(self, node, nodeBrothers=None, brothers=None): Loading Loading @@ -570,8 +583,6 @@ class IncompleteNode(PlanarNode): if nodeType == "branch": self.addChild(IncompleteNode([])) else: print("parent: ") print(self.parent) if self.parent is not None: completedNode = PlanarNode(self.children) self.parent[0].changeChild(completedNode, self.parent[1]) Loading Loading
model/levelBinaryTreeToPlanarTree.py +0 −4 Original line number Diff line number Diff line Loading @@ -8,7 +8,6 @@ class LevelBinaryTreeToPlanarTree: self.index = index self.answer = getTree(index) self.planarAnswer = Tree(binaryTreeToPlanarTree(self.answer.root)) self.answer = self.planarAnswer self.tree = None self.score = None self.initialize() Loading @@ -30,9 +29,6 @@ class LevelBinaryTreeToPlanarTree: def checkTree(self, index: int, nodeType: str): copy = self.tree.copyTree() copy.completeNode(index, nodeType) """print("-----------------------") print(self.planarAnswer.root) print(copy.root)""" if self.planarAnswer.root.checkNode(copy.root): self.tree.completeNode(index, nodeType) return True Loading
model/levelEnum.py +20 −1 Original line number Diff line number Diff line import math from enum import Enum from model.node import BinaryNode, Leaf, randomTree from model.node import BinaryNode, Leaf, randomTree, PlanarNode, planarTreeToBinaryTree from model.tree import Tree n = PlanarNode([ PlanarNode([]), PlanarNode([ PlanarNode([ PlanarNode([]), PlanarNode([]), PlanarNode([]), PlanarNode([]) ]) ]), PlanarNode([ PlanarNode([]), PlanarNode([ PlanarNode([]) ]), PlanarNode([]), ]) ]) bn = planarTreeToBinaryTree(n) Levels = Enum("Levels", [ ("Lvl1", Tree(BinaryNode(Leaf(), BinaryNode(Leaf(), Leaf())))), ("Lvl2", Tree(BinaryNode(BinaryNode(Leaf(), Leaf()), BinaryNode(Leaf(), Leaf())))), Loading
model/node.py +24 −13 Original line number Diff line number Diff line Loading @@ -345,32 +345,33 @@ class PlanarNode(Node): child.completeNode(index, nodeType, tree) def checkNode(self, node, nodeBrothers=None, brothers=None): print("node: ") print(node) print(self) if brothers is None: brothers = [] if nodeBrothers is None: nodeBrothers = [] if not isinstance(node, IncompleteNode): if len(self.children) != len(node.children): print("AAAAAAAAAAA") # the node can't have more children than the model if isinstance(node, IncompleteNode): if len(self.children) < len(node.children): return False # moreover, if the node is completed, it should have exactly the same number of children than the model else: if len(self.children) < len(node.children): print("BBBBBBBBBB") if len(self.children) != len(node.children): return False if not self.children: # if they have not children, call this funtion with the brother of the current nodes if brothers: if not nodeBrothers: """if len(nodeBrothers) != len(brothers): print("Z") return True else: else:""" return brothers.pop(0).checkNode(nodeBrothers.pop(0), nodeBrothers, brothers) else: # if they have no children and no brothers, they are exactly the same trees return True else: # if the model has children but the node has not, we call the funtion with the brothers if not node.children: if brothers: if not nodeBrothers: Loading @@ -380,8 +381,20 @@ class PlanarNode(Node): else: return True else: newBrothers = self.children[1:] + brothers # we add the brothers of the model and the node in the lists, for the models, we only add the brothers # which are represented in the node newNodeBrothers = node.children[1:] + nodeBrothers if len(self.children) == len(node.children): newBrothers = self.children[1:] + brothers else: tmp = [] if len(node.children) > 2: for i in range(1, len(node.children[1:])): print(self.children[i]) tmp.append(self.children[i]) elif len(node.children) == 2: tmp.append(self.children[1]) newBrothers = tmp + brothers return self.children[0].checkNode(node.children[0], newNodeBrothers, newBrothers) def isEqual(self, node, nodeBrothers=None, brothers=None): Loading Loading @@ -570,8 +583,6 @@ class IncompleteNode(PlanarNode): if nodeType == "branch": self.addChild(IncompleteNode([])) else: print("parent: ") print(self.parent) if self.parent is not None: completedNode = PlanarNode(self.children) self.parent[0].changeChild(completedNode, self.parent[1]) Loading