Class World

java.lang.Object
  extended by World

public class World
extends java.lang.Object

The World class represents the world in which the simulation takes place. The main components of the World object are the population of organisms and the resource pool. Both these are defined using the Vector class.


Field Summary
static int avg
          The number of updates the efficiency is averaged over
 double bitflipProb
          The bit flip probability of inflowing strings
 int entropyLevel
          The level of entropy calculation
 boolean[] fixedString
          In the case of fixed strings this is the inflowing string
 double flow
          The flow rate of bit strings
 double inEntropy
          The entropy of the inflowing strings
 int[][] interactions
          The matrix holding interactions between the species.
 int noDivisions
          Counter for the number of organism divisions
 double noStringsFlowing
          Counter for the number of bit strings flowing into the system
 java.util.Vector<Organism> organisms
          A Vector containing all the organisms in the World
 double[] productivity
          An array that holds of the productivity for the last avg time steps
 int randomMode
          When strings are random this declares the type of strings being used
 boolean randomStrings
          True if random bit strings are used
 java.util.Vector<BString> resources
          A Vector containing all the bit strings in the World
 int stringLength
          The length of the bit strings
 
Constructor Summary
World(int popSize, int foodSize, double flow, boolean[] fixedString, int entropyLevel)
          Creates a World with a flow of fixed strings
World(int popSize, int foodSize, int stringLength, double flow, double bitflipProb, int randomMode, int entropyLevel)
          Creates a World with a flow of random strings
 
Method Summary
 void addInt(java.util.Vector<java.lang.Integer> H)
          Adds an interaction to the matrix I
 void fakeUpdate()
          Updates all organisms in the population without carrying out the actual divisions
 double getAvgAge()
          The average age of the organisms
 double getAvgEntropy()
          The average entropy of bit strings
 double getAvgIO()
          The average IO (entropy difference) of the organisms
 double getAvgProd()
          The average amount of energy that has been extracted from the bit strings.
 double getAvgStringAge()
          The average age of the bit strings.
 int getDivides()
          The total number of organism divisions that have occured in the system
 double getEff()
          The average efficiency of the organisms, defined as the average IO divided by the maximum amount of energy that can be extracted from the strings
 double getFraction(int rule)
          The fraction of the population that corresponds to a given rule
 double getIO(int rule)
          The average IO (entropy difference) of organisms of a certain genotype
 int getNoPhenotypes(double frac)
          The number of genotypes/rules that exist above a certain threshold
 double[] getState()
          Returns the species distribution
 void Inoculate(int[] rules, double[] fracs)
          Setting the rule frequency to defined values
 void saveEff(java.lang.String file)
          Saves the average efficiency in a data file
 void saveFoodEntropy(int t)
          Saves the entropy of all strings to a data file parametrised by time
 void saveFoodHistory(int t)
          Saves the metablic history of all strings to a data file parametrised by time
 void saveGenotypes(int t, double frac)
          Saves all genotypes above a certain fraction to a data file parametrised by time
 void saveInts(java.lang.String file)
          Saves the interaction matrix interactions in a data file
 void saveState(java.lang.String file)
          Saves the no. of organisms in each species (rule) in a data file
 void saveStats(java.lang.String file, java.lang.String stats)
          Saves any information in a data file
 void setEntLevel(int x)
          Sets the level at which the entropy is calculated
 void setFlow(double fl)
          Sets the flow rate
 void setMutRate(double pc)
          Sets the mutation rate
 BString swapString(BString S)
          Swaps the specified bit string with a random string from the resource pool
 void update()
          Updates all organisms in the population, takes care of the swapping of strings, and calls the divide method of Organism
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

organisms

public java.util.Vector<Organism> organisms
A Vector containing all the organisms in the World


resources

public java.util.Vector<BString> resources
A Vector containing all the bit strings in the World


stringLength

public int stringLength
The length of the bit strings


noDivisions

public int noDivisions
Counter for the number of organism divisions


entropyLevel

public int entropyLevel
The level of entropy calculation


noStringsFlowing

public double noStringsFlowing
Counter for the number of bit strings flowing into the system


flow

public double flow
The flow rate of bit strings


bitflipProb

public double bitflipProb
The bit flip probability of inflowing strings


fixedString

public boolean[] fixedString
In the case of fixed strings this is the inflowing string


randomStrings

public boolean randomStrings
True if random bit strings are used


randomMode

public int randomMode
When strings are random this declares the type of strings being used


interactions

public int[][] interactions
The matrix holding interactions between the species. I(i,j) = the number of bit strings that have been metabolised by species i and then by species j


productivity

public double[] productivity
An array that holds of the productivity for the last avg time steps


avg

public static int avg
The number of updates the efficiency is averaged over


inEntropy

public double inEntropy
The entropy of the inflowing strings

Constructor Detail

World

public World(int popSize,
             int foodSize,
             int stringLength,
             double flow,
             double bitflipProb,
             int randomMode,
             int entropyLevel)
Creates a World with a flow of random strings

Parameters:
popSize - the number of agents in the population
foodSize - the number of bit strings in the resource pool
stringLength - the length of the bit strings
flow - the flow rate of new strings into the system
bitflipProb - the bitflip probability of the inflowing strings
randomMode - the type of random strings flowing into the system
entropyLevel - the block length at which the entropy is calculated
See Also:
BString.BString(int, double, int)

