Class Operation<T>

java.lang.Object
net.bmahe.genetics4j.gp.Operation<T>
Type Parameters:
T - the base type used for computation in this operation
Direct Known Subclasses:
CoefficientOperation, ImmutableOperation, InputOperation

@Immutable public abstract class Operation<T> extends Object
Represents an operation (function or terminal) in genetic programming.

An operation defines a computational unit that can be used as a node in genetic programming trees. Operations can be either functions (with arguments) or terminals (without arguments). Each operation has a defined signature including the types it accepts as input and the type it returns.

Operations are the building blocks of genetic programming expressions and define:

  • The computation to perform
  • Type constraints for strongly-typed GP
  • Arity (number of arguments)
  • Whether it's a terminal or function

Common operation types include:

  • Mathematical functions: +, -, *, /, sin, cos, exp
  • Logical functions: AND, OR, NOT, IF-THEN-ELSE
  • Terminals: constants, variables, input values
  • Domain-specific: problem-specific functions and operators
See Also:
  • Constructor Details

    • Operation

      public Operation()
  • Method Details

    • getName

      @Parameter public abstract String getName()
      Returns the name of this operation.
      Returns:
      the operation name, used for identification and display
    • acceptedTypes

      @Parameter public abstract List<Class> acceptedTypes()
      Returns the list of types that this operation accepts as arguments.

      For strongly-typed genetic programming, this defines the type constraints for each argument position. The list size determines the operation's arity.

      Returns:
      the list of accepted argument types, empty for terminals
    • returnedType

      @Parameter public abstract Class returnedType()
      Returns the type that this operation returns.
      Returns:
      the return type of this operation
    • compute

      @Parameter @Auxiliary public abstract BiFunction<T[],Object[],Object> compute()
      Returns the computation function for this operation.
      Returns:
      a function that takes input arguments and parameters and returns the computed result
    • getPrettyName

      @Default public String getPrettyName()
      Returns a human-readable name for this operation.

      By default, this returns the same value as getName(), but can be overridden to provide more descriptive names for display purposes.

      Returns:
      the pretty name for display purposes
    • apply

      public Object apply(T[] input, Object[] parameters)
      Applies this operation to the given input and parameters.
      Parameters:
      input - the input arguments to the operation
      parameters - additional parameters for the operation
      Returns:
      the result of applying this operation
    • getArity

      public int getArity()
      Returns the arity (number of arguments) of this operation.
      Returns:
      the number of arguments this operation accepts
    • isTerminal

      public boolean isTerminal()
      Checks if this operation is a terminal (has no arguments).
      Returns:
      true if this operation takes no arguments, false otherwise