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.reports;
21 import peersim.config.Configuration;
22 import peersim.graph.GraphAlgorithms;
23 import peersim.util.IncrementalStats;
26 * Control to observe the clustering coefficient.
27 * @see GraphAlgorithms#clustering
29 public class Clustering extends GraphObserver
32 // ===================== fields =======================================
33 // ====================================================================
36 * The number of nodes to collect info about. Defaults to the size of the graph.
39 private static final String PAR_N = "n";
43 // ===================== initialization ================================
44 // =====================================================================
47 * Standard constructor that reads the configuration parameters.
48 * Invoked by the simulation engine.
49 * @param name the configuration prefix for this class
51 public Clustering(String name)
54 n = Configuration.getInt(name + "." + PAR_N, Integer.MAX_VALUE);
57 // ====================== methods ======================================
58 // =====================================================================
61 * Prints information about the clustering coefficient.
62 * It uses {@value #PAR_N} nodes to collect statistics.
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
69 public boolean execute()
71 IncrementalStats stats = new IncrementalStats();
73 for (int i = 0; i < n && i < g.size(); ++i) {
74 stats.add(GraphAlgorithms.clustering(g, i));
76 System.out.println(name + ": " + stats);