Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
peersimgrid release 1.0
[simgrid.git] / contrib / psg / src / peersim / dynamics / WireWS.java
1 /*
2  * Copyright (c) 2003-2005 The BISON Project
3  *
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.
7  *
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.
12  *
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.
16  *
17  */
18                 
19 package peersim.dynamics;
20
21 import peersim.graph.*;
22 import peersim.core.*;
23 import peersim.config.Configuration;
24
25 /**
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
31 */
32 public class WireWS extends WireGraph {
33
34
35 // ========================= fields =================================
36 // ==================================================================
37
38 /**
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}.
42  * @config
43  */
44 private static final String PAR_BETA = "beta";
45
46 /**
47  * The degree of the graph. See {@link GraphFactory#wireRingLattice}.
48  * Passed to {@link GraphFactory#wireWS}.
49  * @config
50  */
51 private static final String PAR_DEGREE = "k";
52
53 /**
54  * The degree of the regular graph
55  */
56 private final int k;
57
58 /**
59  * The degree of the regular graph
60  */
61 private final double beta;
62
63
64 // ==================== initialization ==============================
65 //===================================================================
66
67
68 /**
69  * Standard constructor that reads the configuration parameters.
70  * Invoked by the simulation engine.
71  * @param prefix the configuration prefix for this class
72  */
73 public WireWS(String prefix) {
74
75         super(prefix);
76         k = Configuration.getInt(prefix+"."+PAR_DEGREE);
77         beta = Configuration.getDouble(prefix+"."+PAR_BETA);
78 }
79
80
81 // ===================== public methods ==============================
82 // ===================================================================
83
84
85 /** calls {@link GraphFactory#wireWS}.*/
86 public void wire(Graph g) {
87
88         GraphFactory.wireWS(g,k,beta,CommonState.r);
89 }
90
91 }
92