Skip to content

Commit 0c1ecbf

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 0c1ecbf

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

core/src/container.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -534,24 +534,24 @@ 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
538-
ordered<SolutionSequencePtr> sorted;
537+
// collect (and lift) all solutions spanning from start to end of this container
539538
for (auto& in : incoming.solutions) {
540539
for (auto& out : outgoing.solutions) {
541540
InterfaceState::Priority prio = in.second + InterfaceState::Priority(1u, current.cost()) + out.second;
542541
assert(prio.enabled());
543542
// found a complete solution path connecting start to end?
544543
if (prio.depth() == children.size()) {
545-
SolutionSequence::container_type solution;
546-
solution.reserve(children.size());
544+
SolutionSequence::container_type seq;
545+
seq.reserve(children.size());
547546
// insert incoming solutions in reverse order
548-
solution.insert(solution.end(), in.first.rbegin(), in.first.rend());
547+
seq.insert(seq.end(), in.first.rbegin(), in.first.rend());
549548
// insert current solution
550-
solution.push_back(&current);
549+
seq.push_back(&current);
551550
// 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));
551+
seq.insert(seq.end(), out.first.begin(), out.first.end());
552+
// create SolutionSequence and lift it to external interface
553+
auto solution = std::make_shared<SolutionSequence>(std::move(seq), prio.cost(), this);
554+
impl->liftSolution(solution, solution->internalStart(), solution->internalEnd());
555555
}
556556
if (prio.depth() > 1) {
557557
// update state priorities along the whole partial solution path
@@ -561,10 +561,6 @@ void SerialContainer::onNewSolution(const SolutionBase& current) {
561561
}
562562
}
563563
// 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());
568564
}
569565

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

0 commit comments

Comments
 (0)