Package edu.uky.ai
Class SearchBudget
java.lang.Object
edu.uky.ai.SearchBudget
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
FieldsModifier and TypeFieldDescriptionstatic final SearchBudget
A search budget with no limitationsstatic final int
Represents no limit on the number of operationsstatic final long
Represents no limit on the amount of time -
Constructor Summary
ConstructorsConstructorDescriptionSearchBudget
(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 TypeMethodDescriptionvoid
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
getTime()
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.toString()
-
Field Details
-
INFINITE_OPERATIONS
public static final int INFINITE_OPERATIONSRepresents no limit on the number of operations- See Also:
-
INFINITE_TIME
public static final long INFINITE_TIMERepresents no limit on the amount of time- See Also:
-
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
-
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
-