GENERATE: return correct canCompute() result as early as possible

Moving to next child generator only in compute() requires an extra call
to canCompute() to notice the failure of the next generator(s).
This commit is contained in:
Robert Haschke 2021-09-09 11:52:44 +02:00
parent b6ac5b09ba
commit b783173b27
2 changed files with 11 additions and 15 deletions

View File

@ -263,8 +263,8 @@ protected:
ordered<ExternalState> pending_states_;
ExternalState current_external_state_;
void computeGenerate();
container_type::const_iterator current_generator_;
inline void computeGenerate();
mutable container_type::const_iterator current_generator_;
private:
void initializeExternalInterfaces() override;

View File

@ -828,11 +828,16 @@ bool Fallbacks::canCompute() const {
if (impl->requiredInterface() == GENERATE) {
// current_generator_ is fixed if it produced solutions before
if( !solutions().empty() )
if (!solutions().empty())
return (*impl->current_generator_)->pimpl()->canCompute();
else
// we still have children to try
else {
// move to first generator that can run
while(impl->current_generator_ != impl->children().end() && !(*impl->current_generator_)->pimpl()->canCompute()) {
ROS_DEBUG_STREAM_NAMED("Fallbacks", "Generator '" << (*impl->current_generator_)->name() << "' can't compute, trying next one.");
++impl->current_generator_;
}
return impl->current_generator_ != impl->children().end();
}
}
else
return !impl->pending_states_.empty() || impl->current_external_state_.stage != impl->children().cend();
@ -873,16 +878,7 @@ void FallbacksPrivate::onNewFailure(const Stage& /*child*/, const InterfaceState
}
void FallbacksPrivate::computeGenerate() {
if(solutions_.empty())
// move to first generator that can run
while(current_generator_ != children().end() && !(*current_generator_)->pimpl()->canCompute()) {
ROS_DEBUG_STREAM_NAMED("Fallbacks", "Generator '" << (*current_generator_)->name() << "' can't compute, trying next one.");
++current_generator_;
}
if(current_generator_ == children().end())
return;
assert(current_generator_ != children().end());
(*current_generator_)->pimpl()->runCompute();
}