Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/Problem.java @ 6755

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

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

File size: 5.9 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;
9
10import ec.util.*;
11
12/*
13 * Problem.java
14 *
15 * Created: Fri Oct 15 14:16:17 1999
16 * By: Sean Luke
17 */
18
19/**
20 * Problem is a prototype which defines the problem against which we will
21 * evaluate individuals in a population.
22 *
23 * <p>Since Problems are Prototypes, you should expect a new Problem class to be
24 * cloned and used, on a per-thread basis, for the evolution of each
25 * chunk of individuals in a new population.  If you for some reason
26 * need global Problem information, you will have to provide it
27 * statically, or copy pointers over during the clone() process
28 * (there is likely only one Problem prototype, depending on the
29 * Evaluator class used).
30 *
31 * <p>Note that Problem does not implement a specific evaluation method.
32 * Your particular Problem subclass will need to implement a some kind of
33 * Problem Form (for example, SimpleProblemForm) appropriate to the kind of
34 * evaluation being performed on the Problem.  These Problem Forms will provide
35 * the evaluation methods necessary.
36 *
37 * <p>Problem forms will define some kind of <i>evaluation</i> method.  This method
38 * may be called in one of two ways by the Evaluator.
39 *
40 * <ul>
41 * <li> The evaluation is called for a series of individuals.  This is the old approach,
42 * and it means that each individual must be evaluated and modified as specified by the
43 * Problem Form during the evaluation call.
44 * <li> prepareToEvaluate is called, then a series of individuals is evaluated, and then
45 * finishEvaluating is called.  This is the new approach, and in this case the Problem
46 * is free to delay evaluating and modifying the individuals until finishEvaluating has
47 * been called.  The Problem may perfectly well evaluate and modify the individuals during
48 * each evaluation call if it likes.  It's just given this additional option.
49 * </ul>
50 *
51 * <p>Problems should be prepared for both of the above situations.  The easiest way
52 * to handle it is to simply evaluate each individual as his evaluate(...) method is called,
53 * and do nothing during prepareToEvaluate or finishEvaluating.  That should be true for
54 * the vast majority of Problem types.
55 *
56 * @author Sean Luke
57 * @version 2.0
58 */
59
60public abstract class Problem implements Prototype
61    {
62    public static final String P_PROBLEM = "problem";
63   
64    /** Here's a nice default base for you -- you can change it if you like */
65    public Parameter defaultBase()
66        {
67        return new Parameter(P_PROBLEM);
68        }
69
70    // default form does nothing
71    public void setup(final EvolutionState state, final Parameter base)
72        {
73        }
74
75    public Object clone()
76        {
77        try { return super.clone(); }
78        catch (CloneNotSupportedException e)
79            { throw new InternalError(); } // never happens
80        }
81
82    /** May be called by the Evaluator prior to a series of individuals to
83        evaluate, and then ended with a finishEvaluating(...).  If this is the
84        case then the Problem is free to delay modifying the individuals or their
85        fitnesses until at finishEvaluating(...).  If no prepareToEvaluate(...)
86        is called prior to evaluation, the Problem must complete its modification
87        of the individuals and their fitnesses as they are evaluated as stipulated
88        in the relevant evaluate(...) documentation for SimpleProblemForm
89        or GroupedProblemForm.  The default method does nothing.  Note that
90        prepareToEvaluate() can be called *multiple times* prior to finishEvaluating()
91        being called -- in this case, the subsequent calls may be ignored. */
92    public void prepareToEvaluate(final EvolutionState state, final int threadnum)
93        {
94        }
95       
96    /** Will be called by the Evaluator after prepareToEvaluate(...) is called
97        and then a series of individuals are evaluated.  However individuals may
98        be evaluated without prepareToEvaluate or finishEvaluating being called
99        at all.  See the documentation for prepareToEvaluate for more information.
100        The default method does nothing.*/
101    public void finishEvaluating(final EvolutionState state, final int threadnum)
102        {
103        }
104
105    /** Called to set up remote evaluation network contacts when the run is started.  By default does nothing. */
106    public void initializeContacts( EvolutionState state )
107        {
108        }
109
110    /**  Called to reinitialize remote evaluation network contacts when the run is restarted from checkpoint.  By default does nothing. */
111    public void reinitializeContacts( EvolutionState state )
112        {
113        }
114   
115    /**  Called to shut down remote evaluation network contacts when the run is completed.  By default does nothing. */
116    public void closeContacts(EvolutionState state, int result)
117        {
118        }
119       
120    /** Asynchronous Steady-State EC only: Returns true if the problem is ready to evaluate.  In most cases,
121        the default is true.  */
122    public boolean canEvaluate()
123        {
124        return true;
125        }
126
127    /** Part of SimpleProblemForm.  Included here so you don't have to write the default version, which usually does nothing. */
128    public void describe(
129        final EvolutionState state,
130        final Individual ind,
131        final int subpopulation,
132        final int threadnum,
133        final int log)
134        {
135        return;
136        }
137
138    /** @deprecated.  Use the version without verbosity */
139    public final void describe(final Individual ind,
140        final EvolutionState state,
141        final int subpopulation,
142        final int threadnum,
143        final int log,
144        final int verbosity)
145        {
146        describe(state, ind, subpopulation, threadnum, log);
147        }
148    }
149
150
Note: See TracBrowser for help on using the repository browser.