def staticLimit(key, max_value):
 def decorator(func):
  @wraps(func)
  def wrapper(*args, **kwargs):
   keep_inds = [copy.deepcopy(ind) for ind in args]
   new_inds = list(func(*args, **kwargs))
   for (i, ind) in enumerate(new_inds):
    if (key(ind) > max_value):
     new_inds[i] = random.choice(keep_inds)
   return new_inds
  return wrapper
 return decorator

def staticLimit ( key , max_value ) : def decorator ( func ) : @ wraps ( func ) def wrapper ( * args , ** kwargs ) : keep_inds = [ copy . deepcopy ( ind ) for ind in args ] new_inds = list ( func ( * args , ** kwargs ) ) for ( i , ind ) in enumerate ( new_inds ) : if ( key ( ind ) > max_value ) : new_inds [ i ] = random . choice ( keep_inds ) return new_inds return wrapper return decorator
implement a static limit on some measurement on a gp tree .