All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
IntegratedQueue.cpp
50 BITstar::IntegratedQueue::IntegratedQueue(const ompl::base::OptimizationObjectivePtr& opt, const DistanceFunc& distanceFunc, const NeighbourhoodFunc& nearSamplesFunc, const NeighbourhoodFunc& nearVerticesFunc, const VertexHeuristicFunc& lowerBoundHeuristicVertex, const VertexHeuristicFunc& currentHeuristicVertex, const EdgeHeuristicFunc& lowerBoundHeuristicEdge, const EdgeHeuristicFunc& currentHeuristicEdge, const EdgeHeuristicFunc& currentHeuristicEdgeTarget)
64 std::placeholders::_1, std::placeholders::_2) ), //This tells the vertexQueue_ to use the vertexQueueComparison for sorting
67 std::placeholders::_1, std::placeholders::_2) ), //This tells the edgeQueue_ to use the edgeQueueComparison for sorting
103 void BITstar::IntegratedQueue::eraseVertex(const VertexPtr& oldVertex, bool disconnectParent, const VertexPtrNNPtr& vertexNN, const VertexPtrNNPtr& freeStateNN, std::vector<VertexPtr>* recycledVertices)
249 for (EdgeQueueIterList::iterator listIter = toDeleteIter->second.begin(); listIter != toDeleteIter->second.end(); ++listIter)
251 //Erase the edge, removing it from the *other* lookup. No need to remove from this lookup, as that's being cleared:
287 for (EdgeQueueIterList::iterator listIter = toDeleteIter->second.begin(); listIter != toDeleteIter->second.end(); ++listIter)
289 //Erase the edge, removing it from the *other* lookup. No need to remove from this lookup, as that's being cleared:
300 throw ompl::Exception("Removing edges in the queue coming from a vertex requires parent vertex lookup, which is not enabled for this instance of the container.");
315 //The iterator to the key,value of the child-lookup map, i.e., an iterator to a pair whose second is a list of edges to the child (which are actually iterators to the queue):
329 for (EdgeQueueIterList::iterator listIter = itersToVertex->second.begin(); listIter != itersToVertex->second.end(); ++listIter)
345 //And finally erase the lookup iterator from the from lookup. If this was done first, the iterator would be invalidated for the above.
353 throw ompl::Exception("Removing edges in the queue going to a vertex requires child vertex lookup, which is not enabled for this instance of the container.");
368 //The iterator to the key, value of the parent-lookup map, i.e., an iterator to a pair whose second is a list of edges from the child (which are actually iterators to the queue):
382 for (EdgeQueueIterList::iterator listIter = itersFromVertex->second.begin(); listIter != itersFromVertex->second.end(); ++listIter)
398 //And finally erase the lookup iterator from the from lookup. If this was done first, the iterator would be invalidated for the above.
430 std::pair<unsigned int, unsigned int> BITstar::IntegratedQueue::prune(const VertexPtr& pruneStartPtr, const VertexPtrNNPtr& vertexNN, const VertexPtrNNPtr& freeStateNN, std::vector<VertexPtr>* recycledVertices)
436 //The vertex expansion queue is sorted on an estimated solution cost considering the *current* cost-to-come of the vertices, while we prune by considering the best-case cost-to-come.
437 //This means that the value of the vertices in the queue are an upper-bounding estimate of the value we will use to prune them.
438 //Therefore, we can start our pruning at the goal vertex and iterate forward through the queue from there.
496 std::pair<unsigned int, unsigned int> BITstar::IntegratedQueue::resort(const VertexPtrNNPtr& vertexNN, const VertexPtrNNPtr& freeStateNN, std::vector<VertexPtr>* recycledVertices)
514 //Iterate over the vector and place into the unique queue indexed on *depth*. This guarantees that we won't process a branch multiple times by being given different vertices down its chain
515 for (std::list<VertexPtr>::iterator vIter = resortVertices_.begin(); vIter != resortVertices_.end(); ++vIter)
526 for (DepthToUMapMap::iterator deepIter = uniqueResorts.begin(); deepIter != uniqueResorts.end(); ++deepIter)
528 for (VertexIdToVertexPtrUMap::iterator vIter = deepIter->second.begin(); vIter != deepIter->second.end(); ++vIter)
537 if (this->vertexPruneCondition(vIter->second) == true && static_cast<bool>(vertexNN) == true && static_cast<bool>(freeStateNN) == true)
558 //Get a reference to the container for the children, all children are 1 level deeper than their parent.:
562 //Place the children into the container, as the container is a map, it will not allow the children to be entered twice.
573 //No else, this vertex was a child of a vertex pruned during the resort. It has been returned to the set of free samples.
645 //As the sample is in the graph (and therefore could be part of g_t), prune iff g^(v) + h^(v) > g_t(x_g)
655 //As the sample is not in the graph (and therefore not part of g_t), prune if g^(v) + h^(v) >= g_t(x_g)
656 return this->isCostWorseThanOrEquivalentTo(lowerBoundHeuristicVertexFunc_(state), costThreshold_);
670 //If the child is connected already, we need to check if we could do better than it's current connection. But only if we're not pruning based on the first check
674 //rval = this->isCostWorseThan(opt_->combineCosts(this->costToComeHeuristic(edge.first), this->edgeCostHeuristic(edge)), edge.second->getCost()); //Ever rewire?
676 rval = this->isCostWorseThan(currentHeuristicEdgeTargetFunc_(edge), edge.second->getCost()); //Currently rewire?
701 for (CostToVertexMMap::const_iterator vIter = vertexToExpand_; vIter != vertexQueue_.end(); ++vIter)
846 //By virtue of the vertex expansion rules, the token will always sit at the front of a group of equivalent cost vertices (that is to say, all vertices with the same cost get expanded at the same time)
860 for (CostToVertexMMap::const_iterator vIter = vertexToExpand_; vIter != vertexQueue_.end(); ++vIter)
869 void BITstar::IntegratedQueue::listEdges(std::vector<std::pair<VertexConstPtr, VertexConstPtr> >* edgeQueue)
875 for( CostToVertexPtrPairMMap::const_iterator eIter = edgeQueue_.begin(); eIter != edgeQueue_.end(); ++eIter )
904 //This is isCostBetterThanOrEquivalentTo because of the second ordering criteria. The vertex expanded could match the edge in queue on total cost, but have less cost-to-come.
905 else if (this->isCostBetterThanOrEquivalentTo( vertexToExpand_->first, edgeQueue_.begin()->first.first ) == true)
967 //If we're usjng k-nearest, we always have to also get the neighbourVertices and the do some post-processing
994 //It has, which means that outgoing edges to old unconnected vertices have already been considered. Only add those that lead to new vertices
1007 //If the vertex has never been expanded into possible rewiring edges *and* either we're not delaying rewiring or we have a solution, we add those rewiring candidates:
1008 if (vertex->hasBeenExpandedToVertices() == false && (delayRewiring_ == false || hasSolution_ == true))
1010 //If we're not using k-nearest, we will not have gotten the neighbour vertices yet, get them now
1018 //Iterate over the vector of connected targets and add only those who could ever provide a better solution:
1074 void BITstar::IntegratedQueue::processKNearest(unsigned int k, const VertexConstPtr& vertex, std::vector<VertexPtr>* kNearSamples, std::vector<VertexPtr>* kNearVertices)
1085 while (samplePos + vertexPos < k && (samplePos < kNearSamples->size() || vertexPos < kNearVertices->size()))
1101 if ( distanceFunc_(kNearVertices->at(vertexPos), vertex) < distanceFunc_(kNearSamples->at(samplePos), vertex) )
1146 else if ( this->vertexQueueComparison(myLookup->second->first, vertexToExpand_->first) == true )
1148 //The vertexQueueCondition says that this vertex was entered with a cost that is in front of the current token:
1180 //Iterate over the list of iters to resort, inserting each one as a new edge, and then removing it as an iterator from the edge queue and the incoming lookup
1181 for (EdgeQueueIterList::iterator resortIter = edgeItersToResort.begin(); resortIter != edgeItersToResort.end(); ++resortIter)
1191 //Remove the old edge and its entry in the incoming lookup. No need to remove from this lookup, as that's been cleared:
1200 std::pair<unsigned int, unsigned int> BITstar::IntegratedQueue::pruneBranch(const VertexPtr& branchBase, const VertexPtrNNPtr& vertexNN, const VertexPtrNNPtr& freeStateNN, std::vector<VertexPtr>* recycledVertices)
1222 //Disconnect myself from my parent, not cascading costs as I know my children are also being disconnected:
1229 numPruned.second = this->vertexRemoveHelper(branchBase, vertexNN, freeStateNN, recycledVertices, true);
1252 void BITstar::IntegratedQueue::disconnectParent(const VertexPtr& oldVertex, bool cascadeCostUpdates)
1256 throw ompl::Exception("An orphaned vertex has been passed for disconnection. Something went wrong.");
1259 //Check if my parent has already been pruned. This can occur if we're cascading vertex disconnections.
1272 void BITstar::IntegratedQueue::vertexInsertHelper(const VertexPtr& newVertex, bool expandIfBeforeToken)
1279 vertexIter = vertexQueue_.insert( std::make_pair(this->vertexQueueValue(newVertex), newVertex) );
1287 //If the vertex queue is now of size 1, that means that this was the first vertex. Set the token to it and don't even think of expanding anything:
1297 2 The new vertex is before the token, but *not* immediately (i.e., there are vertices between it):
1300 3 The new vertex is after the token: Don't expand. It cleanly goes into the list of vertices to expand
1301 Note: By shifting the token, we assure that if the new vertex is better than the best edge, it will get expanded on the next pop.
1303 The cases look like this (-: expanded vertex, x: unexpanded vertex, X: token (next to expand), *: new vertex):
1314 //The vertex before the token. Remember that since we have already added the new vertex, this could be ourselves:
1324 //The vertex before the token is the newly added vertex. Therefore we can just move the token up to the newly added vertex:
1334 //It is. We've expanded the whole queue, and the new vertex isn't at the end of the queue. Expand!
1341 if ( this->vertexQueueComparison(this->vertexQueueValue(newVertex), vertexToExpand_->first) == true )
1354 unsigned int BITstar::IntegratedQueue::vertexRemoveHelper(VertexPtr oldVertex, const VertexPtrNNPtr& vertexNN, const VertexPtrNNPtr& freeStateNN, std::vector<VertexPtr>* recycledVertices, bool removeLookups)
1363 throw ompl::Exception("Cannot delete a vertex connected to a parent unless the vertex is being immediately reinserted, in which case removeLookups should be false.");
1405 if (static_cast<bool>(vertexNN) == true && static_cast<bool>(freeStateNN) == true && static_cast<bool>(recycledVertices) == true)
1432 //Mark myself as a "new" sample. This assures that all possible incoming edges will be considered
1442 //Else, if I was given null pointers, that's because this sample is not allowed to change sets.
1456 void BITstar::IntegratedQueue::edgeInsertHelper(const VertexPtrPair& newEdge, EdgeQueueIter positionHint)
1471 edgeIter = edgeQueue_.insert(positionHint, std::make_pair(this->edgeQueueValue(newEdge), newEdge));
1491 void BITstar::IntegratedQueue::edgeRemoveHelper(const EdgeQueueIter& oldEdgeIter, bool rmIncomingLookup, bool rmOutgoingLookup)
1536 void BITstar::IntegratedQueue::rmEdgeLookupHelper(VertexIdToEdgeQueueIterListUMap& lookup, const BITstar::VertexId& idx, const EdgeQueueIter& mmapIterToRm)
1598 BITstar::IntegratedQueue::CostPair BITstar::IntegratedQueue::edgeQueueValue(const VertexPtrPair& edge) const
1605 bool BITstar::IntegratedQueue::vertexQueueComparison(const ompl::base::Cost& lhs, const ompl::base::Cost& rhs) const
1613 bool BITstar::IntegratedQueue::edgeQueueComparison(const CostPair& lhs, const CostPair& rhs) const
1639 bool BITstar::IntegratedQueue::isCostWorseThan(const ompl::base::Cost& a, const ompl::base::Cost& b) const
1647 bool BITstar::IntegratedQueue::isCostNotEquivalentTo(const ompl::base::Cost& a, const ompl::base::Cost& b) const
1655 bool BITstar::IntegratedQueue::isCostBetterThanOrEquivalentTo(const ompl::base::Cost& a, const ompl::base::Cost& b) const
1663 bool BITstar::IntegratedQueue::isCostWorseThanOrEquivalentTo(const ompl::base::Cost& a, const ompl::base::Cost& b) const
std::function< ompl::base::Cost(const VertexConstPtr &)> VertexHeuristicFunc
A std::function definition of a heuristic function for a vertex.
Definition: IntegratedQueue.h:102
void pruneEdgesTo(const VertexPtr &cVertex)
Prune edges in the edge queue that lead to the given vertex using the prune function.
Definition: IntegratedQueue.cpp:308
void listVertices(std::vector< VertexConstPtr > *vertexQueue)
Get a copy of the vertices in the vertex queue that are left to be expanded. This is expensive and is...
Definition: IntegratedQueue.cpp:854
ompl::base::OptimizationObjectivePtr opt_
Optimization objective copied from ProblemDefinition.
Definition: BITstar.h:525
void setDelayedRewiring(bool delayRewiring)
Delay considering rewiring edges until an initial solution is found. This improves the time required ...
Definition: IntegratedQueue.cpp:1674
bool samplePruneCondition(const VertexPtr &vertex) const
The condition used to prune disconnected samples from the free set. Compares lowerBoundHeuristicVerte...
Definition: IntegratedQueue.cpp:652
void markVertexUnsorted(const VertexPtr &vertex)
Mark the queue as requiring resorting downstream of the specified vertex.
Definition: IntegratedQueue.cpp:415
std::pair< ompl::base::Cost, ompl::base::Cost > CostPair
A typedef for a pair of costs, i.e., the edge sorting key.
Definition: IntegratedQueue.h:96
void eraseVertex(const VertexPtr &oldVertex, bool disconnectParent, const VertexPtrNNPtr &vertexNN, const VertexPtrNNPtr &freeStateNN, std::vector< VertexPtr > *recycledVertices)
Erase a vertex from the vertex expansion queue. Will disconnect the vertex from its parent and remove...
Definition: IntegratedQueue.cpp:103
unsigned int numVertices() const
Returns the number of vertices left to expand. This has nontrivial cost, as the token must be moved t...
Definition: IntegratedQueue.cpp:691
bool isCostWorseThanOrEquivalentTo(const ompl::base::Cost &a, const ompl::base::Cost &b) const
Compare whether cost a is worse or equivalent to cost b by checking that a is not better than b...
Definition: BITstar.cpp:1793
std::shared_ptr< NearestNeighbors< VertexPtr > > VertexPtrNNPtr
The OMPL::NearestNeighbors structure.
Definition: BITstar.h:137
bool edgePruneCondition(const VertexPtrPair &edge) const
The condition used to prune edge (i.e., vertex-pair) out of the queue. Compares lowerBoundHeuristicEd...
Definition: IntegratedQueue.cpp:661
unsigned int numEdgesTo(const VertexPtr &cVertex) const
Get the number of edges in the queue pointing to a specific vertex.
Definition: IntegratedQueue.cpp:713
std::function< ompl::base::Cost(const VertexConstPtrPair &)> EdgeHeuristicFunc
A std::function definition of a heuristic function for an edge.
Definition: IntegratedQueue.h:105
std::pair< unsigned int, unsigned int > resort(const VertexPtrNNPtr &vertexNN, const VertexPtrNNPtr &freeStateNN, std::vector< VertexPtr > *recycledVertices)
Resort the queue, only reinserting edges/vertices if their lower-bound heuristic is less then the thr...
Definition: IntegratedQueue.cpp:496
unsigned int numEdges() const
Returns the number of edges in the queue.
Definition: IntegratedQueue.cpp:684
std::function< double(const VertexConstPtr &, const VertexConstPtr &)> DistanceFunc
A std::function definition for the distance between two vertices.
Definition: IntegratedQueue.h:108
VertexPtr frontVertex()
Get the best vertex on the queue without incrementing the vertex queue.
Definition: IntegratedQueue.cpp:117
void pruneEdgesFrom(const VertexPtr &pVertex)
Prune edges in the edge queue that leave from the given vertex using the prune function.
Definition: IntegratedQueue.cpp:361
std::shared_ptr< const Vertex > VertexConstPtr
A constant vertex shared pointer.
Definition: BITstar.h:125
void insertEdge(const VertexPtrPair &newEdge)
Insert an edge into the edge processing queue. Edges are removed from the processing queue...
Definition: IntegratedQueue.cpp:95
bool isCostBetterThanOrEquivalentTo(const ompl::base::Cost &a, const ompl::base::Cost &b) const
Compare whether cost a is better or equivalent to cost b by checking that b is not better than a...
Definition: BITstar.cpp:1785
bool isVertexExpanded(const VertexConstPtr &vertex) const
Returns whether a given vertex has been expanded or not.
Definition: IntegratedQueue.cpp:824
CostPair frontEdgeValue()
Get the value of the best edge on the queue, leaving it on the edge queue.
Definition: IntegratedQueue.cpp:165
VertexPtrPair frontEdge()
Get the best edge on the queue, leaving it on the edge queue.
Definition: IntegratedQueue.cpp:133
bool isEmpty()
Returns true if the queue is empty. In the case where the edge queue is empty but the vertex queue is...
Definition: IntegratedQueue.cpp:809
bool delayRewiring_
Whether to delay rewiring until a solution is found (param)
Definition: BITstar.h:661
A queue of edges to be processed that integrates both the expansion of Vertices and the ordering of t...
Definition: IntegratedQueue.h:90
void reset()
Reset the queue, clearing all the edge containers and moving the vertex expansion token to the start...
Definition: IntegratedQueue.cpp:603
void setThreshold(const ompl::base::Cost &costThreshold)
Set the threshold of the queue.
Definition: IntegratedQueue.cpp:218
unsigned int numEdgesFrom(const VertexPtr &pVertex) const
Get the number of edges in the queue coming from a specific vertex.
Definition: IntegratedQueue.cpp:754
std::pair< VertexPtr, VertexPtr > VertexPtrPair
A pair of vertices, i.e., an edge.
Definition: BITstar.h:133
ompl::base::Cost getThreshold() const
Get the threshold of the queue.
Definition: IntegratedQueue.cpp:225
VertexPtrPair popFrontEdge()
Pop the best edge off the queue, removing it from the edge queue in the process.
Definition: IntegratedQueue.cpp:200
A shared pointer wrapper for ompl::base::OptimizationObjective.
IntegratedQueue(const ompl::base::OptimizationObjectivePtr &opt, const DistanceFunc &distanceFunc, const NeighbourhoodFunc &nearSamplesFunc, const NeighbourhoodFunc &nearVerticesFunc, const VertexHeuristicFunc &lowerBoundHeuristicVertex, const VertexHeuristicFunc ¤tHeuristicVertex, const EdgeHeuristicFunc &lowerBoundHeuristicEdge, const EdgeHeuristicFunc ¤tHeuristicEdge, const EdgeHeuristicFunc ¤tHeuristicEdgeTarget)
Construct an integrated queue.
Definition: IntegratedQueue.cpp:50
std::pair< unsigned int, unsigned int > prune(const VertexPtr &pruneStartPtr, const VertexPtrNNPtr &vertexNN, const VertexPtrNNPtr &freeStateNN, std::vector< VertexPtr > *recycledVertices)
Prune the vertex queue of vertices whose their lower-bound heuristic is greater then the threshold...
Definition: IntegratedQueue.cpp:430
void removeEdgesFrom(const VertexPtr &pVertex)
Erase all edges in the edge queue that leave from the given vertex.
Definition: IntegratedQueue.cpp:270
bool vertexPruneCondition(const VertexPtr &vertex) const
The condition used to prune vertices out of the queue. Compares lowerBoundHeuristicVertex to the give...
Definition: IntegratedQueue.cpp:642
ompl::base::Cost frontVertexValue()
Get the value of the best vertex on the queue without incrementing the vertex queue.
Definition: IntegratedQueue.cpp:149
void removeEdgesTo(const VertexPtr &cVertex)
Erase all edges in the edge queue that lead to the given vertex.
Definition: IntegratedQueue.cpp:232
bool isCostWorseThan(const ompl::base::Cost &a, const ompl::base::Cost &b) const
Compare whether cost a is worse than cost b by checking whether b is better than a.
Definition: BITstar.cpp:1769
void listEdges(std::vector< std::pair< VertexConstPtr, VertexConstPtr > > *edgeQueue)
Get a copy of the edge queue. This is expensive and is only meant for animations/debugging.
Definition: IntegratedQueue.cpp:869
void insertVertex(const VertexPtr &newVertex)
Insert a vertex into the vertex expansion queue. Vertices remain in the vertex queue until pruned or ...
Definition: IntegratedQueue.cpp:87
std::function< unsigned int(const VertexPtr &, std::vector< VertexPtr > *)> NeighbourhoodFunc
A std::function definition for the neighbourhood of a vertex .
Definition: IntegratedQueue.h:111
bool getDelayedRewiring() const
Get whether BIT* is delaying rewiring until a solution is found.
Definition: IntegratedQueue.cpp:1681
bool isReset() const
Returns true if the queue is reset. This means that no edges have been expanded and the vertex expans...
Definition: IntegratedQueue.cpp:802
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:47
void finish()
Finish the queue, clearing all the edge containers and moving the vertex expansion token to the end...
Definition: IntegratedQueue.cpp:586