ec.eval
Class MasterProblem

java.lang.Object
  extended by ec.Problem
      extended by ec.eval.MasterProblem
All Implemented Interfaces:
GroupedProblemForm, Prototype, Setup, SimpleProblemForm, java.io.Serializable, java.lang.Cloneable

public class MasterProblem
extends Problem
implements SimpleProblemForm, GroupedProblemForm, java.io.Serializable

MasterProblem.java

The MasterProblem is an ECJ problem that performs evaluations by pooling an available slave and sending all information necessary for the evaluation to that slave. In some sense, the MasterProblem is the "master" of the master-slave architecture. As it implements both the SimpleProblemForm and the GroupedProblemForm interfaces, the MasterProblem can perform both traditional EC evaluations, as well as coevolutionary evaluations.

Parameters

base.debug-info
boolean
(whether the system should display information useful for debugging purposes)

Version:
1.0
Author:
Liviu Panait
See Also:
Serialized Form

Field Summary
 boolean batchMode
           
protected static org.apache.commons.logging.Log log
           
static java.lang.String P_DEBUG_INFO
           
static java.lang.String P_JOB_SIZE
           
 Problem problem
           
 IMasterProblemServer server
           
 java.lang.Thread serverThread
           
 
Fields inherited from class ec.Problem
P_PROBLEM
 
Constructor Summary
MasterProblem()
           
 
Method Summary
 boolean canEvaluate()
          Asynchronous Steady-State EC only: Returns true if the problem is ready to evaluate.
 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)
          Gracefully close contacts with the slaves
 void describe(Individual ind, EvolutionState state, int threadnum, int log, int verbosity)
           
 void describe(Individual ind, EvolutionState state, int subpopulation, int threadnum, int log, int verbosity)
          "Reevaluates" an individual, for the purpose of printing out interesting facts about the individual in the context of the Problem, and logs the results.
protected  void doReadObject(java.io.ObjectInputStream in)
          Custom serialization
protected  void doWriteObject(java.io.ObjectOutputStream out)
          Custom serialization
 void evaluate(EvolutionState state, Individual[] ind, boolean[] updateFitness, boolean countVictoriesOnly, int threadnum)
           
 void evaluate(EvolutionState state, Individual[] inds, boolean[] updateFitness, boolean countVictoriesOnly, int[] subpops, int threadnum)
          Evaluates the individuals found in ind together.
 void evaluate(EvolutionState state, Individual ind, int subpopulation, int threadnum)
          Evaluates the individual in ind, if necessary (perhaps not evaluating them if their evaluated flags are true), and sets their fitness appropriately.
 boolean evaluatedIndividualAvailable()
          This will only return true if (1) the EvolutionState is a SteadyStateEvolutionState and (2) an individual has returned from the system.
 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 flush(EvolutionState state, int threadnum)
           
 int getJobSize()
           
 Individual getNextEvaluatedIndividual(EvolutionState state)
          This method blocks until an individual is available from the slaves (which will cause evaluatedIndividualAvailable() to return true), at which time it returns the individual.
 void initializeContacts(EvolutionState state)
          Initialize contacts with the slaves
 void postprocessPopulation(EvolutionState state, Population pop)
          Finish processing the population (such as fitness information) after evaluation.
 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 preprocessPopulation(EvolutionState state, Population pop)
          Set up the population pop (such as fitness information) prior to evaluation.
 void reinitializeContacts(EvolutionState state)
          Reinitialize contacts with the slaves
 void setJobSize(int newJobSize)
          Sets number of individuals sent to each slave task.
 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 ec.Problem
defaultBase, evaluate, getBase, setBase
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ec.simple.SimpleProblemForm
evaluate
 

Field Detail

P_DEBUG_INFO

public static final java.lang.String P_DEBUG_INFO
See Also:
Constant Field Values

P_JOB_SIZE

public static final java.lang.String P_JOB_SIZE
See Also:
Constant Field Values

log

protected static final org.apache.commons.logging.Log log

problem

public Problem problem

server

public IMasterProblemServer server

serverThread

public java.lang.Thread serverThread

batchMode

public boolean batchMode
Constructor Detail

MasterProblem

public MasterProblem()
Method Detail

setJobSize

public void setJobSize(int newJobSize)
Sets number of individuals sent to each slave task. Override in subclasses that need to reconfigure slaves when this parameter changes.

Parameters:
newJobSize -

getJobSize

public int getJobSize()

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.

Typically this should be a full "deep" clone. However, you may share certain elements with other objects rather than clone hem, depending on the situation:

Implementations.

Specified by:
clone in interface Prototype
Overrides:
clone in class Problem

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
Specified by:
setup in interface Setup
Overrides:
setup in class Problem

prepareToEvaluate

public void prepareToEvaluate(EvolutionState state,
                              int threadnum)
Description copied from class: Problem
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. Note that prepareToEvaluate() can be called *multiple times* prior to finishEvaluating() being called -- in this case, the subsequent calls may be ignored.

Overrides:
prepareToEvaluate in class Problem

finishEvaluating

public void finishEvaluating(EvolutionState state,
                             int threadnum)
Description copied from class: Problem
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.

Overrides:
finishEvaluating in class Problem

