nct.graph.util
Class DegreePreservingRandomizer<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>

java.lang.Object
  extended by nct.graph.util.DegreePreservingRandomizer<NodeType,WeightType>
All Implemented Interfaces:
GraphRandomizer<NodeType,WeightType>
Direct Known Subclasses:
ThresholdRandomizer

public class DegreePreservingRandomizer<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
extends java.lang.Object
implements GraphRandomizer<NodeType,WeightType>

This class shuffles the edges in a graph while preserving the degree of each node in the class and only swapping edges with "similar" edge weights. In the default implementation of this class "similar" means equal weight. To create an alternative definition of "similar" simply extend this class and re-implement the weightsSimilar() method.


Field Summary
protected  boolean ignoreWeights
           
protected  java.util.Random rand
           
 
Constructor Summary
DegreePreservingRandomizer(java.util.Random r, boolean ignoreWeights)
           
 
Method Summary
 void randomize(Graph<NodeType,WeightType> g)
          The method that performs the randomization.
 boolean weightsSimilar(WeightType a, WeightType b)
          Checks to see if the given weights are "similar".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rand

protected java.util.Random rand

ignoreWeights

protected boolean ignoreWeights
Constructor Detail

DegreePreservingRandomizer

public DegreePreservingRandomizer(java.util.Random r,
                                  boolean ignoreWeights)
Method Detail

randomize

public void randomize(Graph<NodeType,WeightType> g)
The method that performs the randomization.

Specified by:
randomize in interface GraphRandomizer<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
Parameters:
g - The Graph whose edges are to be randomized.

weightsSimilar

public boolean weightsSimilar(WeightType a,
                              WeightType b)
Checks to see if the given weights are "similar". The default (this) implementation treats weights as similar if they are equal. To get different behavior simply extend this class and override this method.

Parameters:
a - Weight a to be compared.
b - Weight b to be compared.
Returns:
true if if the weights are "similar", false otherwise.