I'm trying to construct a scale-free network using the Barabasi-Albert algorithm in C++. I've seen some other questions on here concerning the algorithm (and I'm using an algorithm similar to this one), but I wanted to make sure that I wasn't misunderstanding something about the mathematics. The algorithm I am using has the following steps:
- Create an initial completely connected graph with m0 = 10 nodes.
- Create a new node -- call this new node n.
- Select a node i in the original connected graph.
- Draw a random number r from a uniform distribution on [0,1].
- Set p = k_i/k_tot, where k_i is the number of edges connected to node i and k_tot is the sum of k_j for all edges in the original connected graph.
- If r
- Repeat steps 2-6 until the graph has N = 30,000 nodes.
When I use this algorithm, the resulting degree distribution is exponential and not a power law as it should be. When plotted on a linear-log plot, the degree distribution is a striaght line over several orders of magnitude; plotted on a log-log plot, the degree distribution is very clearly a curve.
What am I doing wrong? Is my algorithm correct, or is there something fundamental I've misunderstand? By the way: the exponential distribution resulting from my present code is actually really pretty, so I wonder if I've instead reproduced some other well known process instead of preferential attachment.