Skip to content

Commit 5120ca5

Browse files
committed
Directly lift solutions of SerialContainer
To avoid the impression of starvation, directly lift solutions instead of enumerating and sorting them first. Sorting is handled in the parent's container too.
1 parent edcb472 commit 5120ca5

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

core/src/container.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -534,24 +534,25 @@ void SerialContainer::onNewSolution(const SolutionBase& current) {
534534
SolutionCollector<Interface::BACKWARD> incoming(num_before, current);
535535
SolutionCollector<Interface::FORWARD> outgoing(num_after, current);
536536

537-
// collect (and sort) all solutions spanning from start to end of this container
537+
// collect (and lift) all solutions spanning from start to end of this container
538538
ordered<SolutionSequencePtr> sorted;
539539
for (auto& in : incoming.solutions) {
540540
for (auto& out : outgoing.solutions) {
541541
InterfaceState::Priority prio = in.second + InterfaceState::Priority(1u, current.cost()) + out.second;
542542
assert(prio.enabled());
543543
// found a complete solution path connecting start to end?
544544
if (prio.depth() == children.size()) {
545-
SolutionSequence::container_type solution;
546-
solution.reserve(children.size());
545+
SolutionSequence::container_type seq;
546+
seq.reserve(children.size());
547547
// insert incoming solutions in reverse order
548-
solution.insert(solution.end(), in.first.rbegin(), in.first.rend());
548+
seq.insert(seq.end(), in.first.rbegin(), in.first.rend());
549549
// insert current solution
550-
solution.push_back(&current);
550+
seq.push_back(&current);
551551
// insert outgoing solutions in normal order
552-
solution.insert(solution.end(), out.first.begin(), out.first.end());
553-
// store solution in sorted list
554-
sorted.insert(std::make_shared<SolutionSequence>(std::move(solution), prio.cost(), this));
552+
seq.insert(seq.end(), out.first.begin(), out.first.end());
553+
// create SolutionSequence and lift it to external interface
554+
auto solution = std::make_shared<SolutionSequence>(std::move(seq), prio.cost(), this);
555+
impl->liftSolution(solution, solution->internalStart(), solution->internalEnd());
555556
}
556557
if (prio.depth() > 1) {
557558
// update state priorities along the whole partial solution path
@@ -561,10 +562,6 @@ void SerialContainer::onNewSolution(const SolutionBase& current) {
561562
}
562563
}
563564
// printChildrenInterfaces(*this->pimpl(), true, *current.creator());
564-
565-
// finally, store + announce new solutions to external interface
566-
for (const auto& solution : sorted)
567-
impl->liftSolution(solution, solution->internalStart(), solution->internalEnd());
568565
}
569566

570567
SerialContainer::SerialContainer(SerialContainerPrivate* impl) : ContainerBase(impl) {}

0 commit comments

Comments
 (0)