Package nl.tue.astar.impl
Class AbstractAStarThread<H extends Head,T extends Tail>
- java.lang.Object
-
- nl.tue.astar.impl.AbstractAStarThread<H,T>
-
- All Implemented Interfaces:
AStarThread<H,T>,ObservableAStarThread<H,T>
- Direct Known Subclasses:
AStarThread.CPUEfficient,AStarThread.MemoryEfficient
public abstract class AbstractAStarThread<H extends Head,T extends Tail> extends java.lang.Object implements ObservableAStarThread<H,T>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAbstractAStarThread.StorageHandler<H extends Head,T extends Tail>The storageHandler handles the storing and retrieving of elements from the statespace searched by the AStar algorithm-
Nested classes/interfaces inherited from interface nl.tue.astar.AStarThread
AStarThread.ASynchronousMoveSorting, AStarThread.Canceller, AStarThread.CPUEfficient<H extends Head,T extends Tail>, AStarThread.MemoryEfficient<H extends Head,T extends Tail>, AStarThread.QueueingModel, AStarThread.Type
-
-
Field Summary
Fields Modifier and Type Field Description protected intcomputedEstimateCountprotected gnu.trove.set.TLongSetconsideredprotected Delegate<H,T>delegateprotected doubleepsilonprotected doubleexpectedLengthprotected static intiprotected intmaxStatesprotected java.util.List<AStarObserver>observersprotected intpollprotected FastLookupPriorityQueuequeueprotected intqueuedStateCountprotected booleanreliableprotected AStarThread.ASynchronousMoveSortingsortingprotected AbstractAStarThread.StorageHandler<H,T>storageHandlerprotected Tracetraceprotected inttraversedArcCountprotected AStarThread.Typetype-
Fields inherited from interface nl.tue.astar.AStarThread
NOMOVE
-
Fields inherited from interface nl.tue.astar.ObservableAStarThread
ESTIMATEIRRELEVANT
-
-
Constructor Summary
Constructors Constructor Description AbstractAStarThread(Delegate<H,T> delegate, Trace trace, int maxStates, AbstractAStarThread.StorageHandler<H,T> storageHandler)any implementation should, after calling this constructor, call initializeQueue(initialHead);
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddObserver(AStarObserver observer)protected booleanallowMove(Record rec, int modelMove, int logMove)This method handles the filtering of moves in the situation the total ordering is implied.protected TcomputeNewTail(Record newRec, T tail, H newHead, int modelMove, int movedEvent, int activity)protected HcomputeNextHead(Record rec, H head, int modelMove, int movedEvent, int activity)intgetComputedEstimateCount()Delegate<H,T>getDelegate()returns the delegate used for determining the possible moves during replay.RecordgetOptimalRecord(AStarThread.Canceller c)Returns a Record for an optimal alignment.RecordgetOptimalRecord(AStarThread.Canceller c, double timeLimit)RecordgetOptimalRecord(AStarThread.Canceller c, int stopAt)Returns a Record for an optimal alignment.RecordgetOptimalRecord(AStarThread.Canceller c, int stopAt, double timeLimit)gets the optimal record.booleangetPreferBreadth()Deprecated.intgetQueuedStateCount()Returns the number of nodes queueud.AStarThread.ASynchronousMoveSortinggetSorting()TracegetTrace()Returns the trace for which this AStarThread was instantiated.intgetTraversedArcCount()Returns the number of arcs that were traversed in the statespace.AStarThread.TypegetType()Returns the type of AStar usedintgetVisitedStateCount()Returns the number of visited states.protected voidinitializeQueue(H head)protected booleanisValidMoveOnLog(Record rec, int nextEvent, int activity, gnu.trove.list.TIntList modelMoves, gnu.trove.list.TIntList syncMoves)protected booleanisValidMoveOnModel(Record rec, gnu.trove.TIntCollection nextEvents, int activity, gnu.trove.list.TIntList modelMoves)protected Recordpoll()protected voidprocessMove(H head, T tail, Record rec, int modelMove, int movedEvent, int activity)protected voidprocessMovesForRecord(Record rec, H head, T tail, int stopAt, double timeLimit, long endTime)protected voidprocessMovesForRecordWithUpToDateTail(Record rec, H head, T tail, int stopAt, double timeLimit, long endTime)voidremoveObserver(AStarObserver observer)voidsetASynchronousMoveSorting(AStarThread.ASynchronousMoveSorting sorting)When aligning a trace with a model, any moves between two synchronous moves can be sorted.protected voidsetConsidered(Record record)voidsetEpsilon(double epsilon)Set epsilon for the weighted variants of A StarvoidsetExpectedLength(int length)Set expected length for the dynamic weighted variant of A StarvoidsetPreferBreadth(boolean preferBreadth)Deprecated.voidsetQueue(FastLookupPriorityQueue newQueue)voidsetQueueingModel(AStarThread.QueueingModel model)voidsetType(AStarThread.Type type)Sets the type of the AStar algorithm.java.lang.StringtoString()booleanwasReliable()After a call to run(), this method returns true if the returned Record yields the optimal result.
-
-
-
Field Detail
-
queue
protected FastLookupPriorityQueue queue
-
trace
protected final Trace trace
-
maxStates
protected final int maxStates
-
queuedStateCount
protected int queuedStateCount
-
traversedArcCount
protected int traversedArcCount
-
computedEstimateCount
protected int computedEstimateCount
-
poll
protected int poll
-
i
protected static int i
-
sorting
protected AStarThread.ASynchronousMoveSorting sorting
-
reliable
protected boolean reliable
-
considered
protected final gnu.trove.set.TLongSet considered
-
observers
protected java.util.List<AStarObserver> observers
-
storageHandler
protected final AbstractAStarThread.StorageHandler<H extends Head,T extends Tail> storageHandler
-
type
protected AStarThread.Type type
-
epsilon
protected double epsilon
-
expectedLength
protected double expectedLength
-
-
Constructor Detail
-
AbstractAStarThread
public AbstractAStarThread(Delegate<H,T> delegate, Trace trace, int maxStates, AbstractAStarThread.StorageHandler<H,T> storageHandler)
any implementation should, after calling this constructor, call initializeQueue(initialHead);- Parameters:
delegate-trace-maxStates-storageHandler-
-
-
Method Detail
-
getTrace
public Trace getTrace()
Description copied from interface:AStarThreadReturns the trace for which this AStarThread was instantiated.
-
getDelegate
public Delegate<H,T> getDelegate()
Description copied from interface:AStarThreadreturns the delegate used for determining the possible moves during replay.- Specified by:
getDelegatein interfaceAStarThread<H extends Head,T extends Tail>- Returns:
-
setPreferBreadth
@Deprecated public void setPreferBreadth(boolean preferBreadth)
Deprecated.Use setQueueingModel() or setQueue instead;- Specified by:
setPreferBreadthin interfaceAStarThread<H extends Head,T extends Tail>
-
setQueueingModel
public void setQueueingModel(AStarThread.QueueingModel model)
- Specified by:
setQueueingModelin interfaceAStarThread<H extends Head,T extends Tail>
-
setQueue
public void setQueue(FastLookupPriorityQueue newQueue)
-
addObserver
public void addObserver(AStarObserver observer)
- Specified by:
addObserverin interfaceObservableAStarThread<H extends Head,T extends Tail>
-
removeObserver
public void removeObserver(AStarObserver observer)
- Specified by:
removeObserverin interfaceObservableAStarThread<H extends Head,T extends Tail>
-
getPreferBreadth
@Deprecated public boolean getPreferBreadth()
Deprecated.- Specified by:
getPreferBreadthin interfaceAStarThread<H extends Head,T extends Tail>
-
setASynchronousMoveSorting
public void setASynchronousMoveSorting(AStarThread.ASynchronousMoveSorting sorting)
Description copied from interface:AStarThreadWhen aligning a trace with a model, any moves between two synchronous moves can be sorted. When sorting is set to LOGMOVEFIRST, then no logMove can ever follow a modelMove. If sorting is set to ModelMoveFirst, then no modelMove can ever follow a logMove. The default is LOGMOVEFIRST;- Specified by:
setASynchronousMoveSortingin interfaceAStarThread<H extends Head,T extends Tail>
-
getSorting
public AStarThread.ASynchronousMoveSorting getSorting()
- Specified by:
getSortingin interfaceAStarThread<H extends Head,T extends Tail>
-
getOptimalRecord
public Record getOptimalRecord(AStarThread.Canceller c) throws AStarException
Description copied from interface:AStarThreadReturns a Record for an optimal alignment. If no optimal alignment exists, or if none is found in time, a "best guess" is returned. To check whether the returned alignment is optimal, the method isReliable() can be used. To make sure you investigated the entire graph from which the (a) final node is reachable, keep calling the method getOptimalRecord(c, stopAt) with the stopAt cost equal to the total cost of the first record. When doing so until the first unreliable result, the entire search space is covered.- Specified by:
getOptimalRecordin interfaceAStarThread<H extends Head,T extends Tail>- Returns:
- Throws:
AStarException
-
getOptimalRecord
public Record getOptimalRecord(AStarThread.Canceller c, int stopAt) throws AStarException
Description copied from interface:AStarThreadReturns a Record for an optimal alignment. If no optimal alignment exists, if none is found in time or if the cost of an optimal alignment is higher than stopAt a "best guess" is returned. To check whether the returned alignment is optimal, the method isReliable() can be used. To make sure you investigated the entire graph from which the (a) final node is reachable, keep calling the method getOptimalRecord(c, stopAt) with the stopAt cost equal to the total cost of the first record. When doing so until the first unreliable result, the entire search space is covered.- Specified by:
getOptimalRecordin interfaceAStarThread<H extends Head,T extends Tail>- Returns:
- Throws:
AStarException
-
getOptimalRecord
public Record getOptimalRecord(AStarThread.Canceller c, double timeLimit) throws AStarException
- Throws:
AStarException
-
poll
protected Record poll()
-
getOptimalRecord
public Record getOptimalRecord(AStarThread.Canceller c, int stopAt, double timeLimit) throws AStarException
gets the optimal record. The search stops and returns the best prefix so far if either the stopAt value is reached in terms of cost, or if the timeLimit in seconds is reached. If the timelimit is negative, then time is unlimited.- Parameters:
c-stopAt-timeLimit-- Returns:
- Throws:
AStarException
-
processMovesForRecord
protected void processMovesForRecord(Record rec, H head, T tail, int stopAt, double timeLimit, long endTime) throws AStarException
- Throws:
AStarException
-
processMovesForRecordWithUpToDateTail
protected void processMovesForRecordWithUpToDateTail(Record rec, H head, T tail, int stopAt, double timeLimit, long endTime) throws AStarException
- Throws:
AStarException
-
setConsidered
protected void setConsidered(Record record)
-
isValidMoveOnModel
protected boolean isValidMoveOnModel(Record rec, gnu.trove.TIntCollection nextEvents, int activity, gnu.trove.list.TIntList modelMoves)
-
isValidMoveOnLog
protected boolean isValidMoveOnLog(Record rec, int nextEvent, int activity, gnu.trove.list.TIntList modelMoves, gnu.trove.list.TIntList syncMoves)
-
allowMove
protected boolean allowMove(Record rec, int modelMove, int logMove) throws AStarException
This method handles the filtering of moves in the situation the total ordering is implied. We assume a total ordering > on all moves (l,m) is the requested move (l',m') is the preceeding move (l'm') blocks the occurrence of (l,m) if and only if: 1) (l,m) was enabled before, i.e. no token flow 2) (l'm') > (l,m) Assume T(model) > T(log) > T(sync) Interpretation is: You can only do model or log moves with the intent to enable sync moves and among them, model and log moves are scheduled log move first- Parameters:
rec-nextEvent-modelMove-- Returns:
- Throws:
AStarException
-
wasReliable
public boolean wasReliable()
Description copied from interface:AStarThreadAfter a call to run(), this method returns true if the returned Record yields the optimal result. If this method returns false, then the returned Record was subOptimal, for example because the maximum state count was reached, of because no solution was found. The Record returned by the previous call to run should be considered as a best guess.- Specified by:
wasReliablein interfaceAStarThread<H extends Head,T extends Tail>- Returns:
-
processMove
protected void processMove(H head, T tail, Record rec, int modelMove, int movedEvent, int activity) throws AStarException
- Throws:
AStarException
-
computeNextHead
protected H computeNextHead(Record rec, H head, int modelMove, int movedEvent, int activity)
-
computeNewTail
protected T computeNewTail(Record newRec, T tail, H newHead, int modelMove, int movedEvent, int activity)
-
initializeQueue
protected void initializeQueue(H head) throws AStarException
- Throws:
AStarException
-
getVisitedStateCount
public int getVisitedStateCount()
Description copied from interface:AStarThreadReturns the number of visited states.- Specified by:
getVisitedStateCountin interfaceAStarThread<H extends Head,T extends Tail>- Returns:
-
getQueuedStateCount
public int getQueuedStateCount()
Description copied from interface:AStarThreadReturns the number of nodes queueud. This is at least the number of nodes visisted, but can be higher due to updates.- Specified by:
getQueuedStateCountin interfaceAStarThread<H extends Head,T extends Tail>- Returns:
-
getTraversedArcCount
public int getTraversedArcCount()
Description copied from interface:AStarThreadReturns the number of arcs that were traversed in the statespace.- Specified by:
getTraversedArcCountin interfaceAStarThread<H extends Head,T extends Tail>- Returns:
-
getComputedEstimateCount
public int getComputedEstimateCount()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
setType
public void setType(AStarThread.Type type)
Description copied from interface:AStarThreadSets the type of the AStar algorithm. Can be changed during execution, however if type is set to any weighted variant, the epsilon and expected length should be set.
-
getType
public AStarThread.Type getType()
Returns the type of AStar used
-
setEpsilon
public void setEpsilon(double epsilon)
Set epsilon for the weighted variants of A Star- Specified by:
setEpsilonin interfaceAStarThread<H extends Head,T extends Tail>- Parameters:
epsilon-
-
setExpectedLength
public void setExpectedLength(int length)
Set expected length for the dynamic weighted variant of A Star- Specified by:
setExpectedLengthin interfaceAStarThread<H extends Head,T extends Tail>- Parameters:
length-
-
-