From 3aee2fd43e3059a699af2b63c6f2395e5a55e515 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Wed, 27 Sep 2017 15:06:31 +0100 Subject: First commit on github -- NetBunch 1.0 --- src/bbv/bbv.c | 335 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 335 insertions(+) create mode 100644 src/bbv/bbv.c (limited to 'src/bbv/bbv.c') diff --git a/src/bbv/bbv.c b/src/bbv/bbv.c new file mode 100644 index 0000000..60ddd5c --- /dev/null +++ b/src/bbv/bbv.c @@ -0,0 +1,335 @@ +/** + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + * . + * + * (c) Vincenzo Nicosia 2009-2017 -- + * + * This file is part of NetBunch, a package for complex network + * analysis and modelling. For more information please visit: + * + * http://www.complex-networks.net/ + * + * If you use this software, please add a reference to + * + * V. Latora, V. Nicosia, G. Russo + * "Complex Networks: Principles, Methods and Applications" + * Cambridge University Press (2017) + * ISBN: 9781107103184 + * + *********************************************************************** + * + * + * This program grows a weighted network using the model proposed by + * Barrat, Barthelemy, and Vespignani. + * + * References: + * + * [1] A. Barrat, M. Barthelemy, and A. Vespignani. "Weighted + * Evolving Networks: Coupling Topology and Weight + * Dynamics". Phys. Rev. Lett. 92 (2004), 228701. + * + * [2] A. Barrat, M. Barthelemy, and A. Vespignani. "Modeling the + * evolution of weighted networks". Phys. Rev. E 70 (2004), + * 066149. + * + */ + +#include +#include +#include +#include + +#include "cum_distr.h" + +void usage(char *argv[]){ + printf("********************************************************************\n" + "** **\n" + "** -*- bbv -*- **\n" + "** **\n" + "** Grow a weighted network of 'N' nodes using the model **\n" + "** proposed by Barrat-Barthelemy-Vespignani. **\n" + "** **\n" + "** The initial network is a clique of 'n0' nodes, and each new **\n" + "** node creates 'm' edges. All edges have an initial weight **\n" + "** equal to 'w0', and the attachment probability in of the **\n" + "** form: **\n" + "** **\n" + "** P(i->j) ~ s_j **\n" + "** **\n" + "** where s_j is the strength of node j. The parameter 'delta' **\n" + "** tunes the rearrangement of edge weights due to the **\n" + "** addition of a new edge. The degree, strength, and weight **\n" + "** distributions of the created graphs are power-laws, **\n" + "** whose esponents depend on the values of 'w0' and 'delta'. **\n" + "** **\n" + "********************************************************************\n" + " This is Free Software - You can use and distribute it under \n" + " the terms of the GNU General Public License, version 3 or later\n\n" + " (c) Vincenzo Nicosia 2009-2017 (v.nicosia@qmul.ac.uk)\n\n" + "********************************************************************\n\n" + ); + printf("Usage: %s \n", argv[0]); +} + + +typedef struct{ + int id; + double w; + double delta_w; +} link_t; + + +typedef struct { + int id; + int size; + int deg; + double s; + link_t *neighs; +} node_t; + + +/* create the initial graph as a clique of n0 nodes */ +void init_seed(node_t *G, int n0, double w0, cum_distr_t *d){ + + int i, j, n; + + for(i=0; i< n0; i++){ + G[i].neighs = malloc((n0-1) * sizeof(link_t)); + G[i].size = n0-1; + G[i].deg = n0-1; + n= 0; + for (j=0; j i){ + tot_w += G[i].neighs[j].w; + printf("%d %d %g\n", i, G[i].neighs[j].id, G[i].neighs[j].w); + } + } + } +} + + +/* grow a weighted graph using the BBV model */ +node_t* bbv(unsigned int N, unsigned int n0, unsigned int m, double w0, double delta){ + + node_t *G; + int t, i, j; + cum_distr_t *distr = NULL; + int *tmp_neighs; + + distr = cum_distr_init(N * m); + + + G = malloc(N * sizeof(node_t)); + tmp_neighs = malloc(m * sizeof(int)); + + init_seed(G, n0, w0, distr); + + + for(t=n0; t n0){ + fprintf(stderr, "n0 cannot be smaller than m\n"); + exit(1); + + } + if (n0<1){ + fprintf(stderr, "n0 must be positive\n"); + exit(1); + } + + if (m < 1){ + fprintf(stderr, "m must be positive\n"); + exit(1); + } + + if (w0 <= 0.0){ + fprintf(stderr, "w0 must be positive\n"); + exit(1); + } + + if (delta < 0.0){ + fprintf(stderr, "delta must be positive\n"); + exit(1); + } + + + net = bbv(N, n0, m, w0, delta); + dump_net(net, N); + + for(i=0; i