From cca66b9ec4e494c1d919bff0f71a820d8afab1fa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:24:48 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- .../adaptagrams/libcola/tests/scale_free.cpp | 135 +++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/3rdparty/adaptagrams/libcola/tests/scale_free.cpp (limited to 'src/3rdparty/adaptagrams/libcola/tests/scale_free.cpp') diff --git a/src/3rdparty/adaptagrams/libcola/tests/scale_free.cpp b/src/3rdparty/adaptagrams/libcola/tests/scale_free.cpp new file mode 100644 index 0000000..d9c2934 --- /dev/null +++ b/src/3rdparty/adaptagrams/libcola/tests/scale_free.cpp @@ -0,0 +1,135 @@ +/* + * 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