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

ne_dyn.c

Go to the documentation of this file.
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  ============================================================================*/
00025 #include "ne_dyn.h"
00026 #include <gsl/gsl_rng.h>
00027 #include <string.h>
00028 
00029 
00030 /* Global random number generator (from GSL library). */
00031 extern gsl_rng* neRng;
00032 
00034 ne_dyn_node_lib_t *neNodeDynLib = NULL;
00035 
00037 ne_dyn_edge_lib_t *neEdgeDynLib = NULL;
00038 
00039 
00040 void ne_dyn_finalise (void)
00041 {
00042    ne_dyn_node_lib_t *curNodePtr;
00043    ne_dyn_edge_lib_t *curEdgePtr;
00044    
00045    curNodePtr = neNodeDynLib;
00046    curEdgePtr = neEdgeDynLib;
00047    
00048    /* Free all memory used by the dynamics library */
00049    while (curNodePtr != NULL) {
00050       neNodeDynLib = curNodePtr->next;
00051       free(curNodePtr);
00052       curNodePtr = neNodeDynLib;
00053    }
00054    
00055    /* Free all memory used by the dynamics library */
00056    while (curEdgePtr != NULL) {
00057       neEdgeDynLib = curEdgePtr->next;
00058       free(curEdgePtr);
00059       curEdgePtr = neEdgeDynLib;
00060    }
00061 }
00062 
00063 
00064 ne_err_code_t ne_dyn_add_node_dyn (ne_dyn_node_t *nodeDyn)
00065 {
00066    ne_dyn_node_lib_t *newDyn, *oldStart;
00067    
00068    /* Create the new item */
00069    newDyn = (ne_dyn_node_lib_t *)malloc(sizeof(ne_dyn_node_lib_t));
00070    
00071    /* Hold the current start item */
00072    oldStart = neNodeDynLib;
00073    
00074    /* Setup the new item */
00075    newDyn->nodeDyn = nodeDyn;
00076    newDyn->next = oldStart;
00077    
00078    /* Repoint the start of the list */
00079    neNodeDynLib = newDyn;
00080    
00081    return NE_SUCCESS;
00082 }
00083 
00084 
00085 ne_err_code_t ne_dyn_add_edge_dyn (ne_dyn_edge_t *edgeDyn)
00086 {
00087    ne_dyn_edge_lib_t *newDyn, *oldStart;
00088    
00089    /* Create the new item */
00090    newDyn = (ne_dyn_edge_lib_t *)malloc(sizeof(ne_dyn_edge_lib_t));
00091    
00092    /* Hold the current start item */
00093    oldStart = neEdgeDynLib;
00094    
00095    /* Setup the new item */
00096    newDyn->edgeDyn = edgeDyn;
00097    newDyn->next = oldStart;
00098    
00099    /* Repoint the start of the list */
00100    neEdgeDynLib = newDyn;
00101    
00102    return NE_SUCCESS;
00103 }
00104 
00105 
00106 ne_err_code_t ne_dyn_remove_node_dyn (const char *name)
00107 {
00108    ne_dyn_node_lib_t *curPtr, *prevPtr;
00109    
00110    /* Check that the list exists */
00111    if (neNodeDynLib == NULL) {
00112       return NE_FAILURE;
00113    }
00114    
00115    /* Initialise the pointers */
00116    curPtr = neNodeDynLib;
00117    prevPtr = NULL;
00118    
00119    do {
00120       
00121       /* Check to see if found dynamic */
00122       if (strcmp(name, curPtr->nodeDyn->name) == 0) {
00123       
00124          /* We have found the dynamic reshuffle pointers */
00125          if (prevPtr == NULL) {
00126             neNodeDynLib = curPtr->next;
00127          }
00128          else {
00129             prevPtr->next = curPtr->next;
00130          }
00131          
00132          /* Deallocate the dynamic item */
00133          free(curPtr->nodeDyn);
00134          free(curPtr);
00135          
00136          return NE_SUCCESS;
00137       }
00138       
00139       /* Update the pointers to the next item */
00140       prevPtr = curPtr;
00141       curPtr = curPtr->next;
00142       
00143    } while (curPtr != NULL);
00144    
00145    /* Didn't find dynamic */
00146    return NE_FAILURE;
00147 }
00148 
00149 
00150 ne_err_code_t ne_dyn_remove_edge_dyn (const char *name)
00151 {
00152    ne_dyn_edge_lib_t *curPtr, *prevPtr;
00153    
00154    /* Check that the list exists */
00155    if (neEdgeDynLib == NULL) {
00156       return NE_FAILURE;
00157    }
00158    
00159    /* Initialise the pointers */
00160    curPtr = neEdgeDynLib;
00161    prevPtr = NULL;
00162    
00163    do {
00164       
00165       /* Check to see if found dynamic */
00166       if (strcmp(name, curPtr->edgeDyn->name) == 0) {
00167          
00168          /* We have found the dynamic reshuffle pointers */
00169          if (prevPtr == NULL) {
00170             neEdgeDynLib = curPtr->next;
00171          }
00172          else {
00173             prevPtr->next = curPtr->next;
00174          }
00175          
00176          /* Deallocate the dynamic item */
00177          free(curPtr->edgeDyn);
00178          free(curPtr);
00179          
00180          return NE_SUCCESS;
00181       }
00182       
00183       /* Update the pointers to the next item */
00184       prevPtr = curPtr;
00185       curPtr = curPtr->next;
00186       
00187    } while (curPtr != NULL);
00188    
00189    /* Didn't find dynamic */
00190    return NE_FAILURE;   
00191 }
00192 
00193 
00194 ne_dyn_node_t * ne_dyn_find_node_dyn (const char *name)
00195 {
00196    ne_dyn_node_lib_t *curPtr;
00197    
00198    /* Initialise the current pointer to the start */
00199    curPtr = neNodeDynLib;
00200    
00201    /* Look through the linked list - ends with NULL pointer */
00202    while (curPtr != NULL) {
00203       
00204       /* Check the names */
00205       if (strcmp(name, curPtr->nodeDyn->name) == 0) {
00206          /* Found the dynamic return a pointer to this */
00207          return curPtr->nodeDyn;
00208       }
00209       
00210       /* Update the pointer to next item in list */
00211       curPtr = curPtr->next;
00212    }
00213    
00214    /* Didn't find the name in the list */
00215    return NULL;
00216 }
00217 
00218 
00219 ne_dyn_edge_t * ne_dyn_find_edge_dyn (const char *name)
00220 {
00221    ne_dyn_edge_lib_t *curPtr;
00222    
00223    /* Initialise the current pointer to the start */
00224    curPtr = neEdgeDynLib;
00225    
00226    /* Look through the linked list - ends with NULL pointer */
00227    while (curPtr != NULL) {
00228       
00229       /* Check the names */
00230       if (strcmp(name, curPtr->edgeDyn->name) == 0) {
00231          
00232          /* Found the dynamic return a pointer to this */
00233          return curPtr->edgeDyn;
00234       }
00235       
00236       /* Update the pointer to next item in list */
00237       curPtr = curPtr->next;
00238    } 
00239    
00240    /* Didn't find the name in the list */
00241    return NULL;
00242 }
00243 

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