Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def binary_mutation(self):
"""
Changes one binary operations to another
"""
binary_operations = self._get_all_nodes_by_filter(lambda n: n.is_binary())
if not binary_operations: return
selected_binary = random.choice(binary_operations)
selected_binary.operation = random.choice(Operations.get_binary_operations())
def generate_operator(cls, only_binary:bool=False):
"""
Returns randomly selected allowed operations.
The possibility of a binary operation is higher than possibility
of an unary operation.
IF isBinary = True returns binary operation
"""
if only_binary or random.random() < 0.75:
return random.choice(Operations.get_binary_operations())
else:
return random.choice(Operations.get_unary_operations() +
Operations.get_binary_operations())
def generate_operator(cls, only_binary:bool=False):
"""
Returns randomly selected allowed operations.
The possibility of a binary operation is higher than possibility
of an unary operation.
IF isBinary = True returns binary operation
"""
if only_binary or random.random() < 0.75:
return random.choice(Operations.get_binary_operations())
else:
return random.choice(Operations.get_unary_operations() +
Operations.get_binary_operations())