World

public World(int popSize,
             int foodSize,
             double flow,
             boolean[] fixedString,
             int entropyLevel)
Creates a World with a flow of fixed strings

Parameters:
popSize - the number of agents in the population
foodSize - the number of bit strings in the resource pool
flow - the flow rate of new strings into the system
fixedString - the bit string that flows into the system
entropyLevel - the block length at which the entropy is calculated
Method Detail

Inoculate

public void Inoculate(int[] rules,
                      double[] fracs)
Setting the rule frequency to defined values

Parameters:
rules - the rules with non-zero abundance
fracs - the corresponding frequencies. Should sum to one.

getAvgEntropy

public double getAvgEntropy()
The average entropy of bit strings

Returns:
the average entropy of the strings in the resource pool

getAvgIO

public double getAvgIO()
The average IO (entropy difference) of the organisms

Returns:
the average IO

getIO

public double getIO(int rule)
The average IO (entropy difference) of organisms of a certain genotype

Parameters:
rule - the genotype under consideration
Returns:
the average IO

getAvgAge

public double getAvgAge()
The average age of the organisms

Returns:
the average age (in updates)

getAvgStringAge

public double getAvgStringAge()
The average age of the bit strings. Here the age is defined as the number manipulations the bit string has been through

Returns:
the average age

getAvgProd

public double getAvgProd()
The average amount of energy that has been extracted from the bit strings. This quantity is averaged over the last $avg updates

Returns:
the average productivity

getEff

public double getEff()
The average efficiency of the organisms, defined as the average IO divided by the maximum amount of energy that can be extracted from the strings

Returns:
the average efficiency

getDivides

public int getDivides()
The total number of organism divisions that have occured in the system

Returns:
the number of divisions

getNoPhenotypes

public int getNoPhenotypes(double frac)
The number of genotypes/rules that exist above a certain threshold

Parameters:
frac - the threshold
Returns:
the number of genotypes

getFraction

public double getFraction(int rule)
The fraction of the population that corresponds to a given rule

Parameters:
rule - the rule
Returns:
the fraction

setEntLevel

public void setEntLevel(int x)
Sets the level at which the entropy is calculated

Parameters:
x - the level

setFlow

public void setFlow(double fl)
Sets the flow rate

Parameters:
fl - the rate

setMutRate

public void setMutRate(double pc)
Sets the mutation rate

Parameters:
pc - the mutation rate

addInt

public void addInt(java.util.Vector<java.lang.Integer> H)
Adds an interaction to the matrix I

Parameters:
H - the metabolic history of the bit string manifesting the interaction

update

public void update()
Updates all organisms in the population, takes care of the swapping of strings, and calls the divide method of Organism

See Also:
Organism.divide(), swapString(BString)

fakeUpdate

public void fakeUpdate()
Updates all organisms in the population without carrying out the actual divisions

See Also:
swapString(BString)

swapString

public BString swapString(BString S)
Swaps the specified bit string with a random string from the resource pool

Parameters:
S - the bit string to be swapped
Returns:
the new bit string

saveGenotypes

public void saveGenotypes(int t,
                          double frac)
                   throws java.io.IOException,
                          java.io.FileNotFoundException
Saves all genotypes above a certain fraction to a data file parametrised by time

Parameters:
t - the time, used for naming the data file
frac - the threshold value
Throws:
java.io.IOException
java.io.FileNotFoundException

saveFoodHistory

public void saveFoodHistory(int t)
                     throws java.io.IOException,
                            java.io.FileNotFoundException
Saves the metablic history of all strings to a data file parametrised by time

Parameters:
t - the time, used for naming the data file
Throws:
java.io.IOException
java.io.FileNotFoundException

saveFoodEntropy

public void saveFoodEntropy(int t)
                     throws java.io.IOException,
                            java.io.FileNotFoundException
Saves the entropy of all strings to a data file parametrised by time

Parameters:
t - the time, used for naming the data file
Throws:
java.io.IOException
java.io.FileNotFoundException

saveState

public void saveState(java.lang.String file)
               throws java.io.IOException,
                      java.io.FileNotFoundException
Saves the no. of organisms in each species (rule) in a data file

Parameters:
file - the name of the data file
Throws:
java.io.IOException
java.io.FileNotFoundException

getState

public double[] getState()
Returns the species distribution

Returns:
an array containing the frequency of all 256 species

saveStats

public void saveStats(java.lang.String file,
                      java.lang.String stats)
               throws java.io.IOException,
                      java.io.FileNotFoundException
Saves any information in a data file

Parameters:
file - the name of the data file
stats - the data that is being written
Throws:
java.io.IOException
java.io.FileNotFoundException

saveInts

public void saveInts(java.lang.String file)
              throws java.io.IOException,
                     java.io.FileNotFoundException
Saves the interaction matrix interactions in a data file

Parameters:
file - the name of the data file
Throws:
java.io.IOException
java.io.FileNotFoundException
See Also:
addInt(Vector)

saveEff

public void saveEff(java.lang.String file)
             throws java.io.IOException,
                    java.io.FileNotFoundException
Saves the average efficiency in a data file

Parameters:
file - the name of the data file
Throws:
java.io.IOException
java.io.FileNotFoundException