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>
111 Tree(
const VectorXf& startCfg);
120 void init(
const FullIceTree& iceTree,
121 AdaptiveDynamicDomainParameters newaddParams,
122 std::size_t newWorkerId
200 std::unique_lock<std::mutex> lock {m};
205 ARMARX_ERROR_S <<
"no remote update getter set but missing an update (w/s): " << w <<
"/" << u;
206 throw std::logic_error {
"no remote update getter set but missing an update!"};
218 template<
class LockType,
class RemoteUpdateGetter>
231 template<
class LockType,
class RemoteUpdateGetter,
class UpdateConsumer>
234 RemoteUpdateGetter getRemoteUpdate,
235 UpdateConsumer updateConsumer = [](Update&&) {}
371 template<
class LockType,
class RemoteUpdateGetter,
class UpdateConsumer>
372 void applyPendingUpdate(std::size_t updateIndex, LockType&& treeLock, RemoteUpdateGetter getRemoteUpdate, UpdateConsumer updateConsumer)
380 const auto& dependetOnUpdateIds = u.dependetOnUpdateIds;
383 const auto updateWorkerId =
static_cast<std::size_t
>(u.workerId);
385 if (dependetOnUpdateIds.empty())
392 const auto updateId = dependetOnUpdateIds.at(updateWorkerId) + 1;
404 prepareUpdate(dependetOnUpdateIds, treeLock, getRemoteUpdate, updateConsumer);
410 updateConsumer(std::move(u));
422 template<
class LockType,
class RemoteUpdateGetter,
class UpdateConsumer>
423 void prepareUpdate(Ice::LongSeq dependetOnUpdateIds, LockType&& treeLock, RemoteUpdateGetter getRemoteUpdate, UpdateConsumer updateConsumer)
427 for (std::size_t workerNodeId = 0; workerNodeId < dependetOnUpdateIds.size(); ++workerNodeId)
429 const auto updateSubId = dependetOnUpdateIds.at(workerNodeId);
443 auto missingIndex = (*it).second;
452 Update
update = getRemoteUpdate(workerNodeId, updateSubId);
459 updateConsumer(std::move(
update));
500 void setNodeParent(
const NodeId& child,
const NodeId& newParent,
float fromParentCost)
557 void doSetNodeParent(
const NodeId& child,
const NodeId& newParent,
float fromParentCost,
bool updateFromStartCost =
true);
578 goalNodes.emplace_back(GoalInfo {goal, costToGoToGoal});
601 NodeType&
getNode(
const NodeId&
id);
606 const NodeType&
getNode(
const NodeId&
id)
const;
610 const std::deque<std::deque<NodeType>>&
getNodes()
const
671 return std::min_element(
goalNodes.begin(),
goalNodes.end(), [
this](
const GoalInfo & fst,
const GoalInfo & snd)
673 return (getNode(fst.node).fromStartCost + fst.costToGoToGoal) < (getNode(snd.node).fromStartCost + snd.costToGoToGoal);
698 [&nodeId](
const GoalInfo & info)
700 return info.node == nodeId;
780 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.