Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #1 from mquinson/master
[simgrid.git] / contrib / psg / src / peersim / vector / VectorObserver.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.core.*;
22 import peersim.util.*;
23
24 /**
25  * This class computes and reports statistics information about a vector.
26  * Provided statistics include average, max, min, variance,
27  * etc. Values are printed according to the string format of {@link 
28  * IncrementalStats#toString}.
29  * @see VectControl
30  * @see peersim.vector
31  */
32 public class VectorObserver extends VectControl {
33
34
35 /** The name of this observer in the configuration */
36 private final String prefix;
37
38
39 //--------------------------------------------------------------------------
40 //Initialization
41 //--------------------------------------------------------------------------
42
43 /**
44  * Standard constructor that reads the configuration parameters.
45  * Invoked by the simulation engine.
46  * @param prefix the configuration prefix for this class
47  */
48 public VectorObserver(String prefix) {
49
50         super(prefix);
51         this.prefix = prefix;
52 }
53
54 //--------------------------------------------------------------------------
55 // Methods
56 //--------------------------------------------------------------------------
57
58 /**
59  * Prints statistics information about a vector.
60  * Provided statistics include average, max, min, variance,
61  * etc. Values are printed according to the string format of {@link 
62  * IncrementalStats#toString}.
63  * @return always false
64  */
65 public boolean execute() {
66
67         IncrementalStats stats = new IncrementalStats();
68
69         for (int j = 0; j < Network.size(); j++)
70         {
71                 Number v = getter.get(j);
72                 stats.add( v.doubleValue() );
73         }
74         
75         System.out.println(prefix+": "+stats);  
76
77         return false;
78 }
79
80 }