00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "ne_sim_map.h"
00024 #include "ne_dyn.h"
00025 #include "ne_sim.h"
00026 #include <string.h>
00027
00028
00029 ne_dyn_vec_t * ne_sim_map (ne_sys_t *sys, void *params, double *iy, FILE *file)
00030 {
00031 int i, l, nodes, edges, nStates, eStates, sysStates;
00032 double *y, *yPrev;
00033 ne_dyn_vec_t *dyn;
00034
00035
00036 l = ((int *)params)[0];
00037 nodes = ne_sys_nodes(sys);
00038 edges = ne_sys_edges(sys);
00039 nStates = ne_sys_node_states(sys);
00040 eStates = ne_sys_edge_states(sys);
00041 sysStates = nStates * nodes * eStates * edges;
00042 dyn = ne_dyn_vec_alloc(sysStates);
00043
00044
00045 y = (double *)malloc(sizeof(double) * sysStates);
00046 memcpy(y, iy, sizeof(double) * sysStates);
00047 ne_dyn_vec_append_item(dyn, y);
00048
00049
00050 for (i=1; i<l; i++) {
00051 yPrev = y;
00052 y = (double *)malloc(sizeof(double) * sysStates);
00053 ne_sim_map_step(sys, yPrev, y, i);
00054 ne_dyn_vec_append_item(dyn, y);
00055 }
00056
00057
00058 if (file != NULL) {
00059 ne_sim_fprint_dyn_vec(dyn, file);
00060 }
00061
00062 return dyn;
00063 }
00064
00065
00066 void ne_sim_map_step (ne_sys_t *sys, double *y, double *yNext, int t)
00067 {
00068 ne_int_t i, j;
00069 ne_dyn_node_t *nodeDyn;
00070 ne_dyn_edge_t *edgeDyn;
00071
00072
00073 for (i=0; i<ne_sys_nodes(sys); i++) {
00074 nodeDyn = ne_sys_dyn_node(sys, i);
00075 (nodeDyn->fn)(i, (void *)sys, t, y, yNext, ne_sys_dyn_node_params(sys,i));
00076 }
00077
00078
00079 if (igraph_is_directed(sys->graph)) {
00080 for (j=0; j<ne_sys_edges(sys); i++) {
00081 edgeDyn = ne_sys_dyn_eid(sys, j);
00082 (edgeDyn->fn)(j, (int)IGRAPH_FROM(sys->graph, (igraph_integer_t)j), (int)IGRAPH_TO(sys->graph, (igraph_integer_t)j),
00083 (void *)sys, t, y, yNext, ne_sys_dyn_eid_params(sys,j));
00084 }
00085 }
00086 else {
00087 for (j=0; j<ne_sys_edges(sys); i++) {
00088 edgeDyn = ne_sys_dyn_eid(sys, j);
00089 (edgeDyn->fn)(j, (int)IGRAPH_FROM(sys->graph, (igraph_integer_t)j), (int)IGRAPH_TO(sys->graph, (igraph_integer_t)j),
00090 (void *)sys, t, y, yNext, ne_sys_dyn_eid_params(sys,j));
00091 (edgeDyn->fn)(j, (int)IGRAPH_TO(sys->graph, (igraph_integer_t)j), (int)IGRAPH_FROM(sys->graph, (igraph_integer_t)j),
00092 (void *)sys, t, y, yNext, ne_sys_dyn_eid_params(sys,j));
00093 }
00094 }
00095 }
00096