Package net.bmahe.genetics4j.gp
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
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the list of types that this operation accepts as arguments.Applies this operation to the given input and parameters.abstract BiFunction
<T[], Object[], Object> compute()
Returns the computation function for this operation.int
getArity()
Returns the arity (number of arguments) of this operation.abstract String
getName()
Returns the name of this operation.Returns a human-readable name for this operation.boolean
Checks if this operation is a terminal (has no arguments).abstract Class
Returns the type that this operation returns.
-
Constructor Details
-
Operation
public Operation()
-
-
Method Details
-
getName
Returns the name of this operation.- Returns:
- the operation name, used for identification and display
-
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
Returns the type that this operation returns.- Returns:
- the return type of this operation
-
compute
Returns the computation function for this operation.- Returns:
- a function that takes input arguments and parameters and returns the computed result
-
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
Applies this operation to the given input and parameters.- Parameters:
input
- the input arguments to the operationparameters
- 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
-