View Javadoc
1   /*
2   * Copyright (c) 2003, The JUNG Authors 
3   *
4   * All rights reserved.
5   *
6   * This software is open-source under the BSD license; see either
7   * "license.txt" or
8   * https://github.com/jrtom/jung/blob/master/LICENSE for a description.
9   */
10  package edu.uci.ics.jung.algorithms.importance;
11  
12  import java.util.HashMap;
13  import java.util.Map;
14  import java.util.Set;
15  
16  
17  /**
18   * This class provides basic infrastructure for relative authority algorithms that compute the importance of nodes
19   * relative to one or more root nodes. The services provided are:
20   * <ul>
21   * <li>The set of root nodes (priors) is stored and maintained</li>
22   * <li>Getters and setters for the prior rank score are provided</li>
23   * </ul>
24   * 
25   * @author Scott White
26   */
27  public abstract class RelativeAuthorityRanker<V,E> extends AbstractRanker<V,E> {
28      private Set<V> mPriors;
29      /**
30       * The default key used for the user datum key corresponding to prior rank scores.
31       */
32  
33      protected Map<V,Number> priorRankScoreMap = new HashMap<V,Number>();
34      /**
35       * Cleans up all of the prior rank scores on finalize.
36       */
37      @Override
38      protected void finalizeIterations() {
39          super.finalizeIterations();
40          priorRankScoreMap.clear();
41      }
42  
43      /**
44       * Retrieves the value of the prior rank score.
45       * @param v the root node (prior)
46       * @return the prior rank score
47       */
48      protected double getPriorRankScore(V v) {
49      	return priorRankScoreMap.get(v).doubleValue();
50  
51      }
52  
53      /**
54       * Allows the user to specify a value to set for the prior rank score
55       * @param v the root node (prior)
56       * @param value the score to set to
57       */
58      public void setPriorRankScore(V v, double value) {
59      	this.priorRankScoreMap.put(v, value);
60      }
61  
62      /**
63       * Retrieves the set of priors.
64       * @return the set of root nodes (priors)
65       */
66      protected Set<V> getPriors() { return mPriors; }
67  
68      /**
69       * Specifies which vertices are root nodes (priors).
70       * @param priors the root nodes
71       */
72      protected void setPriors(Set<V> priors) { mPriors = priors; }
73  }