Class IntervalPlanner

java.lang.Object
com.amalgamasimulation.core.scheduling.IntervalPlanner

public class IntervalPlanner extends Object
Class that determines the time intervals when the value of table function is equal to or greater than the specified value.

The typical use of this class is the following: Consider we have resources A, B, C. For each resource, its availability periods are set with a list of time intervals, i.e. List<TimeInterval>. The task is to get all intervals when there are 2 or more resources available simultaneously. This task can be solved with the code below:

 List<TimeInterval> aAvailabilityIntervals = List.of(...);
 List<TimeInterval> bAvailabilityIntervals = List.of(...);
 List<TimeInterval> cAvailabilityIntervals = List.of(...);
 
 IntervalPlanner planner = new IntervalPlanner();
 
 aAvailabilityIntervals.forEach(interval -> planner.addInterval(interval, 1);
 bAvailabilityIntervals.forEach(interval -> planner.addInterval(interval, 1);
 cAvailabilityIntervals.forEach(interval -> planner.addInterval(interval, 1);
 
 planner.getIntervals(2);
 
Author:
Andrey Malykhanov
  • Constructor Details

    • IntervalPlanner

      public IntervalPlanner()
      Creates a new empty instance of IntervalPlanner.
    • IntervalPlanner

      public IntervalPlanner(List<? extends Interval> intervals, int value)
      Creates a new instance of IntervalPlanner and adds the specified value to each of the specified intervals. Intervals may intersect.
      Parameters:
      intervals - intervals for which the value will be added
      value - value that will be added for each of the specified intervals. Can be both positive and negative
  • Method Details

    • forwardIntervalsIterator

      public Iterator<Interval> forwardIntervalsIterator(int withValueMoreEqualThan, Interval intersectingWithTimeInterval)
      Returns an Iterator that iterates through the intervals where the value is equal to or greater than the specified value that have non-zero intersection with the specified interval. The intervals are being iterated in ascending order.

      All intervals in the iterator are within the specified interval.

      Parameters:
      withValueMoreEqualThan - the value in the returned intervals must be equal to or greater than this value
      intersectingWithTimeInterval - the bounding interval with which all the returned intervals are intersected
      Returns:
      Iterator instance
    • backwardIntervalsIterator

      public Iterator<Interval> backwardIntervalsIterator(int withValueMoreEqualThan, TimeInterval intersectingWithTimeInterval)
      Returns an Iterator that iterates through the intervals where the value is equal to or greater than the specified value that have non-zero intersection with the specified interval. The intervals are being iterated in descending order, i.e. starting from the one having the biggest begin time.

      All intervals in the iterator are within the specified interval.

      Parameters:
      withValueMoreEqualThan - the value in the returned intervals must be equal to or greater than this value
      intersectingWithTimeInterval - the bounding interval with which all the returned intervals are intersected
      Returns:
      Iterator instance
    • addInterval

      public void addInterval(double beginTime, double endTime, int value)
      Adds the specified value to the specified interval.
      Parameters:
      beginTime - begin time of the specified interval
      endTime - end time of the specified interval
      value - value that will be added to the specified interval. Can be both positive and negative
    • addInterval

      public void addInterval(Interval interval, int value)
      Adds the specified value to the specified interval.
      Parameters:
      interval - the specified interval
      value - value that will be added to the specified interval. Can be both positive and negative
    • compact

      public void compact()
      Removes the consecutive duplicate values from the underlying data. Speeds up all search operations.
    • getIntervals

      public SortedList<Interval> getIntervals(int withValueMoreEqualThan)
      Returns the SortedList of intervals where the value is equal to or greater than the specified value. The intervals in the returned list are ordered by the begin time in ascending order.
      Parameters:
      withValueMoreEqualThan - the value in the returned intervals must be equal to or greater than this value
      Returns:
      SortedList of intervals where the value is equal to or greater than the specified value
    • getIntervalsBeginningBefore

      public List<Interval> getIntervalsBeginningBefore(double beginningStrictlyBeforeTime, int withValueMoreEqualThan)
      Returns a list of intervals beginning before the specified time where the value is equal to or greater than the specified value. The intervals in the returned list are ordered by the begin time in ascending order.
      Parameters:
      beginningStrictlyBeforeTime - all intervals must begin strictly before this time
      withValueMoreEqualThan - the value in the returned intervals must be equal to or greater than this value
      Returns:
      a list of intervals beginning before the specified time where the value is equal to or greater than the specified value
    • getIntervalsBeginningAfter

      public List<Interval> getIntervalsBeginningAfter(double beginningAtOrAfterTime, int withValueMoreEqualThan)
      Returns a list of intervals beginning at or after the specified time where the value is equal to or greater than the specified value. The intervals in the returned list are ordered by the begin time in ascending order.
      Parameters:
      beginningAtOrAfterTime - all intervals must begin at or after this time
      withValueMoreEqualThan - the value in the returned intervals must be equal to or greater than this value
      Returns:
      a list of intervals beginning at or after the specified time where the value is equal to or greater than the specified value
    • getIntervalsBetween

      public List<Interval> getIntervalsBetween(double beginTime, double endTime, int withValueMoreEqualThan)
      Returns a list of intervals inside the specified interval where the value is equal to or greater than the specified value. The intervals in the returned list are ordered by the begin time in ascending order.

      All intervals in the returned list are inside the specified interval, i.e. all of the intervals in the list are intersected with the specified interval.

      Parameters:
      beginTime - begin time of the specified interval
      endTime - end time of the specified interval
      withValueMoreEqualThan - the value in the returned intervals must be equal to or greater than this value
      Returns:
      list of intervals inside the specified interval where the value is equal to or greater than the specified value
    • getArgumentsAndValues

      public List<Pair<Double,Integer>> getArgumentsAndValues()
      Returns the data of this interval planner in the form of argument-value pairs list. The elements of the returned list are ordered by argument in ascending order.
      Returns:
      data of this interval planner in the form of argument-value pairs list
    • toString

      public String toString()
      Overrides:
      toString in class Object