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/bb_fitness/bb_fitness.c | 241 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 src/bb_fitness/bb_fitness.c (limited to 'src/bb_fitness/bb_fitness.c') diff --git a/src/bb_fitness/bb_fitness.c b/src/bb_fitness/bb_fitness.c new file mode 100644 index 0000000..9f67c74 --- /dev/null +++ b/src/bb_fitness/bb_fitness.c @@ -0,0 +1,241 @@ +/** + * 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 implements the fitness model proposed by Bianconi and + * Barabasi, where the attachment probability is: + * + * \Pi_{i->j} \propto a_j * k_j + * + * where a_j is the actractiveness of node j. + * + * + * References: + * + * [1] G. Bianconi, A.-L. Barabasi, " Competition and multiscaling in + * evolving networks". EPL-Europhys. Lett. 54 (2001), 436. + * + */ + + +#include +#include +#include + +#include "utils.h" +#include "cum_distr.h" + + +void usage(char *argv[]){ + printf("********************************************************************\n" + "** **\n" + "** -*- bb_fitness -*- **\n" + "** **\n" + "** Grow a network of 'N' nodes using the fitness model proposed **\n" + "** by Bianconi and Barabasi. **\n" + "** **\n" + "** The initial network is a clique of 'n0' nodes, and each new **\n" + "** node creates 'm' edges. The attachment probability is of **\n" + "** the form: **\n" + "** **\n" + "** P(i->j) ~ a_j * k_j **\n" + "** **\n" + "** where a_j is the attractiveness of node j. The values of **\n" + "** node attractiveness are sampled uniformly at random in **\n" + "** [0,1]. **\n" + "** **\n" + "** The program prints on STDOUT the edge-list of the final **\n" + "** graph. **\n" + "** **\n" + "** If 'FIT' is specified as a fourth parameter, the values **\n" + "** of node attractiveness are printed on STDERR. **\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 [SHOW]\n", argv[0]); +} + + + + +int init_network(unsigned int *I, unsigned int *J, int n0, + double *a, cum_distr_t *d){ + + unsigned int n, i, S_num; + + + S_num = 0; + for(n=0; n 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); + } + + I = malloc(N * m * sizeof(unsigned int)); + J = malloc(N * m * sizeof(unsigned int)); + a = malloc(N * sizeof(double)); + + init_fitness_uniform(a, N); + + K = bb_fitness(I, J, N, m, n0, a); + + dump_graph(I, J, K); + if (argc > 4 && !my_strcasecmp(argv[4], "SHOW")){ + dump_fitness(a, N); + } + free(a); + free(I); + free(J); + +} -- cgit v1.2.3