code/inC/cellularAutomata.h File Reference

Gives representation and supporting functions for the use of square cellular automata. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <math.h>

Go to the source code of this file.

Data Structures

struct  CA
 Represents a cellular automaton. More...

Functions

int majority (CA *ca)
 Calculates which value holds the majority in the given CA.
CArandomizeToPercentage (CA *ca, int percent, int size)
 Creates a CA which has a percentage of ones equal to the given percentage.
void cpCA (CA *dest, CA *src)
 Makes a copy of a CA.
int aggregate (CA *ca)
 Adds all of the values in the CA.
CA ** randomCAs (int nCAs, int size)
 Creates a specified number of random CAs each of a given dimension.
CArandomCA (int size)
 Creates one random CA of a given size.
int * getRule (char *file)
 Pulls a rule for the CA from a specified file.
CAgetInitCA (char *file, int size)
 Pulls a CA of specified size from a file given by the specified file name.
CAcreateCA (int size)
 Creates a new CA ready for use, all malloc'd and all.
void printInternalCA (CA *ca)
 Prints to stdout our internal representation of the specified CA.
void printCA (CA *ca)
 Prints to stdout the CA in its normal form.
void step (CA *curr, CA *next, int *rules)
 Performs the transition for one generation of the CA to the next, based on the specified rule set.
int finished (CA *ca)
 Indicates whether or not a CA has been completedly classified, i.e.
void freeCA (CA *ca)
 Frees all memory allocated to the specified CA.
double stepWithCount (CA *curr, CA *next, int *rules)
 Performs the transition from one generation of the specified CA to the next, except that unlike step(), the sum of the values is returned.

Detailed Description

Gives representation and supporting functions for the use of square cellular automata.

Author:
Ben Edwards <bedwards@cs.unm.edu>
Tyler Rush <me@tylerlogic.com>
Date:
Thursday April 1, 2010
Version:
1.0.0

Definition in file cellularAutomata.h.


Function Documentation

int aggregate ( CA ca  ) 

Adds all of the values in the CA.

Parameters:
ca The CA whose values will be summed.
Returns:
The sum of the values in the CA.

Definition at line 142 of file cellularAutomata.c.

void cpCA ( CA dest,
CA src 
)

Makes a copy of a CA.

The specified destination CA should already be malloc'd.

Parameters:
src The CA of which to make a copy.
dest The CA that will be a copy of src.

Definition at line 19 of file cellularAutomata.c.

CA* createCA ( int  size  ) 

Creates a new CA ready for use, all malloc'd and all.

Parameters:
size The desired dimension of the new CA.
See also:
freeCA()
Returns:
The newly created CA.

Definition at line 161 of file cellularAutomata.c.

int finished ( CA ca  ) 

Indicates whether or not a CA has been completedly classified, i.e.

whether or not the CA is either all ones or all zeros.

Parameters:
ca The CA for which to determine whether or not it is fully classified.
Returns:
A zero or one indicating whether or not the specified CA is fully classified.

Definition at line 129 of file cellularAutomata.c.

void freeCA ( CA ca  ) 

Frees all memory allocated to the specified CA.

Parameters:
ca The CA to set free.
See also:
createCA()

Definition at line 30 of file cellularAutomata.c.

CA* getInitCA ( char *  file,
int  size 
)

Pulls a CA of specified size from a file given by the specified file name.

The CA should all be on one line and just be a string of ones and zeros with no separation.

Parameters:
file The name of the file that contains the CA configuration.
size The size of the CA in the file.
Returns:
A pointer to the CA that was pulled from the file.

Definition at line 101 of file cellularAutomata.c.

int* getRule ( char *  file  ) 

Pulls a rule for the CA from a specified file.

The rule should be contained entirely on one line.

Parameters:
file The name of the file that contains the rule.
Returns:
A pointer to an array of integers, which is really the ruleset.

Definition at line 76 of file cellularAutomata.c.

int majority ( CA ca  ) 

Calculates which value holds the majority in the given CA.

Parameters:
ca The cellular automaton for which the majority will be calculated.
Returns:
The value of the majority.

Definition at line 154 of file cellularAutomata.c.

void printCA ( CA ca  ) 

Prints to stdout the CA in its normal form.

Parameters:
ca The CA to print to the screen.
See also:
printInternalCA()

Definition at line 211 of file cellularAutomata.c.

void printInternalCA ( CA ca  ) 

Prints to stdout our internal representation of the specified CA.

Parameters:
ca The CA whose internal representaiton will be printed.
See also:
printCA()

Definition at line 198 of file cellularAutomata.c.

CA* randomCA ( int  size  ) 

Creates one random CA of a given size.

The CA returned is malloc'd during creation, and thus should be freed appropriately.

Parameters:
size The dimension of the CA to be created.
Returns:
The newly created random CA.

Definition at line 62 of file cellularAutomata.c.

CA** randomCAs ( int  nCAs,
int  size 
)

Creates a specified number of random CAs each of a given dimension.

Parameters:
nCAs The number of random CAs to create.
size The dimension of each of the CAs created.
Returns:
A pointer to an array of the randomly generated CAs.

Definition at line 51 of file cellularAutomata.c.

CA* randomizeToPercentage ( CA ca,
int  percent,
int  size 
)

Creates a CA which has a percentage of ones equal to the given percentage.

It should be kept in mind that the percentage is based on a random number generator and as such the percentage of ones will most likely not be exact. If NULL is passed as the argument for the ca, a CA is malloced and returned as the return value, otherwise an already memory allocated CA may be passed, in which case the size parameter will be disregarded.

Parameters:
ca The already malloc'd CA, or else NULL.
percent The percentage of ones in the returning CA.
size The dimension of the square CA.
Returns:
The new or reset CA (depeneding on the nullity of the input ca) that now has the specified percentage of ones.

Definition at line 4 of file cellularAutomata.c.

void step ( CA curr,
CA next,
int *  rules 
)

Performs the transition for one generation of the CA to the next, based on the specified rule set.

The current CA is passed and remains unmodified, with its next generation being put into the CA, next.

Parameters:
curr The current generation.
next The next generation.
rules The rule set that governs how a CA should be updated.
See also:
stepWithCount()

Definition at line 225 of file cellularAutomata.c.

double stepWithCount ( CA curr,
CA next,
int *  rules 
)

Performs the transition from one generation of the specified CA to the next, except that unlike step(), the sum of the values is returned.

The sum of the values is returned as a double so that during calculations, less type conversion has to take place. At least at this point we found that a double was more frequently required of the sum.

Parameters:
curr The current generation.
next The next generation.
rules The rule set that governs how a CA should be updated.
See also:
step()
Returns:
The sum of the values in the CA.

Definition at line 246 of file cellularAutomata.c.


Generated on Mon Apr 12 21:34:48 2010 for CS523: Complex Adaptive Systems, Spring 2010, Assignment 2 by  doxygen 1.6.1