Class GEProblem
- All Implemented Interfaces:
GroupedProblemForm,Prototype,Setup,SimpleProblemForm,Serializable,Cloneable
The procedure is as follows. Let's say your GPProblem is the Artificial Ant problem. Instead of saying...
eval.problem = ec.app.ant.Ant
eval.problem = ec.app.ant.Ant
eval.problem.data = ec.app.ant.AntData
eval.problem.moves = 400
eval.problem.file = santafe.trl
... you instead make your problem a GEProblem like this:
eval.problem = ec.gp.ge.GEProblem
... and then you hang the Ant problem, and all its subsidiary data, as the 'problem' parameter from the GEProblem like so:
eval.problem.problem = ec.app.ant.Ant
eval.problem.problem.data = ec.app.ant.AntData
eval.problem.problem.moves = 400
eval.problem.problem.file = santafe.trl
Everything else should be handled for you. GEProblem is also compatible with the MasterProblem procedure for distributed evaluation, and is also both a SimpleProblemForm and a GroupedProblemForm. We've got you covered.
Parameters
| base.problem classname, inherits from GPProblem |
(The GPProblem which actually performs the evaluation of the mapped GPIndividual) |
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAsynchronous Steady-State EC only: Returns true if the problem is ready to evaluate.clone()Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.voidcloseContacts(EvolutionState state, int result) Called to shut down remote evaluation network contacts when the run is completed.voiddescribe(EvolutionState state, Individual ind, int subpopulation, int threadnum, int log) Part of SimpleProblemForm.voidevaluate(EvolutionState state, Individual[] ind, boolean[] updateFitness, boolean countVictoriesOnly, int[] subpops, int threadnum) Default version assumes that every individual is a GEIndividual.voidevaluate(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.voidfinishEvaluating(EvolutionState state, int threadnum) Will be called by the Evaluator after prepareToEvaluate(...) is called and then a series of individuals are evaluated.voidinitializeContacts(EvolutionState state) Called to set up remote evaluation network contacts when the run is started.booleanReturns true if this method is meant to be a grouped problem.intpostprocessPopulation(EvolutionState state, Population pop, boolean[] assessFitness, boolean countVictoriesOnly) Finish processing the population (such as fitness information) after evaluation.voidprepareToEvaluate(EvolutionState state, int threadnum) May be called by the Evaluator prior to a series of individuals to evaluate, and then ended with a finishEvaluating(...).voidpreprocessPopulation(EvolutionState state, Population pop, boolean[] prepareForFitnessAssessment, boolean countVictoriesOnly) Set up the population pop (such as fitness information) prior to evaluation.voidCalled to reinitialize remote evaluation network contacts when the run is restarted from checkpoint.voidsetup(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, describe, receiveAdditionalData, sendAdditionalData, transferAdditionalData
-
Field Details
-
P_PROBLEM
- See Also:
-
problem
-
-
Constructor Details
-
GEProblem
public GEProblem()
-
-
Method Details
-
setup
Description copied from interface:PrototypeSets 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.
-
clone
Description copied from interface:PrototypeCreates 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:
- If you hold objects which are shared with other instances, don't clone them.
- If you hold objects which must be unique, clone them.
- If you hold objects which were given to you as a gesture of kindness, and aren't owned by you, you probably shouldn't clone them.
- DON'T attempt to clone: Singletons, Cliques, or Populations, or Subpopulation.
- Arrays are not cloned automatically; you may need to clone an array if you're not sharing it with other instances. Arrays have the nice feature of being copyable by calling clone() on them.
Implementations.
- If no ancestor of yours implements clone(), and you have no need to do clone deeply, and you are abstract, then you should not declare clone().
- If no ancestor of yours implements clone(),
and you have no need to do clone deeply,
and you are not abstract, then you should implement
it as follows:
public Object clone() { try { return super.clone(); } catch ((CloneNotSupportedException e) { throw new InternalError(); } // never happens } - If no ancestor of yours implements clone(), but you
need to deep-clone some things, then you should implement it
as follows:
public Object clone() { try { MyObject myobj = (MyObject) (super.clone()); // put your deep-cloning code here... } catch ((CloneNotSupportedException e) { throw new InternalError(); } // never happens return myobj; } - If an ancestor has implemented clone(), and you also need
to deep clone some things, then you should implement it as follows:
public Object clone() { MyObject myobj = (MyObject) (super.clone()); // put your deep-cloning code here... return myobj; }
-
prepareToEvaluate
Description copied from class:ProblemMay 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:
prepareToEvaluatein classProblem
-
finishEvaluating
Description copied from class:ProblemWill 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:
finishEvaluatingin classProblem
-
initializeContacts
Description copied from class:ProblemCalled to set up remote evaluation network contacts when the run is started. By default does nothing.- Overrides:
initializeContactsin classProblem
-
reinitializeContacts
Description copied from class:ProblemCalled to reinitialize remote evaluation network contacts when the run is restarted from checkpoint. By default does nothing.- Overrides:
reinitializeContactsin classProblem
-
closeContacts
Description copied from class:ProblemCalled to shut down remote evaluation network contacts when the run is completed. By default does nothing.- Overrides:
closeContactsin classProblem
-
canEvaluate
public boolean canEvaluate()Description copied from class:ProblemAsynchronous Steady-State EC only: Returns true if the problem is ready to evaluate. In most cases, the default is true.- Overrides:
canEvaluatein classProblem
-
preprocessPopulation
public void preprocessPopulation(EvolutionState state, Population pop, boolean[] prepareForFitnessAssessment, boolean countVictoriesOnly) Description copied from interface:GroupedProblemFormSet 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. Typically you'd use this method to set the Fitness values of all Individuals to 0.countVictoriesOnly will be set if Individuals' fitness is to be based on whether they're the winner of a test, instead of based on the specifics of the scores in the tests. This really only happens for Single-Elimination Tournament one-population competitive coevolution.
prepareForFitnessAssessment will indicate which subpopulations will have their fitness values updated this time around, during postprocessPopulation. It may not be the same as updateFitness[] in evaluate(...).
If you are basing fitness on trials, this method should create the initial trials if the prepareForFitnessAssessment[...] is true for that subpopulation.
- Specified by:
preprocessPopulationin interfaceGroupedProblemForm
-
postprocessPopulation
public int postprocessPopulation(EvolutionState state, Population pop, boolean[] assessFitness, boolean countVictoriesOnly) Description copied from interface:GroupedProblemFormFinish 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.countVictoriesOnly will be set if Individuals' fitness is to be based on whether they're the winner of a test, instead of based on the specifics of the scores in the tests. This really only happens for Single-Elimination Tournament one-population competitive coevolution. If this is set, probably would leave the Fitnesses as they are here (they've been set and incremented in evaluate(...)), but if it's not set, you may want to set the Fitnesses to the maximum or average or the various trials performed.
assessFitness will indicate which subpopulations should have their final fitness values assessed. You should not clear the trials of individuals for which assessFitness[] is false. Instead allow trials to accumulate and ultimately update the fitnesses later when the flag is set. assessFitness[] may not be the same as updateFitness[] in evaluate(...).
Should return the number of individuals evaluated (not tested: but actually had their fitnesses modified -- or would have if the evaluated flag wasn't set).
- Specified by:
postprocessPopulationin interfaceGroupedProblemForm
-
evaluate
public void evaluate(EvolutionState state, Individual[] ind, boolean[] updateFitness, boolean countVictoriesOnly, int[] subpops, int threadnum) Default version assumes that every individual is a GEIndividual. The underlying problem.evaluate() must be prepared for the possibility that some GPIndividuals handed it are in fact null, meaning that they couldn't be extracted from the GEIndividual string. You should assign them bad fitness in some appropriate way.- Specified by:
evaluatein interfaceGroupedProblemForm
-
evaluate
Description copied from interface:SimpleProblemFormEvaluates the individual in ind, if necessary (perhaps not evaluating them if their evaluated flags are true), and sets their fitness appropriately.- Specified by:
evaluatein interfaceSimpleProblemForm
-
describe
public void describe(EvolutionState state, Individual ind, int subpopulation, int threadnum, int log) Description copied from class:ProblemPart of SimpleProblemForm. Included here so you don't have to write the default version, which usually does nothing.- Specified by:
describein interfaceSimpleProblemForm- Overrides:
describein classProblem
-
isGroupedProblem
public boolean isGroupedProblem()Description copied from class:ProblemReturns true if this method is meant to be a grouped problem. You should not override this method: by default it simply returns (this instanceof GroupedProblemForm), but some wrapper problems override it to query their underlying Problems. The purpose of this method is to enable objects to dynamically indicate that they support GroupedProblemForm (perhaps they are a wrapper object around an underlying object which might or might not support it).- Overrides:
isGroupedProblemin classProblem
-