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. | |
CA * | randomizeToPercentage (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. | |
CA * | randomCA (int size) |
Creates one random CA of a given size. | |
int * | getRule (char *file) |
Pulls a rule for the CA from a specified file. | |
CA * | getInitCA (char *file, int size) |
Pulls a CA of specified size from a file given by the specified file name. | |
CA * | createCA (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. |
Gives representation and supporting functions for the use of square cellular automata.
Definition in file cellularAutomata.h.
int aggregate | ( | CA * | ca | ) |
Adds all of the values in the CA.
ca | The CA whose values will be summed. |
Definition at line 142 of file cellularAutomata.c.
CA* createCA | ( | int | size | ) |
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.
ca | The CA for which to determine whether or not it is fully classified. |
Definition at line 129 of file cellularAutomata.c.
void freeCA | ( | CA * | ca | ) |
Frees all memory allocated to the specified CA.
ca | The CA to set free. |
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.
file | The name of the file that contains the CA configuration. | |
size | The size of the CA in 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.
file | The name of the file that contains the rule. |
Definition at line 76 of file cellularAutomata.c.
int majority | ( | CA * | ca | ) |
Calculates which value holds the majority in the given CA.
ca | The cellular automaton for which the majority will be calculated. |
Definition at line 154 of file cellularAutomata.c.
void printCA | ( | CA * | ca | ) |
Prints to stdout the CA in its normal form.
ca | The CA to print to the screen. |
Definition at line 211 of file cellularAutomata.c.
void printInternalCA | ( | CA * | ca | ) |
Prints to stdout our internal representation of the specified CA.
ca | The CA whose internal representaiton will be printed. |
Definition at line 198 of file cellularAutomata.c.
CA* randomCA | ( | int | size | ) |
CA** randomCAs | ( | int | nCAs, | |
int | size | |||
) |
Creates a specified number of random CAs each of a given dimension.
nCAs | The number of random CAs to create. | |
size | The dimension of each of the CAs created. |
Definition at line 51 of file cellularAutomata.c.
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.
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. |
Definition at line 4 of file cellularAutomata.c.
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.
curr | The current generation. | |
next | The next generation. | |
rules | The rule set that governs how a CA should be updated. |
Definition at line 225 of file cellularAutomata.c.
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.
curr | The current generation. | |
next | The next generation. | |
rules | The rule set that governs how a CA should be updated. |
Definition at line 246 of file cellularAutomata.c.