30 #include "../../util/CollisionCheckUtil.h"
45 cspace->initCollisionTest();
75 std::vector<std::pair<float, float>> dimensionBounds {};
78 for (
const auto& dim : cspace->getDimensionsBounds())
80 dimensionBounds.emplace_back(dim.min, dim.max);
90 dimensionBounds.begin(), dimensionBounds.end(),
91 startCfg.begin(), startCfg.end(), goalCfg.begin(),
94 std::mt19937{std::random_device{}()}
97 rotationMatrix.clear();
118 std::this_thread::sleep_for(std::chrono::seconds(2));
128 manager->setWorkersFinalUpdateId(workerId, finalUpdateId);
137 for (
Ice::Long currentBatchIteration = 0; currentBatchIteration < batchSize; ++currentBatchIteration)
150 const auto& workersNodes =
tree.
getNodes().at(workerId);
154 NodeId goalConnectNodeNearestId;
155 goalConnectNodeNearestId.workerId = workerId;
156 float goalConnectNodeNearestDistance = std::numeric_limits<float>::infinity();
159 for (std::size_t numberOfNode =
onePastLastGoalConnect; numberOfNode < workersNodes.size(); ++numberOfNode)
162 const float currNodeDistance =
distance(goalCfg, currNode.
config);
164 if (currNodeDistance < goalConnectNodeNearestDistance)
166 goalConnectNodeNearestDistance = currNodeDistance;
167 goalConnectNodeNearestId.numberOfNode = numberOfNode;
171 if (goalConnectNodeNearestDistance < std::numeric_limits<float>::infinity())
180 else if (cfgReached == goalCfg)
225 NodeId nodeNearestId;
226 float nodeNearestDistance;
230 u_int64_t samplingTries {0};
234 if (!(samplingTries % 1000))
244 if (!((samplingTries + 1000) % 10000))
249 (*sampler)(cfgRnd.data());
274 const NodeId& nodeNearestId)
277 float costReachedToNodeBest;
278 std::vector<std::pair<NodeId, float>> kNearestIdsAndDistances;
279 std::map<NodeId, bool> isCollisionFreeCache;
287 costReachedToNodeBest,
288 kNearestIdsAndDistances,
296 costReachedToNodeBest
299 rewire(nodeReachedId, kNearestIdsAndDistances, isCollisionFreeCache);
303 const NodeId& nodeId,
304 const std::vector<std::pair<NodeId, float>>& kNearestIdsAndDistances,
305 const std::map<NodeId, bool>& isCollisionFreeCache
311 const float nodeFromStartCost = node.fromStartCost;
313 for (
const auto& nearIdAndDist : kNearestIdsAndDistances)
315 const auto& nodeNearId = nearIdAndDist.first;
317 const auto& cfgNodeNear = nodeNear.
config;
319 const auto costPathToNearOld = nodeNear.fromStartCost;
320 const auto costNodeToNear = nearIdAndDist.second;
321 const auto costPathToNearOverNode = nodeFromStartCost + costNodeToNear;
324 if (costPathToNearOverNode < costPathToNearOld)
327 const auto it = isCollisionFreeCache.find(nodeNearId);
329 if ((it != isCollisionFreeCache.end() && (*it).second) ||
isPathCollisionFree(cfgNode, cfgNodeNear))
340 const NodeId& nodeNearestId,
342 NodeId& outNodeBestId,
343 float& outCostReachedToNodeBest,
344 std::vector<std::pair<NodeId, float>>& outKNearestIdsAndDistances,
345 std::map<NodeId, bool>& outIsCollisionFreeCache
349 outNodeBestId = nodeNearestId;
354 for (
const auto& nearIdAndDist : outKNearestIdsAndDistances)
357 auto& nodeNearId = nearIdAndDist.first;
359 const auto& cfgNodeNear = nodeNear.
config;
361 const auto costReachedToNodeNear = nearIdAndDist.second;
362 const auto costPathToReachedOverNodeNear = nodeNear.fromStartCost + costReachedToNodeNear;
364 if (costPathToReachedOverNodeNear < costPathToReachedOverNodeBest)
369 outNodeBestId = nodeNearId;
370 costPathToReachedOverNodeBest = costPathToReachedOverNodeNear;
371 outCostReachedToNodeBest = costReachedToNodeNear;
372 outIsCollisionFreeCache[nodeNearId] =
true;
376 outIsCollisionFreeCache[nodeNearId] =
false;
404 bufferCDRange.first = cfg.data();
405 bufferCDRange.second = bufferCDRange.first + cfg.size();
406 return cspace->isCollisionFree(bufferCDRange);
412 const auto kRRT = std::pow(2.f, dim + 1.f) * M_E * (1.f + 1.f / dim);
413 const auto k = kRRT * std::log(
static_cast<float>(
tree.
size()));
414 return static_cast<std::size_t
>(std::ceil(k));
427 return manager->getUpdate(workerNodeId, updateSubId);