Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill another out of date script
[simgrid.git] / contrib / psg / src / peersim / vector / PeakDistribution.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.vector;
20
21 import peersim.config.*;
22 import peersim.core.*;
23
24
25 /**
26  * Initializes the values so that {@value #PAR_PEAKS} nodes have value
27  * {@value #PAR_VALUE}/{@value #PAR_PEAKS}, the rest {@value #PAR_LVALUE}
28  * (zero by default).
29  * @see VectControl
30  * @see peersim.vector
31  */
32 public class PeakDistribution extends VectControl
33 {
34
35 // --------------------------------------------------------------------------
36 // Parameters
37 // --------------------------------------------------------------------------
38
39 /** 
40  * The sum of values in the system, to be equally distributed between peak 
41  * nodes.
42  * @config
43  */
44 private static final String PAR_VALUE = "value";
45
46 /** 
47  * The value for the nodes that are not peaks. This parameter is optional,
48  * by default, the nodes that are
49  * not peaks are set to zero. This value overrides that behavior.
50  * @config
51  */
52 private static final String PAR_LVALUE = "background";
53
54 /** 
55  * The number of peaks in the system. If this value is greater than or equal to
56  * 1, it is interpreted as the actual number of peaks. If it is included in 
57  * the range [0, 1] it is interpreted as a percentage with respect to the
58  * current network size. Defaults to 1. 
59  * @config
60  */
61 private static final String PAR_PEAKS = "peaks";
62
63
64 // --------------------------------------------------------------------------
65 // Fields
66 // --------------------------------------------------------------------------
67
68 /** Total load */
69 private final Number lvalue;
70
71 /** Total load */
72 private final Number value;
73
74 /** Number of peaks */
75 private final double peaks;
76
77 // --------------------------------------------------------------------------
78 // Initialization
79 // --------------------------------------------------------------------------
80
81 /**
82  * Standard constructor that reads the configuration parameters.
83  * Invoked by the simulation engine.
84  * @param prefix the configuration prefix for this class
85  */
86 public PeakDistribution(String prefix)
87 {
88         super(prefix);
89         
90         peaks = Configuration.getDouble(prefix+"."+PAR_PEAKS, 1);
91         
92         if( setter.isInteger() )
93         {
94                 value=Long.valueOf(Configuration.getLong(prefix+"."+PAR_VALUE));
95                 lvalue=Long.valueOf(Configuration.getLong(prefix+"."+PAR_LVALUE,0));
96         }
97         else
98         {
99                 value = new Double(Configuration.getDouble(prefix + "." +
100                 PAR_VALUE));
101                 lvalue = new Double(Configuration.getDouble(prefix + "." +
102                 PAR_LVALUE,0));
103         }
104 }
105
106 // --------------------------------------------------------------------------
107 // Methods
108 // --------------------------------------------------------------------------
109
110 /**
111  * Initializes the values so that {@value #PAR_PEAKS} nodes have value
112  * {@value #PAR_VALUE}/{@value #PAR_PEAKS}, the rest zero.
113  * @return always false
114  */
115 public boolean execute()
116 {
117         int pn = (peaks < 1 ? (int) (peaks*Network.size()) : (int) peaks);
118         
119         if( setter.isInteger() )
120         {
121                 long v = value.longValue()/pn;
122                 long lv = lvalue.longValue();
123                 for (int i=0; i < pn; i++) setter.set(i, v);
124                 for (int i=pn; i < Network.size(); i++) setter.set(i,lv);
125         }
126         else
127         {
128                 double v = value.doubleValue()/pn;
129                 double lv = lvalue.doubleValue();
130                 for (int i=0; i < pn; i++) setter.set(i, v);
131                 for (int i=pn; i < Network.size(); i++) setter.set(i,lv);
132         }
133
134         return false;
135 }
136
137 // --------------------------------------------------------------------------
138
139 }