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/power_law/power_law.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 src/power_law/power_law.c (limited to 'src/power_law/power_law.c') diff --git a/src/power_law/power_law.c b/src/power_law/power_law.c new file mode 100644 index 0000000..4733019 --- /dev/null +++ b/src/power_law/power_law.c @@ -0,0 +1,146 @@ +/** + * 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 samples a degree sequence from a discrete power-law + * distribution with a given exponent. + * + */ + + +#include +#include +#include +#include +#include + + +void usage(char *argv[]){ + printf("********************************************************************\n" + "** **\n" + "** -*- power_law -*- **\n" + "** **\n" + "** Sample 'N' elements from a power law degree distribution **\n" + "** P(k) ~= k^{gamma} **\n" + "** with degrees in the range [k_min, k_max], and print them **\n" + "** on STDOUT. **\n" + "** **\n" + "** If the obtained degree sequence is even, i.e., if the sum **\n" + "** of all the sampled degrees is even, the program returns 0 **\n" + "** (zero), otherwise it returns 1. **\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 2010-2017 (v.nicosia@qmul.ac.uk)\n\n" + "********************************************************************\n\n" + ); + printf("Usage: %s \n" , argv[0]); +} + + + +void create_distr(double *v, double gamma, int k_min, int k_max){ + int n, i; + double sum, new_sum; + + n = k_max-k_min + 1; + + sum = 0; + for(i=0; i v[i]) + i++; + return i; + +} + + +int main(int argc, char *argv[]){ + + double gamma, xi, val, q; + unsigned int N, i, distr_num, k, k_min, k_max, K; + double *distr; + + if (argc < 5){ + usage(argv); + exit(1); + } + + srand(time(NULL)); + + gamma = atof(argv[1]); + k_min = atoi(argv[2]); + k_max = atoi(argv[3]); + N = atoi(argv[4]); + + K = 0; + + distr_num = k_max - k_min + 1; + distr = malloc(distr_num * sizeof(double)); + + create_distr(distr, gamma, k_min, k_max); + + for(i=0; i