solver: Emit single items together and early

Technically, we simply sort by the "hint-size", but it for most parts
have the effect of putting single item earlier.  Note this is /not/ a
perfect solution, but it is a simple heuristic exploiting the common
case.

Signed-off-by: Niels Thykier <niels@thykier.net>
master
Niels Thykier 9 years ago
parent 326cc0d98b
commit 37c179f5f3

@ -17,6 +17,7 @@
from __future__ import print_function from __future__ import print_function
import os import os
from collections import deque
from installability.tester import InstallabilityTester from installability.tester import InstallabilityTester
from britney_util import (ifilter_only, iter_except) from britney_util import (ifilter_only, iter_except)
@ -54,7 +55,7 @@ class InstallabilitySolver(InstallabilityTester):
revuniverse = self._revuniverse revuniverse = self._revuniverse
result = [] result = []
emitted = set() emitted = set()
check = set() queue = deque()
order = {} order = {}
ptable = {} ptable = {}
key2item = {} key2item = {}
@ -226,22 +227,26 @@ class InstallabilitySolver(InstallabilityTester):
if debug_solver: if debug_solver:
print("N: -- PARTIAL ORDER --") print("N: -- PARTIAL ORDER --")
initial_round = []
for com in sorted(order): for com in sorted(order):
if debug_solver and order[com]['before']: if debug_solver and order[com]['before']:
print("N: %s <= %s" % (com, str(sorted(order[com]['before'])))) print("N: %s <= %s" % (com, str(sorted(order[com]['before']))))
if not order[com]['after']: if not order[com]['after']:
# This component can be scheduled immediately, add it # This component can be scheduled immediately, add it
# to "check" # to the queue
check.add(com) initial_round.append(com)
elif debug_solver: elif debug_solver:
print("N: %s >= %s" % (com, str(sorted(order[com]['after'])))) print("N: %s >= %s" % (com, str(sorted(order[com]['after']))))
queue.extend(sorted(initial_round, key=len))
del initial_round
if debug_solver: if debug_solver:
print("N: -- END PARTIAL ORDER --") print("N: -- END PARTIAL ORDER --")
print("N: -- LINEARIZED ORDER --") print("N: -- LINEARIZED ORDER --")
for cur in iter_except(check.pop, KeyError): for cur in iter_except(queue.popleft, IndexError):
if order[cur]['after'] <= emitted: if order[cur]['after'] <= emitted and cur not in emitted:
# This item is ready to be emitted right now # This item is ready to be emitted right now
if debug_solver: if debug_solver:
print("N: %s -- %s" % (cur, sorted(scc[cur]))) print("N: %s -- %s" % (cur, sorted(scc[cur])))
@ -249,10 +254,10 @@ class InstallabilitySolver(InstallabilityTester):
result.append([key2item[x] for x in scc[cur]]) result.append([key2item[x] for x in scc[cur]])
if order[cur]['before']: if order[cur]['before']:
# There are components that come after this one. # There are components that come after this one.
# Add it to "check": # Add it to queue:
# - if it is ready, it will be emitted. # - if it is ready, it will be emitted.
# - else, it will be dropped and re-added later. # - else, it will be dropped and re-added later.
check.update(order[cur]['before'] - emitted) queue.extend(sorted(order[cur]['before'] - emitted, key=len))
if debug_solver: if debug_solver:
print("N: -- END LINEARIZED ORDER --") print("N: -- END LINEARIZED ORDER --")

Loading…
Cancel
Save