Class Calculations


  • public final class Calculations
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Calculations()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double distance​(int x1, int y1, int x2, int y2)
      Calculates the distance between two sets of coordinates
      static double distance​(java.awt.Point p1, java.awt.Point p2)
      Calculates the distance between two points
      static double distance​(Tile t1, Tile t2)
      Calculates the distance between two tiles.
      static long elapsed​(long prevTime)
      Calculates the time elapsed from the supplied previous time.
      static java.lang.String generateRandomString()  
      static java.util.Random getRandom()  
      static boolean isBefore​(long futureTime)
      Returns true if System time is less than input
      static double nextGammaRandom​(int shape, int scale)
      Generates a random value from the GammaDistribution
      static double nextGaussianRandom​(double mean, double sigma)
      Generates a random value from the Normal (or Gaussian) distribution with specified mean and standard deviation.
      static double nextHypergeometricRandom​(int populationSize, int numberOfSuccesses, int sampleSize)
      Generates a random value from the HypergeometricDistribution.
      static double nextLogNormalDistributionRandom​(double scale, double shape)
      Generates a lognormal distribution using the provided parameters with an inverse absolute accuracy of 1e-9 and uses a Well19937c number generator to return a sample
      static double random​(double lower, double upper)
      Generates a uniformly distributed random value from the open interval (lower, upper) (i.e., endpoints excluded).
      static int random​(int high)
      Returns a number between 0 (inclusive) and high (exclusive)
      static int random​(int min, int max)
      Gets a random number between min (inclusive) and max (exclusive)
      static long random​(long min, long max)
      Gets a random number between min (inclusive) and max (exclusive)
      static void setRandomSeed​(long seed)  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Calculations

        public Calculations()
    • Method Detail

      • random

        public static int random​(int high)
        Returns a number between 0 (inclusive) and high (exclusive)
        Parameters:
        high - upper bounds of random number (exclusive)
        Returns:
        int between 0(inclusive) and max(exclusive)
      • random

        public static int random​(int min,
                                 int max)
        Gets a random number between min (inclusive) and max (exclusive)
        Parameters:
        min - minimum number
        max - maximum number
        Returns:
        int between min(inclusive) and max(exclusive)
      • nextLogNormalDistributionRandom

        public static double nextLogNormalDistributionRandom​(double scale,
                                                             double shape)
                                                      throws org.apache.commons.math3.exception.NotStrictlyPositiveException
        Generates a lognormal distribution using the provided parameters with an inverse absolute accuracy of 1e-9 and uses a Well19937c number generator to return a sample
        Parameters:
        scale - scale parameter (median of the distribution)
        shape - shape parameter (std. dev. of the log of the distribution)
        Returns:
        a sample from the distribution
        Throws:
        org.apache.commons.math3.exception.NotStrictlyPositiveException - if shape is less than or equal to 0
      • random

        public static double random​(double lower,
                                    double upper)
        Generates a uniformly distributed random value from the open interval (lower, upper) (i.e., endpoints excluded).
        Parameters:
        lower - the exclusive lower bound of the support
        upper - the exclusive upper bound of the support
        Returns:
        a uniformly distributed random value between lower and upper (exclusive)
        Throws:
        org.apache.commons.math3.exception.NumberIsTooLargeException - if lower is greater than upper.
        org.apache.commons.math3.exception.NotFiniteNumberException - if one of the bounds is infinite
        org.apache.commons.math3.exception.NotANumberException - if one of the bounds is NaN
      • random

        public static long random​(long min,
                                  long max)
        Gets a random number between min (inclusive) and max (exclusive)
        Parameters:
        min - minimum number
        max - maximum number
        Returns:
        Long between min(inclusive) and max(exclusive)
      • nextGaussianRandom

        public static double nextGaussianRandom​(double mean,
                                                double sigma)
        Generates a random value from the Normal (or Gaussian) distribution with specified mean and standard deviation.
        Parameters:
        mean - the standard mean of the distribution
        sigma - the standard deviation of the distribution
        Returns:
        a random value following the specified Gaussian distribution.
        Throws:
        org.apache.commons.math3.exception.NotStrictlyPositiveException - if sigma less or equal to 0.
      • nextHypergeometricRandom

        public static double nextHypergeometricRandom​(int populationSize,
                                                      int numberOfSuccesses,
                                                      int sampleSize)
        Generates a random value from the HypergeometricDistribution.
        Parameters:
        populationSize - the population size of the Hypergeometric distribution.
        numberOfSuccesses - number of successes in the population of the Hypergeometric distribution.
        sampleSize - the sample size of the Hypergeometric distribution.
        Returns:
        random value sampled from the Hypergeometric(populationSize, numberOfSuccesses, sampleSize) distribution.
        Throws:
        org.apache.commons.math3.exception.NotStrictlyPositiveException - if shape less or equal to 0 or scale less or equal to 0.
      • nextGammaRandom

        public static double nextGammaRandom​(int shape,
                                             int scale)
        Generates a random value from the GammaDistribution
        Parameters:
        shape - the median of the Gamma distribution
        scale - the scale parameter of the Gamma distribution
        Returns:
        random value sampled from the Gamma(shape, scale) distribution.
        Throws:
        org.apache.commons.math3.exception.NotStrictlyPositiveException - if shape less or equal to 0 or scale less or equal to 0.
      • setRandomSeed

        public static void setRandomSeed​(long seed)
      • distance

        public static double distance​(Tile t1,
                                      Tile t2)
        Calculates the distance between two tiles.
        Parameters:
        t1 - tile getForceLEShortA
        t2 - tile B
        Returns:
        distance between getForceLEShortA B
      • distance

        public static double distance​(java.awt.Point p1,
                                      java.awt.Point p2)
        Calculates the distance between two points
        Parameters:
        p1 - Point getForceLEShortA
        p2 - Point B
        Returns:
        distance between getForceLEShortA B
      • distance

        public static double distance​(int x1,
                                      int y1,
                                      int x2,
                                      int y2)
        Calculates the distance between two sets of coordinates
        Parameters:
        x1 - X-coordinate A
        y1 - Y-coordinate A
        x2 - X-coordinate B
        y2 - Y-coordinate B
        Returns:
        distance between getForceLEShortA B
      • getRandom

        public static java.util.Random getRandom()
      • isBefore

        public static boolean isBefore​(long futureTime)
        Returns true if System time is less than input
        Parameters:
        futureTime - The future time in milliseconds.
        Returns:
        true if true
      • elapsed

        public static long elapsed​(long prevTime)
        Calculates the time elapsed from the supplied previous time.
        Parameters:
        prevTime -
        Returns:
        The Elapsed time
      • generateRandomString

        public static java.lang.String generateRandomString()