java.lang.Object
com.amalgamasimulation.discreterate.flowstatistic.FlowProfile<T>
Type Parameters:
T - the type of elements managed by this flow profile

public class FlowProfile<T> extends Object
Represents a flow profile for elements of type T. Stores the flow history over time. Allows users to get statistics for any given time interval.

Effectively, this class is analogous to PiecewiseFunction, but with Accumulator of elements as values, not just doubles.

Author:
Alexander Morozov
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addRate(double fromArgument, Accumulator<T> flowRates)
    Adds flow rates for elements starting from the specified argument and continuing indefinitely.
    void
    addRate(Interval withinArgumentInterval, Accumulator<T> flowRates)
    Adds flow rates for elements within the specified interval.
    void
    addStepChange(double argument, Accumulator<T> flowStepChanges)
    Adds a step change based on the provided argument and Accumulator of flow step changes.
    void
    addStepChange(Interval argumentInterval, Accumulator<T> flowStepChanges)
    Adds step changes for the specified argument interval and Accumulator of flow step changes.
    Creates a new instance of this FlowProfile that is a copy of this profile, and returns this instance.
    double
    firstArgumentWithValueLessEqualThan(double lessEqualThanValue, double startingFromArgument)
    Finds and returns the first argument in the summary linear function where its value is less than or equal to the specified threshold, starting the search from the given argument, inclusive.
    double
    firstArgumentWithValueMoreEqualThan(double moreEqualThanValue, double startingFromArgument)
    Finds and returns the first argument in the summary linear function where its value is greater than or equal to the specified threshold, starting the search from the given argument, inclusive.
    Returns the PiecewiseFunction associated with a given flow element.
    Returns the PiecewiseFunction associated with the summary linear function of all the elements.
    integral(Interval interval)
    Calculates the integral of all flow profiles over a specified interval and returns the accumulated results.
    multiply(double factor)
    Multiplies the values of this profile by the specified factor.
    plus(FlowProfile<T> other)
    Adds the points of another profile to this profile.
    rateAt(double argument)
    Returns the flow rate for all element at the specified argument.
    double
    rateAt(T element, double argument)
    Returns the flow rate for a specific element at the specified argument.
    void
    setRate(double startingAtArgument, Accumulator<T> flowRates)
    Sets new flow rates for the elements starting from the specified argument.
    subProfile(IntervalLike withinArgumentInterval)
    Computes and returns a new instance of FlowProfile which is a sub-function of this profile, i.e.
    subProfile(IntervalLike withinArgumentInterval, boolean shouldContinueLastValues)
    Computes and returns a new instance of FlowProfile which is a sub-function of this profile, i.e.
    double
    summaryIntegral(Interval withinArgumentInterval)
    Calculates the integral of the summary piecewise linear function over the specified argument interval.
    double
    sumRateAt(double argument)
    Returns the sum of all flow rate at the specified argument.
    double
    sumValueAt(double argument)
    Returns the sum of all flow values at the specified argument.
    valueAt(double argument)
    Returns the flow values for all elements at the specified argument.
    double
    valueAt(T element, double argument)
    Returns the flow value for a specific element at the specified argument.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FlowProfile

      public FlowProfile()
  • Method Details

    • setRate

      public void setRate(double startingAtArgument, Accumulator<T> flowRates)
      Sets new flow rates for the elements starting from the specified argument. Previous rate is discarded, if any.
      Parameters:
      startingAtArgument - the argument at which to set the rates
      flowRates - an Accumulator containing the new rates for the elements
    • addRate

      public void addRate(Interval withinArgumentInterval, Accumulator<T> flowRates)
      Adds flow rates for elements within the specified interval.
      Parameters:
      withinArgumentInterval - the argument interval within which to set the rates
      flowRates - an Accumulator containing the flow rates to add for each element.
    • addRate

      public void addRate(double fromArgument, Accumulator<T> flowRates)
      Adds flow rates for elements starting from the specified argument and continuing indefinitely.
      Parameters:
      fromArgument - the argument at which to set the rates
      flowRates - an Accumulator containing the flow rates to add for each element.
    • addStepChange

      public void addStepChange(double argument, Accumulator<T> flowStepChanges)
      Adds a step change based on the provided argument and Accumulator of flow step changes.
      Parameters:
      argument - the argument at which to set the step changes
      flowStepChanges - an Accumulator of flow step changes that contains pairs (flow element, change value).
    • addStepChange

      public void addStepChange(Interval argumentInterval, Accumulator<T> flowStepChanges)
      Adds step changes for the specified argument interval and Accumulator of flow step changes. Negative step changes are added at the end of the specified interval.
      Parameters:
      argumentInterval - the Interval where the step change occurs. Must be finite and not null
      flowStepChanges - an Accumulator of flow changes that contains pairs (flow element, change value).
    • valueAt

      public Accumulator<T> valueAt(double argument)
      Returns the flow values for all elements at the specified argument.
      Parameters:
      argument - the argument at which to evaluate the flow values
      Returns:
      an Accumulator containing the flow values for all elements
    • valueAt

      public double valueAt(T element, double argument)
      Returns the flow value for a specific element at the specified argument. If the element is not present in the profile, returns 0.0.
      Parameters:
      element - the element for which to calculate the flow
      argument - the argument at which to evaluate the flow value
      Returns:
      the flow value for the specified element at the specified argument
    • sumValueAt

      public double sumValueAt(double argument)
      Returns the sum of all flow values at the specified argument.
      Parameters:
      argument - the argument at which to evaluate the flow value
      Returns:
      the summed flow value across all elements at the specified argument
    • rateAt

      public Accumulator<T> rateAt(double argument)
      Returns the flow rate for all element at the specified argument.
      Parameters:
      argument - the argument at which to evaluate the flow rate
      Returns:
      the calculated rate at the specified argument
    • rateAt

      public double rateAt(T element, double argument)
      Returns the flow rate for a specific element at the specified argument. If the element is not present in the profile, returns 0.0.
      Parameters:
      element - element the flow element whose rate is to be calculated
      argument - the argument at which to evaluate the flow rate
      Returns:
      the calculated rate at the specified argument for the given element
    • sumRateAt

      public double sumRateAt(double argument)
      Returns the sum of all flow rate at the specified argument.
      Parameters:
      argument - the argument at which to evaluate the flow rate
      Returns:
      the calculated rate at the specified argument
    • integral

      public Accumulator<T> integral(Interval interval)
      Calculates the integral of all flow profiles over a specified interval and returns the accumulated results.

      Analogous to PiecewiseFunction.integral()

      Parameters:
      interval - the interval over which the integrals are calculated
      Returns:
      an Accumulator containing the results of the integration for each flow element
    • flowElementProfile

      public PiecewiseFunction flowElementProfile(T element)
      Returns the PiecewiseFunction associated with a given flow element.
      Parameters:
      element - the flow element for which the flow profile is requested
      Returns:
      the corresponding PiecewiseFunction for the given element
    • getSummaryFunction

      public PiecewiseFunction getSummaryFunction()
      Returns the PiecewiseFunction associated with the summary linear function of all the elements.
      Returns:
      the summary linear function of all the elements
    • firstArgumentWithValueMoreEqualThan

      public double firstArgumentWithValueMoreEqualThan(double moreEqualThanValue, double startingFromArgument)
      Finds and returns the first argument in the summary linear function where its value is greater than or equal to the specified threshold, starting the search from the given argument, inclusive.

      If the value of the function at the given argument is already greater than or equal to the specified threshold, returns this given argument.

      Parameters:
      moreEqualThanValue - the threshold value to compare against. Must be finite and not Double.NaN
      startingFromArgument - the argument from which to start the search, inclusive. Must not be Double.NaN
      Returns:
      the first argument where the value is greater than or equal to the specified threshold, or Double.POSITIVE_INFINITY if no such argument is found
    • firstArgumentWithValueLessEqualThan

      public double firstArgumentWithValueLessEqualThan(double lessEqualThanValue, double startingFromArgument)
      Finds and returns the first argument in the summary linear function where its value is less than or equal to the specified threshold, starting the search from the given argument, inclusive.

      If the value of the function at the given argument is already less than or equal to the specified threshold, returns this given argument.

      Parameters:
      lessEqualThanValue - the threshold value to compare against. Must be finite and not Double.NaN
      startingFromArgument - the argument from which to start the search, inclusive. Must not be Double.NaN
      Returns:
      the first argument where the value is less than or equal to the specified threshold, or Double.POSITIVE_INFINITY if no such argument is found
    • summaryIntegral

      public double summaryIntegral(Interval withinArgumentInterval)
      Calculates the integral of the summary piecewise linear function over the specified argument interval.
      Parameters:
      withinArgumentInterval - the interval within which to calculate the integral. Must not be null.
      Returns:
      the integral of the function over the specified interval
    • subProfile

      public FlowProfile<T> subProfile(IntervalLike withinArgumentInterval)
      Computes and returns a new instance of FlowProfile which is a sub-function of this profile, i.e. profile which is:
      • equal to this profile inside the specified argument interval or interval set,
      • zero elsewhere.

      If the specified interval is Interval.UNIVERSE, returns a copy of this profile.

      Parameters:
      withinArgumentInterval - argument where the values of this profile are preserved, can be empty but must not be zero-length
      Returns:
      a new instance of FlowProfile which is a sub-profile of this function
    • subProfile

      public FlowProfile<T> subProfile(IntervalLike withinArgumentInterval, boolean shouldContinueLastValues)
      Computes and returns a new instance of FlowProfile which is a sub-function of this profile, i.e. profile which is:
      • equal to this profile inside the specified argument interval or interval set,
      • zero elsewhere.

      If the specified interval is Interval.UNIVERSE, returns a copy of this profile.

      Parameters:
      withinArgumentInterval - argument where the values of this profile are preserved, can be empty but must not be zero-length
      shouldContinueLastValues - if true, then the sub profile continues at the ends of the intervals as if the value was accumulating if this is the case in the original profile
      Returns:
      a new instance of FlowProfile which is a sub-profile of this function
    • plus

      public FlowProfile<T> plus(FlowProfile<T> other)
      Adds the points of another profile to this profile. Creates and returns a new instance of FlowProfile with the combined points. The current instance remains unchanged.
      Parameters:
      other - the other profile whose points are to be added, must not be null
      Returns:
      a new FlowProfile instance with the points of both profiles combined
    • multiply

      public FlowProfile<T> multiply(double factor)
      Multiplies the values of this profile by the specified factor. Creates and returns a new instance of FlowProfile with the values multiplied by the factor. The current instance remains unchanged.
      Parameters:
      factor - the factor by which to multiply the values of the profile. Must be finite and not Double.NaN
      Returns:
      a new FlowProfile instance with the values multiplied by the factor
    • copy

      public FlowProfile<T> copy()
      Creates a new instance of this FlowProfile that is a copy of this profile, and returns this instance.
      Returns:
      a copy of this profile