2 * Copyright (c) 2008, the JUNG Project and the Regents of the University
6 * This software is open-source under the BSD license; see either
8 * http://jung.sourceforge.net/license.txt for a description.
9 * Created on Jul 14, 2008
12 package edu.uci.ics.jung.algorithms.scoring.util;
14 import org.apache.commons.collections15.Transformer;
16 import edu.uci.ics.jung.graph.Hypergraph;
17 import edu.uci.ics.jung.graph.util.EdgeType;
20 * An edge weight function that assigns weights as uniform
21 * transition probabilities.
22 * For undirected edges, returns 1/degree(v) (where 'v' is the
23 * vertex in the VEPair.
24 * For directed edges, returns 1/outdegree(source(e)) (where 'e'
25 * is the edge in the VEPair).
26 * Throws an <code>IllegalArgumentException</code> if the input
27 * edge is neither EdgeType.UNDIRECTED nor EdgeType.DIRECTED.
30 public class UniformDegreeWeight<V, E> implements
31 Transformer<VEPair<V, E>, Double>
33 private Hypergraph<V, E> graph;
36 * Creates an instance for the specified graph.
38 public UniformDegreeWeight(Hypergraph<V, E> graph)
44 * @see org.apache.commons.collections15.Transformer#transform(java.lang.Object)
46 public Double transform(VEPair<V, E> ve_pair)
50 EdgeType edge_type = graph.getEdgeType(e);
51 if (edge_type == EdgeType.UNDIRECTED)
52 return 1.0 / graph.degree(v);
53 if (edge_type == EdgeType.DIRECTED)
54 return 1.0 / graph.outDegree(graph.getSource(e));
55 throw new IllegalArgumentException("can't handle edge type: " + edge_type);