@@ -203,37 +203,45 @@ void ContainerBasePrivate::copyState(Interface::iterator external, const Interfa
203203}
204204
205205void ContainerBasePrivate::liftSolution (const SolutionBasePtr& solution, const InterfaceState* internal_from,
206- const InterfaceState* internal_to) {
207- computeCost (*internal_from, *internal_to, *solution);
206+ const InterfaceState* internal_to, const InterfaceState* new_external) {
207+ const bool create_from{ requiredInterface ().testFlag (WRITES_PREV_END) };
208+ const bool create_to{ requiredInterface ().testFlag (WRITES_NEXT_START) };
208209
209- // map internal to external states
210- auto find_or_create_external = [this ](const InterfaceState* internal, bool & created) -> InterfaceState* {
211- auto it = internalToExternalMap ().find (internal);
212- if (it != internalToExternalMap ().end ())
213- return const_cast <InterfaceState*>(it->second );
210+ // external states, nullptr if they don't exist yet
211+ const InterfaceState* external_from{ create_from ? new_external : internalToExternalMap ().at (internal_from) };
212+ const InterfaceState* external_to{ create_to ? new_external : internalToExternalMap ().at (internal_to) };
214213
215- InterfaceState* external = &*states_.insert (states_.end (), InterfaceState (*internal));
214+ // computeCost
215+ computeCost (external_from ? *external_from : InterfaceState (*internal_from),
216+ external_to ? *external_to : InterfaceState (*internal_to), *solution);
217+
218+ // storeSolution
219+ if (!storeSolution (solution, external_from, external_to)) {
220+ return ;
221+ }
222+
223+ auto create_state = [this , new_external](const InterfaceState& internal) {
224+ InterfaceState* external{ &*states_.insert (states_.cend (), new_external ? *new_external : internal) };
216225 internalToExternalMap ().insert (std::make_pair (internal, external));
217- created = true ;
218226 return external;
219227 };
220- bool created_from = false ;
221- bool created_to = false ;
222- InterfaceState* external_from = find_or_create_external (internal_from, created_from);
223- InterfaceState* external_to = find_or_create_external (internal_to, created_to);
224228
225- if (!storeSolution (solution, external_from, external_to))
226- return ;
229+ if (create_from)
230+ external_from = create_state (*internal_from);
231+ if (create_to)
232+ external_to = create_state (*internal_to);
227233
228- // connect solution to start/end state
234+ // connect solution to states
229235 solution->setStartState (*external_from);
230236 solution->setEndState (*external_to);
231237
232- // spawn created states in external interfaces
233- if (created_from)
234- prevEnds ()->add (*external_from);
235- if (created_to)
236- nextStarts ()->add (*external_to);
238+ // spawn new external states
239+ if (!solution->isFailure ()) {
240+ if (create_from)
241+ prevEnds ()->add (*const_cast <InterfaceState*>(external_from));
242+ if (create_to)
243+ nextStarts ()->add (*const_cast <InterfaceState*>(external_to));
244+ }
237245
238246 newSolution (solution);
239247}
@@ -737,16 +745,20 @@ void ParallelContainerBase::liftSolution(const SolutionBase& solution, double co
737745 solution.start (), solution.end ());
738746}
739747
740- void ParallelContainerBase::spawn (InterfaceState&& state, SubTrajectory&& t) {
741- pimpl ()->StagePrivate ::spawn (std::move (state), std::make_shared<SubTrajectory>(std::move (t)));
742- }
748+ void ParallelContainerBase::liftModifiedSolution (SolutionBasePtr&& modified_solution, const SolutionBase &child_solution) {
749+ // child_solution is correctly prepared by a child of this container
750+ assert (child_solution.creator ());
751+ assert (child_solution.creator ()->parent () == this );
743752
744- void ParallelContainerBase::sendForward ( const InterfaceState& from, InterfaceState&& to, SubTrajectory&& t) {
745- pimpl ()-> StagePrivate ::sendForward (from, std::move (to ), std::make_shared<SubTrajectory>( std::move (t) ));
753+ pimpl ()-> liftSolution ( std::move (modified_solution),
754+ child_solution. start ( ), child_solution. end ( ));
746755}
747756
748- void ParallelContainerBase::sendBackward (InterfaceState&& from, const InterfaceState& to, SubTrajectory&& t) {
749- pimpl ()->StagePrivate ::sendBackward (std::move (from), to, std::make_shared<SubTrajectory>(std::move (t)));
757+ void ParallelContainerBase::liftModifiedSolution (SolutionBasePtr &&new_solution, InterfaceState &&new_propagated_state, const SolutionBase &child_solution) {
758+ assert (child_solution.creator ());
759+ assert (child_solution.creator ()->parent () == this );
760+
761+ pimpl ()->liftSolution (std::move (new_solution), child_solution.start (), child_solution.end (), &new_propagated_state);
750762}
751763
752764WrapperBasePrivate::WrapperBasePrivate (WrapperBase* me, const std::string& name)
0 commit comments