2 * Created on Jul 11, 2008
4 * Copyright (c) 2008, the JUNG Project and the Regents of the University
8 * This software is open-source under the BSD license; see either
10 * http://jung.sourceforge.net/license.txt for a description.
12 package edu.uci.ics.jung.algorithms.scoring.util;
14 import org.apache.commons.collections15.Transformer;
16 import edu.uci.ics.jung.graph.Graph;
17 import edu.uci.ics.jung.graph.util.EdgeType;
20 * Assigns weights to directed edges (the edge of the vertex/edge pair) depending on
21 * whether the vertex is the edge's source or its destination.
22 * If the vertex v is the edge's source, assigns 1/outdegree(v).
23 * Otherwise, assigns 1/indegree(w).
24 * Throws <code>IllegalArgumentException</code> if the edge is not directed.
26 public class UniformInOut<V,E> implements Transformer<VEPair<V,E>, Double>
29 * The graph for which the edge weights are defined.
31 protected Graph<V,E> graph;
34 * Creates an instance for the specified graph.
35 * @param graph the graph for which the edge weights will be defined
37 public UniformInOut(Graph<V,E> graph)
43 * @see org.apache.commons.collections15.Transformer#transform(Object)
44 * @throws IllegalArgumentException
46 public Double transform(VEPair<V,E> ve_pair)
50 if (graph.getEdgeType(e) != EdgeType.DIRECTED)
51 throw new IllegalArgumentException("This transformer only" +
52 " operates on directed edges");
53 return 1.0 / (graph.isSource(v, e) ?