1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pub use ToDot;
pub use *;
pub use *;
pub use ;
pub use ;
pub use ;
pub use ;
/// [Eval] trait is used to evaluate a [Tree] or [Graph] of node's.
/// It is implemented directly on the [Tree] and [TreeNode] types as well as
/// on the [GraphEvaluator] struct.
///
/// The [Eval] trait and subsequent method is used to transform the `Input` into
/// the `Output`. This is extremely useful for evaluating the [Graph] or [Tree] with a given input
/// as traversing each can be very slow or sometimes cumbersome to do manually.
///
/// # Example
/// ```rust
/// use radiate_gp::{Op, Eval, TreeNode};
///
/// let root = TreeNode::new(Op::add())
/// .attach(
/// TreeNode::new(Op::mul())
/// .attach(TreeNode::new(Op::constant(2.0)))
/// .attach(TreeNode::new(Op::constant(3.0))),
/// )
/// .attach(
/// TreeNode::new(Op::add())
/// .attach(TreeNode::new(Op::constant(2.0)))
/// .attach(TreeNode::new(Op::var(0))),
/// );
///
/// // And the result of evaluating this tree with an input of `1` would be:
/// let result = root.eval(&vec![1_f32]);
/// assert_eq!(result, 9.0);
/// ```
/// This creates a `Tree` that looks like:
/// ```text
/// +
/// / \
/// * +
/// / \ / \
/// 2 3 2 x
/// ```
/// Where `x` is the first variable in the input.
///
/// This can also be thought of (and is functionally equivalent) as:
/// ```text
/// f(x) = (2 * 3) + (2 + x)
/// ```