- java.lang.Object
-
- org.jgrapht.generate.netgen.Distributor<K>
-
- Type Parameters:
K
- the element type.
public class Distributor<K> extends java.lang.Object
Distributes value units among keys given lower and upper bound constraints.Let's define a set of elements $\{k_1, k_2, \dots, k_n\}$. For every element a set of lower bounds $\{l_1, l_2, \dots, l_t\}$ and upper bounds $\{u_1, u_2, \dots, u_p\}$ is specified. The problem is to randomly distribute a number of abstract value units $V$ among keys such that the lower bound and upper bound constraints are satisfied. This class solves this problem.
- See Also:
NetworkGenerator
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.util.function.Function<K,java.lang.Integer>>
lowerBounds
Lower bounds.private java.util.Random
rng
Random number generator used by this distributor.private java.util.List<java.util.function.Function<K,java.lang.Integer>>
upperBounds
Upper bounds.
-
Constructor Summary
Constructors Constructor Description Distributor()
Creates a Distributor using random seed.Distributor(long seed)
Creates a distributor using the specifiedseed
.Distributor(java.util.Random rng)
Creates a distributor which uses the random number generatowrng
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLowerBound(java.util.function.Function<K,java.lang.Integer> lowerBound)
Adds a lower bound function.void
addUpperBound(java.util.function.Function<K,java.lang.Integer> upperBound)
Adds an upper bounding function.private java.util.List<java.lang.Integer>
computeLowerBounds(java.util.List<K> keys)
Finds a maximum lower bound for every key.private Pair<java.util.List<java.lang.Integer>,java.lang.Long>
computeSuffixSum(java.util.List<java.lang.Integer> bounds)
Computes a suffix sum of thebounds
.private java.util.List<java.lang.Integer>
computeUpperBounds(java.util.List<K> keys)
Finds a minimum lower bound for every key.java.util.List<java.lang.Integer>
getDistribution(java.util.List<K> keys, int valueNum)
Computes and returns a value distribution for the list of keys.
-
-
-
Field Detail
-
rng
private final java.util.Random rng
Random number generator used by this distributor.
-
lowerBounds
private final java.util.List<java.util.function.Function<K,java.lang.Integer>> lowerBounds
Lower bounds.
-
upperBounds
private final java.util.List<java.util.function.Function<K,java.lang.Integer>> upperBounds
Upper bounds.
-
-
Constructor Detail
-
Distributor
public Distributor()
Creates a Distributor using random seed.
-
Distributor
public Distributor(long seed)
Creates a distributor using the specifiedseed
.- Parameters:
seed
- the seed for the random number generator.
-
Distributor
public Distributor(java.util.Random rng)
Creates a distributor which uses the random number generatowrng
.- Parameters:
rng
- a random number generator to use.
-
-
Method Detail
-
addUpperBound
public void addUpperBound(java.util.function.Function<K,java.lang.Integer> upperBound)
Adds an upper bounding function. This function must be defined for all keys.- Parameters:
upperBound
- an upper bound function.
-
addLowerBound
public void addLowerBound(java.util.function.Function<K,java.lang.Integer> lowerBound)
Adds a lower bound function. This function must be defined for all keys.- Parameters:
lowerBound
- a lower bound function.
-
computeLowerBounds
private java.util.List<java.lang.Integer> computeLowerBounds(java.util.List<K> keys)
Finds a maximum lower bound for every key.- Parameters:
keys
- list of keys.- Returns:
- the computed key lower bounds.
-
computeUpperBounds
private java.util.List<java.lang.Integer> computeUpperBounds(java.util.List<K> keys)
Finds a minimum lower bound for every key.- Parameters:
keys
- a list of keys.- Returns:
- the computed key upper bound.
-
computeSuffixSum
private Pair<java.util.List<java.lang.Integer>,java.lang.Long> computeSuffixSum(java.util.List<java.lang.Integer> bounds)
Computes a suffix sum of thebounds
. Returns computed suffix sum and the sum of all elements in thebounds list
.- Parameters:
bounds
- list of integers.- Returns:
- computed pair of suffix sum list and a sum of all elements.
-
getDistribution
public java.util.List<java.lang.Integer> getDistribution(java.util.List<K> keys, int valueNum)
Computes and returns a value distribution for the list of keys. The resulting distribution will satisfy the (possibly empty) sets of lower and upper bound constraints. Distributed values will be in the same order as the keys in the key list.- Parameters:
keys
- the list of keys.valueNum
- the number of abstract value units to distribute.- Returns:
- the computed value distribution.
-
-