Class Capacity

java.lang.Object
com.graphhopper.jsprit.core.problem.Capacity

public class Capacity extends Object
Capacity with an arbitrary number of capacity-dimension.

Note that this assumes the the values of each capacity dimension can be added up and subtracted

Author:
schroeder
  • Method Details

    • addup

      public static Capacity addup(Capacity cap1, Capacity cap2)
      Adds up two capacities, i.e. sums up each and every capacity dimension, and returns the resulting Capacity.

      Note that this assumes that capacity dimension can be added up.

      Parameters:
      cap1 - capacity to be added up
      cap2 - capacity to be added up
      Returns:
      new capacity
      Throws:
      NullPointerException - if one of the args is null
    • subtract

      public static Capacity subtract(Capacity cap, Capacity cap2subtract)
      Subtracts cap2subtract from cap and returns the resulting Capacity.
      Parameters:
      cap - capacity to be subtracted from
      cap2subtract - capacity to subtract
      Returns:
      new capacity
      Throws:
      NullPointerException - if one of the args is null
    • invert

      public static Capacity invert(Capacity cap2invert)
      Returns the inverted capacity, i.e. it multiplies all capacity dimensions with -1.
      Parameters:
      cap2invert - capacity to be inverted
      Returns:
      inverted capacity
      Throws:
      NullPointerException - if one of the args is null
    • divide

      public static double divide(Capacity numerator, Capacity denominator)
      Divides every dimension of numerator capacity by the corresponding dimension of denominator capacity, , and averages each quotient.

      If both nominator.get(i) and denominator.get(i) equal to 0, dimension i is ignored.

      If both capacities are have only dimensions with dimensionVal=0, it returns 0.0

      Parameters:
      numerator - the numerator
      denominator - the denominator
      Returns:
      quotient
      Throws:
      IllegalStateException - if numerator.get(i) != 0 and denominator.get(i) == 0
    • copyOf

      public static Capacity copyOf(Capacity capacity)
      Makes a deep copy of Capacity.
      Parameters:
      capacity - capacity to be copied
      Returns:
      copy
    • getNuOfDimensions

      public int getNuOfDimensions()
      Returns the number of specified capacity dimensions.
      Returns:
      noDimensions
    • get

      public int get(int index)
      Returns value of capacity-dimension with specified index.

      If capacity dimension does not exist, it returns 0 (rather than IndexOutOfBoundsException).

      Parameters:
      index - dimension index of the capacity value to be retrieved
      Returns:
      the according dimension value
    • isLessOrEqual

      public boolean isLessOrEqual(Capacity toCompare)
      Returns true if this capacity is less or equal than the capacity toCompare, i.e. if none of the capacity dimensions > than the corresponding dimension in toCompare.
      Parameters:
      toCompare - the capacity to compare
      Returns:
      true if this capacity is less or equal than toCompare
      Throws:
      NullPointerException - if one of the args is null
    • isGreaterOrEqual

      public boolean isGreaterOrEqual(Capacity toCompare)
      Returns true if this capacity is greater or equal than the capacity toCompare
      Parameters:
      toCompare - the capacity to compare
      Returns:
      true if this capacity is greater or equal than toCompare
      Throws:
      NullPointerException - if one of the args is null
    • isZero

      public boolean isZero()
      Check if this is a zero capacity (all dimensions are zero)
      Returns:
      true if all dimensions are zero
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • max

      public static Capacity max(Capacity cap1, Capacity cap2)
      Return the maximum, i.e. the maximum of each capacity dimension.
      Parameters:
      cap1 - first capacity to compare
      cap2 - second capacity to compare
      Returns:
      capacity maximum of each capacity dimension
    • min

      public static Capacity min(Capacity cap1, Capacity cap2)
      Return the minimum, i.e. the minimum of each capacity dimension.
      Parameters:
      cap1 - first capacity to compare
      cap2 - second capacity to compare
      Returns:
      capacity minimum of each capacity dimension
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object