uint8_t graph_threshold_components( graph_t *gin, graph_t *gout, uint32_t cmplimit, uint32_t igndis, void *opt, uint8_t (*init)(graph_t *g), uint8_t (*remove)( graph_t *g, double *space, array_t *edges, graph_edge_t *edge), uint8_t (*recalc)( graph_t *g, graph_edge_t *edge) ) { uint32_t nnodes; uint64_t ncmps; double *space; array_t edges; graph_edge_t edge; edges.data = NULL; space = NULL; nnodes = graph_num_nodes(gin); if (cmplimit > nnodes) goto fail; if (array_create(&edges, sizeof(graph_edge_t), 10)) goto fail; if (graph_copy(gin, gout)) goto fail; if (stats_cache_init(gout)) goto fail; space = calloc(nnodes,sizeof(double)); if (space == NULL) goto fail; init(gout); ncmps = stats_num_components(gout, igndis, NULL, NULL); while (ncmps < cmplimit) { array_clear(&edges); if (remove(gout, space, &edges, &edge)) goto fail; ncmps = stats_num_components(gout, igndis, NULL, NULL); if (ncmps >= cmplimit) break; if (recalc(gout, &edge)) goto fail; } free(space); array_free(&edges); return 0; fail: if (space != NULL) free(space); if (edges.data != NULL) array_free(&edges); return 1; }
void graph_spread_disease(graph *g, graph *n) { int i, j; graph_copy(g, n); for(i = 0; i < NETWORK_SIZE; i++) { if(g->states[i] == SUSCEPTIBLE) { } else if(g->states[i] == LATENT) { } else if(g->states[i] == INFECTIOUS) { for(j = 0; j < NETWORK_SIZE; j++) { if(graph_edge_exists(i, j, g)) { } } } else if(g->states[i] == RECOVERED) { } g->counter[i]++; } }
graph_t *graph_plus_node(const graph_t *g, const node_t *n) { graph_t *copy; if(g) copy = graph_copy(g); else copy = init_graph(); add_node(copy, n); return copy; }
uint8_t graph_threshold_edges( graph_t *gin, graph_t *gout, uint32_t nedges, uint32_t flags, void *opt, uint8_t (*init)(graph_t *g), uint8_t (*remove)( graph_t *g, double *space, array_t *edges, graph_edge_t *edge), uint8_t (*recalc)( graph_t *g, graph_edge_t *edge) ) { uint64_t i; uint32_t nnodes; double *space; array_t edges; graph_edge_t edge; edges.data = NULL; space = NULL; nnodes = graph_num_nodes(gin); if (array_create(&edges, sizeof(graph_edge_t), 10)) goto fail; if (graph_copy(gin, gout)) goto fail; if (stats_cache_init(gout)) goto fail; space = calloc(nnodes,sizeof(double)); if (space == NULL) goto fail; init(gout); for (i = 0; i < nedges; i++) { array_clear(&edges); if (remove(gout, space, &edges, &edge)) goto fail; if (i == nedges -1) break; if (recalc(gout, &edge)) goto fail; } array_free(&edges); free(space); return 0; fail: if (edges.data != NULL) array_free(&edges); if (space != NULL) free(space); return 1; }
/* removes all nodes of *right that exist in *left from *left */ graph_t *minus(const graph_t *left, const graph_t *right) { list_t *temp; graph_t *copy = graph_copy(left); for(temp = right->nodes; temp; temp = temp->next) { printf("removing temp = %x\n", (int) temp); int i = remove_node(copy, temp->data); if(i) printf("not removed!\n"); } return copy; }
struct sys * sys_copy(struct sys *sys) { struct sys *copy; int i; copy = malloc(sizeof(struct sys)); memcpy(copy, sys, sizeof(struct sys)); copy->graph = graph_copy(sys->graph); copy->sel = sel_copy(sys->sel); copy->visible = sel_copy(sys->visible); copy->frames = malloc(copy->nframesalloc * sizeof(struct frame)); for (i = 0; i < sys_get_frame_count(sys); i++) copy->frames[i].atoms = atoms_copy(sys->frames[i].atoms); return (copy); }
uint8_t graph_threshold_chira( graph_t *gin, graph_t *gout, uint32_t edgelimit, uint32_t flags, void *opt, uint8_t (*init)(graph_t *g), uint8_t (*remove)( graph_t *g, double *space, array_t *edges, graph_edge_t *edge), uint8_t (*recalc)( graph_t *g, graph_edge_t *edge) ) { uint32_t nnodes; uint64_t i; graph_t lgin; array_t edges; graph_edge_t edge; graph_t gmod; double *space; double mod; double maxmod; uint32_t ncmps; uint32_t *components; maxmod = -1.0; space = NULL; edges.data = NULL; gmod.neighbours = NULL; components = NULL; nnodes = graph_num_nodes(gin); if (graph_copy(gin, &lgin)) goto fail; if (stats_cache_init(&lgin)) goto fail; if (array_create(&edges, sizeof(graph_edge_t), 10)) goto fail; components = calloc(nnodes,sizeof(uint32_t)); if (components == NULL) goto fail; space = calloc(nnodes,sizeof(double)); if (space == NULL) goto fail; init(&lgin); for (i = 0; i < edgelimit; i++) { array_clear(&edges); if (remove(&lgin, space, &edges, &edge)) goto fail; /* * modularity is calculated on the original graph, with * the discovered components as the community structure */ ncmps = stats_num_components(&lgin, 0, NULL, components); mod = stats_chira(gin, ncmps, components); if (mod >= maxmod) { maxmod = mod; if (gmod.neighbours != NULL) graph_free(&gmod); gmod.neighbours = NULL; if (graph_copy(&lgin, &gmod)) goto fail; } if (recalc(&lgin, &edge)) goto fail; } if (graph_copy(&gmod, gout)) goto fail; free(space); array_free(&edges); return 0; fail: if (space != NULL) free(space); if (edges.data != NULL) array_free(&edges); if (gmod.neighbours != NULL) graph_free(&gmod); if (components != NULL) free(components); return 1; }