es.udc.gii.common.eaf.algorithm.operator.replace.mmga
Class Hypercube

java.lang.Object
  extended by es.udc.gii.common.eaf.algorithm.operator.replace.mmga.Hypercube

public class Hypercube
extends java.lang.Object

This class represents a hypercube with individuals inside. Each individual is stored in a single cell.

Author:
Rafael Tedin Alvarez

Nested Class Summary
 class Hypercube.Cell
          This class represents a cell of a hypercube.
 
Field Summary
private  java.util.Map<java.lang.Long,Hypercube.Cell> crowdedCells
          Maps cell numbers to cells.
private  boolean dirty
          If the hypercube is modified without updating it, dirty is set to true.
private  double[] divisionSize
          Size of a division in each dimension.
private  java.util.Map<Individual,Hypercube.Cell> individualCellMapping
          Maps an individual to the cell where it belongs.
private  java.util.List<Individual> individuals
          Contains all the individuals in the hypercube.
private  int numberOfDimensions
          Number of dimensions of the hypercube.
private  int numberOfDivisionsPerDimension
          Number of divisions into which we divide each dimension.
private  double[] origin
          Represents the origin of the hypercube.
 
Constructor Summary
Hypercube(java.util.List<Individual> individuals, int numberOfDimensions, int numberOfDivisionsPerDimension)
          Class constructor.
 
Method Summary
 void addAllIndividuals(java.util.List<Individual> toAdd)
          Adds individuals to the hypercube.
 void addIndividual(Individual individual)
          Adds a new individual to the hypercube.
 Hypercube.Cell findCell(Individual individual)
          Finds the cell of an individual.
private  java.lang.Long getCellNumber(Individual individual)
          Returns the cell number of the cell to wich a individual belongs.
 java.util.List<Hypercube.Cell> getCrowdedCells()
          Returns the cells that have at least one individual.
 java.util.List<Individual> getIndividuals()
          Returns all individuals from the hypercube.
 Hypercube.Cell getMostCrowdedCell()
          Returns one cell among those which are most populated.
private  double getObjectiveValue(Individual individual, int dimension)
          Returns the objective value of an individual on a dimension.
 int getSize()
          Returns the number of individuals in the hypercube.
private  void initializeHypercube()
          Initializes the hypercube.
 boolean isDirty()
          Returns true if the hypercube has been modified without updating it.
 void removeAllIndividuals(java.util.List<Individual> toRemove)
          Removes individuals from hypercube.
 void removeIndividual(Individual individual)
          Removes an individual from hypercube.
 void setIndividuals(java.util.List<Individual> newIndividuals)
          Set a new list of individuals.
 void update()
          Updates the hypercube.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numberOfDimensions

private int numberOfDimensions
Number of dimensions of the hypercube.


numberOfDivisionsPerDimension

private int numberOfDivisionsPerDimension
Number of divisions into which we divide each dimension.


divisionSize

private double[] divisionSize
Size of a division in each dimension.


origin

private double[] origin
Represents the origin of the hypercube.


crowdedCells

private java.util.Map<java.lang.Long,Hypercube.Cell> crowdedCells
Maps cell numbers to cells. It stores the cells that are populated.


individualCellMapping

private java.util.Map<Individual,Hypercube.Cell> individualCellMapping
Maps an individual to the cell where it belongs.


individuals

private java.util.List<Individual> individuals
Contains all the individuals in the hypercube.


dirty

private boolean dirty
If the hypercube is modified without updating it, dirty is set to true. Updating the hypercube sets dirty to false. Any method which needs a clean hypercube (i.e. those which use the bounds and origin) performs an update automatically if dirty is true before it executes.

Constructor Detail

Hypercube

public Hypercube(java.util.List<Individual> individuals,
                 int numberOfDimensions,
                 int numberOfDivisionsPerDimension)
Class constructor.

Parameters:
individuals - List of individuals that will be inside the hypercube.
numberOfDimensions - The number of objectives of the problem.
numberOfDivisionsPerDimension - Number of parts in wich each dimension will be divided for constructing cell. Each division on a dimension represents the coordinate of a cell on that dimension.
Method Detail

getObjectiveValue

private double getObjectiveValue(Individual individual,
                                 int dimension)
Returns the objective value of an individual on a dimension.


initializeHypercube

private void initializeHypercube()
Initializes the hypercube.


getCrowdedCells

public java.util.List<Hypercube.Cell> getCrowdedCells()
Returns the cells that have at least one individual.


getMostCrowdedCell

public Hypercube.Cell getMostCrowdedCell()
Returns one cell among those which are most populated.


getCellNumber

private java.lang.Long getCellNumber(Individual individual)
Returns the cell number of the cell to wich a individual belongs. If The individual belongs to no cell (i.e. the individual is out of the bounds of the current hypercube) this method returns null.


findCell

public Hypercube.Cell findCell(Individual individual)
Finds the cell of an individual.

Returns:
Returns the cell to wich the individual belongs or null if the individual is out of the current hypercube's bounds.

update

public void update()
Updates the hypercube. The bounds and origin are recalculated.


setIndividuals

public void setIndividuals(java.util.List<Individual> newIndividuals)
Set a new list of individuals. The hypercube is not updated.


addIndividual

public void addIndividual(Individual individual)
Adds a new individual to the hypercube. The hypercube is not updated.


addAllIndividuals

public void addAllIndividuals(java.util.List<Individual> toAdd)
Adds individuals to the hypercube. The hypercube is not updated.


removeIndividual

public void removeIndividual(Individual individual)
Removes an individual from hypercube. The hypercube is not updated.


removeAllIndividuals

public void removeAllIndividuals(java.util.List<Individual> toRemove)
Removes individuals from hypercube. The hypercube is not updated.


getSize

public int getSize()
Returns the number of individuals in the hypercube.


isDirty

public boolean isDirty()
Returns true if the hypercube has been modified without updating it.


getIndividuals

public java.util.List<Individual> getIndividuals()
Returns all individuals from the hypercube.