8.1 Tools/ FileIO

An essential piece of HAL, the FileIO class facilitates easily writing to and reading from files. this is important for collecting data from your models as well as systematically paramaterizing them. the API for the FileIO object is discussed.

FileIO(filename,mode):
the FileIO constructor expects a filename or path as a string, and a mode string, of which there are 6 options:
  • “r” creates a FileIO in read mode, this FileIO is able to read text files
  • “w” creates a FileIO in write mode, this FileIO is able to write to a new text file
  • “a” creates a FileIO in append mode, this FileIO is able to append to an existing text file or write to a new file.
  • “rb” creates a FileIO in read binary mode, this FileIO is able to read binary files
  • “wb” creates a FileIO in write binary mode, this FileIO is able to write to binary files.
  • “ab” creates a FileIO in append binary mode, this FileIO is able to append to an existing binary file or write to a new file.

The functions in the next sections are split up based on which mode was used to open the FileIO

Close():
make sure to call this function when finished with the FileIO. The FileIO uses buffers internally to make writing more efficient. Without calling Close() the buffers may never be fully written out.

Read Mode Functions

Read():
returns an ArrayList of Strings. each string is one line from the file
ReadLine():
returns the next line from the file as a string
ReadLineDelimit(delimeter),ReadLineIntDelimit(delimeter):
returns an array of strings,ints,or doubles, etc. Each entry is parsed using the delimeter.
ReadDelimit(delimeter),ReadIntDelimit(delimeter):
returns an ArrayList of arrays of strings,ints,or doubles, etc. Each entry is parsed using the delimeter. Each array in the ArrayList contains data from one line of the file.

Write Mode Functions

Write(string):
writes the string argument to a file
WriteDelimit(arr,delimit):
writes the contents of the provided array to a file, entries are separated using the delimiter.

ReadBinary Mode Functions

ReadBinBool(bool),ReadBinInt(int),ReadBinDouble(double):
read the next single value from the binary file.
ReadBinBools(bool[]),ReadBinInts(int[]),ReadBinDoubles(double[]):
fills the array arugment with values read from the binary file.

WriteBinary Mode Functions

WriteBinBool(bool),WriteBinInt(int),WriteBinDouble(double):
writes a single value to the binary file.
WriteBinBools(bool[]),WriteBinInts(int[]),WriteBinDouble(double[]):
writes every entry in the array to the binary file.

8.2 Tools/ MultiWellExperiment

the multiwell experiment class will visualize many models simultaneously on a single GridWindow. It can also run the models in parallel for better throughput.

MultiWellExperiment(numWellsX,numWellsY,models[],visXdim,visYdim,borderColor,scaleFactor,StepFn,ColorFn):
the constructor for the MultiWellExperiment class. numWellsX, numWellsY define the number of well (model) rows, models[] is an array of the starting conditions of the models. visXdim, visYdim, scaleFactor define the x pixels, y pixels, and scaling of the visualization of each model. borderColor defines the color of the separator between models. StepFn is a function argument that takes a model, a well index, and a timestep as argument, and should update the model argument for one timestep. ColorFn is a function argument that takes a model, x, and y, and is used to set one pixel of the visualization.
Run(numTicks,multiThread?,tickPause):
runs a multiwell experiment for a numTicks duration. if the multiThread boolean is set to true, the model execution will be multithreaded.
Step():
runs a single timestep
LoadWells(models[]):
sets up the multiwell experiment with a new array of models
RunGif(numTicks,outFileName,recordPeriod,multithread?):
runs a multiwell experiment for a numTicks duration. If the multiThread boolean is set to true, the model execution will be multithreaded. Saves every recordPeriod fames to a gif.

8.3 Tools/ Modularity/ ModuleSetManager

The ModuleSetManager class is used to store and use module objects. The type argument is the baseclass module type that the ModuleSetManager will manage. For a semi-complete example of the concept in action, see the ModuleSetExample code in the Examples folder.

ModuleSetManager(baseClass):
the module base class object should define all of the method hooks that modules can use, the behavior of the base class object will be ignored
AddModule(newModule):
adds a module to the ModuleSetManager. The module should override any functions in the baseClass that will be used with the model
IterMethod(methodName):
use this function with a foreach loop to iterate over modules that override a given method. Used to run the module functions when appropriate

8.4 Tools/ Modularity/ VarSetManager

The VarSetManager class maintains a count of double variables that are requested for an agent class that implements the VarSet interface. This tool is useful along with the ModuleSetManger to add agent variables that are only manipulated by one module. See the ModuleSetExample code in the Examples folder.

NewVar():
generates a new variable as part of the var array, returns the index of the variable.
AddVarSet(agent):
adds a new variable set to the given agent. does nothing if the variable set already exists for that agent.

8.5 Tools/ PhylogenyTracker/ Genome

The genome class is useful for keeping track of shared genetic information and phylogenies. Extend this class to add any genetic/inherited information that needs to be tracked. An instance of the Genome class should be created once for every new mutation, and all agents with the same genome should share the same class instance as a member variable

Genome(parent,removeLeaves?):
call this with the parent set to null to create a new phylogeny. The removeLeaves option specifies whether the phylogeny should continue to store dead leaves (lineages with no active individuals). This should also be called whenever a new clone is created, along with IncPop to add one individual to the new clone.
GetId():
gets the ID of the genome, which indicates the order in which it arose
GetPop():
returns the current active population that shares this genome
GetParent():
returns the parent genome that was mutated to give rise to this genome
SetPop(pop):
sets the active population size for this genome to a specific value.
IncPop():
adds an individual to the genome population, should be called as part of the initialization of all agents that share this genome.
DecPop():
removes an individual from the genome population, should be called as part of the disposal of all agents that share this genome.
Traverse(GenomeFunction):
runs the GenomeFunction argument on every descendant of this genome
TraverseWithLineage(ArrayList<Genome>lineageStorage,GenomeFunction):
runs the GenomeFunction argument on every descendant of this genome, will pass as argument the lineage from this genome to the descendant
GetChildren(ArrayList<Genome>childrenStorage):
adds all direct descendants of the genome to the ArrayList
GetLineage(ArrayList<Genome>lineageStorage):
adds all ancestors of the genome to the ArrayList
GetNumGenomes():
returns the total number of genomes that have ever existed in the phylogeny
GetNumLivingGenomes():
returns the number of currently active unique genomes
GetNumTreeGenomes():
returns the number of genomes that exist in the phylogeny (not counting removed leaves)
Pop():
returns the current population size that shares this genome
PhylogenyPop():
returns the total population of all living members of the phylogeny
GetRoot():
gets the first genome that started the phylogeny