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};
212 [](std::size_t w, Ice::Long u)
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&&) {}
339 std::copy(newGoalNodes.begin(), newGoalNodes.end(), std::back_inserter(
goalNodes));
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; });
832 return {
static_cast<Ice::Long
>(
workerId),
867 std::deque<std::deque<NodeType>>
nodes;
NodeId addNode(ConfigType cfg, const NodeId &parent, float fromParentCost)
Adds a node to the tree.
std::deque< GoalInfo > goalNodes
List of nodes able to reach the goal configuration.
PathWithCost getNthPathWithCost(std::size_t n) const
std::unordered_map< std::pair< std::size_t, std::size_t >, std::size_t > PendingUpdateLookuptableType
Lookuptable for pending updates.
FullIceTree getIceTree() const
std::pair< NodeId, float > getNearestNeighbourAndDistance(const ConfigType &cfg)
void init(const FullIceTree &iceTree, AdaptiveDynamicDomainParameters newaddParams, std::size_t newWorkerId)
Initailizes the tree from the given tree.
NodeId doAddNode(ConfigType cfg, const NodeId &parent, float fromParentCost, std::size_t workerId)
Adds a node to the tree.
void applyNodeCreationUpdate(const NodeCreationUpdate &u, std::size_t workerId)
Applies a node creation update to the tree.
Ice::Long getCurrentUpdateId() const
void sendCurrentUpdate(TreeUpdateInterfacePrx &prx)
Sends the current update to the given proxy.
PendingUpdateLookuptableConstIterator findPendingUpdate(std::size_t workerId, std::size_t updateId) const
void applyPendingUpdates()
Applies all pending updates.
NodeId getNextNodeIdFor(std::size_t workerId)
AdaptiveDynamicDomainParameters addParams
The parameters of adaptive dynamic domain)
NodeType & at(std::size_t index)
void decreaseRadius(const NodeId &id)
Decreases a node's radius.
std::deque< GoalInfo >::const_iterator getBestCostIt() const
std::size_t workerId
The worker id of this trees owner.
void createNewGoalReachedUpdate(const NodeId &goal, float costToGoToGoal)
Adds a new goal reached update to the current update.
Update & getCurrentUpdateNonConst()
void applyGoalReachedUpdates(const GoalInfoList newGoalNodes)
Applies multiple goal reached updates to the tree.
const Update & getPendingUpdate(std::size_t workerId, std::size_t updateId) const
NodeType & getNode(const NodeId &id)
PendingUpdateLookuptableIterator findPendingUpdate(std::size_t workerId, std::size_t updateId)
void applyUpdate(const Update &u)
Applies the given update.
std::deque< Update > pendingUpdates
Updates to apply to the tree.
void doSetNodeParent(const NodeId &child, const NodeId &newParent, float fromParentCost, bool updateFromStartCost=true)
Sets the parent node of child to parent.
void doDecreaseRadius(const NodeId &id)
Decreases a node's radius.
std::size_t nodeCount
The number of nodes in the rrt.
PathWithCost getBestPath() const
std::deque< Update > localUpdates
Updates created by this tree.
VectorXf ConfigType
The type of configurations.
float getBestCost() const
std::deque< std::deque< NodeType > > nodes
Holds all nodes.
Tree()=default
Default ctor.
const Ice::LongSeq & getAppliedUpdateIds() const
void applyRadiusUpdate(const RadiusUpdate &u)
Applies a radius update to the tree.
void doAddGoalReached(const NodeId &goal, float costToGoToGoal)
Adds a node to the list of nodes that can reach the goal configuration.
void doIncreaseRadius(const NodeId &id)
Increases a node's radius.
void createNewNodeCreationUpdate(const ConfigType &cfg, const NodeId &parent, float fromParentCost)
Adds a new node creation update to the current update.
Ice::LongSeq appliedUpdateIds
List of ids of applied updates.
void addGoalReached(const NodeId &goal, float costToGoToGoal)
Adds a node to the list of nodes that can reach the goal configuration.
const Update & getCurrentUpdate() const
NodeType & at(const NodeId &id)
typename PendingUpdateLookuptableType::iterator PendingUpdateLookuptableIterator
Iterator for the PendingUpdateLookuptable.
PendingUpdateLookuptableType pendingUpdatesLookupTable
Speeds up lookup for available updates.
const NodeType & at(const NodeId &id) const
NodeIdList getNthPathIds(std::size_t n) const
const std::deque< std::deque< NodeType > > & getNodes() const
bool hasGoalNode(const NodeId &nodeId) const
void applyPendingUpdate(std::size_t updateIndex, LockType &&treeLock, RemoteUpdateGetter getRemoteUpdate, UpdateConsumer updateConsumer)
Applies one pending update from the list of pending updates.
bool hasAppliedUpdate(std::size_t workerId, Ice::Long updateId)
void increaseWorkerCountTo(std::size_t count)
Increases the storage of all data structures to be appropriate for count workers.
bool hasPendingUpdate(std::size_t workerId, std::size_t updateId) const
const std::deque< Update > & getLocalUpdates() const
NodeId getIdOfIndex(std::size_t index) const
void prepareUpdate(Ice::LongSeq dependetOnUpdateIds, LockType &&treeLock, RemoteUpdateGetter getRemoteUpdate, UpdateConsumer updateConsumer)
Prepares an update by applying all dependet on updates.
void pushCosts(const NodeId &root)
Updates fromStartCosts for all children from root.
void createNewRadiusUpdate(const NodeId &id, bool increaseRadius)
Adds a new radius update to the current update.
void increaseRadius(const NodeId &id)
Increases a node's radius.
const NodeType & at(std::size_t index) const
void addPendingUpdate(const Update &u)
Adds a new update to the list of pending updates.
void createNewRewireUpdate(const NodeId &child, const NodeId &newParent, float fromParentCost)
Adds a new node creation update to the current update.
bool canApplyUpdate(const Update &u)
void applyPendingUpdates(LockType &&treeLock, RemoteUpdateGetter getRemoteUpdate)
The same as applyPendingUpdates(LockType, RemoteUpdateGetter, UpdateConsumer) but uses an noop as upd...
void setNodeParent(const NodeId &child, const NodeId &newParent, float fromParentCost)
Sets the parent node of child to parent.
void applyPendingUpdates(LockType &&treeLock, RemoteUpdateGetter getRemoteUpdate, UpdateConsumer updateConsumer=[](Update &&) {})
Applies all pending updates.
typename PendingUpdateLookuptableType::const_iterator PendingUpdateLookuptableConstIterator
Const iterator for the PendingUpdateLookuptable.
Ice::Long getPreviousUpdateId() const
float getNthPathCost(std::size_t n) const
std::size_t getPathCount() const
VectorXfSeq getPathTo(NodeId id) const
static const NodeId ROOT_ID
The root node's id.
void prepareNextUpdate()
Prepares the next update.
void applyRewireUpdate(const RewireUpdate &rewireUpdate)
Applies a rewire update to the tree.
std::vector< std::pair< NodeId, float > > getKNearestNeighboursAndDistances(const ConfigType &cfg, std::size_t k)
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_ERROR_S
The logging level for unexpected behaviour, that must be fixed.
Represents a node of thr rrt.
float radius
The node's radius.
float fromStartCost
Cost of the path (sttart node, this node)
NodeId parent
The node's parent.
ConfigType config
The node's configuration.
std::set< NodeId > children
Link to all children nodes.
float fromParentCost
Cost of the edge (parent node, this node)