Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/app/multiplexer/func/If.java @ 6152

Last change on this file since 6152 was 6152, checked in by bfarka, 13 years ago

added ecj and custom statistics to communicate with the okb services #1441

File size: 3.5 KB
Line 
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
8package ec.app.multiplexer.func;
9import ec.*;
10import ec.app.multiplexer.*;
11import ec.gp.*;
12import ec.util.*;
13
14/*
15 * If.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
26public class If extends GPNode
27    {
28    public String toString() { return "if"; }
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!=3)
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        MultiplexerData md = (MultiplexerData)input;
50        long[] dat_11_1=null;  // quiets compiler complaints
51        long[] dat_11_2=null;  // quiets compiler complaints
52        long dat_6_1=0L;
53        long dat_6_2=0L;
54        byte dat_3_1=0;
55        byte dat_3_2=0;
56
57        // No shortcuts for now
58        children[0].eval(state,thread,input,stack,individual,problem);
59
60        if (md.status == MultiplexerData.STATUS_3)
61            dat_3_1 = md.dat_3;
62        else if (md.status == MultiplexerData.STATUS_6)
63            dat_6_1 = md.dat_6;
64        else // md.status == MultiplexerData.STATUS_11
65            {
66            dat_11_1 = md.popDat11();
67            System.arraycopy(md.dat_11,0,
68                dat_11_1,0,
69                MultiplexerData.MULTI_11_NUM_BITSTRINGS);
70            }
71
72        children[1].eval(state,thread,input,stack,individual,problem);
73
74        if (md.status == MultiplexerData.STATUS_3)
75            dat_3_2 = md.dat_3;
76        else if (md.status == MultiplexerData.STATUS_6)
77            dat_6_2  = md.dat_6;
78        else // md.status == MultiplexerData.STATUS_11
79            {
80            dat_11_2 = md.popDat11();
81            System.arraycopy(md.dat_11,0,
82                dat_11_2,0,
83                MultiplexerData.MULTI_11_NUM_BITSTRINGS);
84            }
85
86        // tweak -- if a then b else c is equivalent to
87        // (a -> b) ^ (~a -> c) which is equivalent to
88        // (~a v b) ^ (a v c).  In Java, ^ (-1) is the same
89        // is bitwise not.
90
91        children[2].eval(state,thread,input,stack,individual,problem);
92
93        if (md.status == MultiplexerData.STATUS_3)
94            md.dat_3 = (byte)(
95                ((dat_3_1 ^ (byte)(-1)) | dat_3_2 ) &
96                ((dat_3_1 | md.dat_3)));
97
98        else if (md.status == MultiplexerData.STATUS_6)
99            md.dat_6 =
100                ((dat_6_1 ^ (-1L)) | dat_6_2 ) &
101                ((dat_6_1 | md.dat_6));
102
103        else // md.status == MultiplexerData.STATUS_11
104            {
105            for(int x=0;x<MultiplexerData.MULTI_11_NUM_BITSTRINGS;x++)
106                md.dat_11[x] =
107                    ((dat_11_1[x] ^ (-1L)) | dat_11_2[x] ) &
108                    ((dat_11_1[x] | md.dat_11[x]));
109            md.pushDat11(dat_11_2);
110            md.pushDat11(dat_11_1);
111            }
112        }
113    }
114
115
116
Note: See TracBrowser for help on using the repository browser.