Declaration Remarks Revisions Example See Also
| Declarationvoid __stdcall onSimCreate(void);

Remarks
This optional function may be provided by the model. It is called just after a new simulation has been created (but before the agents have been created). You can use this function to set global variables (shortcuts) to the model parameters. Also, set local neighbourhoods in this function with the nbrhd* functions, as demonstrated in the example below.

Revisions
API v1.5- new! Replaces simBegin and setNbrhd.

Exampleunsigned short fadeRate;
double *workspace = NULL;
//---------------------------------------------------------------------------
void __stdcall onSimCreate(void)
{
// shortcuts
fadeRate = (unsigned short)(*getParamRef("Fade Rate"));
// allocate workspace
workspace = new double[100];
// set nbr shortcuts for each agent. Much faster than calling agentAtXY().
int range = int(*getParamRef("Neighbourhood Range")); // truncated
switch (int(*getParamRef("Neighbourhood Type"))) {
case 0: /* mean-field, ignore */
break;
case 1: nbrhd1D(range,btPeriodic);
break;
case 2: nbrhdMoore(range,btPeriodic);
break;
case 3: // use floating point "Neighbourhood Range"
nbrhdRandomER(*getParamRef("Neighbourhood Range"),true);
break;
case 4: // demonstrates how multiple neighbourhoods can be overlapped
nbrhdBlocks(range,range);
nbrhdFractal(range,range,true,true);
break;
}
}
//---------------------------------------------------------------------------
void __stdcall onSimDestroy(void);
{
// free workspace
delete [] workspace;
workspace = NULL;
}
//---------------------------------------------------------------------------

See Also
onSimReady, onSimDestroy, nbrhd1D, nbrhdBlocks, nbrhdCCDM, nbrhdFractal, nbrhdMoore, nbrhdRandom, nbrhdRandomER, nbrhdVonNeumann. |