ec
Class Problem

java.lang.Object
  extended byec.Problem
All Implemented Interfaces:
java.lang.Cloneable, Prototype, java.io.Serializable, Setup
Direct Known Subclasses:
GPProblem, MasterProblem, TeambotsProblem

public abstract class Problem
extends java.lang.Object
implements Prototype

Problem is a prototype which defines the problem against which we will evaluate individuals in a population.

Since Problems are Prototypes, you should expect a new Problem class to be cloned and used, on a per-thread basis, for the evolution of each chunk of individuals in a new population. If you for some reason need global Problem information, you will have to provide it statically, or copy pointers over during the protoClone() process (there is likely only one Problem prototype, depending on the Evaluator class used).

Note that Problem does not implement a specific evaluation method. Your particular Problem subclass will need to implement a some kind of Problem Form (for example, SimpleProblemForm) appropriate to the kind of evaluation being performed on the Problem. These Problem Forms will provide the evaluation methods necessary.

Problem forms will define some kind of evaluation method. This method may be called in one of two ways by the Evaluator.

Problems should be prepared for both of the above situations. The easiest way to handle it is to simply evaluate each individual as his evaluate(...) method is called, and do nothing during prepareToEvaluate or finishEvaluating. That should be true for the vast majority of Problem types.

See Also:
Serialized Form

Field Summary
static java.lang.String P_PROBLEM
           
 
Constructor Summary
Problem()
           
 
Method Summary
 java.lang.Object clone()
          Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
 void closeContacts(EvolutionState state, int result)
          Called to shut down remote evaluation network contacts when the run is completed.
 Parameter defaultBase()
          Here's a nice default base for you -- you can change it if you like
 void finishEvaluating(EvolutionState state, int threadnum)
          Will be called by the Evaluator after prepareToEvaluate(...) is called and then a series of individuals are evaluated.
 void initializeContacts(EvolutionState state)
          Called to set up remote evaluation network contacts when the run is started.
 void prepareToEvaluate(EvolutionState state, int threadnum)
          May be called by the Evaluator prior to a series of individuals to evaluate, and then ended with a finishEvaluating(...).
 void reinitializeContacts(EvolutionState state)
          Called to reinitialize remote evaluation network contacts when the run is restarted from checkpoint.
 void setup(EvolutionState state, Parameter base)
          Sets up the object by reading it from the parameters stored in state, built off of the parameter base base.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

P_PROBLEM

public static final java.lang.String P_PROBLEM
See Also:
Constant Field Values
Constructor Detail

Problem

public Problem()
Method Detail

defaultBase

public Parameter defaultBase()
Here's a nice default base for you -- you can change it if you like

Specified by:
defaultBase in interface Prototype

setup

public void setup(EvolutionState state,
                  Parameter base)
Description copied from interface: Prototype
Sets up the object by reading it from the parameters stored in state, built off of the parameter base base. If an ancestor implements this method, be sure to call super.setup(state,base); before you do anything else.

For prototypes, setup(...) is typically called once for the prototype instance; cloned instances do not receive the setup(...) call. setup(...) may be called more than once; the only guarantee is that it will get called at least once on an instance or some "parent" object from which it was ultimately cloned.

Specified by:
setup in interface Prototype

clone

public java.lang.Object clone()
Description copied from interface: Prototype
Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.

The question here is whether or not this means to perform a "deep" or "light" ("shallow") clone, or something in-between. You may need to deep-clone parts of your object rather than simply copying their references, depending on the situation:

Implementations.

If you know that your superclasses will never change their protoClone() implementations, you might try inlining them in your overridden protoClone() method. But this is dangerous (though it yields a small net increase).

In general, you want to keep your deep cloning to an absolute minimum, so that you don't have to call protoClone() but one time.

The approach taken here is the fastest that I am aware of while still permitting objects to be specified at runtime from a parameter file. It would be faster to use the "new" operator; but that would require hard-coding that we can't do. Although using java.lang.Object.clone() entails an extra layer that deals with stripping away the "protected" keyword and also wrapping the exception handling (which is a BIG hit, about three times as slow as using "new"), it's still MUCH faster than using java.lang.Class.newInstance(), and also much faster than rolling our own Clone() method.

Specified by:
clone in interface Prototype

prepareToEvaluate

public void prepareToEvaluate(EvolutionState state,
                              int threadnum)
May be called by the Evaluator prior to a series of individuals to evaluate, and then ended with a finishEvaluating(...). If this is the case then the Problem is free to delay modifying the individuals or their fitnesses until at finishEvaluating(...). If no prepareToEvaluate(...) is called prior to evaluation, the Problem must complete its modification of the individuals and their fitnesses as they are evaluated as stipulated in the relevant evaluate(...) documentation for SimpleProblemForm or GroupedProblemForm. The default method does nothing.


finishEvaluating

public void finishEvaluating(EvolutionState state,
                             int threadnum)
Will be called by the Evaluator after prepareToEvaluate(...) is called and then a series of individuals are evaluated. However individuals may be evaluated without prepareToEvaluate or finishEvaluating being called at all. See the documentation for prepareToEvaluate for more information. The default method does nothing.


initializeContacts

public void initializeContacts(EvolutionState state)
Called to set up remote evaluation network contacts when the run is started. By default does nothing.


reinitializeContacts

public void reinitializeContacts(EvolutionState state)
Called to reinitialize remote evaluation network contacts when the run is restarted from checkpoint. By default does nothing.


closeContacts

public void closeContacts(EvolutionState state,
                          int result)
Called to shut down remote evaluation network contacts when the run is completed. By default does nothing.