Coverage details for edu.uci.ics.jung.algorithms.importance.DegreeDistributionRanker

LineHitsSource
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) {
441        this(graph, true);
451    }
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      */
525    public DegreeDistributionRanker(Graph graph,boolean useInDegree) {
535        initialize(graph,true,false);
545        mUseInDegree = useInDegree;
555        directed = PredicateUtils.enforcesEdgeConstraint(getGraph(), Graph.DIRECTED_EDGE);
565    }
57  
58  
59     protected double evaluateIteration() {
605        Vertex currentVertex = null;
615        for (Iterator it = getVertices().iterator(); it.hasNext();) {
6220015            currentVertex = (Vertex) it.next();
6320015            if (directed)
64             {
6510015                if (mUseInDegree)
6610010                    setRankScore(currentVertex,(currentVertex).inDegree());
67                 else
685                    setRankScore(currentVertex,(currentVertex).outDegree());
69             }
70             else
7110000                setRankScore(currentVertex,currentVertex.degree());
72         }
735        normalizeRankings();
74  
755        return 0;
76     }
77  
78     public String getRankScoreKey() {
79140105        return KEY;
80     }
81 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.