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.edge.func;
|
---|
9 | import ec.*;
|
---|
10 | import ec.app.edge.*;
|
---|
11 | import ec.gp.*;
|
---|
12 | import ec.util.*;
|
---|
13 |
|
---|
14 | /*
|
---|
15 | * Bud.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 Bud extends GPNode
|
---|
27 | {
|
---|
28 | public String toString() { return "bud"; }
|
---|
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 | int edge = ((EdgeData)(input)).edge;
|
---|
50 | Edge prob = (Edge)problem;
|
---|
51 |
|
---|
52 | if (prob.from.length==prob.numEdges) // we're full, need to expand
|
---|
53 | {
|
---|
54 | int[] from_ = new int[prob.numEdges*2];
|
---|
55 | int[] to_ = new int[prob.numEdges*2];
|
---|
56 | int[] reading_ = new int[prob.numEdges*2];
|
---|
57 | System.arraycopy(prob.from,0,from_,0,prob.from.length);
|
---|
58 | System.arraycopy(prob.to,0,to_,0,prob.to.length);
|
---|
59 | System.arraycopy(prob.reading,0,reading_,0,prob.reading.length);
|
---|
60 | prob.from = from_;
|
---|
61 | prob.to = to_;
|
---|
62 | prob.reading = reading_;
|
---|
63 | }
|
---|
64 |
|
---|
65 | if (prob.start.length==prob.numNodes) // we're full, need to expand
|
---|
66 | {
|
---|
67 | boolean[] start_ = new boolean[prob.numNodes*2];
|
---|
68 | boolean[] accept_ = new boolean[prob.numNodes*2];
|
---|
69 | System.arraycopy(prob.start,0,start_,0,prob.start.length);
|
---|
70 | System.arraycopy(prob.accept,0,accept_,0,prob.accept.length);
|
---|
71 | prob.start = start_;
|
---|
72 | prob.accept = accept_;
|
---|
73 | }
|
---|
74 |
|
---|
75 | int newedge = prob.numEdges;
|
---|
76 | prob.numEdges++;
|
---|
77 | int newnode = prob.numNodes;
|
---|
78 | prob.numNodes++;
|
---|
79 |
|
---|
80 | // set up new node
|
---|
81 | prob.accept[newnode] = false;
|
---|
82 | prob.start[newnode] = false;
|
---|
83 |
|
---|
84 | // set up new edge
|
---|
85 | prob.from[newedge] = prob.to[edge];
|
---|
86 | prob.to[newedge] = newnode;
|
---|
87 | prob.reading[newedge] = prob.reading[edge];
|
---|
88 |
|
---|
89 | // pass the original edge down the left child
|
---|
90 |
|
---|
91 | children[0].eval(state,thread,input,stack,individual,problem);
|
---|
92 |
|
---|
93 | // reset input for right child
|
---|
94 | ((EdgeData)(input)).edge = newedge;
|
---|
95 |
|
---|
96 | // pass the new edge down the right child
|
---|
97 |
|
---|
98 | children[1].eval(state,thread,input,stack,individual,problem);
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 |
|
---|