|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Observable
es.udc.gii.common.eaf.algorithm.parallel.evaluation.DistributedEvaluation
public class DistributedEvaluation
This clas is a evaluation strategy for a distributed environment.
An instance of this class has an instance of the EvaluationTopology
class
which is in charge of the underlying communications between master and slaves.
It also has an instance of a implementation of SerialEvaluationStrategy
which
asumes the real evaluation of the individuals.
Both masters and slaves perfom evaluation of individuals. That is, the master scatters the individuals and elavuates some individuals. The slaves perfom only evaluations.
Each master has two threads. One thread is responsible for evaluating a chunk of the population and the other thread exchanges chunks of individuals between the master and the slaves. When the evaluation thread has evaluated a chunk of individuals it tries to get another chunk and repeats its procedure. When a slave has finished evaluating a received chunk, it sends the chunk back to the master and waits for another. As soon as the master receives the evaluated chunk within its communication thread, this thread sends another free chunk to the slave who is waiting. The process goes on until no more individuals remain to be evaluated.
The master stops its execution when no more individuals are pending for evaluation,
but the slaves wait until the finish()
method is called by the master. Be sure to
call this method in order to terminate the whole process appropiately in your algorithm.
Nested Class Summary | |
---|---|
private class |
DistributedEvaluation.CommunicationThread
|
class |
DistributedEvaluation.DistributedEvaluationStatistics
|
Field Summary | |
---|---|
private java.util.concurrent.CyclicBarrier |
barrier
Barrier for synchronizing the threads. |
private int[] |
chunkIndex
Stores the first index of a chunk for each process. |
private int |
chunkSize
The maximum amount of individuals sent each time to a node for evaluating them. |
private boolean |
collectStatistics
true if statistics about the evaluations should be collected. |
private boolean |
commThreadMustWait
|
private java.lang.Thread |
communicationThread
The communication thread. |
private FitnessComparator |
comparator
|
private java.util.List<Constraint> |
constraints
the problem's constraints. |
static int |
CURRENT_EVALUATION_ENDED
|
static int |
CURRENT_EVALUATION_NOT_STARTED
|
static int |
CURRENT_EVALUATION_STARTED
|
static int |
EVALUATED
|
private int |
evaluatedIndividuals
Number of evaluated individuals so far. |
static int |
EVALUATION_NOT_INITIALIZED
|
private SerialEvaluationStrategy |
evaluationStrategy
Evaluation strategy that is in charge for the real evaluation of the individuals. |
protected boolean |
finished
true if the evaluation process is finished. |
private int |
firtstInd
Pointer to the first not evaluated individual. |
private java.util.List<ObjectiveFunction> |
functions
The problem's objective functions. |
private java.util.List<Individual> |
individualsToEvaluate
The individuals to be evaluated. |
private static int |
NO_CHUNK
Special value for process with no chunk in chunkIndex . |
private int |
popSize
The amount of individuals for evaluation. |
static int |
RECEIVED
|
static int |
SENT
|
private int |
state
|
private DistributedEvaluation.DistributedEvaluationStatistics |
statistics
Some statistics: eval time, idle time, total evals, etc. |
static int |
TO_EVALUATE
|
private EvaluationTopology |
topology
The master-slave topology defining the communication functions between master and slaves. |
Constructor Summary | |
---|---|
DistributedEvaluation()
Creates a new instance of DistributedEvaluation |
|
DistributedEvaluation(SerialEvaluationStrategy evaluationStrategy,
EvaluationTopology topology,
int chunkSize)
Creates a new instance of DistributedEvaluation. |
Method Summary | |
---|---|
void |
configure(org.apache.commons.configuration.Configuration conf)
Configures this class. |
void |
evaluate(Individual individual,
java.util.List<ObjectiveFunction> functions,
java.util.List<Constraint> constraints)
Evaluates an individual. |
void |
evaluate(java.util.List<Individual> individuals,
java.util.List<ObjectiveFunction> functions,
java.util.List<Constraint> constraints)
Evaluates a list of individiduals. |
private void |
evaluationThread()
|
void |
finish()
|
private java.util.List<Individual> |
getChunk(int forRank)
Retrives a chunk from the not evaluated part of the individual's list. |
int |
getChunkSize()
|
FitnessComparator |
getComparator()
|
SerialEvaluationStrategy |
getEvaluationStrategy()
|
java.util.List<Individual> |
getIndividualsToEvaluate()
|
int |
getState()
|
DistributedEvaluation.DistributedEvaluationStatistics |
getStatistics()
|
EvaluationTopology |
getTopology()
|
boolean |
isCollectStatistics()
|
boolean |
isFinished()
|
boolean |
isMaster()
|
protected void |
master(java.util.List<Individual> individuals,
java.util.List<ObjectiveFunction> functions,
java.util.List<Constraint> constraints)
|
void |
notifyObservers(int state,
java.lang.Object arg)
|
void |
reset()
Resets this object. |
private void |
setChunk(int fromRank,
java.util.List<Individual> evaluated)
Sets an evaluated chunk in the place where it belongs within the individuals list. |
void |
setChunkSize(int chunkSize)
|
void |
setCollectStatistics(boolean collectStatistics)
|
void |
setComparator(FitnessComparator comparator)
|
void |
setEvaluationStrategy(SerialEvaluationStrategy evaluationStrategy)
|
protected void |
setState(int state)
|
void |
setTopology(EvaluationTopology topology)
|
protected void |
slave(java.util.List<ObjectiveFunction> functions,
java.util.List<Constraint> constraints)
|
private void |
updateComparator(EvaluationObject eo)
|
Methods inherited from class java.util.Observable |
---|
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SENT
public static final int RECEIVED
public static final int TO_EVALUATE
public static final int EVALUATED
public static final int CURRENT_EVALUATION_ENDED
public static final int CURRENT_EVALUATION_NOT_STARTED
public static final int CURRENT_EVALUATION_STARTED
public static final int EVALUATION_NOT_INITIALIZED
private int state
private FitnessComparator comparator
private SerialEvaluationStrategy evaluationStrategy
private EvaluationTopology topology
protected boolean finished
true
if the evaluation process is finished.
private int chunkSize
private java.util.List<ObjectiveFunction> functions
private java.util.List<Constraint> constraints
private int popSize
private java.util.concurrent.CyclicBarrier barrier
private boolean collectStatistics
true
if statistics about the evaluations should be collected.
private DistributedEvaluation.DistributedEvaluationStatistics statistics
private int[] chunkIndex
private java.util.List<Individual> individualsToEvaluate
private int firtstInd
private static final int NO_CHUNK
chunkIndex
.
private int evaluatedIndividuals
private transient java.lang.Thread communicationThread
private transient boolean commThreadMustWait
Constructor Detail |
---|
public DistributedEvaluation()
public DistributedEvaluation(SerialEvaluationStrategy evaluationStrategy, EvaluationTopology topology, int chunkSize)
The argument chunkSize
is the amount of individuals sent each
time to a node for evaluating them. If is set to 0, then a chunk is choosen so that:
let S be the size of the population to be evaluated, let n be the number
of proceses (master and slaves), then the chunk size will be S/n
(integer division).
For instance: if there are a master, two slaves and chunkSize
is 2, then the master tries to retain the first 2 individuals, tries to send the next 2
to the first slave and the next 2 to the second slave. After that, two threads
of execution exist in the master: one for evaluating and one for comunication.
The evaluation thread tries to get new chunks and evaluates them until no more chunk can be retrived. The comunication thread listens for messages from slaves and sends them new chunks when slaves are ready until no more chunk might be retrived. There's no way to control which thread runs, the s.o. is responsible for doing that, and they interleave with each other.
Method Detail |
---|
public void notifyObservers(int state, java.lang.Object arg)
private void evaluationThread()
private java.util.List<Individual> getChunk(int forRank)
forRank
- - rank of the process which is going to evaluate the chunk.
private void setChunk(int fromRank, java.util.List<Individual> evaluated)
fromRank
- - rank of the process who has evaluated the chunkevaluated
- - the evaluated individualsprotected void master(java.util.List<Individual> individuals, java.util.List<ObjectiveFunction> functions, java.util.List<Constraint> constraints)
private void updateComparator(EvaluationObject eo)
protected void slave(java.util.List<ObjectiveFunction> functions, java.util.List<Constraint> constraints)
public void finish()
public void configure(org.apache.commons.configuration.Configuration conf)
Configuration example:
... <EvaluationStrategy> <Class>es.udc.gii.common.eaf.algorithm.parallel.evaluation.DistributedEvaluation<Class> <ChunkSize>3</ChunkSize> <Races>2</Races> <CollectStatistics/> </EvaluationStrategy> ...
This configures a master-slave model with 2 masters (races). The master
sends 3 individuals each time a slave asks for individuals (chunk size).
Statistics about the whole process are collected (CollectStatistics
).
If ChunkSize
is set to 0, then a chunk is choosen so that:
let S be the size of the population to be evaluated, let n be the number
of proceses (master and slaves), then the chunk size will be S/n
(integer division).
configure
in interface Configurable
conf
- Configuration.public void evaluate(java.util.List<Individual> individuals, java.util.List<ObjectiveFunction> functions, java.util.List<Constraint> constraints)
evaluate
in interface EvaluationStrategy
individuals
- A list of individuals to be evaluated by the list of
objective functions.functions
- An objective functions' list with wich we will evaluate
the individuals' list.constraints
- A list of constraints with wich we will evaluate the
individuals list.public void evaluate(Individual individual, java.util.List<ObjectiveFunction> functions, java.util.List<Constraint> constraints)
evaluate
in interface EvaluationStrategy
individual
- An individual to be evaluated by the list of
objective functions.functions
- An objective functions' list with wich we will evaluate
the individual.constraints
- A list of constraints with wich we will evaluate the
individual.public void reset()
public int getChunkSize()
public void setChunkSize(int chunkSize)
public EvaluationTopology getTopology()
public void setTopology(EvaluationTopology topology)
public SerialEvaluationStrategy getEvaluationStrategy()
public void setEvaluationStrategy(SerialEvaluationStrategy evaluationStrategy)
public boolean isMaster()
public boolean isFinished()
public int getState()
protected void setState(int state)
public FitnessComparator getComparator()
public void setComparator(FitnessComparator comparator)
public boolean isCollectStatistics()
public void setCollectStatistics(boolean collectStatistics)
public DistributedEvaluation.DistributedEvaluationStatistics getStatistics()
public java.util.List<Individual> getIndividualsToEvaluate()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |