Seitenende | Letzte Änderung: 2. Juni 1999 | Home

The ca Library

The ca shared library consists of a C++ class CA_Drawer and some functions to create a window and draw onto it.

 

THE TECHNICAL TODO LIST

For using ca, you must
  • include caGraph.H in your program: *
    #include <caGraph.H>
  • compile with the include path set to where the caGraph.H file resides: *
    g++ ... -I<path to the dir containing caGraph.H> ...
  • link with the library path set to where the ca and the fltk libraries are installed: *
    g++ ... -L<path to the dir containing libca.so*> -L<path to the dir containing libfltk.so*> ...
  • link with the ca and fltk library: *
    g++ ... -lca -lfltk ...
  • set your LD_LIBRARY_PATH environment variable to wherever the ca and fltk libraries are whenever you want to run programs which use the libraries. You don't need to do this if the libraries are installed at locations where libraries are usually searched for, like /usr/local/lib, /usr/lib etc.
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path to dir where the libraries are installed>
 

THE JUST-DO-IT DESCRIPTION

In case you use the given Makefile and
makeinclude files together with the library installed at /home/stud/ftschelh/lib at the Lehre-Netz Informatik at Osnabrueck, you don't need to do anything of the marked (*) items above, but you probably need to set your LD_LIBRARY_PATH.

Just copy the 'Makefile', 'makeinclude' and 'makedepend' files, write your program (let's say auto.C - note the uppercase C) and write the basename (which would then be auto) after the 'all' target in the 'Makefile'. Just have a look into 'Makefile' how this is done for the dummy.C program.

If you use other libraries as well, append the linker and include options to the appropriate lines in 'Makefile'.

Below is the complete header file of the library. If you have more questions, write to me.

/* return state at the position i,j */
typedef int (*getValueCallback_type) (int, int);
/* return new state of the automaton at the position i, j with
* neighbourhood nx, ny
*/
typedef int (*ruleCallback_type) (int *, int, int, int *, int *);

/* creates a window for the array autom */
CA_Drawer * createArrayWindow(int x, int y, int zoom, int * autom, const char * title);

/* creates a window for the array autom, which draws a hexagonal pattern */
CA_Drawer * createHexArrayWindow(int x, int y, int zoom, int * autom, const char * title);

/* creates a window which uses the callback */
CA_Drawer * createCbWindow(int x, int y, int zoom, getValueCallback_type cb, const char * title);

/* creates a window which uses the callback and draws a hexagonal pattern */
CA_Drawer * createHexCbWindow(int x, int y, int zoom, getValueCallback_type cb, const char * title);

/* sets an alternative map from states to colors */
void setColormap( CA_Drawer * window, int * colormap );

/* draws the ca using the callback function
thus the setGetValueCallback function must be invoked before
with a valid parameter */
void drawCallback( int step, CA_Drawer *window );

/* draws one line at the position line using the callback function
thus the setGetValueCallback function must be invoked before
with a valid parameter */
void drawArrayLine( int step, CA_Drawer *window, int * autom, int line );

/* draws the array autom without calling the getValueCallback
uses previously set size of the ca */
void drawArray( int step, CA_Drawer *window, int * autom );

/* draws the first line of the array autom at the position line
without calling the getValueCallback
uses previously set size of the ca */
void drawArrayLine( int step, CA_Drawer *window, int * autom, int line );

/* this function is called during the draw(..) operation
for retrieving the value at the current position */
void setGetValueCallback( CA_Drawer *window, getValueCallback_type cb );

/* m lines as '*' and '.' */
void out( int * autom, int * high, int m );

/* m lines with state as number */
void numOut( int * autom, int n, int m );

/* m lines as '*' and '.' */
void formOut( int *autom, int n, int m, int t);

/* positive random integer */
int randInt( int max );

/* random init states with specified distribution
* dist is cumulative */
void initDist( int * autom, int n, int m, int k, int seed, double * dist );

/* random init states */
void init( int * autom, int n, int m, int k, int seed );

/* executes numSteps steps of the given ca
* autom is the array containing the given configuration
* n is the width of the automata
* m is the height of the automata
* k is the number of possible states
* r is the number of neighbours
* nx and ny contain the distance to the neighbouring cells
* rule is the table encoding the transition function
*      s[i,j] means state of cell at (i,j)
*      s[i,j] = rule[sum(s[i+nx[0], j+ny[0]]*k^0, s[i+nx[1], j+ny[1]]*k^1,
*                      ... s[i+nx[r-1], j+ny[r-1]]*k^(r-1)]
* current is the start time
* numSteps is the number of steps
* window is the window to draw on or NULL
*         if collect == true and m == 1, all timesteps are drawn
* collect == true: writes the configuration sequentially to one memory vector
*          returns a pointer to the calling configuration
*          you can find the configuration at timestep current+t at the position *               returnValue + n*m*t      for 2dimensional cas (m > 1)
*               returnValue + n*t        for 1dimensional cas (m == 1)
* collect == false: overwrite previous configuration
*          returns a pointer to the configuration after t timesteps
*/
int * steps ( int * autom, int n, int m, int k, int r, int * nx, int * ny, int * rule, int current, int numSteps, int collect, CA_Drawer * window );

/* use rule for computing the new state */
int * stepsRule ( int * autom, int n, int m, int k, int r, int * nx, int * ny, ruleCallback_type rule, int current, int numSteps, int collect, CA_Drawer * window );

/* computes one step of the ca
* arguments as above
* buffer is the source (timestep t), autom the target (timestep t+1)
* returns a pointer to the new configuration
*         (ie autom - but don't rely on it!)
*/
int * step ( int * autom, int * buffer, int n, int m, int k, int r, int * nx, int * ny, int * rule );

/* use rule for computing the new state */
int * stepRule ( int * autom, int * buffer, int n, int m, int k, int r, int * nx, int * ny, ruleCallback_type rule );

/*
* nxEven and nxOdd are neighbourhood x coordinates for even resp. odd line numbers (counted from 0)
*/
int * hexSteps ( int * autom, int n, int m, int k, int r, int * nxEven, int * nxOdd, int * ny, int * rule, int current, int numSteps, int collect, CA_Drawer * window );

/* use rule for computing the new state */
int * hexStepsRule ( int * autom, int n, int m, int k, int r, int * nxEven, int * nxOdd, int * ny, ruleCallback_type rule, int current, int numSteps, int collect, CA_Drawer * window );

/* computes one step of the ca
* arguments as above
* buffer is the source (timestep t), autom the target (timestep t+1)
* returns a pointer to the new configuration
*         (ie autom - but don't rely on it!)
*/
int * hexStep ( int * autom, int * buffer, int n, int m, int k, int r, int * nxEven, int * nxOdd, int * ny, int * rule );

/* use rule for computing the new state */
int * hexStepRule ( int * autom, int * buffer, int n, int m, int k, int r, int * nxEven, int * nxOdd, int * ny, ruleCallback_type rule );

© 1998 Thorsten Schelhorn

Seitenanfang