• Main Page
  • Data Structures
  • Files
  • File List
  • Globals

ne_sim_map.c

00001 /*===========================================================================
00002  NetEvo Foundation Library
00003  Copyright (C) 2009, 2010 Thomas E. Gorochowski <tgorochowski@me.com>
00004  Bristol Centre for Complexity Sciences, University of Bristol, Bristol, UK
00005  ---------------------------------------------------------------------------- 
00006  NetEvo is a computing framework designed to allow researchers to investigate 
00007  evolutionary aspects of dynamical complex networks. By providing tools to 
00008  easily integrate each of these factors in a coherent way, it is hoped a 
00009  greater understanding can be gained of key attributes and features displayed 
00010  by complex systems.
00011  
00012  NetEvo is open-source software released under the Open Source Initiative 
00013  (OSI) approved Non-Profit Open Software License ("Non-Profit OSL") 3.0. 
00014  Detailed information about this licence can be found in the COPYING file 
00015  included as part of the source distribution.
00016  
00017  This library is distributed in the hope that it will be useful, but
00018  WITHOUT ANY WARRANTY; without even the implied warranty of
00019  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
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    /* We are in discrete time to find number of steps */
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    /* Store the initial conditions in the output */
00045    y = (double *)malloc(sizeof(double) * sysStates);
00046    memcpy(y, iy, sizeof(double) * sysStates);
00047    ne_dyn_vec_append_item(dyn, y);
00048    
00049    /* Run each step of the simulation */
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    /* Print dynamics to file if defined */
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    /* Loop through nodes */
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    /* Loop through edges */
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 

Generated on Thu Aug 26 2010 11:04:24 for NetEvo by  doxygen 1.7.1