| 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.graph.Graph; | |
| 15 | import edu.uci.ics.jung.graph.Vertex; | |
| 16 | import edu.uci.ics.jung.utils.PredicateUtils; | |
| 17 | ||
| 18 | /** | |
| 19 | * A simple node importance ranker based on the degree of the node. The user can specify whether s/he wants | |
| 20 | * to use the indegree or the outdegree as the metric. If the graph is undirected this option is effectively | |
| 21 | * ignored. So for example, if the graph is directed and the user chooses to use in-degree, nodes with the highest | |
| 22 | * in-degree will be ranked highest and similarly nodes with the lowest in-degree will be ranked lowest. | |
| 23 | * <p> | |
| 24 | * A simple example of usage is: | |
| 25 | * <pre> | |
| 26 | * DegreeDistributionRanker ranker = new DegreeDistributionRanker(someGraph); | |
| 27 | * ranker.evaluate(); | |
| 28 | * ranker.printRankings(); | |
| 29 | * </pre> | |
| 30 | * | |
| 31 | * @author Scott White | |
| 32 | */ | |
| 33 | public class DegreeDistributionRanker extends AbstractRanker { | |
| 34 | public final static String KEY = "jung.algorithms.importance.DegreeDistributionRanker.RankScore"; | |
| 35 | ||
| 36 | private boolean mUseInDegree; | |
| 37 | private boolean directed; | |
| 38 | ||
| 39 | /** | |
| 40 | * Default constructor which assumes if the graph is directed the indegree is to be used. | |
| 41 | * @param graph the graph whose nodes are to be ranked based on indegree | |
| 42 | */ | |
| 43 | public DegreeDistributionRanker(Graph graph) { | |
| 44 | 1 | this(graph, true); |
| 45 | 1 | } |
| 46 | ||
| 47 | /** | |
| 48 | * This constructor allows you to specify whether to use indegree or outdegree. | |
| 49 | * @param graph the graph whose nodes are to be ranked based | |
| 50 | * @param useInDegree if <code>true</code>, indicates indegree is to be used, if <code>false</code> outdegree | |
| 51 | */ | |
| 52 | 5 | public DegreeDistributionRanker(Graph graph,boolean useInDegree) { |
| 53 | 5 | initialize(graph,true,false); |
| 54 | 5 | mUseInDegree = useInDegree; |
| 55 | 5 | directed = PredicateUtils.enforcesEdgeConstraint(getGraph(), Graph.DIRECTED_EDGE); |
| 56 | 5 | } |
| 57 | ||
| 58 | ||
| 59 | protected double evaluateIteration() { | |
| 60 | 5 | Vertex currentVertex = null; |
| 61 | 5 | for (Iterator it = getVertices().iterator(); it.hasNext();) { |
| 62 | 20015 | currentVertex = (Vertex) it.next(); |
| 63 | 20015 | if (directed) |
| 64 | { | |
| 65 | 10015 | if (mUseInDegree) |
| 66 | 10010 | setRankScore(currentVertex,(currentVertex).inDegree()); |
| 67 | else | |
| 68 | 5 | setRankScore(currentVertex,(currentVertex).outDegree()); |
| 69 | } | |
| 70 | else | |
| 71 | 10000 | setRankScore(currentVertex,currentVertex.degree()); |
| 72 | } | |
| 73 | 5 | normalizeRankings(); |
| 74 | ||
| 75 | 5 | return 0; |
| 76 | } | |
| 77 | ||
| 78 | public String getRankScoreKey() { | |
| 79 | 140105 | return KEY; |
| 80 | } | |
| 81 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |