Package nl.tue.astar.util
Class AbstractFastLookupPriorityQueue
- java.lang.Object
-
- nl.tue.astar.util.AbstractFastLookupPriorityQueue
-
- All Implemented Interfaces:
FastLookupPriorityQueue
- Direct Known Subclasses:
BreadthFirstFastLookupPriorityQueue,DepthFirstFastLookupPriorityQueue,RandomFastLookupPriorityQueue
public abstract class AbstractFastLookupPriorityQueue extends java.lang.Object implements FastLookupPriorityQueue
-
-
Field Summary
Fields Modifier and Type Field Description protected gnu.trove.map.TLongIntMaplocationMapprotected intmaxCostThe maximum total cost for any record in this queue.protected static intNEVprotected Record[]queuePriority queue represented as a balanced binary heap: the two children of queue[n] are queue[2*n+1] and queue[2*(n+1)].protected intsizeThe number of elements in the priority queue.
-
Constructor Summary
Constructors Constructor Description AbstractFastLookupPriorityQueue(int initialCapacity)AbstractFastLookupPriorityQueue(int initialCapacity, int maxCost)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanadd(Record newE)Inserts the specified element into this priority queue.booleancheckInv()protected booleancheckInv(int loc)Recordcontains(Record newRec)Checks if the queue contains a record pointing to the same state as the given record.intgetMaxCost()protected voidgrow(int minCapacity)Increases the capacity of the array.inthashCode()protected abstract booleanisBetter(Record r1, Record r2)booleanisEmpty()protected voidoffer(Record e)Inserts the specified element into this priority queue.Recordpeek()protected Recordpeek(int location)Recordpoll()voidsetMaxCost(int maxCost)protected voidsiftDown(int k, Record x)Inserts item x at position k, maintaining heap invariant by demoting x down the tree repeatedly until it is less than or equal to its children or is a leaf.protected voidsiftUp(int k, Record x)Inserts item x at position k, maintaining heap invariant by promoting x up the tree until it is greater than or equal to its parent, or is the root.intsize()java.lang.StringtoString()protected voidupdateToBetter(int index, Record newRecord)
-
-
-
Field Detail
-
locationMap
protected final gnu.trove.map.TLongIntMap locationMap
-
NEV
protected static final int NEV
- See Also:
- Constant Field Values
-
queue
protected Record[] queue
Priority queue represented as a balanced binary heap: the two children of queue[n] are queue[2*n+1] and queue[2*(n+1)]. The priority queue is ordered by the record's natural ordering: For each node n in the heap and each descendant d of n, n <= d. The element with the best value is in queue[0], assuming the queue is nonempty.
-
size
protected int size
The number of elements in the priority queue.
-
maxCost
protected int maxCost
The maximum total cost for any record in this queue. If the cost of a record which is added is higher that this value, it is not added
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceFastLookupPriorityQueue
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
setMaxCost
public void setMaxCost(int maxCost)
- Specified by:
setMaxCostin interfaceFastLookupPriorityQueue
-
getMaxCost
public int getMaxCost()
- Specified by:
getMaxCostin interfaceFastLookupPriorityQueue
-
contains
public Record contains(Record newRec)
Description copied from interface:FastLookupPriorityQueueChecks if the queue contains a record pointing to the same state as the given record. If so, it returns that record, if not, it returns null;- Specified by:
containsin interfaceFastLookupPriorityQueue- Returns:
-
checkInv
public boolean checkInv()
-
grow
protected void grow(int minCapacity)
Increases the capacity of the array.- Parameters:
minCapacity- the desired minimum capacity
-
peek
public Record peek()
- Specified by:
peekin interfaceFastLookupPriorityQueue
-
size
public int size()
- Specified by:
sizein interfaceFastLookupPriorityQueue
-
poll
public Record poll()
- Specified by:
pollin interfaceFastLookupPriorityQueue
-
peek
protected Record peek(int location)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
updateToBetter
protected void updateToBetter(int index, Record newRecord)
-
add
public boolean add(Record newE)
Inserts the specified element into this priority queue.- Specified by:
addin interfaceFastLookupPriorityQueue- Returns:
true(as specified byCollection.add(E))- Throws:
java.lang.ClassCastException- if the specified element cannot be compared with elements currently in this priority queue according to the priority queue's orderingjava.lang.NullPointerException- if the specified element is null
-
offer
protected void offer(Record e)
Inserts the specified element into this priority queue.- Throws:
java.lang.ClassCastException- if the specified element cannot be compared with elements currently in this priority queue according to the priority queue's orderingjava.lang.NullPointerException- if the specified element is null
-
siftUp
protected void siftUp(int k, Record x)Inserts item x at position k, maintaining heap invariant by promoting x up the tree until it is greater than or equal to its parent, or is the root.- Parameters:
k-x- the item to insert
-
siftDown
protected void siftDown(int k, Record x)Inserts item x at position k, maintaining heap invariant by demoting x down the tree repeatedly until it is less than or equal to its children or is a leaf.- Parameters:
k- the position to fillx- the item to insert
-
checkInv
protected boolean checkInv(int loc)
-
-