Class Distributor<K>

  • Type Parameters:
    K - the element type.

    public class Distributor<K>
    extends 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.

    Author:
    Timofey Chudakov
    See Also:
    NetworkGenerator
    • Constructor Detail

      • Distributor

        public Distributor()
        Creates a Distributor using random seed.
      • Distributor

        public Distributor​(long seed)
        Creates a distributor using the specified seed.
        Parameters:
        seed - the seed for the random number generator.
      • Distributor

        public Distributor​(Random rng)
        Creates a distributor which uses the random number generatow rng.
        Parameters:
        rng - a random number generator to use.
    • Method Detail

      • addUpperBound

        public void addUpperBound​(Function<K,​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​(Function<K,​Integer> lowerBound)
        Adds a lower bound function. This function must be defined for all keys.
        Parameters:
        lowerBound - a lower bound function.
      • getDistribution

        public List<Integer> getDistribution​(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.