GeneratorMockup: Add solutions_per_compute argument

This commit is contained in:
JafarAbdi 2021-11-15 21:33:36 +04:00 committed by v4hn
parent 79869b856c
commit 2d775ffe28
2 changed files with 9 additions and 4 deletions

View File

@ -46,8 +46,10 @@ double PredefinedCosts::cost() const {
return c;
}
GeneratorMockup::GeneratorMockup(PredefinedCosts&& costs)
: Generator{ "GEN" + std::to_string(++id_) }, costs_{ std::move(costs) } {}
GeneratorMockup::GeneratorMockup(PredefinedCosts&& costs, std::size_t solutions_per_compute)
: Generator{ "GEN" + std::to_string(++id_) }
, costs_{ std::move(costs) }
, solutions_per_compute_{ solutions_per_compute } {}
void GeneratorMockup::init(const moveit::core::RobotModelConstPtr& robot_model) {
ps_.reset(new planning_scene::PlanningScene(robot_model));
@ -63,7 +65,8 @@ bool GeneratorMockup::canCompute() const {
void GeneratorMockup::compute() {
++runs_;
spawn(InterfaceState(ps_), costs_.cost());
for (std::size_t i = 0; canCompute() && i < solutions_per_compute_; ++i)
spawn(InterfaceState(ps_), costs_.cost());
}
MonitoringGeneratorMockup::MonitoringGeneratorMockup(Stage* monitored, PredefinedCosts&& costs)

View File

@ -40,11 +40,13 @@ struct GeneratorMockup : public Generator
PredefinedCosts costs_;
size_t runs_{ 0 };
std::size_t solutions_per_compute_;
static unsigned int id_;
// default to one solution to avoid infinity loops
GeneratorMockup(PredefinedCosts&& costs = PredefinedCosts{ std::list<double>{ 0.0 }, true });
GeneratorMockup(PredefinedCosts&& costs = PredefinedCosts{ std::list<double>{ 0.0 }, true },
std::size_t solutions_per_compute = 1);
GeneratorMockup(std::initializer_list<double> costs)
: GeneratorMockup{ PredefinedCosts{ std::list<double>{ costs }, true } } {}