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 java.util.Iterator;
23 import peersim.config.Configuration;
24 import peersim.util.IncrementalStats;
27 * Reports statistics about connectivity properties of the network, such as
28 * weakly or strongly connected clusters.
30 public class ConnectivityObserver extends GraphObserver
33 //--------------------------------------------------------------------------
35 //--------------------------------------------------------------------------
38 * The parameter used to request cluster size statistics instead of the usual
39 * list of clusters. Not set by default.
42 private static final String PAR_STATS = "stats";
45 * Defines the types of connected clusters to discover.
48 * <li>"wcc": weakly connected clusters</li>
49 * <li>"scc": strongly connected clusters</li>
54 private static final String PAR_TYPE = "type";
56 //--------------------------------------------------------------------------
58 //--------------------------------------------------------------------------
60 /** {@link #PAR_STATS} */
61 private final boolean sizestats;
63 /** {@link #PAR_TYPE} */
64 private final String type;
66 //--------------------------------------------------------------------------
68 //--------------------------------------------------------------------------
71 * Standard constructor that reads the configuration parameters.
72 * Invoked by the simulation engine.
73 * @param name the configuration prefix for this class
75 public ConnectivityObserver(String name)
78 sizestats = Configuration.contains(name + "." + PAR_STATS);
79 type = Configuration.getString(name + "." + PAR_TYPE,"wcc");
82 //--------------------------------------------------------------------------
84 //--------------------------------------------------------------------------
87 * Prints information about clusters.
88 * If parameter {@value #PAR_STATS} is defined then the output is
89 * produced by {@link IncrementalStats#toString}, over the sizes of the
91 * Otherwise one line is printed that contains the string representation of
92 * a map, that holds cluster IDs mapped to cluster sizes.
93 * The meaning of the cluster IDs is not specified, but is printed for
95 * @return always false
96 * @see peersim.graph.GraphAlgorithms#tarjan
97 * @see peersim.graph.GraphAlgorithms#weaklyConnectedClusters
99 public boolean execute()
104 if(type.equals("wcc"))
105 clst=ga.weaklyConnectedClusters(g);
106 else if(type.equals("scc"))
109 throw new RuntimeException(
110 "Unsupported connted cluster type '"+type+"'");
113 System.out.println(name + ": " + clst);
115 IncrementalStats stats = new IncrementalStats();
116 Iterator it = clst.values().iterator();
117 while (it.hasNext()) {
118 stats.add(((Integer) it.next()).intValue());
120 System.out.println(name + ": " + stats);