From 37c179f5f3d8a82b4ba02a9542e42e0eef2b3394 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sat, 30 May 2015 12:35:20 +0200 Subject: [PATCH] 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 --- installability/solver.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/installability/solver.py b/installability/solver.py index 9e1f1d8..9e6e1b7 100644 --- a/installability/solver.py +++ b/installability/solver.py @@ -17,6 +17,7 @@ from __future__ import print_function import os +from collections import deque from installability.tester import InstallabilityTester from britney_util import (ifilter_only, iter_except) @@ -54,7 +55,7 @@ class InstallabilitySolver(InstallabilityTester): revuniverse = self._revuniverse result = [] emitted = set() - check = set() + queue = deque() order = {} ptable = {} key2item = {} @@ -226,22 +227,26 @@ class InstallabilitySolver(InstallabilityTester): if debug_solver: print("N: -- PARTIAL ORDER --") + initial_round = [] for com in sorted(order): if debug_solver and order[com]['before']: print("N: %s <= %s" % (com, str(sorted(order[com]['before'])))) if not order[com]['after']: # This component can be scheduled immediately, add it - # to "check" - check.add(com) + # to the queue + initial_round.append(com) elif debug_solver: print("N: %s >= %s" % (com, str(sorted(order[com]['after'])))) + queue.extend(sorted(initial_round, key=len)) + del initial_round + if debug_solver: print("N: -- END PARTIAL ORDER --") print("N: -- LINEARIZED ORDER --") - for cur in iter_except(check.pop, KeyError): - if order[cur]['after'] <= emitted: + for cur in iter_except(queue.popleft, IndexError): + if order[cur]['after'] <= emitted and cur not in emitted: # This item is ready to be emitted right now if debug_solver: print("N: %s -- %s" % (cur, sorted(scc[cur]))) @@ -249,10 +254,10 @@ class InstallabilitySolver(InstallabilityTester): result.append([key2item[x] for x in scc[cur]]) if order[cur]['before']: # There are components that come after this one. - # Add it to "check": + # Add it to queue: # - if it is ready, it will be emitted. # - 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: print("N: -- END LINEARIZED ORDER --")