Package edu.uky.ai

Class SearchBudget

java.lang.Object
edu.uky.ai.SearchBudget

public final class SearchBudget extends Object
Represents the limitations placed on an algorithm in terms of how many operations it may perform and how long it make take to solve a problem.
Author:
Stephen G. Ware
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final SearchBudget
    A search budget with no limitations
    static final int
    Represents no limit on the number of operations
    static final long
    Represents no limit on the amount of time
  • Constructor Summary

    Constructors
    Constructor
    Description
    SearchBudget(int operations, long time)
    Constructs a new search budget that allows the given number of operations and the give amount of time.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    When this method is called, it will throw an exception if the maximum amount of time has passed, otherwise it will do nothing.
    int
    Returns the number of operations executed so far.
    int
    Returns the number of operations that may still be executed.
    long
    Returns the amount of time remaining before time is up.
    long
    Returns the amount of time spent so far.
    boolean
    Returns true if there are no more operations or time remaining.
    void
    This method is called to signal that one operations has been performed.
    boolean
    Returns whether or not it is possible for this budget to run out.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • INFINITE_OPERATIONS

      public static final int INFINITE_OPERATIONS
      Represents no limit on the number of operations
      See Also:
    • INFINITE_TIME

      public static final long INFINITE_TIME
      Represents no limit on the amount of time
      See Also:
    • INFINITE

      public static final SearchBudget INFINITE
      A search budget with no limitations
  • Constructor Details

    • SearchBudget

      public SearchBudget(int operations, long time)
      Constructs a new search budget that allows the given number of operations and the give amount of time.
      Parameters:
      operations - the maximum number of operations
      time - the number of milliseconds that may elapse
  • Method Details

    • toString

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

      public boolean isInfinite()
      Returns whether or not it is possible for this budget to run out.
      Returns:
      true if the number of operations or time is finite, false if both are infinite
    • hasBeenExhausted

      public boolean hasBeenExhausted()
      Returns true if there are no more operations or time remaining.
      Returns:
      true if resources have been used up, false otherwise
    • getOperations

      public int getOperations()
      Returns the number of operations executed so far.
      Returns:
      the number of operations
    • getRemainingOperations

      public int getRemainingOperations()
      Returns the number of operations that may still be executed.
      Returns:
      the number of operations
    • getTime

      public long getTime()
      Returns the amount of time spent so far.
      Returns:
      the number of milliseconds that has elapse since this object was created
    • getRemainingTime

      public long getRemainingTime()
      Returns the amount of time remaining before time is up.
      Returns:
      the number of milliseconds remaining before time is up
    • incrementOperations

      public void incrementOperations()
      This method is called to signal that one operations has been performed.
      Throws:
      OperationsBudgetExceededException - if the maximum number of operations have already been performed
    • checkTime

      public void checkTime()
      When this method is called, it will throw an exception if the maximum amount of time has passed, otherwise it will do nothing.
      Throws:
      TimeBudgetExceededException - if the maximum number of milliseconds have passed