Exemple #1
0
def arg_no(f):
    try:
        if spec(f).defaults is None: return 0
        return len(spec(f).args) - len(spec(f).defaults)
    except Exception as e:
        print("inspect Error: %s" % e)
        return float('nan')
Exemple #2
0
 def inner(*args, **kwargs):
     if statement is not None:
         Context.statement = args[spec(func).args.index(statement)]
         Context.expression = None
     if expression is not None:
         Context.expression = args[spec(func).args.index(expression)]
     return func(*args, **kwargs)
def countNodes(root, sum=0):
	if not hasattr(root, "operands"):
		return sum+1
	else:
		for i in xrange(len(spec(root.operation))):
			sum += countNodes(root.operands[i], sum+1)
		return sum
def pointMutation(indiv, F, T):
	M = getCrossPoint(indiv)
	iparent,isubtree = None, indiv
	i = [0] if not M else M
	
	while i:
		iparent = isubtree
		isubtree = isubtree.operands[i.pop(0)]
		
	if hasattr(isubtree.operator, "__call__"):
		arity = len(spec(isubtree.operator))
		otherGuys = [f for f in F if len(spec(f)) == arity and f!=isubtree.operator]
		isubtree.operator = choose(otherGuys)
	else:
		otherGuys = [t for t in T if t!=isubtree.operator]
		isubtree.operator = choose(otherGuys)
	
	return [indiv]
def generateFull(F, T, root, height):
	if height < 0:
		root.operator = choose(T)
		return root
	
	else:
		root.operator = choose(F)
		for _ in spec(root.operator).args:
			n = Node()
			root.operands.append(generateFull(F, T, n, height-1))
	
		return root
def generateGrow(F, T, root, height, minheight):
	if height < 0:
		root.operator = choose(T)
		return root
	
	else:
		if minheight>0: root.operator = choose(F)
		else: root.operator = choose(F+T)
		if hasattr(root.operator, "__call__"):
			for _ in spec(root.operator).args:
				n = Node()
				root.operands.append(generateGrow(F, T, n, height-1, minheight-1))
			return root
		else:
			return root