2.6. Node Operators

These classes define the operations that nodes can perform.

2.6.1. Custom operators

2.6.1.1. Base Operator

class natural_selection.genetic_programs.node_operators.__init__.Operator(operator_label: str = '', function=None, min_arity: int = 0, max_arity: int = 10, strict_precedence: bool = True)

Default class for creating custom operators. The class can either be extended or a custom function can be given.

Parameters
  • operator_label (str) – The label used for node representation (default = ‘’).

  • function (Callable) – A custom function used for performing the execution (default = None).

  • min_arity (int) – The minimum arity of the function (default = 0).

  • max_arity (int) – The maximum arity of the function (default = 10).

  • strict_precedence (bool) – Whether the order of the arguments are strictly required (default = True).

exec(args)

Takes a list of values (arguments) and performs the given or defined function, then returns the result.

Parameters

args (list) – The list of ordered arguments for the function.

Raises

AssertionError – If the length of the list of args is not in the range of the min and max arity.

Returns

The resulting value.

Return type

result

2.6.2. Standard operators

2.6.2.1. Return Operator

class natural_selection.genetic_programs.node_operators.__init__.OperatorReturn(operator_label: str = 'return')
exec(args)

Takes a list of length 1 and returns the value.

Parameters

args (list) – The list of ordered arguments for the function.

Raises

AssertionError – If the length of the list of args is not in the range of the min and max arity.

Returns

The resulting value.

Return type

result

2.6.2.2. Addition Operator

class natural_selection.genetic_programs.node_operators.__init__.OperatorAdd(operator_label: str = 'add', max_arity: int = 2)

Simple addition of arguments.

Parameters
  • operator_label (str) – The label used for node representation (default = ‘add’).

  • max_arity (int) – The maximum arity of the function (default = 2).

exec(args)

Takes a list of values (arguments) and performs addition, then returns the result.

Parameters

args (list) – The list of ordered arguments for the function.

Raises

AssertionError – If the length of the list of args is not in the range of the min and max arity.

Returns

The resulting value.

Return type

result

2.6.2.3. Subtraction Operator

class natural_selection.genetic_programs.node_operators.__init__.OperatorSub(operator_label: str = 'sub', max_arity: int = 2)

Simple subtraction of arguments.

Parameters
  • operator_label (str) – The label used for node representation (default = ‘sub’).

  • max_arity (int) – The maximum arity of the function (default = 2).

exec(args)

Takes a list of values (arguments) and performs subtraction, then returns the result.

Parameters

args (list) – The list of ordered arguments for the function.

Raises

AssertionError – If the length of the list of args is not in the range of the min and max arity.

Returns

The resulting value.

Return type

result

2.6.2.4. Multiplication Operator

class natural_selection.genetic_programs.node_operators.__init__.OperatorMul(operator_label: str = 'mul', max_arity: int = 2)

Simple multiplication of arguments.

Parameters
  • operator_label (str) – The label used for node representation (default = ‘mul’).

  • max_arity (int) – The maximum arity of the function (default = 2).

exec(args)

Takes a list of values (arguments) and performs multiplication, then returns the result.

Parameters

args (list) – The list of ordered arguments for the function.

Raises

AssertionError – If the length of the list of args is not in the range of the min and max arity.

Returns

The resulting value.

Return type

result

2.6.2.5. Division Operator

class natural_selection.genetic_programs.node_operators.__init__.OperatorDiv(operator_label: str = 'div', max_arity: int = 2)

Simple division of arguments.

Parameters
  • operator_label (str) – The label used for node representation (default = ‘div’).

  • max_arity (int) – The maximum arity of the function (default = 2).

exec(args)

Takes a list of values (arguments) and performs division, then returns the result.

Parameters

args (list) – The list of ordered arguments for the function.

Raises

AssertionError – If the length of the list of args is not in the range of the min and max arity.

Returns

The resulting value.

