Current version of MagNet implements transient analysis of Markovian agent based models. The analysis is arranged throughout some parameters to set before the starting of the analysis. Parameter names, C type to use for their definition, their semantics, and their default values are summarized in the following table:
Parameter name | C type | Default value | Semantics |
---|---|---|---|
SOLUTION_START_TIME | Time | 0.0 | starting time point value in transient analysis evaluation |
SOLUTION_END_TIME | Time | 0.0 | final time point value in transient analysis evaluation |
SOLUTION_STEP | Step | 0.0 | advancement step used in transient analysis evaluation |
SOLUTION_TOL | Tolerance | 10 -6 | tolerance level used to compare values used in numerical algorithms |
SOLUTION_MAX_ITERATIONS | unsigned int | 20 | maximum number of possible iterations; the iteration is stopped when this value is reached
used with Euler methods only, ignored if othe methods are selected |
SOLUTION_THREADS | unsigned int | 1 | number of threads to generate if the implementation of the selected method supports multi-threading |
SOLUTION_ALG | SolveType | OLE_2_RKF45 | type of solution method to use in the transient ananlysis |
OUTPUT | OUT_Mode | NO_MODE | how the results are shown |
Where the multi-threading is supported, the number of thread MagNet uses is computed at runtime. In the current version, multi-threading is implemented in the Forward Euler (explicit) method and backward Euler (implicit) method.
The values different parameters can have are as in the following table; when a value is not set the default value written above are assumed.
Parameter name | Range | Note |
---|---|---|
SOLUTION_START_TIME | >=0.0 | |
SOLUTION_END_TIME | >=0.0 | it is user responsibility to verify that SOLUTION_END_TIME is greater than SOLUTION_START_TIME |
SOLUTION_STEP | >=0.0 | |
SOLUTION_TOL | >=0.0 | |
SOLUTION_MAX_ITERATIONS | > 0 | |
SOLUTION_THREADS | >=0 | |
SOLUTION_ALG | EEULER | Forward Euler (explicit) method |
IEULER | Backward Euler (implicit) method | |
OLE2_RK2 | The GSL explicit embedded Runge-Kutta (2, 3) method | |
OLE2_RK4 | The GSL explicit 4th order Runge-Kutta | |
OLE2_RKF45 | The GSL explicit embedded Runge-Kutta-Fehlberg (4, 5) method | |
OLE2_RKCK | The GSL explicit embedded Runge-Kutta Cash-Karp (4, 5) method | |
OLE2_RK8PD | The GSL explicit embedded Runge-Kutta Prince-Dormand (8, 9) | |
OUTPUT | W_MODE | Density vectors are written in a set of files, one per deployed agent |
NO_MODE | No file is produced |
When W_MODE is used as OUTPUT, MagNET generate one file per agent whose names are agent_name.csv
, where agent_name
is the same string used as name when the Markovian agent is created with m3am_NewAgent
.
Error m3am_SetParams(M3AM *m, ParType Pt, void *val);
m3am_SetParams
sets the parameter Pt
of the model m
to the value val
. Pt
is one of the values in column Name of the table. The value of a model parameter is passed by reference by using a generic pointer to void, thus the most appropriate way is to use a variable defined as appropriate type according to the model parameter the user want to set and then pass its reference as second parameter of m3am_SetParams
. Here is an example where 10.0 and forward Euler method are set as final time point and solution method respectively when “My_Markovian_Agent_model” is solved
myModel=m3am_NewModel("My_Markovian_Agent_model", 2);
.
.
.
double p=5.0;
m3am_SetParams(VoIP, SOLUTION_END_TIME, &p);
SolveType p3=IEULER;
m3am_SetParams(VoIP, SOLUTION_ALG, &p3);
.
.
Error m3am_Solve(M3AM *m);
m3am_Solve
performs the transient analysis of the model referenced by m
from SOLUTION_START_TIME to SOLUTION_END_TIME using the parameter values previously set. The vectors defined with m3am_AddInitProb
together with the density value used in m3am_NewAgent
contribute to create the initial density state used as boundary conditions for the transient analysis. The results can be recovered throughout the set of files generated setting OUTPUT parameter to W_MODE, otherwise the vectors of density values at SOLUTION_END_TIME only can be recovered by using m3amGetAgentDensities
function.
Vector *m3am_GetAgentDensities(M3AM *m, const char *ma_label)
m3am_GetAgentDensities
gets back a vector storing the densities of an agent, whose name is ma_label
, in the model referenced by m at last evaluated time point.