Class TriangularNumbers

java.lang.Object
org.optaplanner.core.impl.heuristic.selector.list.TriangularNumbers

public final class TriangularNumbers extends Object
  • Method Details

    • nthTriangle

      public static int nthTriangle(int n) throws ArithmeticException
      Calculate nth triangular number. This is used to calculate the number of subLists for a given list variable of size n. To be able to use int arithmetic to calculate the triangular number, n must be less than or equal to HIGHEST_SAFE_N. If the n is higher, the method throws an exception.
      Parameters:
      n - size of the triangle (the length of its side)
      Returns:
      nth triangular number
      Throws:
      ArithmeticException - if n is higher than HIGHEST_SAFE_N