T
- the argument type of the operationpublic class Program<T> extends Object implements Op<T>, Serializable
Constructor and Description |
---|
Program(String name,
Tree<? extends Op<T>,?> tree)
Create a new program with the given name and the given operation tree.
|
Modifier and Type | Method and Description |
---|---|
T |
apply(T[] args) |
int |
arity()
Return the arity of the operation function.
|
static void |
check(Tree<? extends Op<?>,?> program)
Validates the given program tree.
|
boolean |
equals(Object obj) |
T |
eval(T... args)
Convenient method, which lets you apply the program function without
explicitly create a wrapper array.
|
static <T> T |
eval(Tree<? extends Op<T>,?> tree,
T... variables)
Evaluates the given operation tree with the given variables.
|
int |
hashCode() |
String |
name()
Return the name of the operation.
|
static <A> TreeNode<Op<A>> |
of(int depth,
ISeq<? extends Op<A>> operations,
ISeq<? extends Op<A>> terminals)
Create a new, random program tree from the given (non) terminal
operations with the desired depth.
|
static <A> TreeNode<Op<A>> |
of(int depth,
ISeq<? extends Op<A>> operations,
ISeq<? extends Op<A>> terminals,
Random random)
Create a new, random program tree from the given (non) terminal
operations with the desired depth.
|
static <A> Program<A> |
of(String name,
int depth,
ISeq<? extends Op<A>> operations,
ISeq<? extends Op<A>> terminals)
Create a new, random program from the given (non) terminal operations
with the desired depth.
|
static <A> Program<A> |
of(String name,
int depth,
ISeq<? extends Op<A>> operations,
ISeq<? extends Op<A>> terminals,
Random random)
Create a new, random program from the given (non) terminal operations
with the desired depth.
|
String |
toString() |
static <A> TreeNode<Op<A>> |
toTree(ISeq<? extends FlatTree<? extends Op<A>,?>> nodes,
ISeq<? extends Op<A>> terminals)
Creates a valid program tree from the given flattened sequence of
op nodes.
|
Tree<? extends Op<T>,?> |
tree()
Return the underlying expression tree.
|
public Program(String name, Tree<? extends Op<T>,?> tree)
name
- the program nametree
- the operation treeNullPointerException
- if one of the given arguments is null
IllegalArgumentException
- if the given operation tree is invalid,
which means there is at least one node where the operation arity
and the node child count differ.public int arity()
Op
public Tree<? extends Op<T>,?> tree()
@SafeVarargs public final T eval(T... args)
args
- the function argumentsNullPointerException
- if the given variable array is null
IllegalArgumentException
- if the length of the arguments array
is smaller than the program arityapply(Object[])
@SafeVarargs public static <T> T eval(Tree<? extends Op<T>,?> tree, T... variables)
T
- the argument typetree
- the operation treevariables
- the input variablesNullPointerException
- if one of the arguments is null
IllegalArgumentException
- if the length of the variable array
is smaller than the program aritypublic static void check(Tree<? extends Op<?>,?> program)
program
- the program to validateNullPointerException
- if the given program
is null
IllegalArgumentException
- if the given operation tree is invalid,
which means there is at least one node where the operation arity
and the node child count differ.public static <A> Program<A> of(String name, int depth, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals)
A
- the operational typename
- the program namedepth
- the desired depth of the program treeoperations
- the list of non-terminal operationsterminals
- the list of terminal operationsNullPointerException
- if one of the given operations is
null
IllegalArgumentException
- if the given tree depth is smaller than
zeropublic static <A> Program<A> of(String name, int depth, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals, Random random)
A
- the operational typename
- the program namedepth
- the desired depth of the program treeoperations
- the list of non-terminal operationsterminals
- the list of terminal operationsrandom
- the random engine used for creating the programNullPointerException
- if one of the given operations is
null
IllegalArgumentException
- if the given tree depth is smaller than
zeropublic static <A> TreeNode<Op<A>> of(int depth, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals)
A
- the operational typedepth
- the desired depth of the program treeoperations
- the list of non-terminal operationsterminals
- the list of terminal operationsNullPointerException
- if one of the given operations is
null
IllegalArgumentException
- if the given tree depth is smaller than
zeropublic static <A> TreeNode<Op<A>> of(int depth, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals, Random random)
A
- the operational typedepth
- the desired depth of the program treeoperations
- the list of non-terminal operationsterminals
- the list of terminal operationsrandom
- the random engine used for creating the programNullPointerException
- if one of the given operations is
null
IllegalArgumentException
- if the given tree depth is smaller than
zeropublic static <A> TreeNode<Op<A>> toTree(ISeq<? extends FlatTree<? extends Op<A>,?>> nodes, ISeq<? extends Op<A>> terminals)
operations
and termination
nodes are
used for repairing the program tree, if necessary.A
- the operation argument typenodes
- the flattened, possible corrupt, program treeterminals
- the usable non-terminal operation nodes to use for
reparationNullPointerException
- if one of the arguments is null
IllegalArgumentException
- if the nodes
sequence is empty© 2007-2019 Franz Wilhelmstötter (2019-11-18 20:30)