es.udc.gii.common.eaf.algorithm.parallel.operator
Class MasterSlaveEvaluationOperator

java.lang.Object
  extended by java.util.Observable
      extended by es.udc.gii.common.eaf.algorithm.operator.evaluate.EvaluationOperator
          extended by es.udc.gii.common.eaf.algorithm.parallel.operator.MasterSlaveEvaluationOperator
All Implemented Interfaces:
Operator, Configurable

public abstract class MasterSlaveEvaluationOperator
extends EvaluationOperator

Author:
rafa

Nested Class Summary
private  class MasterSlaveEvaluationOperator.CommunicationThread
           
 
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
           
private  boolean commThreadMustWait
           
private  java.lang.Thread communicationThread
          The communication thread.
protected  boolean finished
           
private  int firtstInd
          Pointer to the first not operated individual.
private  java.util.List<Individual> individualsToOperate
          The individuals to be operated.
private static int NO_CHUNK
          Special value for process with no chunk in chunkIndex.
private  int operatedIndividuals
          Number of operated individuals so far.
private  EvaluationOperator operator
           
private  int popSize
          The amount of individuals for the operation.
private  MSTopology topology
           
 
Constructor Summary
MasterSlaveEvaluationOperator()
           
MasterSlaveEvaluationOperator(EvaluationOperator operator, int chunkSize)
           
 
Method Summary
 void configure(org.apache.commons.configuration.Configuration conf)
           
 void finish()
           
private  java.util.List<Individual> getChunk(int forRank)
          Retrives a chunk from the not operated part of the individual's list.
 int getChunkSize()
           
 java.util.List<Individual> getIndividualsToEvaluate()
           
 EvaluationOperator getOperator()
           
 MSTopology getTopology()
           
 boolean isFinished()
           
 boolean isMaster()
           
protected  void master(EvolutionaryAlgorithm alg, java.util.List<Individual> individuals)
           
 java.util.List<Individual> operate(EvolutionaryAlgorithm alg, java.util.List<Individual> individuals)
          Evaluates a list of individiduals.
private  void operationThread(EvolutionaryAlgorithm alg)
           
 void reset()
          Resets this object.
private  void setChunk(int fromRank, java.util.List<Individual> operated)
          Sets an operated chunk in the place where it belongs within the individuals list.
 void setChunkSize(int chunkSize)
           
 void setOperator(EvaluationOperator operator)
           
 void setTopology(MSTopology topology)
           
protected  void slave(EvolutionaryAlgorithm alg)
           
 
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

operator

private EvaluationOperator operator

topology

private MSTopology topology

chunkSize

private int chunkSize

popSize

private int popSize
The amount of individuals for the operation.


barrier

private java.util.concurrent.CyclicBarrier barrier
Barrier for synchronizing the threads.


chunkIndex

private int[] chunkIndex
Stores the first index of a chunk for each process.


individualsToOperate

private java.util.List<Individual> individualsToOperate
The individuals to be operated.


firtstInd

private int firtstInd
Pointer to the first not operated individual.


NO_CHUNK

private static final int NO_CHUNK
Special value for process with no chunk in chunkIndex.

See Also:
Constant Field Values

operatedIndividuals

private int operatedIndividuals
Number of operated individuals so far.


communicationThread

private transient java.lang.Thread communicationThread
The communication thread.


commThreadMustWait

private transient boolean commThreadMustWait

finished

protected boolean finished
Constructor Detail

MasterSlaveEvaluationOperator

public MasterSlaveEvaluationOperator(EvaluationOperator operator,
                                     int chunkSize)

MasterSlaveEvaluationOperator

public MasterSlaveEvaluationOperator()
Method Detail

operationThread

private void operationThread(EvolutionaryAlgorithm alg)

getChunk

private java.util.List<Individual> getChunk(int forRank)
Retrives a chunk from the not operated part of the individual's list.

Parameters:
forRank - - rank of the process which is going to evaluate the chunk.
Returns:
An empty list if there is no more individual to evaluate or a list with individuals not operated yet. The size of the list is less or equal the chunk size.

setChunk

private void setChunk(int fromRank,
                      java.util.List<Individual> operated)
Sets an operated chunk in the place where it belongs within the individuals list.

Parameters:
fromRank - - rank of the process who has operated the chunk
operated - - the operated individuals

master

protected void master(EvolutionaryAlgorithm alg,
                      java.util.List<Individual> individuals)

slave

protected void slave(EvolutionaryAlgorithm alg)

finish

public void finish()

operate

public java.util.List<Individual> operate(EvolutionaryAlgorithm alg,
                                          java.util.List<Individual> individuals)
Evaluates a list of individiduals.

Parameters:
alg - the current algorithm, to visit when it is necessary.
individuals - list of individuals on wich we will apply the operator.
Returns:
the result of apply this operator to a individuals' lisr.

reset

public void reset()
Resets this object. After doing this, this object can be used again in a new evaluation process.


getChunkSize

public int getChunkSize()

setChunkSize

public void setChunkSize(int chunkSize)

isMaster

public boolean isMaster()

isFinished

public boolean isFinished()

getIndividualsToEvaluate

public java.util.List<Individual> getIndividualsToEvaluate()

getOperator

public EvaluationOperator getOperator()

setOperator

public void setOperator(EvaluationOperator operator)

getTopology

public MSTopology getTopology()

setTopology

public void setTopology(MSTopology topology)

configure

public void configure(org.apache.commons.configuration.Configuration conf)
Specified by:
configure in interface Configurable
Overrides:
configure in class EvaluationOperator