Go to the documentation of this file.
28 #include <unordered_map>
32 #include <RobotComponents/interface/components/MotionPlanning/Tasks/AdaptiveDynamicDomainInformedRRTStar/DataStructures.h>
33 #include <RobotComponents/interface/components/MotionPlanning/Tasks/AdaptiveDynamicDomainInformedRRTStar/Task.h>
93 std::unordered_map<std::pair<std::size_t, std::size_t>, std::size_t>;
102 typename PendingUpdateLookuptableType::const_iterator;
114 Tree(
const VectorXf& startCfg);
123 void init(
const FullIceTree& iceTree,
124 AdaptiveDynamicDomainParameters newaddParams,
125 std::size_t newWorkerId);
159 const std::deque<Update>&
209 std::unique_lock<std::mutex> lock{m};
215 <<
"no remote update getter set but missing an update (w/s): " << w <<
"/"
217 throw std::logic_error{
"no remote update getter set but missing an update!"};
228 template <
class LockType,
class RemoteUpdateGetter>
242 template <
class LockType,
class RemoteUpdateGetter,
class UpdateConsumer>
246 RemoteUpdateGetter getRemoteUpdate,
247 UpdateConsumer updateConsumer = [](Update&&) {}
366 const NodeId& parent,
367 float fromParentCost)
370 NodeCreationUpdate{cfg, parent, fromParentCost});
383 RewireUpdate{child, newParent, fromParentCost});
405 template <
class LockType,
class RemoteUpdateGetter,
class UpdateConsumer>
409 RemoteUpdateGetter getRemoteUpdate,
410 UpdateConsumer updateConsumer)
418 const auto& dependetOnUpdateIds = u.dependetOnUpdateIds;
421 const auto updateWorkerId =
static_cast<std::size_t
>(u.workerId);
423 if (dependetOnUpdateIds.empty())
430 const auto updateId = dependetOnUpdateIds.at(updateWorkerId) + 1;
441 prepareUpdate(dependetOnUpdateIds, treeLock, getRemoteUpdate, updateConsumer);
447 updateConsumer(std::move(u));
459 template <
class LockType,
class RemoteUpdateGetter,
class UpdateConsumer>
463 RemoteUpdateGetter getRemoteUpdate,
464 UpdateConsumer updateConsumer)
468 for (std::size_t workerNodeId = 0; workerNodeId < dependetOnUpdateIds.size();
471 const auto updateSubId = dependetOnUpdateIds.at(workerNodeId);
485 auto missingIndex = (*it).second;
494 Update
update = getRemoteUpdate(workerNodeId, updateSubId);
498 update.dependetOnUpdateIds, treeLock, getRemoteUpdate, updateConsumer);
502 updateConsumer(std::move(
update));
548 setNodeParent(
const NodeId& child,
const NodeId& newParent,
float fromParentCost)
614 const NodeId& newParent,
615 float fromParentCost,
616 bool updateFromStartCost =
true);
641 goalNodes.emplace_back(GoalInfo{goal, costToGoToGoal});
651 std::vector<std::pair<NodeId, float>>
658 std::pair<NodeId, float>
668 NodeType&
getNode(
const NodeId&
id);
673 const NodeType&
getNode(
const NodeId&
id)
const;
678 const std::deque<std::deque<NodeType>>&
714 at(
const NodeId&
id)
const
748 typename std::deque<GoalInfo>::const_iterator
751 return std::min_element(
754 [
this](
const GoalInfo& fst,
const GoalInfo& snd)
756 return (getNode(fst.node).fromStartCost + fst.costToGoToGoal) <
757 (getNode(snd.node).fromStartCost + snd.costToGoToGoal);
782 [&nodeId](
const GoalInfo& info) { return info.node == nodeId; });
867 std::deque<std::deque<NodeType>>
nodes;
void createNewNodeCreationUpdate(const ConfigType &cfg, const NodeId &parent, float fromParentCost)
Adds a new node creation update to the current update.
PendingUpdateLookuptableType pendingUpdatesLookupTable
Speeds up lookup for available updates.
NodeType & at(const NodeId &id)
bool canApplyUpdate(const Update &u)
NodeType & at(std::size_t index)
const Update & getPendingUpdate(std::size_t workerId, std::size_t updateId) const
NodeIdList getNthPathIds(std::size_t n) const
void doDecreaseRadius(const NodeId &id)
Decreases a node's radius.
void setNodeParent(const NodeId &child, const NodeId &newParent, float fromParentCost)
Sets the parent node of child to parent.
PathWithCost getBestPath() const
bool hasAppliedUpdate(std::size_t workerId, Ice::Long updateId)
std::size_t nodeCount
The number of nodes in the rrt.
AdaptiveDynamicDomainParameters addParams
The parameters of adaptive dynamic domain)
void decreaseRadius(const NodeId &id)
Decreases a node's radius.
typename PendingUpdateLookuptableType::iterator PendingUpdateLookuptableIterator
Iterator for the PendingUpdateLookuptable.
void init(const FullIceTree &iceTree, AdaptiveDynamicDomainParameters newaddParams, std::size_t newWorkerId)
Initailizes the tree from the given tree.
NodeId getNextNodeIdFor(std::size_t workerId)
void applyPendingUpdates()
Applies all pending updates.
ConfigType config
The node's configuration.
PendingUpdateLookuptableIterator findPendingUpdate(std::size_t workerId, std::size_t updateId)
float getNthPathCost(std::size_t n) const
Ice::LongSeq appliedUpdateIds
List of ids of applied updates.
Represents a node of thr rrt.
NodeId addNode(ConfigType cfg, const NodeId &parent, float fromParentCost)
Adds a node to the tree.
PendingUpdateLookuptableConstIterator findPendingUpdate(std::size_t workerId, std::size_t updateId) const
NodeId doAddNode(ConfigType cfg, const NodeId &parent, float fromParentCost, std::size_t workerId)
Adds a node to the tree.
VectorXf ConfigType
The type of configurations.
std::pair< NodeId, float > getNearestNeighbourAndDistance(const ConfigType &cfg)
void applyNodeCreationUpdate(const NodeCreationUpdate &u, std::size_t workerId)
Applies a node creation update to the tree.
float radius
The node's radius.
void createNewGoalReachedUpdate(const NodeId &goal, float costToGoToGoal)
Adds a new goal reached update to the current update.
void applyGoalReachedUpdates(const GoalInfoList newGoalNodes)
Applies multiple goal reached updates to the tree.
NodeId parent
The node's parent.
void applyUpdate(const Update &u)
Applies the given update.
void createNewRadiusUpdate(const NodeId &id, bool increaseRadius)
Adds a new radius update to the current update.
void applyRewireUpdate(const RewireUpdate &rewireUpdate)
Applies a rewire update to the tree.
std::size_t getPathCount() const
void sendCurrentUpdate(TreeUpdateInterfacePrx &prx)
Sends the current update to the given proxy.
VectorXfSeq getPathTo(NodeId id) const
std::size_t workerId
The worker id of this trees owner.
void increaseRadius(const NodeId &id)
Increases a node's radius.
Use of this software is granted under one of the following two to be chosen freely by the user Boost Software License Version Marcin Kalicinski Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN TORT OR ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE The MIT Marcin Kalicinski Permission is hereby free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
void applyRadiusUpdate(const RadiusUpdate &u)
Applies a radius update to the tree.
std::unordered_map< std::pair< std::size_t, std::size_t >, std::size_t > PendingUpdateLookuptableType
Lookuptable for pending updates.
Tree()=default
Default ctor.
const std::deque< Update > & getLocalUpdates() const
const NodeType & at(const NodeId &id) const
const Ice::LongSeq & getAppliedUpdateIds() const
void doIncreaseRadius(const NodeId &id)
Increases a node's radius.
void applyPendingUpdate(std::size_t updateIndex, LockType &&treeLock, RemoteUpdateGetter getRemoteUpdate, UpdateConsumer updateConsumer)
Applies one pending update from the list of pending updates.
bool hasPendingUpdate(std::size_t workerId, std::size_t updateId) const
bool hasGoalNode(const NodeId &nodeId) const
FullIceTree getIceTree() const
NodeType & getNode(const NodeId &id)
NodeId getIdOfIndex(std::size_t index) const
std::deque< Update > localUpdates
Updates created by this tree.
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Ice::Long getPreviousUpdateId() const
static const NodeId ROOT_ID
The root node's id.
std::deque< std::deque< NodeType > > nodes
Holds all nodes.
float fromStartCost
Cost of the path (sttart node, this node)
std::vector< std::pair< NodeId, float > > getKNearestNeighboursAndDistances(const ConfigType &cfg, std::size_t k)
std::deque< GoalInfo > goalNodes
List of nodes able to reach the goal configuration.
float fromParentCost
Cost of the edge (parent node, this node)
const Update & getCurrentUpdate() const
void applyPendingUpdates(LockType &&treeLock, RemoteUpdateGetter getRemoteUpdate, UpdateConsumer updateConsumer=[](Update &&) {})
Applies all pending updates.
PathWithCost getNthPathWithCost(std::size_t n) const
void doSetNodeParent(const NodeId &child, const NodeId &newParent, float fromParentCost, bool updateFromStartCost=true)
Sets the parent node of child to parent.
Ice::Long getCurrentUpdateId() const
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
A structure holding and managing all data connected to the tree used in the ADDIRRT* algorithm.
std::set< NodeId > children
Link to all children nodes.
void addPendingUpdate(const Update &u)
Adds a new update to the list of pending updates.
void increaseWorkerCountTo(std::size_t count)
Increases the storage of all data structures to be appropriate for count workers.
float getBestCost() const
std::deque< GoalInfo >::const_iterator getBestCostIt() const
void addGoalReached(const NodeId &goal, float costToGoToGoal)
Adds a node to the list of nodes that can reach the goal configuration.
const NodeType & at(std::size_t index) const
std::deque< Update > pendingUpdates
Updates to apply to the tree.
Update & getCurrentUpdateNonConst()
void doAddGoalReached(const NodeId &goal, float costToGoToGoal)
Adds a node to the list of nodes that can reach the goal configuration.
void pushCosts(const NodeId &root)
Updates fromStartCosts for all children from root.
void prepareUpdate(Ice::LongSeq dependetOnUpdateIds, LockType &&treeLock, RemoteUpdateGetter getRemoteUpdate, UpdateConsumer updateConsumer)
Prepares an update by applying all dependet on updates.
const std::deque< std::deque< NodeType > > & getNodes() const
void createNewRewireUpdate(const NodeId &child, const NodeId &newParent, float fromParentCost)
Adds a new node creation update to the current update.
void prepareNextUpdate()
Prepares the next update.
void applyPendingUpdates(LockType &&treeLock, RemoteUpdateGetter getRemoteUpdate)
The same as applyPendingUpdates(LockType, RemoteUpdateGetter, UpdateConsumer) but uses an noop as upd...
typename PendingUpdateLookuptableType::const_iterator PendingUpdateLookuptableConstIterator
Const iterator for the PendingUpdateLookuptable.