|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectec.Problem
ec.eval.MasterProblem
public class MasterProblem
MasterProblem.java
The MasterProblem is a special ECJ problem that performs evaluations by sending them to a remote Slave process to be evaluated. As it implements both the SimpleProblemForm and the GroupedProblemForm interfaces, the MasterProblem can perform both traditional EC evaluations as well as coevolutionary evaluations.
When a MasterProblem is specified by the Evaluator, the Problem is set up as usual, but then the MasterProblem replaces it. The Problem is not garbage collected -- instead, it's hung off the MasterProblem's problem variable. In some sense the Problem is "pushed aside".
If the Evaluator begins by calling prepareToEvaluate(), and we're not doing coevolution, then the MasterProblem does not evaluate individuals immediately. Instead, it waits for at most jobSize individuals be submitted via evaluate(), and then sends them all off in a group, called a job, to the remote slave. In other situations (coevolution, or no prepareToEvaluate()) the MasterProblem sends off individuals immediately.
It may be the case that no Slave has space in its queue to accept a new job containing, among others, your new individual. In this case, calling evaluate() will block until one comes available. You can avoid this by testing for availability first by calling canEvaluate(). Note that canEvaluate() and evaluate() together are not atomic and so you should not rely on this facility if your system uses multiple threads.
When the individuals or their fitnesses return, they are immediately updated in place. You have three options to wait for them:
You can wait for all the individuals to finish evaluation by calling finishEvaluating(). If you call this method before a job is entirely filled, it will be sent in truncated format (which generally is perfectly fine). You then block until all the jobs have been completed and the individuals updated.
You can block until at least one individual is available, by calling getNextEvaluatedIndividual(), which blocks and then returns the individual that was just completed.
You can test in non-blocking fashion to see if an individual is available, by calling evaluatedIndividualAvailable(). If this returns true, you may then call getNextEvaluatedIndividual() to get the individual. Note that this isn't atomic, so don't use it if you have multiple threads.
Parameters
base.debug-info boolean |
(whether the system should display information useful for debugging purposes) |
base.job-size integer > 0 |
(how large should a job be at most?) |
eval.master.port int |
(the port where the slaves will connect) |
eval.compression boolean |
(whether the communication with the slaves should be compressed or not) |
eval.masterproblem.max-jobs-per-slave int |
(the maximum load (number of jobs) per slave at any point in time) |
Field Summary | |
---|---|
boolean |
batchMode
|
SlaveMonitor |
monitor
|
static java.lang.String |
P_DEBUG_INFO
|
static java.lang.String |
P_JOB_SIZE
|
Problem |
problem
|
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 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. |
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. |
QueueIndividual |
getNextEvaluatedIndividual()
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 |
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 |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String P_DEBUG_INFO
public static final java.lang.String P_JOB_SIZE
public Problem problem
public boolean batchMode
public SlaveMonitor monitor
Constructor Detail |
---|
public MasterProblem()
Method Detail |
---|
public java.lang.Object clone()
Prototype
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.
public Object clone()
{
try
{
return super.clone();
}
catch ((CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
}
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;
}
public Object clone()
{
MyObject myobj = (MyObject) (super.clone());
// put your deep-cloning code here...
return myobj;
}
clone
in interface Prototype
clone
in class Problem
public void setup(EvolutionState state, Parameter base)
Prototype
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.
setup
in interface Prototype
setup
in interface Setup
setup
in class Problem
public void prepareToEvaluate(EvolutionState state, int threadnum)
Problem
prepareToEvaluate
in class Problem
public void finishEvaluating(EvolutionState state, int threadnum)
Problem
finishEvaluating
in class Problem
public void evaluate(EvolutionState state, Individual ind, int subpopulation, int threadnum)
SimpleProblemForm
evaluate
in interface SimpleProblemForm
public void describe(Individual ind, EvolutionState state, int subpopulation, int threadnum, int log, int verbosity)
SimpleProblemForm
describe
in interface SimpleProblemForm
public void preprocessPopulation(EvolutionState state, Population pop)
GroupedProblemForm
preprocessPopulation
in interface GroupedProblemForm
public void postprocessPopulation(EvolutionState state, Population pop)
GroupedProblemForm
postprocessPopulation
in interface GroupedProblemForm
public void evaluate(EvolutionState state, Individual[] inds, boolean[] updateFitness, boolean countVictoriesOnly, int[] subpops, int threadnum)
GroupedProblemForm
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.
evaluate
in interface GroupedProblemForm
public void initializeContacts(EvolutionState state)
initializeContacts
in class Problem
public void reinitializeContacts(EvolutionState state)
reinitializeContacts
in class Problem
public void closeContacts(EvolutionState state, int result)
closeContacts
in class Problem
public boolean canEvaluate()
Problem
canEvaluate
in class Problem
public boolean evaluatedIndividualAvailable()
public QueueIndividual getNextEvaluatedIndividual()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |