Mapper
Class GEGrammar

java.lang.Object
  extended by Mapper.Grammar
      extended by Mapper.ContextFreeGrammar
          extended by Mapper.GEGrammar
All Implemented Interfaces:
Mapper, ParameterI

public class GEGrammar
extends ContextFreeGrammar
implements ParameterI

Class for GEGrammar. GEGrammar uses a GEChromosome to map out a Phenotype

Version:
2006.1013
Author:
EHemberg

Constructor Summary
GEGrammar()
          Creates a new instance of GEGrammar
GEGrammar(GEGrammar copy)
          Copy constructor.
GEGrammar(java.util.Properties p)
          New instance
GEGrammar(java.lang.String file)
          New instance
 
Method Summary
 void clear()
          Clear the grammar
 boolean equals(java.lang.Object obj)
           
 void generatePRC()
          Replaces constants in the grammar with an array of randomly generated constants
 boolean genotype2Phenotype()
          Map input to output
 boolean genotype2Phenotype(boolean b)
          Instanciates a derivation tree and calls buildDerivationTree() if b is true else sets valid map to true
 java.lang.String getDerivationString()
           
 DerivationTree getDerivationTree()
           
 int getDTNodeCount()
           
 GEChromosome getGenotype()
          Returns the mappers input (genotype)
static GEGrammar getGrammar(GEGrammar g)
          Get a grammar of the right type
 int getMaxChromosomeLengthByDepth()
          This method calculates an upper bound for the number of inputs needed to build a derivation tree according to the specified maxDerivationTreeDepth and the max number of non terminals in a production of the grammars rules.
 int getMaxCurrentTreeDepth()
          Get the max depth of the derivation tree built by the grammar
 int getMaxDerivationTreeDepth()
           
 int getMaxWraps()
          Get max wraps allowed
 java.lang.String getName()
           
 Phenotype getPhenotype()
          Returns the mappers output (phenotype)
 int getUsedCodons()
          Get used inputs (codons in the genotype)
 int getUsedWraps()
          Get used wraps (Number of times the input was reread from the start)
 int hashCode()
           
 boolean phenotype2Genotype()
          Map output to input
 void setDerivationTree(DerivationTree dT)
          Set the derivation tree
 void setDerivationTreeType(java.lang.String derivationTreeType)
           
 void setGenotype(GEChromosome genotype)
          Set input
 void setGenotype(java.lang.Object g)
          Sets the input (genotype)
 void setMaxCurrentTreeDepth(int maxCurrentTreeDepth)
          Set the max depth of the derriation tree that was built by this grammar
 void setMaxDerivationTreeDepth(int maxDerivationTreeDepth)
           
 void setMaxWraps(int i)
          Set max wraps
 void setPhenotype(java.lang.Object p)
          Sets the output(phenotype)
 void setPhenotype(Phenotype phenotype)
          Set output
 void setProperties(java.util.Properties p)
          Set properties
 
Methods inherited from class Mapper.ContextFreeGrammar
findRule, findRule, getNonTerminalRules, getTerminalRules, readBNFFile
 
Methods inherited from class Mapper.Grammar
getProductionCount, getRules, getStartRule, getStartSymbol, getTerminals, getTerminalStrings, setRules, setStartSymbol, setStartSymbol
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GEGrammar

public GEGrammar()
Creates a new instance of GEGrammar


GEGrammar

public GEGrammar(java.lang.String file)
New instance

Parameters:
file - file to read grammar from

GEGrammar

public GEGrammar(java.util.Properties p)
New instance

Parameters:
p - properties

GEGrammar

public GEGrammar(GEGrammar copy)
Copy constructor. Does not copy the genotype and phenotype

Parameters:
copy - grammar to copy
Method Detail

setProperties

public void setProperties(java.util.Properties p)
Set properties

Specified by:
setProperties in interface ParameterI
Parameters:
p - object containing properties

genotype2Phenotype

public boolean genotype2Phenotype()
Map input to output

Specified by:
genotype2Phenotype in interface Mapper
Specified by:
genotype2Phenotype in class ContextFreeGrammar
Returns:
validity of mapping

phenotype2Genotype

public boolean phenotype2Genotype()
Map output to input

Specified by:
phenotype2Genotype in interface Mapper
Specified by:
phenotype2Genotype in class ContextFreeGrammar
Returns:
boolean Is the mapping valid

generatePRC

public void generatePRC()
Replaces constants in the grammar with an array of randomly generated constants


clear

public void clear()
Clear the grammar

Specified by:
clear in interface Mapper
Specified by:
clear in class Grammar

genotype2Phenotype

public boolean genotype2Phenotype(boolean b)
Instanciates a derivation tree and calls buildDerivationTree() if b is true else sets valid map to true

Parameters:
b - if tree should be built
Returns:
validity of mapping

getGrammar

public static GEGrammar getGrammar(GEGrammar g)
Get a grammar of the right type

Parameters:
g - grammar to create new instance of;
Returns:
a new grammar object of the right type

getMaxCurrentTreeDepth

public int getMaxCurrentTreeDepth()
Get the max depth of the derivation tree built by the grammar

Returns:
max derivation tree depth

setMaxCurrentTreeDepth

public void setMaxCurrentTreeDepth(int maxCurrentTreeDepth)
Set the max depth of the derriation tree that was built by this grammar

Parameters:
maxCurrentTreeDepth -

getMaxWraps

public int getMaxWraps()
Get max wraps allowed

Returns:
max wraps

setMaxWraps

public void setMaxWraps(int i)
Set max wraps

Parameters:
i - max wraps

setGenotype

public void setGenotype(GEChromosome genotype)
Set input

Parameters:
genotype - input

setPhenotype

public void setPhenotype(Phenotype phenotype)
Set output

Parameters:
phenotype - output

getPhenotype

public Phenotype getPhenotype()
Description copied from interface: Mapper
Returns the mappers output (phenotype)

Specified by:
getPhenotype in interface Mapper
Returns:
output of the mapping

getGenotype

public GEChromosome getGenotype()
Description copied from interface: Mapper
Returns the mappers input (genotype)

Specified by:
getGenotype in interface Mapper
Returns:
input of the mapper

setPhenotype

public void setPhenotype(java.lang.Object p)
Description copied from interface: Mapper
Sets the output(phenotype)

Specified by:
setPhenotype in interface Mapper
Parameters:
p - output to set

setGenotype

public void setGenotype(java.lang.Object g)
Description copied from interface: Mapper
Sets the input (genotype)

Specified by:
setGenotype in interface Mapper
Parameters:
g - input to set

getUsedCodons

public int getUsedCodons()
Get used inputs (codons in the genotype)

Specified by:
getUsedCodons in class ContextFreeGrammar
Returns:
number of used inputs

getUsedWraps

public int getUsedWraps()
Get used wraps (Number of times the input was reread from the start)

Specified by:
getUsedWraps in class ContextFreeGrammar
Returns:
number of wraps

getMaxDerivationTreeDepth

public int getMaxDerivationTreeDepth()

setMaxDerivationTreeDepth

public void setMaxDerivationTreeDepth(int maxDerivationTreeDepth)

setDerivationTree

public void setDerivationTree(DerivationTree dT)
Set the derivation tree

Parameters:
dT - Derivation Tree

getDerivationTree

public DerivationTree getDerivationTree()

getMaxChromosomeLengthByDepth

public int getMaxChromosomeLengthByDepth()
This method calculates an upper bound for the number of inputs needed to build a derivation tree according to the specified maxDerivationTreeDepth and the max number of non terminals in a production of the grammars rules. The upper bound is calculated as the sum of the max non terminals at each depth of the tree. (length = Sum_i=0^D a^i, D=max depth, a = max non terminals in a production)

Returns:
int Max number of inputs

getName

public java.lang.String getName()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getDTNodeCount

public int getDTNodeCount()

setDerivationTreeType

public void setDerivationTreeType(java.lang.String derivationTreeType)

getDerivationString

public java.lang.String getDerivationString()
Specified by:
getDerivationString in class Grammar