Return type

result

2.6.2.6. Power Operator

class natural_selection.genetic_programs.node_operators.__init__.OperatorPow(operator_label: str = 'pow', max_arity: int = 2)

Simple power of arguments.

Parameters
  • operator_label (str) – The label used for node representation (default = ‘pow’).

  • max_arity (int) – The maximum arity of the function (default = 2).

exec(args)

Takes a list of values (arguments) and performs powering, then returns the result.

Parameters

args (list) – The list of ordered arguments for the function.

Raises

AssertionError – If the length of the list of args is not in the range of the min and max arity.

Returns

The resulting value.

Return type

result

2.6.2.7. Less-Equal Operator

class natural_selection.genetic_programs.node_operators.__init__.OperatorLTE(operator_label: str = 'lte')

Simple logical operation, less than or equal.

Parameters

operator_label (str) – The label used for node representation (default = ‘lte’).

exec(args)

Takes a list of values (arguments) and tests if the left most is less than or equal to the right.

Parameters

args (list) – The list of ordered arguments for the function.

Raises

AssertionError – If the length of the list of args is not in the range of the min and max arity.

Returns

The resulting value.

Return type

bool

2.6.2.8. Less than Operator

class natural_selection.genetic_programs.node_operators.__init__.OperatorLT(operator_label: str = 'lt')

Simple logical operation, less than.

Parameters

operator_label (str) – The label used for node representation (default = ‘lt’).

exec(args)

Takes a list of values (arguments) and tests if the left most is less than to the right.

Parameters

args (list) – The list of ordered arguments for the function.

Raises

AssertionError – If the length of the list of args is not in the range of the min and max arity.

Returns

The resulting value.

Return type

bool

2.6.2.9. Greater-Equal Operator

class natural_selection.genetic_programs.node_operators.__init__.OperatorGTE(operator_label: str = 'gte')

Simple logical operation, greater than or equal.

Parameters

operator_label (str) – The label used for node representation (default = ‘gte’).

exec(args)

Takes a list of values (arguments) and tests if the left most is greater than or equal to the right.

Parameters

args (list) – The list of ordered arguments for the function.

Raises

AssertionError – If the length of the list of args is not in the range of the min and max arity.

Returns

The resulting value.

Return type

bool

2.6.2.10. Greater than Operator

class natural_selection.genetic_programs.node_operators.__init__.OperatorGT(operator_label: str = 'gt')

Simple logical operation, greater than or equal.

Parameters

operator_label (str) – The label used for node representation (default = ‘gt’).

exec(args)

Takes a list of values (arguments) and tests if the left most is greater than to the right.

Parameters

args (list) – The list of ordered arguments for the function.

Raises

AssertionError – If the length of the list of args is not in the range of the min and max arity.

Returns

The resulting value.

Return type

bool

2.6.2.11. Equality Operator

class natural_selection.genetic_programs.node_operators.__init__.OperatorEq(operator_label: str = 'eq')

Simple logical operation, arguments are equal.

Parameters

operator_label (str) – The label used for node representation (default = ‘eq’).

exec(args)

Takes a list of values (arguments) and tests if the left most is equal to the right.

Parameters

args (list) – The list of ordered arguments for the function.

Raises

AssertionError – If the length of the list of args is not in the range of the min and max arity.

Returns

The resulting value.

Return type

bool

2.6.2.12. Non-Equality Operator

class natural_selection.genetic_programs.node_operators.__init__.OperatorNE(operator_label: str = 'ne')

Simple logical operation, arguments are not equal.

Parameters

operator_label (str) – The label used for node representation (default = ‘ne’).

exec(args)

Takes a list of values (arguments) and tests if the left most is not equal to the right.

Parameters

args (list) – The list of ordered arguments for the function.

Raises

AssertionError – If the length of the list of args is not in the range of the min and max arity.

Returns

The resulting value.

Return type

bool