|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectai.search.SearchEngine
public abstract class SearchEngine
This class is a generic AI search engine that traverses a search space defined by an initial search state and a set of available actions.
What mainly distinguishes different search engines is the order in which the
search states that constitute the search space are explored. An inheriting
class must specify this search strategy. Thus, the most important function of
this class that needs to be overridden by an inheriting class is
doSearch()
, the function that actually explores the search space
according to some strategy.
Nested Class Summary | |
---|---|
static class |
SearchEngine.GraphType
|
Field Summary | |
---|---|
protected boolean |
doInterrupt
flag to be set if doSearch is to be interrupted |
protected boolean |
doRepeatTest
indicates whether the test for repeated states should take place |
protected long |
searchLimit
the maximum number of search nodes to be generated |
protected boolean |
searchStarted
indicates whether the search has been started |
protected java.io.OutputStream |
traceStream
the stream to which trace output should be written or null, the default value, for no tracing |
protected int |
yieldFrequency
the search engine will call yield() every so many explored nodes; the default value is Integer.MAX_VALUE |
Constructor Summary | |
---|---|
SearchEngine(long limit,
SearchEngine.GraphType structure)
This constructor creates a new SearchEngine for the given search limit, and type of search space. |
Method Summary | |
---|---|
protected java.lang.Object |
clone()
This class does not support cloning and an exception will be thrown if this method is called. |
abstract boolean |
continuable()
This function tests whether the search may be continued. |
abstract void |
doSearch()
This function must be called to start or continue the search. |
boolean |
equals(java.lang.Object obj)
This class does not support equality testing and an exception will be thrown if this method is called. |
abstract boolean |
foundGoalState()
This function returns whether a goal state has been found. |
abstract long |
getNrOfExploredStates()
This function returns the number of states that have been explored during this search. |
abstract long |
getNrOfGeneratedStates()
This function returns the number of states that have been generated during this search. |
long |
getSearchLimit()
This function returns the current search limit, that is, the maximal number of search states to be generated. |
abstract int |
getSolutionDepth()
This function returns the depth of the found goal node in the generated search tree. |
int |
hashCode()
This class does not support hashing and an exception will be thrown if this method is called. |
void |
interrupt()
This function sets the interrupt flag for this SearchEngine. |
void |
printTrace(java.lang.String msg)
This function must be called to print out tracing messages. |
void |
setSearchLimit(long limit)
This function can be used to set a new limit for the number of search states that are to be generated. |
void |
setTraceStream(java.io.OutputStream stream)
This function can be used to activate tracing of the search activity. |
void |
setYieldFrequency(int frequency)
This function can be used to set a new yield frequency. |
java.lang.String |
toString()
This class does not support a printable representation and an exception will be thrown if this method is called. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.io.OutputStream traceStream
protected boolean searchStarted
protected boolean doRepeatTest
protected long searchLimit
protected int yieldFrequency
protected boolean doInterrupt
Constructor Detail |
---|
public SearchEngine(long limit, SearchEngine.GraphType structure)
This constructor creates a new SearchEngine for the given search limit,
and type of search space. The search does not start immediately but waits
for the function doSearch()
to be called.
limit
- the initial value for the search limitstructure
- TREE or GRAPH, depending on what is to be be searchedMethod Detail |
---|
protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
This class does not support cloning and an exception will be thrown if this method is called.
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- will be thrownpublic abstract void doSearch()
This function must be called to start or continue the search. It will only return when one of the following conditions becomes true:
foundGoalState()
will return true foundGoalState()
will return false, the search cannot be
continued (continuable()
will return false); to make the search
continuable the search limit has to be increased using
setSearchLimit(long)
foundGoalState()
will return false, the search will not be
continuable (continuable()
will return false)
public abstract boolean foundGoalState()
This function returns whether a goal state has been found. Notice that a
call to this function only makes sense after doSearch()
has been
called at least once.
public abstract int getSolutionDepth()
This function returns the depth of the found goal node in the generated search tree.
public abstract boolean continuable()
This function tests whether the search may be continued. Usually this is the case if there are more search states to be explored and the search limit has not yet been exceeded.
public abstract long getNrOfExploredStates()
This function returns the number of states that have been explored during this search. A state counts as explored when the goal test has been performed on the state and its successors have been generated.
public abstract long getNrOfGeneratedStates()
This function returns the number of states that have been generated during this search. Note that these states may not all be different.
public void setSearchLimit(long limit)
This function can be used to set a new limit for the number of search
states that are to be generated. When a new search limit is set
with this function, subsequent calls to doSearch()
continue the
search as if this had been the original limit.
limit
- the new search limit valuepublic long getSearchLimit()
This function returns the current search limit, that is, the maximal number of search states to be generated.
public void setTraceStream(java.io.OutputStream stream)
This function can be used to activate tracing of the search activity. Setting the trace stream to null switches off tracing completely. Otherwise a trace is written to the given stream.
stream
- the OutputStream to which the trace should be written or
null for no tracingpublic void printTrace(java.lang.String msg)
This function must be called to print out tracing messages. Note that this function does not test whether tracing has been switched off, i.e. whether traceStream==null.
msg
- the message to be printed to the trace streampublic void setYieldFrequency(int frequency)
This function can be used to set a new yield frequency. It should only be used if there are indeed multiple threads running. The given value should depend on the time it takes to generate the successors of a state; the longer this time the higher the yield frequency should be.
frequency
- the new frequency with which this search thread will
yield control explicitlypublic void interrupt()
This function sets the interrupt flag for this SearchEngine. The
implementation of doSearch()
is expected to interrupt its search
and return control to the calling Thread when this flag has been set.
public boolean equals(java.lang.Object obj) throws java.lang.UnsupportedOperationException
This class does not support equality testing and an exception will be thrown if this method is called.
equals
in class java.lang.Object
obj
- the object this should be compared to
java.lang.UnsupportedOperationException
- will be thrownpublic int hashCode() throws java.lang.UnsupportedOperationException
This class does not support hashing and an exception will be thrown if this method is called.
hashCode
in class java.lang.Object
java.lang.UnsupportedOperationException
- will be thrownpublic java.lang.String toString() throws java.lang.UnsupportedOperationException
This class does not support a printable representation and an exception will be thrown if this method is called.
toString
in class java.lang.Object
java.lang.UnsupportedOperationException
- will be thrown
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |