Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill another out of date script
[simgrid.git] / contrib / psg / src / peersim / reports / Clustering.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.reports;
20
21 import peersim.config.Configuration;
22 import peersim.graph.GraphAlgorithms;
23 import peersim.util.IncrementalStats;
24
25 /**
26  * Control to observe the clustering coefficient.
27  * @see GraphAlgorithms#clustering
28  */
29 public class Clustering extends GraphObserver
30 {
31
32 // ===================== fields =======================================
33 // ====================================================================
34
35 /**
36  * The number of nodes to collect info about. Defaults to the size of the graph.
37  * @config
38  */
39 private static final String PAR_N = "n";
40
41 private final int n;
42
43 // ===================== initialization ================================
44 // =====================================================================
45
46 /**
47  * Standard constructor that reads the configuration parameters.
48  * Invoked by the simulation engine.
49  * @param name the configuration prefix for this class
50  */
51 public Clustering(String name)
52 {
53         super(name);
54         n = Configuration.getInt(name + "." + PAR_N, Integer.MAX_VALUE);
55 }
56
57 // ====================== methods ======================================
58 // =====================================================================
59
60 /**
61 * Prints information about the clustering coefficient.
62 * It uses {@value #PAR_N} nodes to collect statistics.
63 * The output is
64 * produced by {@link IncrementalStats#toString}, over the values of
65 * the clustering coefficients of the given number of nodes.
66 * Clustering coefficients are calculated by {@link GraphAlgorithms#clustering}.
67 * @return always false
68 */
69 public boolean execute()
70 {
71         IncrementalStats stats = new IncrementalStats();
72         updateGraph();
73         for (int i = 0; i < n && i < g.size(); ++i) {
74                 stats.add(GraphAlgorithms.clustering(g, i));
75         }
76         System.out.println(name + ": " + stats);
77         return false;
78 }
79
80 }