def testClean(self): print "\n----- testing delete on graph -----" root = BinaryNode(self.methodFactory.getBinary('/')) node1 = UnaryNode(self.methodFactory.getUnary('exp')) node2 = UnaryNode(self.methodFactory.getUnary('log')) node3 = UnaryNode(self.methodFactory.getUnary('sin')) node4 = UnaryNode(self.methodFactory.getUnary('log')) # immutable data - stored constant1 = DataNode(self.methodFactory.getData('pi')) # mutable data - might require one function call then the value is fixed value = CGAFunctions.uniform() constant2 = DataNode(CGAFunctions.DataFunction(str(value),str(value),value)) tree = AlgorithmTree(root) root.setChildren(node1, node2) node1.setChildren(node3) node3.setChildren(node4) node2.setChildren(constant1) node4.setChildren(constant2) print 'Tree before node cleaning:' print tree root.setChildren(DataNode(), None) # tree.nodesHaveChanged() node1.clean() print 'Tree after node cleaning:' print tree draw(tree.getGraph()) pylab.show()
def testRecursion(self): print "\n----- testing tree recursion -----" root = BinaryNode(self.methodFactory.getBinary('/')) node1 = UnaryNode(self.methodFactory.getUnary('exp')) node2 = UnaryNode(self.methodFactory.getUnary('log')) node3 = UnaryNode(self.methodFactory.getUnary('sin')) node4 = UnaryNode(self.methodFactory.getUnary('log')) # immutable data - stored constant1 = DataNode(self.methodFactory.getData('pi')) # mutable data - might require one function call then the value is fixed value = CGAFunctions.uniform() constant2 = DataNode(CGAFunctions.DataFunction(str(value),str(value),value)) tree = AlgorithmTree(root) root.setChildren(node1, node2) node1.setChildren(node3) node3.setChildren(node4) node2.setChildren(constant1) node4.setChildren(constant2) print tree