| Line | Hits | Source |
|---|---|---|
| 1 | /* | |
| 2 | * Copyright (c) 2003, the JUNG Project and the Regents of the University | |
| 3 | * of California | |
| 4 | * All rights reserved. | |
| 5 | * | |
| 6 | * This software is open-source under the BSD license; see either | |
| 7 | * "license.txt" or | |
| 8 | * http://jung.sourceforge.net/license.txt for a description. | |
| 9 | */ | |
| 10 | package edu.uci.ics.jung.algorithms.importance; | |
| 11 | ||
| 12 | import java.util.Iterator; | |
| 13 | ||
| 14 | import edu.uci.ics.jung.algorithms.shortestpath.DijkstraDistance; | |
| 15 | import edu.uci.ics.jung.graph.Graph; | |
| 16 | import edu.uci.ics.jung.graph.Vertex; | |
| 17 | ||
| 18 | ||
| 19 | /** | |
| 20 | * A simple node importance ranker based on the total shortest path of the | |
| 21 | * node. More central nodes in a connected component will have smaller | |
| 22 | * overall shortest paths, and 'peripheral' nodes on the network will have | |
| 23 | * larger overall shortest paths. Runing this ranker on a graph with more | |
| 24 | * than one connected component will arbitarily mix nodes from both | |
| 25 | * components. For this reason you should probably run this ranker on one | |
| 26 | * component only (but that goes for all rankers). | |
| 27 | * | |
| 28 | * <p> | |
| 29 | * A simple example of usage is: | |
| 30 | * <pre> | |
| 31 | * BaryCenter ranker = new BaryCenter(someGraph); | |
| 32 | * ranker.evaluate(); | |
| 33 | * ranker.printRankings(); | |
| 34 | * </pre> | |
| 35 | * | |
| 36 | * @author Dan Bolser, Scott White | |
| 37 | */ | |
| 38 | public class BaryCenter extends AbstractRanker { | |
| 39 | ||
| 40 | public final static String KEY = | |
| 41 | "edu.uci.ics.jung.algorithms.importance.BaryCenter.RankScore"; | |
| 42 | ||
| 43 | /** | |
| 44 | * Constructor which initializes the algorithm | |
| 45 | * @param g the graph whose nodes are to be analyzed | |
| 46 | */ | |
| 47 | public BaryCenter(Graph g) | |
| 48 | 0 | { |
| 49 | 0 | initialize(g, true, false); |
| 50 | 0 | } |
| 51 | ||
| 52 | protected double evaluateIteration() | |
| 53 | { | |
| 54 | // Use this class to compute shortest path lengths. | |
| 55 | 0 | DijkstraDistance p = new DijkstraDistance(getGraph()); |
| 56 | ||
| 57 | 0 | Iterator i = getVertices().iterator(); |
| 58 | ||
| 59 | 0 | while (i.hasNext()) |
| 60 | { | |
| 61 | 0 | Vertex u = (Vertex) i.next(); |
| 62 | ||
| 63 | 0 | double baryCenter = 0; |
| 64 | ||
| 65 | 0 | Iterator j = p.getDistanceMap(u).values().iterator(); |
| 66 | ||
| 67 | 0 | while (j.hasNext()) |
| 68 | { | |
| 69 | 0 | baryCenter += ((Number) j.next()).doubleValue(); |
| 70 | } | |
| 71 | 0 | setRankScore(u, baryCenter); |
| 72 | } | |
| 73 | 0 | return 0; |
| 74 | } | |
| 75 | ||
| 76 | public String getRankScoreKey() | |
| 77 | { | |
| 78 | 0 | return KEY; |
| 79 | } | |
| 80 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |