/* * vim: ts=4 sw=4 et tw=0 wm=0 * * libcola - A library providing force-directed network layout using the * stress-majorization method subject to separation constraints. * * Copyright (C) 2006-2008 Monash University * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file LICENSE; if not, * write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * */ // generates a random graph with a power-law distribution of node degrees // the algorithm is pretty much the Barabasi-Albert model but with an extra step // so that I can guarantee the number of nodes in the graph. // We begin with an initial chain of m nodes. // Then, we add new nodes, connecting them to existing nodes v with probability // degree(v)/(sum all degrees) // We perform an extra step, looking for disconnected nodes, connecting them // to other nodes again with probability dependent on degree #include #include #include #include #include #include "graphlayouttest.h" void scale_free(const unsigned n = 50) { const unsigned m = 3; // begin with a chain of m nodes const double g=0.08; // edge density, every time we add a node we add 1+g*rand(0-1) edges // connecting them to existing nodes with probability based on degree unsigned d[n]; double defaultEdgeLength=100; vector es; CompoundConstraints cx,cy; for(unsigned i=0;ig) { es.push_back(make_pair(j,i)); d[j]++;d[i]++; sumdegree+=2; } } } for(unsigned i=0;imaxP) { maxP=r*p; end=j; } } if(end>i) { es.push_back(make_pair(i,end)); } else { es.push_back(make_pair(end,i)); } d[end]++;d[i]++; sumdegree+=2; } } valarray eweights(es.size()); sort(d,d+n); unsigned degree=0,ctr=0; printf("degree distribution:\n"); for(unsigned i=0;i