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.*;
22 import peersim.core.*;
23 import peersim.config.Configuration;
26 * Takes a {@link Linkable} protocol and adds connections following the
27 * small-world model of Watts and Strogatz. Note that no
28 * connections are removed, they are only added. So it can be used in
29 * combination with other initializers.
30 * @see GraphFactory#wireWS
32 public class WireWS extends WireGraph {
35 // ========================= fields =================================
36 // ==================================================================
39 * The beta parameter of a Watts-Strogatz graph represents the probability for a
40 * node to be re-wired.
41 * Passed to {@link GraphFactory#wireWS}.
44 private static final String PAR_BETA = "beta";
47 * The degree of the graph. See {@link GraphFactory#wireRingLattice}.
48 * Passed to {@link GraphFactory#wireWS}.
51 private static final String PAR_DEGREE = "k";
54 * The degree of the regular graph
59 * The degree of the regular graph
61 private final double beta;
64 // ==================== initialization ==============================
65 //===================================================================
69 * Standard constructor that reads the configuration parameters.
70 * Invoked by the simulation engine.
71 * @param prefix the configuration prefix for this class
73 public WireWS(String prefix) {
76 k = Configuration.getInt(prefix+"."+PAR_DEGREE);
77 beta = Configuration.getDouble(prefix+"."+PAR_BETA);
81 // ===================== public methods ==============================
82 // ===================================================================
85 /** calls {@link GraphFactory#wireWS}.*/
86 public void wire(Graph g) {
88 GraphFactory.wireWS(g,k,beta,CommonState.r);