2 * Copyright (c) 2003-2005 The BISON Project
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 package peersim.dynamics;
21 import peersim.graph.Graph;
22 import peersim.config.*;
23 import peersim.core.*;
26 * Wires a scale free graph using a method described in
27 * <a href="http://xxx.lanl.gov/abs/cond-mat/0106144">this paper</a>.
28 * It is an incremental technique, where the new nodes are connected to
29 * the two ends of an edge that is already in the network.
30 * This model always wires undirected links.
32 public class WireScaleFreeDM extends WireGraph {
35 //--------------------------------------------------------------------------
37 //--------------------------------------------------------------------------
40 * The number of edges added to each new
41 * node (apart from those forming the initial network) is twice this
45 private static final String PAR_EDGES = "k";
48 //--------------------------------------------------------------------------
50 //--------------------------------------------------------------------------
53 /** The number of edges created for a new node is 2*k. */
57 //--------------------------------------------------------------------------
59 //--------------------------------------------------------------------------
62 * Standard constructor that reads the configuration parameters.
63 * Invoked by the simulation engine.
64 * @param prefix the configuration prefix for this class
66 public WireScaleFreeDM(String prefix)
69 k = Configuration.getInt(prefix + "." + PAR_EDGES);
73 //--------------------------------------------------------------------------
75 //--------------------------------------------------------------------------
78 * Wires a scale free graph using a method described in
79 * <a href="http://xxx.lanl.gov/abs/cond-mat/0106144">this paper</a>.
80 * It is an incremental technique, where the new nodes are connected to
81 * the two ends of an edge that is already in the network.
82 * This model always wires undirected links.
84 public void wire(Graph g) {
87 int[] links = new int[4*k*nodes];
89 // Initial number of nodes connected as a clique
90 int clique = (k > 3 ? k : 3);
92 // Add initial edges, to form a clique
94 for (int i=0; i < clique; i++)
95 for (int j=0; j < clique; j++)
107 for (int i=clique; i < nodes; i++)
108 for (int l=0; l < k; l++)
110 int edge = CommonState.r.nextInt(len);
111 int m = links[edge*2];
112 int j = links[edge*2+1];