evaluate

public void evaluate(EvolutionState state,
                     Individual ind,
                     int subpopulation,
                     int threadnum)
Description copied from interface: SimpleProblemForm
Evaluates the individual in ind, if necessary (perhaps not evaluating them if their evaluated flags are true), and sets their fitness appropriately.

Specified by:
evaluate in interface SimpleProblemForm
Overrides:
evaluate in class Problem

flush

public void flush(EvolutionState state,
                  int threadnum)

describe

public void describe(Individual ind,
                     EvolutionState state,
                     int threadnum,
                     int log,
                     int verbosity)
Specified by:
describe in interface SimpleProblemForm
Overrides:
describe in class Problem

evaluate

public void evaluate(EvolutionState state,
                     Individual[] ind,
                     boolean[] updateFitness,
                     boolean countVictoriesOnly,
                     int threadnum)
Specified by:
evaluate in interface GroupedProblemForm

describe

public void describe(Individual ind,
                     EvolutionState state,
                     int subpopulation,
                     int threadnum,
                     int log,
                     int verbosity)
Description copied from interface: SimpleProblemForm
"Reevaluates" an individual, for the purpose of printing out interesting facts about the individual in the context of the Problem, and logs the results. This might be called to print out facts about the best individual in the population, for example.

Specified by:
describe in interface SimpleProblemForm
Overrides:
describe in class Problem

preprocessPopulation

public void preprocessPopulation(EvolutionState state,
                                 Population pop)
Description copied from interface: GroupedProblemForm
Set up the population pop (such as fitness information) prior to evaluation. Although this method is not static, you should not use it to write to any instance variables in the GroupedProblem instance; this is because it's possible that the instance used is in fact the prototype, and you will have no guarantees that your instance variables will remain valid during the evaluate(...) process. Do not assume that pop will be the same as state.pop -- it may not. state is only provided to give you access to EvolutionState features.

Specified by:
preprocessPopulation in interface GroupedProblemForm

postprocessPopulation

public void postprocessPopulation(EvolutionState state,
                                  Population pop)
Description copied from interface: GroupedProblemForm
Finish processing the population (such as fitness information) after evaluation. Although this method is not static, you should not use it to write to any instance variables in the GroupedProblem instance; this is because it's possible that the instance used is in fact the prototype, and you will have no guarantees that your instance variables will remain valid during the evaluate(...) process. Do not assume that pop will be the same as state.pop -- it may not. state is only provided to give you access to EvolutionState features.

Specified by:
postprocessPopulation in interface GroupedProblemForm

evaluate

public void evaluate(EvolutionState state,
                     Individual[] inds,
                     boolean[] updateFitness,
                     boolean countVictoriesOnly,
                     int[] subpops,
                     int threadnum)
Description copied from interface: GroupedProblemForm
Evaluates the individuals found in ind together. If updateFitness[i] is true, then you should use this evaluation to update the fitness of the individual in ind[i]. Individuals which are updated should have their fitnesses modified so that immediately after evaluation (and prior to postprocessPopulation(...) being called) individuals' fitnesses can be checked to see which is better than which. Do not assume that the individuals in ind will actually be in state.pop (they may not -- this method may be called at the end of a run to determine the best individual of the run in some kind of contest).

If countVictoriesOnly is true, you should update fitnesses such that if two individuals' fitnesses are compared, the one which has won the most times has a superior fitness. This will be used in single elimination tournament style evaluators.

Specified by:
evaluate in interface GroupedProblemForm

doWriteObject

protected void doWriteObject(java.io.ObjectOutputStream out)
                      throws java.io.IOException
Custom serialization

Throws:
java.io.IOException

doReadObject

protected void doReadObject(java.io.ObjectInputStream in)
                     throws java.io.IOException,
                            java.lang.ClassNotFoundException
Custom serialization

Throws:
java.io.IOException
java.lang.ClassNotFoundException

initializeContacts

public void initializeContacts(EvolutionState state)
Initialize contacts with the slaves

Overrides:
initializeContacts in class Problem

reinitializeContacts

public void reinitializeContacts(EvolutionState state)
Reinitialize contacts with the slaves

Overrides:
reinitializeContacts in class Problem

closeContacts

public void closeContacts(EvolutionState state,
                          int result)
Gracefully close contacts with the slaves

Overrides:
closeContacts in class Problem

canEvaluate

public boolean canEvaluate()
Description copied from class: Problem
Asynchronous Steady-State EC only: Returns true if the problem is ready to evaluate. In most cases, the default is true.

Specified by:
canEvaluate in interface SimpleProblemForm
Overrides:
canEvaluate in class Problem

evaluatedIndividualAvailable

public boolean evaluatedIndividualAvailable()
This will only return true if (1) the EvolutionState is a SteadyStateEvolutionState and (2) an individual has returned from the system. If you're not doing steady state evolution, you should not call this method.


getNextEvaluatedIndividual

public Individual getNextEvaluatedIndividual(EvolutionState state)
This method blocks until an individual is available from the slaves (which will cause evaluatedIndividualAvailable() to return true), at which time it returns the individual. You should only call this method if you're doing steady state evolution -- otherwise, the method will block forever.