38#include <ompl/base/goals/GoalLazySamples.h>
42ompl::base::SpaceInformationPtr getGoalsSI(
const std::vector<ompl::base::GoalPtr>& goals)
45 return ompl::base::SpaceInformationPtr();
46 for (
const ompl::base::GoalPtr& goal : goals)
48 if (!goal->hasType(ompl::base::GOAL_SAMPLEABLE_REGION))
49 throw ompl::Exception(
"Multiplexed goals must be instances of GoalSampleableRegion");
51 for (
const ompl::base::GoalPtr& goal : goals)
53 if (goal->getSpaceInformation() != goals[0]->getSpaceInformation())
54 throw ompl::Exception(
"The instance of SpaceInformation must be the same among the goals to be considered");
56 return goals[0]->getSpaceInformation();
61 : ompl::base::GoalSampleableRegion(getGoalsSI(goals)), goals_(goals), gindex_(0)
67 for (ompl::base::GoalPtr& goal : goals_)
69 if (goal->hasType(ompl::base::GOAL_LAZY_SAMPLES))
70 static_cast<ompl::base::GoalLazySamples*
>(goal.get())->startSampling();
76 for (ompl::base::GoalPtr& goal : goals_)
78 if (goal->hasType(ompl::base::GOAL_LAZY_SAMPLES))
79 static_cast<ompl::base::GoalLazySamples*
>(goal.get())->stopSampling();
85 for (std::size_t i = 0; i < goals_.size(); ++i)
87 if (goals_[gindex_]->as<ompl::base::GoalSampleableRegion>()->maxSampleCount() > 0)
89 goals_[gindex_]->as<ompl::base::GoalSampleableRegion>()->sampleGoal(st);
92 gindex_ = (gindex_ + 1) % goals_.size();
94 throw ompl::Exception(
"There are no states to sample");
100 for (
const ompl::base::GoalPtr& goal : goals_)
101 sc += goal->as<GoalSampleableRegion>()->maxSampleCount();
107 for (
const ompl::base::GoalPtr& goal : goals_)
109 if (goal->as<ompl::base::GoalSampleableRegion>()->canSample())
117 for (
const ompl::base::GoalPtr& goal : goals_)
119 if (goal->as<ompl::base::GoalSampleableRegion>()->couldSample())
127 for (
const ompl::base::GoalPtr& goal : goals_)
129 if (goal->isSatisfied(st, distance))
137 double min_d = std::numeric_limits<double>::infinity();
138 for (
const ompl::base::GoalPtr& goal : goals_)
140 double d = goal->as<ompl::base::GoalRegion>()->distanceGoal(st);
149 out <<
"MultiGoal [\n";
150 for (
const ompl::base::GoalPtr& goal : goals_)
void startSampling()
If there are any member lazy samplers, start them.
bool couldSample() const override
Query if sampler could find a sample in the future.
double distanceGoal(const ompl::base::State *st) const override
Find the distance of this state from the goal.
virtual bool canSample() const
Query if sampler can find any sample.
unsigned int maxSampleCount() const override
Get the max sample count.
GoalSampleableRegionMux(const std::vector< ompl::base::GoalPtr > &goals)
Constructor.
void print(std::ostream &out=std::cout) const override
Pretty print goal information.
void sampleGoal(ompl::base::State *st) const override
Sample a goal.
bool isSatisfied(const ompl::base::State *st, double *distance) const override
Is the goal satisfied for this state (given a distance)
void stopSampling()
If there are any member lazy samplers, stop them.