32 #include "../../util/CollisionCheckUtil.h"
46 cspace->initCollisionTest();
80 std::vector<std::pair<float, float>> dimensionBounds{};
83 for (
const auto& dim : cspace->getDimensionsBounds())
85 dimensionBounds.emplace_back(dim.min, dim.max);
93 dimensionBounds.end(),
98 std::mt19937{std::random_device{}()}});
99 rotationMatrix.clear();
120 std::this_thread::sleep_for(std::chrono::seconds(2));
130 manager->setWorkersFinalUpdateId(workerId, finalUpdateId);
140 for (
Ice::Long currentBatchIteration = 0; currentBatchIteration < batchSize;
141 ++currentBatchIteration)
154 const auto& workersNodes =
tree.
getNodes().at(workerId);
158 NodeId goalConnectNodeNearestId;
159 goalConnectNodeNearestId.workerId = workerId;
160 float goalConnectNodeNearestDistance = std::numeric_limits<float>::infinity();
164 numberOfNode < workersNodes.size();
168 const float currNodeDistance =
distance(goalCfg, currNode.
config);
170 if (currNodeDistance < goalConnectNodeNearestDistance)
172 goalConnectNodeNearestDistance = currNodeDistance;
173 goalConnectNodeNearestId.numberOfNode = numberOfNode;
177 if (goalConnectNodeNearestDistance < std::numeric_limits<float>::infinity())
179 const auto cfgReached =
187 else if (cfgReached == goalCfg)
232 NodeId nodeNearestId;
233 float nodeNearestDistance;
237 u_int64_t samplingTries{0};
241 if (!(samplingTries % 1000))
251 if (!((samplingTries + 1000) % 10000))
256 (*sampler)(cfgRnd.data());
257 std::tie(nodeNearestId, nodeNearestDistance) =
283 float costReachedToNodeBest;
284 std::vector<std::pair<NodeId, float>> kNearestIdsAndDistances;
285 std::map<NodeId, bool> isCollisionFreeCache;
292 costReachedToNodeBest,
293 kNearestIdsAndDistances,
294 isCollisionFreeCache);
297 const auto nodeReachedId =
tree.
addNode(cfgReached,
299 costReachedToNodeBest
302 rewire(nodeReachedId, kNearestIdsAndDistances, isCollisionFreeCache);
307 const std::vector<std::pair<NodeId, float>>& kNearestIdsAndDistances,
308 const std::map<NodeId, bool>& isCollisionFreeCache)
313 const float nodeFromStartCost = node.fromStartCost;
315 for (
const auto& nearIdAndDist : kNearestIdsAndDistances)
317 const auto& nodeNearId = nearIdAndDist.first;
319 const auto& cfgNodeNear = nodeNear.
config;
321 const auto costPathToNearOld = nodeNear.fromStartCost;
322 const auto costNodeToNear = nearIdAndDist.second;
323 const auto costPathToNearOverNode = nodeFromStartCost + costNodeToNear;
326 if (costPathToNearOverNode < costPathToNearOld)
329 const auto it = isCollisionFreeCache.find(nodeNearId);
331 if ((it != isCollisionFreeCache.end() && (*it).second) ||
344 NodeId& outNodeBestId,
345 float& outCostReachedToNodeBest,
346 std::vector<std::pair<NodeId, float>>& outKNearestIdsAndDistances,
347 std::map<NodeId, bool>& outIsCollisionFreeCache)
350 outNodeBestId = nodeNearestId;
352 auto costPathToReachedOverNodeBest =
356 for (
const auto& nearIdAndDist : outKNearestIdsAndDistances)
359 auto& nodeNearId = nearIdAndDist.first;
361 const auto& cfgNodeNear = nodeNear.
config;
363 const auto costReachedToNodeNear = nearIdAndDist.second;
364 const auto costPathToReachedOverNodeNear =
365 nodeNear.fromStartCost + costReachedToNodeNear;
367 if (costPathToReachedOverNodeNear < costPathToReachedOverNodeBest)
372 outNodeBestId = nodeNearId;
373 costPathToReachedOverNodeBest = costPathToReachedOverNodeNear;
374 outCostReachedToNodeBest = costReachedToNodeNear;
375 outIsCollisionFreeCache[nodeNearId] =
true;
379 outIsCollisionFreeCache[nodeNearId] =
false;
410 bufferCDRange.first = cfg.data();
411 bufferCDRange.second = bufferCDRange.first + cfg.size();
412 return cspace->isCollisionFree(bufferCDRange);
419 const auto kRRT = std::pow(2.f, dim + 1.f) * M_E * (1.f + 1.f / dim);
420 const auto k = kRRT * std::log(
static_cast<float>(
tree.
size()));
421 return static_cast<std::size_t
>(std::ceil(k));
436 return manager->getUpdate(workerNodeId, updateSubId);