39 #include <ompl/multilevel/datastructures/graphsampler/GraphSampler.h>
41 ompl::multilevel::BundleSpaceGraphSampler::BundleSpaceGraphSampler(BundleSpaceGraph *bundleSpaceGraph)
42 : bundleSpaceGraph_(bundleSpaceGraph)
44 double mu = bundleSpaceGraph_->getBundle()->getMaximumExtent();
45 epsilonGraphThickening_ = mu * epsilonGraphThickeningFraction_;
46 OMPL_DEBUG(
"Epsilon Graph Thickening constant set to %f", epsilonGraphThickening_);
48 pathBiasDecay_.setLambda(exponentialDecayLambda_);
49 pathBiasDecay_.setValueInit(pathBiasFixed_);
51 pathThickeningGrowth_.setLambda(exponentialDecayLambda_);
52 pathThickeningGrowth_.setValueInit(epsilonGraphThickening_);
53 pathThickeningGrowth_.setValueTarget(0.0);
55 graphThickeningGrowth_.setLambda(exponentialDecayLambda_);
56 graphThickeningGrowth_.setValueInit(epsilonGraphThickening_);
57 graphThickeningGrowth_.setValueTarget(0.0);
60 void ompl::multilevel::BundleSpaceGraphSampler::clear()
62 double mu = bundleSpaceGraph_->getBundle()->getMaximumExtent();
63 epsilonGraphThickening_ = mu * epsilonGraphThickeningFraction_;
65 pathBiasDecay_.reset();
66 pathThickeningGrowth_.reset();
67 graphThickeningGrowth_.reset();
70 void ompl::multilevel::BundleSpaceGraphSampler::disableSegmentBias()
72 this->segmentBias_ =
false;
75 void ompl::multilevel::BundleSpaceGraphSampler::disablePathBias()
77 pathBiasDecay_.setLambda(0);
78 pathBiasDecay_.setValueTarget(0);
79 pathBiasDecay_.setValueInit(0);
82 void ompl::multilevel::BundleSpaceGraphSampler::setPathBiasStartSegment(
double s)
86 this->pathBiasStartSegment_ = 0;
90 if (s > this->pathBiasStartSegment_)
92 geometric::PathGeometric &spath =
93 static_cast<geometric::PathGeometric &
>(*bundleSpaceGraph_->getSolutionPathByReference());
94 OMPL_DEBUG(
"Set path bias: %f/%f", s, spath.length());
95 if (s > spath.length())
99 this->pathBiasStartSegment_ = s;
104 double ompl::multilevel::BundleSpaceGraphSampler::getPathBiasStartSegment()
106 return this->pathBiasStartSegment_;
109 void ompl::multilevel::BundleSpaceGraphSampler::sample(base::State *xRandom)
111 base::SpaceInformationPtr bundle = bundleSpaceGraph_->getBundle();
113 double p = rng_.uniform01();
114 double pd = pathBiasDecay_();
116 if (p < pd && !bundleSpaceGraph_->isDynamic())
118 geometric::PathGeometric &spath =
119 static_cast<geometric::PathGeometric &
>(*bundleSpaceGraph_->getSolutionPathByReference());
121 std::vector<base::State *> states = spath.getStates();
123 if (states.size() < 2)
126 sampleImplementation(xRandom);
133 double endLength = spath.length();
134 double distStopping = pathBiasStartSegment_ + rng_.uniform01() * (endLength - pathBiasStartSegment_);
136 base::State *s1 =
nullptr;
137 base::State *s2 =
nullptr;
140 double distLastSegment = 0;
141 double distCountedSegments = 0;
142 while (distCountedSegments < distStopping && (ctr < (
int)states.size() - 1))
145 s2 = states.at(ctr + 1);
146 distLastSegment = bundle->distance(s1, s2);
147 distCountedSegments += distLastSegment;
156 double step = (distLastSegment - (distCountedSegments - distStopping)) / (distLastSegment);
157 bundle->getStateSpace()->interpolate(s1, s2, step, xRandom);
159 if (epsilonGraphThickening_ > 0)
161 double eps = pathThickeningGrowth_();
162 bundleSpaceGraph_->getBundleSamplerPtr()->sampleUniformNear(xRandom, xRandom, eps);
168 sampleImplementation(xRandom);
174 if (epsilonGraphThickening_ > 0)
178 double eps = graphThickeningGrowth_();
179 bundleSpaceGraph_->getBundleSamplerPtr()->sampleUniformNear(xRandom, xRandom, eps);