Package edu.uky.ai
Class SearchBudget
java.lang.Object
edu.uky.ai.SearchBudget
public final class SearchBudget
extends java.lang.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 SearchBudget
INFINITE
A search budget with no limitationsstatic int
INFINITE_OPERATIONS
Represents no limit on the number of operationsstatic long
INFINITE_TIME
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
checkTime()
When this method is called, it will throw an exception if the maximum amount of time has passed, otherwise it will do nothing.int
getOperations()
Returns the number of operations executed so far.int
getRemainingOperations()
Returns the number of operations that may still be executed.long
getRemainingTime()
Returns the amount of time remaining before time is up.long
getTime()
Returns the amount of time spent so far.boolean
hasBeenExhausted()
Returns true if there are no more operations or time remaining.void
incrementOperations()
This method is called to signal that one operations has been performed.boolean
isInfinite()
Returns whether or not it is possible for this budget to run out.java.lang.String
toString()
-
Field Details
-
INFINITE_OPERATIONS
public static final int INFINITE_OPERATIONSRepresents no limit on the number of operations- See Also:
- Constant Field Values
-
INFINITE_TIME
public static final long INFINITE_TIMERepresents no limit on the amount of time- See Also:
- Constant Field Values
-
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 operationstime
- the number of milliseconds that may elapse
-
-
Method Details
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.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
-