Beispiel #1
0
int main()
{
	// define of the life CA and life_simulation simulation objects
	life = calCADef2D(8, 16, CAL_MOORE_NEIGHBORHOOD_2D, CAL_SPACE_TOROIDAL, CAL_NO_OPT);
	life_simulation = calRunDef2D(life, 1, 1, CAL_UPDATE_IMPLICIT);

   	//put OpenCAL - OMP in unsafe state execution(to allow unsafe operation to be used)
	calSetUnsafe2D(life);

	// add the Q substate to the life CA
	Q = calAddSubstate2Di(life);

	// add transition function's elementary process
	calAddElementaryProcess2D(life, lifeTransitionFunction);

	// set the whole substate to 0
	calInitSubstate2Di(life, Q, 0);

	// set a glider
	calInit2Di(life, Q, 0, 2, 1);
	calInit2Di(life, Q, 1, 0, 1);
	calInit2Di(life, Q, 1, 2, 1);
	calInit2Di(life, Q, 2, 1, 1);
	calInit2Di(life, Q, 2, 2, 1);

	// save the Q substate to file
	calSaveSubstate2Di(life, Q, "./life_0000.txt");

	// simulation run
	calRun2D(life_simulation);

	// save the Q substate to file
	calSaveSubstate2Di(life, Q, "./life_LAST.txt");

	// finalize simulation and CA objects
	calRunFinalize2D(life_simulation);
	calFinalize2D(life);

	return 0;
}
Beispiel #2
0
int main()
{
    time_t start_time, end_time;

    //cadef and rundef
    struct CALModel2D* sciddicaT = calCADef2D (ROWS, COLS, CAL_VON_NEUMANN_NEIGHBORHOOD_2D, CAL_SPACE_TOROIDAL, CAL_OPT_ACTIVE_CELLS);
    struct CALRun2D* sciddicaT_simulation = calRunDef2D(sciddicaT, 1, STEPS, CAL_UPDATE_IMPLICIT);

    //add transition function's elementary processes
    calAddElementaryProcess2D(sciddicaT, sciddicaT_transition_function);
    calAddElementaryProcess2D(sciddicaT, sciddicaT_remove_inactive_cells);

    //add substates
    Q.z = calAddSingleLayerSubstate2Dr(sciddicaT);
    Q.h = calAddSubstate2Dr(sciddicaT);

    //load configuration
    calLoadSubstate2Dr(sciddicaT, Q.z, DEM_PATH);
    calLoadSubstate2Dr(sciddicaT, Q.h, SOURCE_PATH);

    //simulation run
    calRunAddInitFunc2D(sciddicaT_simulation, sciddicaT_simulation_init);
    printf ("Starting simulation...\n");
    start_time = time(NULL);
    calRun2D(sciddicaT_simulation);
    end_time = time(NULL);
    printf ("Simulation terminated.\nElapsed time: %d\n", end_time-start_time);


    //saving configuration
    calSaveSubstate2Dr(sciddicaT, Q.h, OUTPUT_PATH);

    //finalizations
    calRunFinalize2D(sciddicaT_simulation);
    calFinalize2D(sciddicaT);

    return 0;
}