1 | /*
|
---|
2 | Copyright 2006 by Sean Luke
|
---|
3 | Licensed under the Academic Free License version 3.0
|
---|
4 | See the file "LICENSE" for more information
|
---|
5 | */
|
---|
6 |
|
---|
7 |
|
---|
8 | package ec.app.regression.func;
|
---|
9 | import ec.*;
|
---|
10 | import ec.app.regression.*;
|
---|
11 | import ec.gp.*;
|
---|
12 | import ec.util.*;
|
---|
13 |
|
---|
14 | /*
|
---|
15 | * Div.java
|
---|
16 | *
|
---|
17 | * Created: Wed Nov 3 18:26:37 1999
|
---|
18 | * By: Sean Luke
|
---|
19 | */
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * @author Sean Luke
|
---|
23 | * @version 1.0
|
---|
24 | */
|
---|
25 |
|
---|
26 | public class Div extends GPNode
|
---|
27 | {
|
---|
28 | public String toString() { return "%"; }
|
---|
29 |
|
---|
30 | public void checkConstraints(final EvolutionState state,
|
---|
31 | final int tree,
|
---|
32 | final GPIndividual typicalIndividual,
|
---|
33 | final Parameter individualBase)
|
---|
34 | {
|
---|
35 | super.checkConstraints(state,tree,typicalIndividual,individualBase);
|
---|
36 | if (children.length!=2)
|
---|
37 | state.output.error("Incorrect number of children for node " +
|
---|
38 | toStringForError() + " at " +
|
---|
39 | individualBase);
|
---|
40 | }
|
---|
41 |
|
---|
42 | public void eval(final EvolutionState state,
|
---|
43 | final int thread,
|
---|
44 | final GPData input,
|
---|
45 | final ADFStack stack,
|
---|
46 | final GPIndividual individual,
|
---|
47 | final Problem problem)
|
---|
48 | {
|
---|
49 | RegressionData rd = ((RegressionData)(input));
|
---|
50 |
|
---|
51 | // evaluate children[1] first to determine if the demoniator is 0
|
---|
52 | children[1].eval(state,thread,input,stack,individual,problem);
|
---|
53 | if (rd.x==0.0)
|
---|
54 | // the answer is 1.0 since the denominator was 0.0
|
---|
55 | rd.x = 1.0;
|
---|
56 | else
|
---|
57 | {
|
---|
58 | double result;
|
---|
59 | result = rd.x;
|
---|
60 |
|
---|
61 | children[0].eval(state,thread,input,stack,individual,problem);
|
---|
62 | rd.x = rd.x / result;
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 |
|
---|