ECF 1.5
IAMul.cpp
1#include "GPSymbRegEvalOp.h"
2
3#include "IAMul.h"
4#include "IATree.h"
5#include <cmath>
6
7void IAMul::execute(void* result, Tree::Tree& tree)
8{
9 if (!calculateBoundsIfRootNode(result, tree)) {
10 return;
11 }
12
14}
15
16IABounds IAMul::calculateBounds(Tree::IATree& tree) {
17 // get next argument
18 tree.iNode_++;
19 IAPrimitiveP prim1 = boost::dynamic_pointer_cast<IAPrimitive>(tree[tree.iNode_]->primitive_);
20 // calculate bounds
21 IABounds bounds1 = prim1->calculateBounds(tree);
22
23 if (!bounds1.isWithinBounds) {
24 // subtree not within bounds, delete expression
25 return bounds1;
26 }
27
28 // get next argument
29 tree.iNode_++;
30 IAPrimitiveP prim2 = boost::dynamic_pointer_cast<IAPrimitive>(tree[tree.iNode_]->primitive_);
31 // calculate bounds
32 IABounds bounds2 = prim2->calculateBounds(tree);
33
34 if (!bounds2.isWithinBounds) {
35 // subtree not within bounds, delete expression
36 return bounds2;
37 } else {
38 // subtree is ok
39 double ll = bounds1.lowerBound * bounds2.lowerBound;
40 double lu = bounds1.lowerBound * bounds2.upperBound;
41 double ul = bounds1.upperBound * bounds2.lowerBound;
42 double uu = bounds1.upperBound * bounds2.upperBound;
43
44 IABounds retVal;
45 if (ll <= lu && ll <= ul && ll <= uu) {
46 // ll is min
47 retVal.isLowerBoundInclusive = bounds1.isLowerBoundInclusive && bounds2.isLowerBoundInclusive;
48 retVal.lowerBound = ll;
49 } else if (lu <= ll && lu <= ul && lu <= uu) {
50 // lu is min
51 retVal.isLowerBoundInclusive = bounds1.isLowerBoundInclusive && bounds2.isUpperBoundInclusive;
52 retVal.lowerBound = lu;
53 } else if (ul <= ll && ul <= lu && ul <= uu) {
54 // ul is min
55 retVal.isLowerBoundInclusive = bounds1.isUpperBoundInclusive && bounds2.isLowerBoundInclusive;
56 retVal.lowerBound = ul;
57 } else {
58 // uu is min
59 retVal.isLowerBoundInclusive = bounds1.isUpperBoundInclusive && bounds2.isUpperBoundInclusive;
60 retVal.lowerBound = uu;
61 }
62
63 if (ll >= lu && ll >= ul && ll >= uu) {
64 // ll is max
65 retVal.isUpperBoundInclusive = bounds1.isLowerBoundInclusive && bounds2.isLowerBoundInclusive;
66 retVal.upperBound = ll;
67 } else if (lu >= ll && lu >= ul && lu >= uu) {
68 // lu is max
69 retVal.isUpperBoundInclusive = bounds1.isLowerBoundInclusive && bounds2.isUpperBoundInclusive;
70 retVal.upperBound = lu;
71 } else if (ul >= ll && ul >= lu && ul >= uu) {
72 // ul is max
73 retVal.isUpperBoundInclusive = bounds1.isUpperBoundInclusive && bounds2.isLowerBoundInclusive;
74 retVal.upperBound = ul;
75 } else {
76 // uu is max
77 retVal.isUpperBoundInclusive = bounds1.isUpperBoundInclusive && bounds2.isUpperBoundInclusive;
78 retVal.upperBound = uu;
79 }
80
81 retVal.isWithinBounds = true;
82 return retVal;
83 }
84}
virtual void execute(void *result, Tree::Tree &tree)
Execute the primitive.
Definition: IAMul.cpp:7
void execute(void *result, Tree &tree)
Execute the primitive.
Definition: Mul.h:38
Tree class - implements genotype as a tree.
Definition: Tree_c.h:29
uint iNode_
current node index (when parsing the tree)
Definition: Tree_c.h:75