Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/gp/GPProblem.java @ 9449

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

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

File size: 2.6 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.gp;
9import ec.util.*;
10import ec.*;
11import ec.simple.*;
12
13/*
14 * GPProblem.java
15 *
16 * Created: Wed Oct 27 18:07:06 1999
17 * By: Sean Luke
18 */
19
20/**
21 * A GPProblem is a Problem which is meant to efficiently handle GP
22 * evaluation.  GPProblems hold one ADFStack, which is used to
23 * evaluate a large number of trees without having to be garbage-collected
24 * and reallocated.  Be sure to call stack.reset() after each
25 * tree evaluation.
26 *
27 <p><b>Parameters</b><br>
28 <table>
29 <tr><td valign=top><i>base</i><tt>.stack</tt><br>
30 <font size=-1>classname, inherits or = ec.ADFStack</font></td>
31 <td valign=top>(the class for the GPProblem's ADF Stack)</td></tr>
32 <tr><td valign=top><i>base</i><tt>.data</tt><br>
33 <font size=-1>classname, inherits and != ec.GPData</font></td>
34 <td valign=top>(the class for the GPProblem's basic GPData type)</td></tr>
35 </table>
36
37 <p><b>Default Base</b><br>
38 gp.problem
39
40 <p><b>Parameter bases</b><br>
41 <table>
42 <tr><td valign=top><i>base</i><tt>.stack</tt><br>
43 <td valign=top>(stack)</td></tr>
44 <tr><td valign=top><i>base</i><tt>.data</tt><br>
45 <td valign=top>(data)</td></tr>
46 </table>
47
48 * @author Sean Luke
49 * @version 1.0
50 */
51
52public abstract class GPProblem extends Problem implements SimpleProblemForm
53    {
54    public final static String P_GPPROBLEM = "problem";
55    public final static String P_STACK = "stack";
56    public final static String P_DATA = "data";
57
58    /** The GPProblem's stack */
59    public ADFStack stack;
60
61    /** The GPProblems' GPData */
62    public GPData data;
63
64    /** GPProblem defines a default base so your subclass doesn't
65        absolutely have to. */
66    public Parameter defaultBase()
67        {
68        return GPDefaults.base().push(P_GPPROBLEM);
69        }
70
71    public void setup(final EvolutionState state, final Parameter base)
72        {
73        Parameter p = base.push(P_STACK);
74        Parameter def = defaultBase();
75
76        stack = (ADFStack)
77            (state.parameters.getInstanceForParameterEq(
78                p,def.push(P_STACK),ADFStack.class));
79        stack.setup(state,p);
80
81        p = base.push(P_DATA);
82        data = (GPData)
83            (state.parameters.getInstanceForParameter(
84                p,def.push(P_DATA),GPData.class));
85        data.setup(state,p);
86        }
87
88    public Object clone()
89        {
90        GPProblem prob = (GPProblem)(super.clone());
91       
92        // deep-clone the stack; it's not shared
93        prob.stack = (ADFStack)(stack.clone());
94        return prob;
95        }
96    }
Note: See TracBrowser for help on using the repository browser.