2 * Copyright (c) 2007-2008, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * SAT based dependency solver
26 #include "solverdebug.h"
28 #define RULES_BLOCK 63
30 static void reenablepolicyrules(Solver *solv, Queue *job, int jobidx);
31 static void addrpmruleinfo(Solver *solv, Id p, Id d, int type, Id dep);
33 /********************************************************************
35 * dependency check helpers
39 /*-------------------------------------------------------------------
40 * handle split provides
44 solver_splitprovides(Solver *solv, Id dep)
46 Pool *pool = solv->pool;
51 if (!solv->dosplitprovides || !solv->installed)
55 rd = GETRELDEP(pool, dep);
56 if (rd->flags != REL_WITH)
58 FOR_PROVIDES(p, pp, dep)
60 s = pool->solvables + p;
61 if (s->repo == solv->installed && s->name == rd->name)
68 /*-------------------------------------------------------------------
69 * solver_dep_installed
73 solver_dep_installed(Solver *solv, Id dep)
76 Pool *pool = solv->pool;
81 Reldep *rd = GETRELDEP(pool, dep);
82 if (rd->flags == REL_AND)
84 if (!solver_dep_installed(solv, rd->name))
86 return solver_dep_installed(solv, rd->evr);
88 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
89 return solver_dep_installed(solv, rd->evr);
91 FOR_PROVIDES(p, pp, dep)
93 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
101 /*-------------------------------------------------------------------
102 * Check if dependenc is possible
104 * this mirrors solver_dep_fulfilled
105 * but uses map m instead of the decisionmap
109 dep_possible(Solver *solv, Id dep, Map *m)
111 Pool *pool = solv->pool;
116 Reldep *rd = GETRELDEP(pool, dep);
117 if (rd->flags == REL_AND)
119 if (!dep_possible(solv, rd->name, m))
121 return dep_possible(solv, rd->evr, m);
123 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
124 return solver_splitprovides(solv, rd->evr);
125 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
126 return solver_dep_installed(solv, rd->evr);
128 FOR_PROVIDES(p, pp, dep)
136 /********************************************************************
140 * - unify rules, remove duplicates
143 static Pool *unifyrules_sortcmp_data;
145 /*-------------------------------------------------------------------
147 * compare rules for unification sort
152 unifyrules_sortcmp(const void *ap, const void *bp)
154 Pool *pool = unifyrules_sortcmp_data;
155 Rule *a = (Rule *)ap;
156 Rule *b = (Rule *)bp;
162 return x; /* p differs */
165 if (a->d == 0 && b->d == 0)
166 return a->w2 - b->w2; /* assertion: return w2 diff */
168 if (a->d == 0) /* a is assertion, b not */
170 x = a->w2 - pool->whatprovidesdata[b->d];
174 if (b->d == 0) /* b is assertion, a not */
176 x = pool->whatprovidesdata[a->d] - b->w2;
180 /* compare whatprovidesdata */
181 ad = pool->whatprovidesdata + a->d;
182 bd = pool->whatprovidesdata + b->d;
184 if ((x = *ad++ - *bd++) != 0)
190 /*-------------------------------------------------------------------
193 * go over all rules and remove duplicates
197 unifyrules(Solver *solv)
199 Pool *pool = solv->pool;
203 if (solv->nrules <= 1) /* nothing to unify */
206 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
208 /* sort rules first */
209 unifyrules_sortcmp_data = solv->pool;
210 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
217 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
219 if (jr && !unifyrules_sortcmp(ir, jr))
220 continue; /* prune! */
221 jr = solv->rules + j++; /* keep! */
226 /* reduced count from nrules to j rules */
227 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
229 /* adapt rule buffer */
231 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
235 IF_POOLDEBUG (SAT_DEBUG_STATS)
242 for (i = 1; i < solv->nrules; i++)
249 dp = solv->pool->whatprovidesdata + r->d;
254 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
255 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
257 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
267 hashrule(Solver *solv, Id p, Id d, int n)
269 unsigned int x = (unsigned int)p;
273 return (x * 37) ^ (unsigned int)d;
274 dp = solv->pool->whatprovidesdata + d;
276 x = (x * 37) ^ (unsigned int)*dp++;
282 /*-------------------------------------------------------------------
288 * p = direct literal; always < 0 for installed rpm rules
289 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
292 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
294 * p < 0 : pkg id of A
295 * d > 0 : Offset in whatprovidesdata (list of providers of b)
297 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
298 * p < 0 : pkg id of A
299 * d < 0 : Id of solvable (e.g. B1)
301 * d == 0: unary rule, assertion => (A) or (-A)
303 * Install: p > 0, d = 0 (A) user requested install
304 * Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
305 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
306 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
307 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
308 * also used for obsoletes
309 * ?: p > 0, d < 0 (A|-B)
310 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
314 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
315 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
316 * every other : w1 = p, w2 = whatprovidesdata[d];
317 * Disabled rule: w1 = 0
319 * always returns a rule for non-rpm rules
323 addrule(Solver *solv, Id p, Id d)
325 Pool *pool = solv->pool;
329 int n = 0; /* number of literals in rule - 1
330 0 = direct assertion (single literal)
335 /* it often happenes that requires lead to adding the same rpm rule
336 * multiple times, so we prune those duplicates right away to make
337 * the work for unifyrules a bit easier */
339 if (solv->nrules /* we already have rules */
340 && !solv->rpmrules_end) /* but are not done with rpm rules */
342 r = solv->rules + solv->nrules - 1; /* get the last added rule */
343 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
348 * compute number of literals (n) in rule
353 /* always a binary rule */
355 return 0; /* ignore self conflict */
360 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
362 return 0; /* rule is self-fulfilling */
364 if (n == 1) /* have single provider */
365 d = dp[-1]; /* take single literal */
368 if (n == 1 && p > d && !solv->rpmrules_end)
370 /* smallest literal first so we can find dups */
371 n = p; p = d; d = n; /* p <-> d */
372 n = 1; /* re-set n, was used as temp var */
376 * check for duplicate
379 /* check if the last added rule (r) is exactly the same as what we're looking for. */
380 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
381 return r; /* binary rule */
383 /* have n-ary rule with same first literal, check other literals */
384 if (r && n > 1 && r->d && r->p == p)
386 /* Rule where d is an offset in whatprovidesdata */
390 dp2 = pool->whatprovidesdata + r->d;
391 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
402 /* extend rule buffer */
403 solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
404 r = solv->rules + solv->nrules++; /* point to rule space */
413 /* direct assertion, no watch needed */
429 r->w2 = pool->whatprovidesdata[d];
434 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
436 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
437 solver_printrule(solv, SAT_DEBUG_RULE_CREATION, r);
443 /*-------------------------------------------------------------------
448 disablerule(Solver *solv, Rule *r)
454 /*-------------------------------------------------------------------
459 enablerule(Solver *solv, Rule *r)
466 /**********************************************************************************/
468 /* a problem is an item on the solver's problem list. It can either be >0, in that
469 * case it is a update rule, or it can be <0, which makes it refer to a job
470 * consisting of multiple job rules.
474 disableproblem(Solver *solv, Id v)
482 if (v >= solv->infarchrules && v < solv->infarchrules_end)
484 Pool *pool = solv->pool;
485 Id name = pool->solvables[-solv->rules[v].p].name;
486 while (v > solv->infarchrules && pool->solvables[-solv->rules[v - 1].p].name == name)
488 for (; v < solv->infarchrules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
489 disablerule(solv, solv->rules + v);
492 if (v >= solv->duprules && v < solv->duprules_end)
494 Pool *pool = solv->pool;
495 Id name = pool->solvables[-solv->rules[v].p].name;
496 while (v > solv->duprules && pool->solvables[-solv->rules[v - 1].p].name == name)
498 for (; v < solv->duprules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
499 disablerule(solv, solv->rules + v);
502 disablerule(solv, solv->rules + v);
506 jp = solv->ruletojob.elements;
507 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
509 disablerule(solv, r);
512 /*-------------------------------------------------------------------
517 enableproblem(Solver *solv, Id v)
525 if (v >= solv->infarchrules && v < solv->infarchrules_end)
527 Pool *pool = solv->pool;
528 Id name = pool->solvables[-solv->rules[v].p].name;
529 while (v > solv->infarchrules && pool->solvables[-solv->rules[v - 1].p].name == name)
531 for (; v < solv->infarchrules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
532 enablerule(solv, solv->rules + v);
535 if (v >= solv->duprules && v < solv->duprules_end)
537 Pool *pool = solv->pool;
538 Id name = pool->solvables[-solv->rules[v].p].name;
539 while (v > solv->duprules && pool->solvables[-solv->rules[v - 1].p].name == name)
541 for (; v < solv->duprules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
542 enablerule(solv, solv->rules + v);
545 if (v >= solv->featurerules && v < solv->featurerules_end)
547 /* do not enable feature rule if update rule is enabled */
548 r = solv->rules + (v - solv->featurerules + solv->updaterules);
552 enablerule(solv, solv->rules + v);
553 if (v >= solv->updaterules && v < solv->updaterules_end)
555 /* disable feature rule when enabling update rule */
556 r = solv->rules + (v - solv->updaterules + solv->featurerules);
558 disablerule(solv, r);
563 jp = solv->ruletojob.elements;
564 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
570 /************************************************************************/
573 * make assertion rules into decisions
575 * go through update and job rules and add direct assertions
576 * to the decisionqueue. If we find a conflict, disable rules and
577 * add them to problem queue.
581 makeruledecisions(Solver *solv)
583 Pool *pool = solv->pool;
589 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
591 decisionstart = solv->decisionq.count;
592 for (ii = 0; ii < solv->ruleassertions.count; ii++)
594 ri = solv->ruleassertions.elements[ii];
595 r = solv->rules + ri;
597 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
599 /* do weak rules in phase 2 */
600 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
606 if (!solv->decisionmap[vv]) /* if not yet decided */
611 queue_push(&solv->decisionq, v);
612 queue_push(&solv->decisionq_why, r - solv->rules);
613 solv->decisionmap[vv] = v > 0 ? 1 : -1;
614 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
616 Solvable *s = solv->pool->solvables + vv;
618 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
620 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
625 * check previous decision: is it sane ?
628 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
630 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
636 * The rule (r) we're currently processing says something
637 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
641 if (ri >= solv->learntrules)
643 /* conflict with a learnt rule */
644 /* can happen when packages cannot be installed for
645 * multiple reasons. */
646 /* we disable the learnt rule in this case */
647 disablerule(solv, r);
652 * find the decision which is the "opposite" of the rule
655 for (i = 0; i < solv->decisionq.count; i++)
656 if (solv->decisionq.elements[i] == -v)
658 assert(i < solv->decisionq.count); /* assert that we found it */
661 * conflict with system solvable ?
664 if (v == -SYSTEMSOLVABLE) {
665 /* conflict with system solvable */
666 queue_push(&solv->problems, solv->learnt_pool.count);
667 queue_push(&solv->learnt_pool, ri);
668 queue_push(&solv->learnt_pool, 0);
669 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
670 if (ri >= solv->jobrules && ri < solv->jobrules_end)
671 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
674 queue_push(&solv->problems, v);
675 queue_push(&solv->problems, 0);
676 disableproblem(solv, v);
680 assert(solv->decisionq_why.elements[i] > 0);
683 * conflict with an rpm rule ?
686 if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
688 /* conflict with rpm rule assertion */
689 queue_push(&solv->problems, solv->learnt_pool.count);
690 queue_push(&solv->learnt_pool, ri);
691 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
692 queue_push(&solv->learnt_pool, 0);
693 assert(v > 0 || v == -SYSTEMSOLVABLE);
694 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
695 if (ri >= solv->jobrules && ri < solv->jobrules_end)
696 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
699 queue_push(&solv->problems, v);
700 queue_push(&solv->problems, 0);
701 disableproblem(solv, v);
706 * conflict with another job or update/feature rule
710 queue_push(&solv->problems, solv->learnt_pool.count);
711 queue_push(&solv->learnt_pool, ri);
712 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
713 queue_push(&solv->learnt_pool, 0);
715 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
718 * push all of our rules (can only be feature or job rules)
719 * asserting this literal on the problem stack
722 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
724 if (rr->d < 0 /* disabled */
725 || rr->w2) /* or no assertion */
727 if (rr->p != vv /* not affecting the literal */
730 if (MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
733 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
735 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, solv->rules + i);
738 /* is is a job rule ? */
739 if (i >= solv->jobrules && i < solv->jobrules_end)
740 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
742 queue_push(&solv->problems, v);
743 disableproblem(solv, v);
745 queue_push(&solv->problems, 0);
749 * (back up from decisions)
751 while (solv->decisionq.count > decisionstart)
753 v = solv->decisionq.elements[--solv->decisionq.count];
754 --solv->decisionq_why.count;
756 solv->decisionmap[vv] = 0;
758 ii = -1; /* restarts loop at 0 */
762 * phase 2: now do the weak assertions
764 for (ii = 0; ii < solv->ruleassertions.count; ii++)
766 ri = solv->ruleassertions.elements[ii];
767 r = solv->rules + ri;
768 if (r->d < 0 || r->w2) /* disabled or no assertion */
770 if (ri >= solv->learntrules || !MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
776 * (if not yet decided)
778 if (!solv->decisionmap[vv])
780 queue_push(&solv->decisionq, v);
781 queue_push(&solv->decisionq_why, r - solv->rules);
782 solv->decisionmap[vv] = v > 0 ? 1 : -1;
783 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
785 Solvable *s = solv->pool->solvables + vv;
787 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", solvable2str(solv->pool, s));
789 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", solvable2str(solv->pool, s));
794 * previously decided, sane ?
796 if (v > 0 && solv->decisionmap[vv] > 0)
798 if (v < 0 && solv->decisionmap[vv] < 0)
801 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
802 solver_printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
804 if (ri >= solv->jobrules && ri < solv->jobrules_end)
805 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
808 disableproblem(solv, v);
810 reenablepolicyrules(solv, &solv->job, -(v + 1));
813 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
817 /*-------------------------------------------------------------------
818 * enable/disable learnt rules
820 * we have enabled or disabled some of our rules. We now reenable all
821 * of our learnt rules except the ones that were learnt from rules that
825 enabledisablelearntrules(Solver *solv)
827 Pool *pool = solv->pool;
832 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
833 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
835 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
836 while ((why = *whyp++) != 0)
838 assert(why > 0 && why < i);
839 if (solv->rules[why].d < 0)
842 /* why != 0: we found a disabled rule, disable the learnt rule */
843 if (why && r->d >= 0)
845 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
847 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling ");
848 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
850 disablerule(solv, r);
852 else if (!why && r->d < 0)
854 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
856 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling ");
857 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
865 /*-------------------------------------------------------------------
868 * Enable all rules, except learnt rules, which are
869 * - disabled and weak (set in weakrulemap)
874 enableweakrules(Solver *solv)
879 for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
881 if (r->d >= 0) /* already enabled? */
883 if (!MAPTST(&solv->weakrulemap, i))
890 /*-------------------------------------------------------------------
891 * policy rule enabling/disabling
893 * we need to disable policy rules that conflict with our job list, and
894 * also reenable such rules with the job was changed due to solution generation
899 disableinfarchrule(Solver *solv, Id name)
901 Pool *pool = solv->pool;
904 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
906 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
907 disablerule(solv, r);
912 reenableinfarchrule(Solver *solv, Id name)
914 Pool *pool = solv->pool;
917 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
919 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
922 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
924 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
925 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
932 disableduprule(Solver *solv, Id name)
934 Pool *pool = solv->pool;
937 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
939 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
940 disablerule(solv, r);
945 reenableduprule(Solver *solv, Id name)
947 Pool *pool = solv->pool;
950 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
952 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
955 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
957 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
958 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
965 disableupdaterule(Solver *solv, Id p)
969 MAPSET(&solv->noupdate, p - solv->installed->start);
970 r = solv->rules + solv->updaterules + (p - solv->installed->start);
971 if (r->p && r->d >= 0)
972 disablerule(solv, r);
973 r = solv->rules + solv->featurerules + (p - solv->installed->start);
974 if (r->p && r->d >= 0)
975 disablerule(solv, r);
979 reenableupdaterule(Solver *solv, Id p)
981 Pool *pool = solv->pool;
984 MAPCLR(&solv->noupdate, p - solv->installed->start);
985 r = solv->rules + solv->updaterules + (p - solv->installed->start);
991 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
993 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
994 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
998 r = solv->rules + solv->featurerules + (p - solv->installed->start);
999 if (r->p && r->d < 0)
1001 enablerule(solv, r);
1002 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1004 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1005 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1010 #define DISABLE_UPDATE 1
1011 #define DISABLE_INFARCH 2
1012 #define DISABLE_DUP 3
1015 jobtodisablelist(Solver *solv, Id how, Id what, Queue *q)
1017 Pool *pool = solv->pool;
1023 installed = solv->installed;
1024 select = how & SOLVER_SELECTMASK;
1025 switch (how & SOLVER_JOBMASK)
1027 case SOLVER_INSTALL:
1028 if ((select == SOLVER_SOLVABLE_NAME || select == SOLVER_SOLVABLE_PROVIDES) && solv->infarchrules != solv->infarchrules_end && ISRELDEP(what))
1030 Reldep *rd = GETRELDEP(pool, what);
1031 if (rd->flags == REL_ARCH)
1033 int qcnt = q->count;
1034 FOR_JOB_SELECT(p, pp, select, what)
1036 s = pool->solvables + p;
1038 for (i = qcnt; i < q->count; i += 2)
1039 if (q->elements[i + 1] == s->name)
1043 queue_push(q, DISABLE_INFARCH);
1044 queue_push(q, s->name);
1048 if (select != SOLVER_SOLVABLE)
1050 s = pool->solvables + what;
1051 if (solv->infarchrules != solv->infarchrules_end)
1053 queue_push(q, DISABLE_INFARCH);
1054 queue_push(q, s->name);
1056 if (solv->duprules != solv->duprules_end)
1058 queue_push(q, DISABLE_DUP);
1059 queue_push(q, s->name);
1063 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, what))
1065 if (s->repo == installed)
1067 queue_push(q, DISABLE_UPDATE);
1068 queue_push(q, what);
1074 obsp = s->repo->idarraydata + s->obsoletes;
1075 while ((obs = *obsp++) != 0)
1076 FOR_PROVIDES(p, pp, obs)
1078 Solvable *ps = pool->solvables + p;
1079 if (ps->repo != installed)
1081 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
1083 queue_push(q, DISABLE_UPDATE);
1087 FOR_PROVIDES(p, pp, s->name)
1089 Solvable *ps = pool->solvables + p;
1090 if (ps->repo != installed)
1092 if (!solv->implicitobsoleteusesprovides && ps->name != s->name)
1094 queue_push(q, DISABLE_UPDATE);
1101 FOR_JOB_SELECT(p, pp, select, what)
1102 if (pool->solvables[p].repo == installed)
1104 queue_push(q, DISABLE_UPDATE);
1113 /* disable all policy rules that are in conflict with our job list */
1115 disablepolicyrules(Solver *solv, Queue *job)
1123 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
1125 for (i = solv->jobrules; i < solv->jobrules_end; i++)
1127 r = solv->rules + i;
1128 if (r->d < 0) /* disabled? */
1130 j = solv->ruletojob.elements[i - solv->jobrules];
1134 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
1136 MAPZERO(&solv->noupdate);
1137 for (i = 0; i < allq.count; i += 2)
1139 Id type = allq.elements[i], arg = allq.elements[i + 1];
1142 case DISABLE_UPDATE:
1143 disableupdaterule(solv, arg);
1145 case DISABLE_INFARCH:
1146 disableinfarchrule(solv, arg);
1149 disableduprule(solv, arg);
1158 /* we just disabled job #jobidx, now reenable all policy rules that were
1159 * disabled because of this job */
1161 reenablepolicyrules(Solver *solv, Queue *job, int jobidx)
1167 Id qbuf[32], allqbuf[128];
1169 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1170 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
1171 jobtodisablelist(solv, job->elements[jobidx], job->elements[jobidx + 1], &q);
1174 for (i = solv->jobrules; i < solv->jobrules_end; i++)
1176 r = solv->rules + i;
1177 if (r->d < 0) /* disabled? */
1179 j = solv->ruletojob.elements[i - solv->jobrules];
1183 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
1185 for (j = 0; j < q.count; j += 2)
1187 Id type = q.elements[j], arg = q.elements[j + 1];
1188 for (i = 0; i < allq.count; i += 2)
1189 if (allq.elements[i] == type && allq.elements[i + 1] == arg)
1192 continue; /* still disabled */
1195 case DISABLE_UPDATE:
1196 reenableupdaterule(solv, arg);
1198 case DISABLE_INFARCH:
1199 reenableinfarchrule(solv, arg);
1202 reenableduprule(solv, arg);
1210 /*-------------------------------------------------------------------
1216 * special multiversion patch conflict handling:
1217 * a patch conflict is also satisfied, if some other
1218 * version with the same name/arch that doesn't conflict
1219 * get's installed. The generated rule is thus:
1220 * -patch|-cpack|opack1|opack2|...
1223 makemultiversionconflict(Solver *solv, Id n, Id con)
1225 Pool *pool = solv->pool;
1230 sn = pool->solvables + n;
1231 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1233 FOR_PROVIDES(p, pp, sn->name)
1235 s = pool->solvables + p;
1236 if (s->name != sn->name || s->arch != sn->arch)
1238 if (!MAPTST(&solv->noobsoletes, p))
1240 if (pool_match_nevr(pool, pool->solvables + p, con))
1242 /* here we have a multiversion solvable that doesn't conflict */
1243 /* thus we're not in conflict if it is installed */
1247 return -n; /* no other package found, generate normal conflict */
1248 return pool_queuetowhatprovides(pool, &q);
1252 addrpmrule(Solver *solv, Id p, Id d, int type, Id dep)
1254 if (!solv->ruleinfoq)
1255 addrule(solv, p, d);
1257 addrpmruleinfo(solv, p, d, type, dep);
1260 /*-------------------------------------------------------------------
1262 * add (install) rules for solvable
1264 * s: Solvable for which to add rules
1265 * m: m[s] = 1 for solvables which have rules, prevent rule duplication
1267 * Algorithm: 'visit all nodes of a graph'. The graph nodes are
1268 * solvables, the edges their dependencies.
1269 * Starting from an installed solvable, this will create all rules
1270 * representing the graph created by the solvables dependencies.
1272 * for unfulfilled requirements, conflicts, obsoletes,....
1273 * add a negative assertion for solvables that are not installable
1275 * It will also create rules for all solvables referenced by 's'
1276 * i.e. descend to all providers of requirements of 's'
1281 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
1283 Pool *pool = solv->pool;
1284 Repo *installed = solv->installed;
1286 /* 'work' queue. keeps Ids of solvables we still have to work on.
1287 And buffer for it. */
1292 /* if to add rules for broken deps ('rpm -V' functionality)
1296 /* Id var and pointer for each dependency
1297 * (not used in parallel)
1304 Id p, pp; /* whatprovides loops */
1305 Id *dp; /* ptr to 'whatprovides' */
1306 Id n; /* Id for current solvable 's' */
1308 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
1310 queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
1311 queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
1313 /* loop until there's no more work left */
1318 * s: Pointer to solvable
1321 n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
1324 if (MAPTST(m, n)) /* continue if already visited */
1326 MAPSET(m, n); /* mark as visited */
1329 s = pool->solvables + n; /* s = Solvable in question */
1332 if (installed /* Installed system available */
1333 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
1334 && s->repo == installed) /* solvable is installed? */
1336 dontfix = 1; /* dont care about broken rpm deps */
1340 && s->arch != ARCH_SRC
1341 && s->arch != ARCH_NOSRC
1342 && !pool_installable(pool, s))
1344 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
1345 addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOT_INSTALLABLE, 0);
1348 /* yet another SUSE hack, sigh */
1349 if (pool->nscallback && !strncmp("product:", id2str(pool, s->name), 8))
1351 Id buddy = pool->nscallback(pool, pool->nscallbackdata, NAMESPACE_PRODUCTBUDDY, n);
1352 if (buddy > 0 && buddy != SYSTEMSOLVABLE && buddy != n && buddy < pool->nsolvables)
1354 addrpmrule(solv, n, -buddy, SOLVER_RULE_RPM_PACKAGE_REQUIRES, solvable_selfprovidedep(pool->solvables + n));
1355 addrpmrule(solv, buddy, -n, SOLVER_RULE_RPM_PACKAGE_REQUIRES, solvable_selfprovidedep(pool->solvables + buddy));
1356 if (m && !MAPTST(m, buddy))
1357 queue_push(&workq, buddy);
1361 /*-----------------------------------------
1362 * check requires of s
1367 reqp = s->repo->idarraydata + s->requires;
1368 while ((req = *reqp++) != 0) /* go through all requires */
1370 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
1373 /* find list of solvables providing 'req' */
1374 dp = pool_whatprovides_ptr(pool, req);
1376 if (*dp == SYSTEMSOLVABLE) /* always installed */
1381 /* the strategy here is to not insist on dependencies
1382 * that are already broken. so if we find one provider
1383 * that was already installed, we know that the
1384 * dependency was not broken before so we enforce it */
1386 /* check if any of the providers for 'req' is installed */
1387 for (i = 0; (p = dp[i]) != 0; i++)
1389 if (pool->solvables[p].repo == installed)
1390 break; /* provider was installed */
1392 /* didn't find an installed provider: previously broken dependency */
1395 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1402 /* nothing provides req! */
1403 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1404 addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP, req);
1408 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1410 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1411 for (i = 0; dp[i]; i++)
1412 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1415 /* add 'requires' dependency */
1416 /* rule: (-requestor|provider1|provider2|...|providerN) */
1417 addrpmrule(solv, -n, dp - pool->whatprovidesdata, SOLVER_RULE_RPM_PACKAGE_REQUIRES, req);
1419 /* descend the dependency tree
1420 push all non-visited providers on the work queue */
1425 if (!MAPTST(m, *dp))
1426 queue_push(&workq, *dp);
1430 } /* while, requirements of n */
1432 } /* if, requirements */
1434 /* that's all we check for src packages */
1435 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1438 /*-----------------------------------------
1439 * check conflicts of s
1446 /* we treat conflicts in patches a bit differen:
1448 * - multiversion handling
1449 * XXX: we should really handle this different, looking
1450 * at the name is a bad hack
1452 if (!strncmp("patch:", id2str(pool, s->name), 6))
1454 conp = s->repo->idarraydata + s->conflicts;
1455 /* foreach conflicts of 's' */
1456 while ((con = *conp++) != 0)
1458 /* foreach providers of a conflict of 's' */
1459 FOR_PROVIDES(p, pp, con)
1461 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
1463 /* dontfix: dont care about conflicts with already installed packs */
1464 if (dontfix && pool->solvables[p].repo == installed)
1466 /* p == n: self conflict */
1467 if (p == n && !solv->allowselfconflicts)
1471 Reldep *rd = GETRELDEP(pool, con);
1472 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
1475 p = 0; /* make it a negative assertion, aka 'uninstallable' */
1477 if (p && ispatch && solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p) && ISRELDEP(con))
1479 /* our patch conflicts with a noobsoletes (aka multiversion) package */
1480 p = -makemultiversionconflict(solv, p, con);
1482 /* rule: -n|-p: either solvable _or_ provider of conflict */
1483 addrpmrule(solv, -n, -p, p ? SOLVER_RULE_RPM_PACKAGE_CONFLICT : SOLVER_RULE_RPM_SELF_CONFLICT, con);
1488 /*-----------------------------------------
1489 * check obsoletes if not installed
1490 * (only installation will trigger the obsoletes in rpm)
1492 if (!installed || pool->solvables[n].repo != installed)
1493 { /* not installed */
1494 int noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
1495 if (s->obsoletes && !noobs)
1497 obsp = s->repo->idarraydata + s->obsoletes;
1498 /* foreach obsoletes */
1499 while ((obs = *obsp++) != 0)
1501 /* foreach provider of an obsoletes of 's' */
1502 FOR_PROVIDES(p, pp, obs)
1504 if (!solv->obsoleteusesprovides /* obsoletes are matched names, not provides */
1505 && !pool_match_nevr(pool, pool->solvables + p, obs))
1507 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_PACKAGE_OBSOLETES, obs);
1511 FOR_PROVIDES(p, pp, s->name)
1513 Solvable *ps = pool->solvables + p;
1514 /* we still obsolete packages with same nevra, like rpm does */
1515 /* (actually, rpm mixes those packages. yuck...) */
1516 if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
1518 if (!solv->implicitobsoleteusesprovides && s->name != ps->name)
1520 if (s->name == ps->name)
1521 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_SAME_NAME, 0);
1523 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_IMPLICIT_OBSOLETES, s->name);
1527 /*-----------------------------------------
1528 * add recommends to the work queue
1530 if (s->recommends && m)
1532 recp = s->repo->idarraydata + s->recommends;
1533 while ((rec = *recp++) != 0)
1535 FOR_PROVIDES(p, pp, rec)
1537 queue_push(&workq, p);
1540 if (s->suggests && m)
1542 sugp = s->repo->idarraydata + s->suggests;
1543 while ((sug = *sugp++) != 0)
1545 FOR_PROVIDES(p, pp, sug)
1547 queue_push(&workq, p);
1552 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1556 /*-------------------------------------------------------------------
1558 * Add package rules for weak rules
1560 * m: visited solvables
1564 addrpmrulesforweak(Solver *solv, Map *m)
1566 Pool *pool = solv->pool;
1571 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1572 /* foreach solvable in pool */
1573 for (i = n = 1; n < pool->nsolvables; i++, n++)
1575 if (i == pool->nsolvables) /* wrap i */
1577 if (MAPTST(m, i)) /* been there */
1580 s = pool->solvables + i;
1581 if (!pool_installable(pool, s)) /* only look at installable ones */
1587 /* find possible supplements */
1588 supp = s->repo->idarraydata + s->supplements;
1589 while ((sup = *supp++) != ID_NULL)
1590 if (dep_possible(solv, sup, m))
1594 /* if nothing found, check for enhances */
1595 if (!sup && s->enhances)
1597 supp = s->repo->idarraydata + s->enhances;
1598 while ((sup = *supp++) != ID_NULL)
1599 if (dep_possible(solv, sup, m))
1602 /* if nothing found, goto next solvables */
1605 addrpmrulesforsolvable(solv, s, m);
1606 n = 0; /* check all solvables again */
1608 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1612 /*-------------------------------------------------------------------
1614 * add package rules for possible updates
1617 * m: map of already visited solvables
1618 * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
1622 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
1624 Pool *pool = solv->pool;
1626 /* queue and buffer for it */
1630 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1632 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1633 /* find update candidates for 's' */
1634 policy_findupdatepackages(solv, s, &qs, allow_all);
1635 /* add rule for 's' if not already done */
1636 if (!MAPTST(m, s - pool->solvables))
1637 addrpmrulesforsolvable(solv, s, m);
1638 /* foreach update candidate, add rule if not already done */
1639 for (i = 0; i < qs.count; i++)
1640 if (!MAPTST(m, qs.elements[i]))
1641 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1644 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1648 finddistupgradepackages(Solver *solv, Solvable *s, Queue *qs, int allow_all)
1650 Pool *pool = solv->pool;
1653 policy_findupdatepackages(solv, s, qs, allow_all);
1657 return 0; /* orphaned, don't create feature rule */
1658 /* check if this is an orphaned package */
1659 policy_findupdatepackages(solv, s, qs, 1);
1661 return 0; /* orphaned, don't create update rule */
1663 return -SYSTEMSOLVABLE; /* supported but not installable */
1666 return s - pool->solvables;
1667 /* check if it is ok to keep the installed package */
1668 for (i = 0; i < qs->count; i++)
1670 Solvable *ns = pool->solvables + qs->elements[i];
1671 if (s->evr == ns->evr && solvable_identical(s, ns))
1672 return s - pool->solvables;
1674 /* nope, it must be some other package */
1675 return -SYSTEMSOLVABLE;
1678 /* add packages from the dup repositories to the update candidates
1679 * this isn't needed for the global dup mode as all packages are
1680 * from dup repos in that case */
1682 addduppackages(Solver *solv, Solvable *s, Queue *qs)
1687 int oldnoupdateprovide = solv->noupdateprovide;
1689 queue_init_buffer(&dupqs, dupqsbuf, sizeof(dupqsbuf)/sizeof(*dupqsbuf));
1690 solv->noupdateprovide = 1;
1691 policy_findupdatepackages(solv, s, &dupqs, 2);
1692 solv->noupdateprovide = oldnoupdateprovide;
1693 for (i = 0; i < dupqs.count; i++)
1695 p = dupqs.elements[i];
1696 if (MAPTST(&solv->dupmap, p))
1697 queue_pushunique(qs, p);
1702 /*-------------------------------------------------------------------
1704 * add rule for update
1705 * (A|A1|A2|A3...) An = update candidates for A
1707 * s = (installed) solvable
1711 addupdaterule(Solver *solv, Solvable *s, int allow_all)
1713 /* installed packages get a special upgrade allowed rule */
1714 Pool *pool = solv->pool;
1719 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1720 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1721 p = s - pool->solvables;
1722 /* find update candidates for 's' */
1723 if (solv->distupgrade)
1724 p = finddistupgradepackages(solv, s, &qs, allow_all);
1726 policy_findupdatepackages(solv, s, &qs, allow_all);
1727 if (!allow_all && !solv->distupgrade && solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
1728 addduppackages(solv, s, &qs);
1730 if (!allow_all && qs.count && solv->noobsoletes.size)
1734 d = pool_queuetowhatprovides(pool, &qs);
1735 /* filter out all noobsoletes packages as they don't update */
1736 for (i = j = 0; i < qs.count; i++)
1738 if (MAPTST(&solv->noobsoletes, qs.elements[i]))
1740 /* it's ok if they have same nevra */
1741 Solvable *ps = pool->solvables + qs.elements[i];
1742 if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
1745 qs.elements[j++] = qs.elements[i];
1747 if (j == 0 && p == -SYSTEMSOLVABLE && solv->distupgrade)
1749 queue_push(&solv->orphaned, s - pool->solvables); /* treat as orphaned */
1754 if (d && solv->updatesystem && solv->installed && s->repo == solv->installed)
1756 if (!solv->multiversionupdaters)
1757 solv->multiversionupdaters = sat_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
1758 solv->multiversionupdaters[s - pool->solvables - solv->installed->start] = d;
1763 if (qs.count && p == -SYSTEMSOLVABLE)
1764 p = queue_shift(&qs);
1765 d = qs.count ? pool_queuetowhatprovides(pool, &qs) : 0;
1767 addrule(solv, p, d); /* allow update of s */
1768 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1772 /********************************************************************/
1776 /*-------------------------------------------------------------------
1779 * initial setup for all watches
1783 makewatches(Solver *solv)
1787 int nsolvables = solv->pool->nsolvables;
1789 sat_free(solv->watches);
1790 /* lower half for removals, upper half for installs */
1791 solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
1793 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
1794 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1796 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1799 if (!r->w2) /* assertions do not need watches */
1802 /* see addwatches_rule(solv, r) */
1803 r->n1 = solv->watches[nsolvables + r->w1];
1804 solv->watches[nsolvables + r->w1] = r - solv->rules;
1806 r->n2 = solv->watches[nsolvables + r->w2];
1807 solv->watches[nsolvables + r->w2] = r - solv->rules;
1812 /*-------------------------------------------------------------------
1814 * add watches (for rule)
1815 * sets up watches for a single rule
1817 * see also makewatches()
1821 addwatches_rule(Solver *solv, Rule *r)
1823 int nsolvables = solv->pool->nsolvables;
1825 r->n1 = solv->watches[nsolvables + r->w1];
1826 solv->watches[nsolvables + r->w1] = r - solv->rules;
1828 r->n2 = solv->watches[nsolvables + r->w2];
1829 solv->watches[nsolvables + r->w2] = r - solv->rules;
1833 /********************************************************************/
1839 /* shortcuts to check if a literal (positive or negative) assignment
1840 * evaluates to 'true' or 'false'
1842 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1843 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
1844 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
1846 /*-------------------------------------------------------------------
1850 * make decision and propagate to all rules
1852 * Evaluate each term affected by the decision (linked through watches)
1853 * If we find unit rules we make new decisions based on them
1855 * Everything's fixed there, it's just finding rules that are
1858 * return : 0 = everything is OK
1859 * rule = conflict found in this rule
1863 propagate(Solver *solv, int level)
1865 Pool *pool = solv->pool;
1866 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
1868 Id p, pkg, other_watch;
1870 Id *decisionmap = solv->decisionmap;
1872 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
1874 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1876 /* foreach non-propagated decision */
1877 while (solv->propagate_index < solv->decisionq.count)
1880 * 'pkg' was just decided
1881 * negate because our watches trigger if literal goes FALSE
1883 pkg = -solv->decisionq.elements[solv->propagate_index++];
1885 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1887 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
1888 solver_printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1891 /* foreach rule where 'pkg' is now FALSE */
1892 for (rp = watches + pkg; *rp; rp = next_rp)
1894 r = solv->rules + *rp;
1897 /* rule is disabled, goto next */
1905 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1907 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1908 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
1911 /* 'pkg' was just decided (was set to FALSE)
1913 * now find other literal watch, check clause
1914 * and advance on linked list
1918 other_watch = r->w2;
1923 other_watch = r->w1;
1928 * This term is already true (through the other literal)
1929 * so we have nothing to do
1931 if (DECISIONMAP_TRUE(other_watch))
1935 * The other literal is FALSE or UNDEF
1941 /* Not a binary clause, try to move our watch.
1943 * Go over all literals and find one that is
1947 * (TRUE is also ok, in that case the rule is fulfilled)
1949 if (r->p /* we have a 'p' */
1950 && r->p != other_watch /* which is not watched */
1951 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
1955 else /* go find a 'd' to make 'true' */
1958 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
1960 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1962 if (p != other_watch /* which is not watched */
1963 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
1971 * if we found some p that is UNDEF or TRUE, move
1974 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1977 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1979 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1995 watches[p] = r - solv->rules;
1998 /* search failed, thus all unwatched literals are FALSE */
2003 * unit clause found, set literal other_watch to TRUE
2006 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
2007 return r; /* eek, a conflict! */
2009 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2011 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
2012 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
2015 if (other_watch > 0)
2016 decisionmap[other_watch] = level; /* install! */
2018 decisionmap[-other_watch] = -level; /* remove! */
2020 queue_push(&solv->decisionq, other_watch);
2021 queue_push(&solv->decisionq_why, r - solv->rules);
2023 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2025 Solvable *s = pool->solvables + (other_watch > 0 ? other_watch : -other_watch);
2026 if (other_watch > 0)
2027 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
2029 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
2032 } /* foreach rule involving 'pkg' */
2034 } /* while we have non-decided decisions */
2036 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
2038 return 0; /* all is well */
2042 /********************************************************************/
2045 /*-------------------------------------------------------------------
2052 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
2054 Pool *pool = solv->pool;
2057 Map seen; /* global? */
2058 Id d, v, vv, *dp, why;
2060 int num = 0, l1num = 0;
2061 int learnt_why = solv->learnt_pool.count;
2062 Id *decisionmap = solv->decisionmap;
2066 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
2067 map_init(&seen, pool->nsolvables);
2068 idx = solv->decisionq.count;
2071 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
2072 solver_printruleclass(solv, SAT_DEBUG_ANALYZE, c);
2073 queue_push(&solv->learnt_pool, c - solv->rules);
2074 d = c->d < 0 ? -c->d - 1 : c->d;
2075 dp = d ? pool->whatprovidesdata + d : 0;
2076 /* go through all literals of the rule */
2088 if (DECISIONMAP_TRUE(v)) /* the one true literal */
2090 vv = v > 0 ? v : -v;
2091 if (MAPTST(&seen, vv))
2093 l = solv->decisionmap[vv];
2098 l1num++; /* need to do this one in level1 pass */
2099 else if (l == level)
2100 num++; /* need to do this one as well */
2103 queue_push(&r, v); /* not level1 or conflict level, add to new rule */
2109 if (!num && !--l1num)
2110 break; /* all level 1 literals done */
2114 v = solv->decisionq.elements[--idx];
2115 vv = v > 0 ? v : -v;
2116 if (MAPTST(&seen, vv))
2120 if (num && --num == 0)
2122 *pr = -v; /* so that v doesn't get lost */
2125 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
2126 for (i = 0; i < r.count; i++)
2129 MAPCLR(&seen, v > 0 ? v : -v);
2131 /* only level 1 marks left */
2135 why = solv->decisionq_why.elements[idx];
2136 if (why <= 0) /* just in case, maybe for SYSTEMSOLVABLE */
2138 c = solv->rules + why;
2144 else if (r.count == 1 && r.elements[0] < 0)
2145 *dr = r.elements[0];
2147 *dr = pool_queuetowhatprovides(pool, &r);
2148 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
2150 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
2151 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
2152 for (i = 0; i < r.count; i++)
2153 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
2155 /* push end marker on learnt reasons stack */
2156 queue_push(&solv->learnt_pool, 0);
2159 solv->stats_learned++;
2164 /*-------------------------------------------------------------------
2168 * reset the solver decisions to right after the rpm rules.
2169 * called after rules have been enabled/disabled
2173 reset_solver(Solver *solv)
2175 Pool *pool = solv->pool;
2179 /* rewind decisions to direct rpm rule assertions */
2180 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
2182 v = solv->decisionq.elements[i];
2183 solv->decisionmap[v > 0 ? v : -v] = 0;
2186 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
2188 solv->decisionq_why.count = solv->directdecisions;
2189 solv->decisionq.count = solv->directdecisions;
2190 solv->recommends_index = -1;
2191 solv->propagate_index = 0;
2193 /* adapt learnt rule status to new set of enabled/disabled rules */
2194 enabledisablelearntrules(solv);
2196 /* redo all job/update decisions */
2197 makeruledecisions(solv);
2198 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
2202 /*-------------------------------------------------------------------
2204 * analyze_unsolvable_rule
2208 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
2210 Pool *pool = solv->pool;
2212 Id why = r - solv->rules;
2214 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
2215 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
2216 if (solv->learntrules && why >= solv->learntrules)
2218 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
2219 if (solv->learnt_pool.elements[i] > 0)
2220 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp);
2223 if (MAPTST(&solv->weakrulemap, why))
2224 if (!*lastweakp || why > *lastweakp)
2226 /* do not add rpm rules to problem */
2227 if (why < solv->rpmrules_end)
2229 /* turn rule into problem */
2230 if (why >= solv->jobrules && why < solv->jobrules_end)
2231 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
2232 /* normalize dup/infarch rules */
2233 if (why > solv->infarchrules && why < solv->infarchrules_end)
2235 Id name = pool->solvables[-solv->rules[why].p].name;
2236 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
2239 if (why > solv->duprules && why < solv->duprules_end)
2241 Id name = pool->solvables[-solv->rules[why].p].name;
2242 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
2246 /* return if problem already countains our rule */
2247 if (solv->problems.count)
2249 for (i = solv->problems.count - 1; i >= 0; i--)
2250 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
2252 else if (solv->problems.elements[i] == why)
2255 queue_push(&solv->problems, why);
2259 /*-------------------------------------------------------------------
2261 * analyze_unsolvable
2263 * return: 1 - disabled some rules, try again
2268 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
2270 Pool *pool = solv->pool;
2272 Map seen; /* global to speed things up? */
2273 Id d, v, vv, *dp, why;
2275 Id *decisionmap = solv->decisionmap;
2276 int oldproblemcount;
2277 int oldlearntpoolcount;
2280 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
2281 solv->stats_unsolvable++;
2282 oldproblemcount = solv->problems.count;
2283 oldlearntpoolcount = solv->learnt_pool.count;
2285 /* make room for proof index */
2286 /* must update it later, as analyze_unsolvable_rule would confuse
2287 * it with a rule index if we put the real value in already */
2288 queue_push(&solv->problems, 0);
2291 map_init(&seen, pool->nsolvables);
2292 queue_push(&solv->learnt_pool, r - solv->rules);
2294 analyze_unsolvable_rule(solv, r, &lastweak);
2295 d = r->d < 0 ? -r->d - 1 : r->d;
2296 dp = d ? pool->whatprovidesdata + d : 0;
2307 if (DECISIONMAP_TRUE(v)) /* the one true literal */
2309 vv = v > 0 ? v : -v;
2310 l = solv->decisionmap[vv];
2315 idx = solv->decisionq.count;
2318 v = solv->decisionq.elements[--idx];
2319 vv = v > 0 ? v : -v;
2320 if (!MAPTST(&seen, vv))
2322 why = solv->decisionq_why.elements[idx];
2324 queue_push(&solv->learnt_pool, why);
2325 r = solv->rules + why;
2326 analyze_unsolvable_rule(solv, r, &lastweak);
2327 d = r->d < 0 ? -r->d - 1 : r->d;
2328 dp = d ? pool->whatprovidesdata + d : 0;
2339 if (DECISIONMAP_TRUE(v)) /* the one true literal */
2341 vv = v > 0 ? v : -v;
2342 l = solv->decisionmap[vv];
2349 queue_push(&solv->problems, 0); /* mark end of this problem */
2354 /* disable last weak rule */
2355 solv->problems.count = oldproblemcount;
2356 solv->learnt_pool.count = oldlearntpoolcount;
2357 if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
2358 v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
2361 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling ");
2362 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, solv->rules + lastweak);
2363 disableproblem(solv, v);
2365 reenablepolicyrules(solv, &solv->job, -(v + 1));
2371 queue_push(&solv->learnt_pool, 0);
2372 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
2376 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
2377 disableproblem(solv, solv->problems.elements[i]);
2378 /* XXX: might want to enable all weak rules again */
2382 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
2387 /********************************************************************/
2388 /* Decision revert */
2390 /*-------------------------------------------------------------------
2393 * revert decision at level
2397 revert(Solver *solv, int level)
2399 Pool *pool = solv->pool;
2401 while (solv->decisionq.count)
2403 v = solv->decisionq.elements[solv->decisionq.count - 1];
2404 vv = v > 0 ? v : -v;
2405 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
2407 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
2408 if (v > 0 && solv->recommendations.count && v == solv->recommendations.elements[solv->recommendations.count - 1])
2409 solv->recommendations.count--;
2410 solv->decisionmap[vv] = 0;
2411 solv->decisionq.count--;
2412 solv->decisionq_why.count--;
2413 solv->propagate_index = solv->decisionq.count;
2415 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
2417 solv->branches.count--;
2418 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
2419 solv->branches.count--;
2421 solv->recommends_index = -1;
2425 /*-------------------------------------------------------------------
2427 * watch2onhighest - put watch2 on literal with highest level
2431 watch2onhighest(Solver *solv, Rule *r)
2436 d = r->d < 0 ? -r->d - 1 : r->d;
2438 return; /* binary rule, both watches are set */
2439 dp = solv->pool->whatprovidesdata + d;
2440 while ((v = *dp++) != 0)
2442 l = solv->decisionmap[v < 0 ? -v : v];
2454 /*-------------------------------------------------------------------
2458 * add free decision (solvable to install) to decisionq
2459 * increase level and propagate decision
2460 * return if no conflict.
2462 * in conflict case, analyze conflict rule, add resulting
2463 * rule to learnt rule set, make decision from learnt
2464 * rule (always unit) and re-propagate.
2466 * returns the new solver level or 0 if unsolvable
2471 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules, Id ruleid)
2473 Pool *pool = solv->pool;
2478 assert(ruleid >= 0);
2483 solv->decisionmap[decision] = level;
2485 solv->decisionmap[-decision] = -level;
2486 queue_push(&solv->decisionq, decision);
2487 queue_push(&solv->decisionq_why, -ruleid); /* <= 0 -> free decision */
2491 r = propagate(solv, level);
2495 return analyze_unsolvable(solv, r, disablerules);
2496 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
2497 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
2498 assert(l > 0 && l < level);
2499 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
2501 revert(solv, level);
2502 r = addrule(solv, p, d);
2504 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
2505 queue_push(&solv->learnt_why, why);
2508 /* at least 2 literals, needs watches */
2509 watch2onhighest(solv, r);
2510 addwatches_rule(solv, r);
2514 /* learnt rule is an assertion */
2515 queue_push(&solv->ruleassertions, r - solv->rules);
2517 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
2518 queue_push(&solv->decisionq, p);
2519 queue_push(&solv->decisionq_why, r - solv->rules);
2520 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
2522 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
2523 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
2524 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
2525 solver_printrule(solv, SAT_DEBUG_ANALYZE, r);
2532 /*-------------------------------------------------------------------
2534 * select and install
2536 * install best package from the queue. We add an extra package, inst, if
2537 * provided. See comment in weak install section.
2539 * returns the new solver level or 0 if unsolvable
2544 selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid)
2546 Pool *pool = solv->pool;
2551 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
2554 /* XXX: didn't we already do that? */
2555 /* XXX: shouldn't we prefer installed packages? */
2556 /* XXX: move to policy.c? */
2557 /* choose the supplemented one */
2558 for (i = 0; i < dq->count; i++)
2559 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
2561 dq->elements[0] = dq->elements[i];
2568 /* multiple candidates, open a branch */
2569 for (i = 1; i < dq->count; i++)
2570 queue_push(&solv->branches, dq->elements[i]);
2571 queue_push(&solv->branches, -level);
2573 p = dq->elements[0];
2575 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
2577 return setpropagatelearn(solv, level, p, disablerules, ruleid);
2581 /********************************************************************/
2582 /* Main solver interface */
2585 /*-------------------------------------------------------------------
2588 * create solver structure
2590 * pool: all available solvables
2591 * installed: installed Solvables
2594 * Upon solving, rules are created to flag the Solvables
2595 * of the 'installed' Repo as installed.
2599 solver_create(Pool *pool)
2602 solv = (Solver *)sat_calloc(1, sizeof(Solver));
2604 solv->installed = pool->installed;
2606 queue_init(&solv->transaction);
2607 queue_init(&solv->transaction_info);
2608 queue_init(&solv->ruletojob);
2609 queue_init(&solv->decisionq);
2610 queue_init(&solv->decisionq_why);
2611 queue_init(&solv->problems);
2612 queue_init(&solv->suggestions);
2613 queue_init(&solv->recommendations);
2614 queue_init(&solv->orphaned);
2615 queue_init(&solv->learnt_why);
2616 queue_init(&solv->learnt_pool);
2617 queue_init(&solv->branches);
2618 queue_init(&solv->covenantq);
2619 queue_init(&solv->weakruleq);
2620 queue_init(&solv->ruleassertions);
2622 map_init(&solv->recommendsmap, pool->nsolvables);
2623 map_init(&solv->suggestsmap, pool->nsolvables);
2624 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
2625 solv->recommends_index = 0;
2627 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2629 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
2630 memset(solv->rules, 0, sizeof(Rule));
2636 /*-------------------------------------------------------------------
2642 solver_free(Solver *solv)
2644 queue_free(&solv->transaction);
2645 queue_free(&solv->transaction_info);
2646 queue_free(&solv->job);
2647 queue_free(&solv->ruletojob);
2648 queue_free(&solv->decisionq);
2649 queue_free(&solv->decisionq_why);
2650 queue_free(&solv->learnt_why);
2651 queue_free(&solv->learnt_pool);
2652 queue_free(&solv->problems);
2653 queue_free(&solv->solutions);
2654 queue_free(&solv->suggestions);
2655 queue_free(&solv->recommendations);
2656 queue_free(&solv->orphaned);
2657 queue_free(&solv->branches);
2658 queue_free(&solv->covenantq);
2659 queue_free(&solv->weakruleq);
2660 queue_free(&solv->ruleassertions);
2662 map_free(&solv->recommendsmap);
2663 map_free(&solv->suggestsmap);
2664 map_free(&solv->noupdate);
2665 map_free(&solv->weakrulemap);
2666 map_free(&solv->noobsoletes);
2668 map_free(&solv->updatemap);
2669 map_free(&solv->dupmap);
2670 map_free(&solv->dupinvolvedmap);
2672 sat_free(solv->decisionmap);
2673 sat_free(solv->rules);
2674 sat_free(solv->watches);
2675 sat_free(solv->obsoletes);
2676 sat_free(solv->obsoletes_data);
2677 sat_free(solv->multiversionupdaters);
2682 /*-------------------------------------------------------------------
2686 * all rules have been set up, now actually run the solver
2691 run_solver(Solver *solv, int disablerules, int doweak)
2693 Queue dq; /* local decisionqueue */
2694 Queue dqs; /* local decisionqueue for supplements */
2700 Pool *pool = solv->pool;
2702 int minimizationsteps;
2704 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2706 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2707 for (i = 1; i < solv->nrules; i++)
2708 solver_printruleclass(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2711 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2713 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2714 solver_printdecisions(solv);
2716 /* start SAT algorithm */
2718 systemlevel = level + 1;
2719 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2725 * here's the main loop:
2726 * 1) propagate new decisions (only needed for level 1)
2727 * 2) try to keep installed packages
2728 * 3) fulfill all unresolved rules
2729 * 4) install recommended packages
2730 * 5) minimalize solution if we had choices
2731 * if we encounter a problem, we rewind to a safe level and restart
2735 minimizationsteps = 0;
2744 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2745 if ((r = propagate(solv, level)) != 0)
2747 if (analyze_unsolvable(solv, r, disablerules))
2755 if (level < systemlevel)
2757 POOL_DEBUG(SAT_DEBUG_STATS, "resolving job rules\n");
2758 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
2761 if (r->d < 0) /* ignore disabled rules */
2764 FOR_RULELITERALS(l, dp, r)
2768 if (solv->decisionmap[-l] <= 0)
2773 if (solv->decisionmap[l] > 0)
2775 if (solv->decisionmap[l] == 0)
2781 /* prune to installed if not updating */
2782 if (!solv->updatesystem && solv->installed && dq.count > 1)
2785 for (j = k = 0; j < dq.count; j++)
2787 Solvable *s = pool->solvables + dq.elements[j];
2788 if (s->repo == solv->installed)
2789 dq.elements[k++] = dq.elements[j];
2795 level = selectandinstall(solv, level, &dq, disablerules, i);
2802 if (level <= olevel)
2805 systemlevel = level + 1;
2806 if (i < solv->jobrules_end)
2812 * installed packages
2815 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2817 Repo *installed = solv->installed;
2820 /* we use two passes if we need to update packages
2821 * to create a better user experience */
2822 for (pass = solv->updatemap.size ? 0 : 1; pass < 2; pass++)
2824 FOR_REPO_SOLVABLES(installed, i, s)
2829 /* XXX: noupdate check is probably no longer needed, as all jobs should
2830 * already be satisfied */
2831 if (MAPTST(&solv->noupdate, i - installed->start))
2833 if (solv->decisionmap[i] > 0)
2835 if (!pass && solv->updatemap.size && !MAPTST(&solv->updatemap, i - installed->start))
2836 continue; /* updates first */
2837 r = solv->rules + solv->updaterules + (i - installed->start);
2839 if (!rr->p || rr->d < 0) /* disabled -> look at feature rule */
2840 rr -= solv->installed->end - solv->installed->start;
2841 if (!rr->p) /* identical to update rule? */
2844 continue; /* orpaned package */
2847 if (solv->decisionmap[i] < 0 || solv->updatesystem || (solv->updatemap.size && MAPTST(&solv->updatemap, i - installed->start)) || rr->p != i)
2849 if (solv->noobsoletes.size && solv->multiversionupdaters
2850 && (d = solv->multiversionupdaters[i - installed->start]) != 0)
2852 /* special multiversion handling, make sure best version is chosen */
2854 while ((p = pool->whatprovidesdata[d++]) != 0)
2855 if (solv->decisionmap[p] >= 0)
2857 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2859 if (p != i && solv->decisionmap[p] == 0)
2861 rr = solv->rules + solv->featurerules + (i - solv->installed->start);
2862 if (!rr->p) /* update rule == feature rule? */
2863 rr = rr - solv->featurerules + solv->updaterules;
2871 /* update to best package */
2872 FOR_RULELITERALS(p, dp, rr)
2874 if (solv->decisionmap[p] > 0)
2876 dq.count = 0; /* already fulfilled */
2879 if (!solv->decisionmap[p])
2884 /* install best version */
2888 level = selectandinstall(solv, level, &dq, disablerules, rr - solv->rules);
2895 if (level <= olevel)
2898 /* if still undecided keep package */
2899 if (solv->decisionmap[i] == 0)
2902 POOL_DEBUG(SAT_DEBUG_POLICY, "keeping %s\n", solvable2str(pool, pool->solvables + i));
2903 level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules);
2910 if (level <= olevel)
2914 if (i < installed->end)
2917 systemlevel = level + 1;
2919 continue; /* had trouble, retry */
2922 if (level < systemlevel)
2923 systemlevel = level;
2929 POOL_DEBUG(SAT_DEBUG_POLICY, "deciding unresolved rules\n");
2930 for (i = 1, n = 1; ; i++, n++)
2932 if (n == solv->nrules)
2934 if (i == solv->nrules)
2936 r = solv->rules + i;
2937 if (r->d < 0) /* ignore disabled rules */
2942 /* binary or unary rule */
2943 /* need two positive undecided literals */
2944 if (r->p < 0 || r->w2 <= 0)
2946 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2948 queue_push(&dq, r->p);
2949 queue_push(&dq, r->w2);
2954 * all negative literals are installed
2955 * no positive literal is installed
2956 * i.e. the rule is not fulfilled and we
2957 * just need to decide on the positive literals
2961 if (solv->decisionmap[-r->p] <= 0)
2966 if (solv->decisionmap[r->p] > 0)
2968 if (solv->decisionmap[r->p] == 0)
2969 queue_push(&dq, r->p);
2971 dp = pool->whatprovidesdata + r->d;
2972 while ((p = *dp++) != 0)
2976 if (solv->decisionmap[-p] <= 0)
2981 if (solv->decisionmap[p] > 0)
2983 if (solv->decisionmap[p] == 0)
2990 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2992 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2993 solver_printruleclass(solv, SAT_DEBUG_PROPAGATE, r);
2995 /* dq.count < 2 cannot happen as this means that
2996 * the rule is unit */
2997 assert(dq.count > 1);
3000 level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
3007 if (level < systemlevel)
3010 } /* for(), decide */
3012 if (n != solv->nrules) /* continue if level < systemlevel */
3019 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended packages\n");
3020 queue_empty(&dq); /* recommended packages */
3021 queue_empty(&dqs); /* supplemented packages */
3022 for (i = 1; i < pool->nsolvables; i++)
3024 if (solv->decisionmap[i] < 0)
3026 if (solv->decisionmap[i] > 0)
3028 /* installed, check for recommends */
3029 Id *recp, rec, pp, p;
3030 s = pool->solvables + i;
3031 if (solv->ignorealreadyrecommended && s->repo == solv->installed)
3033 /* XXX need to special case AND ? */
3036 recp = s->repo->idarraydata + s->recommends;
3037 while ((rec = *recp++) != 0)
3040 FOR_PROVIDES(p, pp, rec)
3042 if (solv->decisionmap[p] > 0)
3047 else if (solv->decisionmap[p] == 0)
3049 queue_pushunique(&dq, p);
3057 s = pool->solvables + i;
3058 if (!s->supplements)
3060 if (!pool_installable(pool, s))
3062 if (!solver_is_supplementing(solv, s))
3064 queue_push(&dqs, i);
3068 /* filter out all packages obsoleted by installed packages */
3069 /* this is no longer needed if we have reverse obsoletes */
3070 if ((dqs.count || dq.count) && solv->installed)
3073 Id obs, *obsp, po, ppo;
3075 map_init(&obsmap, pool->nsolvables);
3076 for (p = solv->installed->start; p < solv->installed->end; p++)
3078 s = pool->solvables + p;
3079 if (s->repo != solv->installed || !s->obsoletes)
3081 if (solv->decisionmap[p] <= 0)
3083 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p))
3085 obsp = s->repo->idarraydata + s->obsoletes;
3086 /* foreach obsoletes */
3087 while ((obs = *obsp++) != 0)
3088 FOR_PROVIDES(po, ppo, obs)
3089 MAPSET(&obsmap, po);
3091 for (i = j = 0; i < dqs.count; i++)
3092 if (!MAPTST(&obsmap, dqs.elements[i]))
3093 dqs.elements[j++] = dqs.elements[i];
3095 for (i = j = 0; i < dq.count; i++)
3096 if (!MAPTST(&obsmap, dq.elements[i]))
3097 dq.elements[j++] = dq.elements[i];
3102 /* filter out all already supplemented packages if requested */
3103 if (solv->ignorealreadyrecommended && dqs.count)
3105 /* turn off all new packages */
3106 for (i = 0; i < solv->decisionq.count; i++)
3108 p = solv->decisionq.elements[i];
3111 s = pool->solvables + p;
3112 if (s->repo && s->repo != solv->installed)
3113 solv->decisionmap[p] = -solv->decisionmap[p];
3115 /* filter out old supplements */
3116 for (i = j = 0; i < dqs.count; i++)
3118 p = dqs.elements[i];
3119 s = pool->solvables + p;
3120 if (!s->supplements)
3122 if (!solver_is_supplementing(solv, s))
3123 dqs.elements[j++] = p;
3126 /* undo turning off */
3127 for (i = 0; i < solv->decisionq.count; i++)
3129 p = solv->decisionq.elements[i];
3132 s = pool->solvables + p;
3133 if (s->repo && s->repo != solv->installed)
3134 solv->decisionmap[p] = -solv->decisionmap[p];
3138 /* make dq contain both recommended and supplemented pkgs */
3141 for (i = 0; i < dqs.count; i++)
3142 queue_pushunique(&dq, dqs.elements[i]);
3149 int decisioncount = solv->decisionq.count;
3153 /* simple case, just one package. no need to choose */
3156 POOL_DEBUG(SAT_DEBUG_POLICY, "installing supplemented %s\n", solvable2str(pool, pool->solvables + p));
3158 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
3159 queue_push(&solv->recommendations, p);
3160 level = setpropagatelearn(solv, level, p, 0, 0);
3164 /* filter and create a map of result */
3165 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
3166 map_init(&dqmap, pool->nsolvables);
3167 for (i = 0; i < dq.count; i++)
3168 MAPSET(&dqmap, dq.elements[i]);
3170 /* install all supplemented packages */
3171 for (i = 0; i < dqs.count; i++)
3173 p = dqs.elements[i];
3174 if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
3176 POOL_DEBUG(SAT_DEBUG_POLICY, "installing supplemented %s\n", solvable2str(pool, pool->solvables + p));
3177 queue_push(&solv->recommendations, p);
3179 level = setpropagatelearn(solv, level, p, 0, 0);
3180 if (level <= olevel)
3183 if (i < dqs.count || solv->decisionq.count < decisioncount)
3189 /* install all recommended packages */
3190 /* more work as we want to created branches if multiple
3191 * choices are valid */
3192 for (i = 0; i < decisioncount; i++)
3195 p = solv->decisionq.elements[i];
3198 s = pool->solvables + p;
3199 if (!s->repo || (solv->ignorealreadyrecommended && s->repo == solv->installed))
3203 recp = s->repo->idarraydata + s->recommends;
3204 while ((rec = *recp++) != 0)
3207 FOR_PROVIDES(p, pp, rec)
3209 if (solv->decisionmap[p] > 0)
3214 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
3215 queue_pushunique(&dq, p);
3221 /* multiple candidates, open a branch */
3222 for (i = 1; i < dq.count; i++)
3223 queue_push(&solv->branches, dq.elements[i]);
3224 queue_push(&solv->branches, -level);
3227 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
3228 queue_push(&solv->recommendations, p);
3230 level = setpropagatelearn(solv, level, p, 0, 0);
3231 if (level <= olevel || solv->decisionq.count < decisioncount)
3235 break; /* had a problem above, quit loop */
3244 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
3246 /* prefer recommended patterns (bnc#450226) */
3247 /* real fix is to minimize recommended packages as well */
3248 for (i = 0; i < dq.count; i++)
3249 if (!strncmp(id2str(pool, pool->solvables[dq.elements[i]].name), "pattern:", 8))
3254 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
3255 queue_push(&solv->recommendations, p);
3256 level = setpropagatelearn(solv, level, p, 0, 0);
3262 if (solv->distupgrade && solv->installed)
3264 int installedone = 0;
3266 /* let's see if we can install some unsupported package */
3267 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unsupported packages\n");
3268 for (i = 0; i < solv->orphaned.count; i++)
3270 p = solv->orphaned.elements[i];
3271 if (solv->decisionmap[p])
3272 continue; /* already decided */
3274 if (solv->distupgrade_removeunsupported)
3276 POOL_DEBUG(SAT_DEBUG_STATS, "removing unsupported %s\n", solvable2str(pool, pool->solvables + p));
3277 level = setpropagatelearn(solv, level, -p, 0, 0);
3281 POOL_DEBUG(SAT_DEBUG_STATS, "keeping unsupported %s\n", solvable2str(pool, pool->solvables + p));
3282 level = setpropagatelearn(solv, level, p, 0, 0);
3288 if (installedone || i < solv->orphaned.count)
3292 if (solv->solution_callback)
3294 solv->solution_callback(solv, solv->solution_callback_data);
3295 if (solv->branches.count)
3297 int i = solv->branches.count - 1;
3298 int l = -solv->branches.elements[i];
3302 if (solv->branches.elements[i - 1] < 0)
3304 p = solv->branches.elements[i];
3305 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
3307 for (j = i + 1; j < solv->branches.count; j++)
3308 queue_push(&dq, solv->branches.elements[j]);
3309 solv->branches.count = i;
3311 revert(solv, level);
3313 for (j = 0; j < dq.count; j++)
3314 queue_push(&solv->branches, dq.elements[j]);
3316 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
3318 level = setpropagatelearn(solv, level, p, disablerules, why);
3327 /* all branches done, we're finally finished */
3331 /* minimization step */
3332 if (solv->branches.count)
3334 int l = 0, lasti = -1, lastl = -1;
3338 for (i = solv->branches.count - 1; i >= 0; i--)
3340 p = solv->branches.elements[i];
3343 else if (p > 0 && solv->decisionmap[p] > l + 1)
3351 /* kill old solvable so that we do not loop */
3352 p = solv->branches.elements[lasti];
3353 solv->branches.elements[lasti] = 0;
3354 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], lastl, solvable2str(pool, pool->solvables + p));
3355 minimizationsteps++;
3358 revert(solv, level);
3359 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
3362 level = setpropagatelearn(solv, level, p, disablerules, why);
3374 POOL_DEBUG(SAT_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
3376 POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
3382 /*-------------------------------------------------------------------
3386 * at this point, all rules that led to conflicts are disabled.
3387 * we re-enable all rules of a problem set but rule "sug", then
3388 * continue to disable more rules until there as again a solution.
3391 /* FIXME: think about conflicting assertions */
3394 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined, int essentialok)
3396 Pool *pool = solv->pool;
3402 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
3404 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
3405 for (i = 0; problem[i]; i++)
3407 if (problem[i] == sug)
3408 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
3409 solver_printproblem(solv, problem[i]);
3412 queue_empty(refined);
3413 if (!essentialok && sug < 0 && (job->elements[-sug - 1] & SOLVER_ESSENTIAL) != 0)
3415 queue_init(&disabled);
3416 queue_push(refined, sug);
3418 /* re-enable all problem rules with the exception of "sug"(gestion) */
3422 for (i = 0; problem[i]; i++)
3423 if (problem[i] != sug)
3424 enableproblem(solv, problem[i]);
3427 reenablepolicyrules(solv, job, -(sug + 1));
3428 else if (sug >= solv->updaterules && sug < solv->updaterules_end)
3430 /* enable feature rule */
3431 Rule *r = solv->rules + solv->featurerules + (sug - solv->updaterules);
3433 enablerule(solv, r);
3436 enableweakrules(solv);
3440 int njob, nfeature, nupdate;
3441 queue_empty(&solv->problems);
3442 revert(solv, 1); /* XXX no longer needed? */
3445 if (!solv->problems.count)
3446 run_solver(solv, 0, 0);
3448 if (!solv->problems.count)
3450 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
3451 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3452 solver_printdecisions(solv);
3453 break; /* great, no more problems */
3455 disabledcnt = disabled.count;
3456 /* start with 1 to skip over proof index */
3457 njob = nfeature = nupdate = 0;
3458 for (i = 1; i < solv->problems.count - 1; i++)
3460 /* ignore solutions in refined */
3461 v = solv->problems.elements[i];
3463 break; /* end of problem reached */
3464 for (j = 0; problem[j]; j++)
3465 if (problem[j] != sug && problem[j] == v)
3469 if (v >= solv->featurerules && v < solv->featurerules_end)
3475 if (!essentialok && (job->elements[-v -1] & SOLVER_ESSENTIAL) != 0)
3476 continue; /* not that one! */
3479 queue_push(&disabled, v);
3481 if (disabled.count == disabledcnt)
3483 /* no solution found, this was an invalid suggestion! */
3484 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
3488 if (!njob && nupdate && nfeature)
3490 /* got only update rules, filter out feature rules */
3491 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "throwing away feature rules\n");
3492 for (i = j = disabledcnt; i < disabled.count; i++)
3494 v = disabled.elements[i];
3495 if (v < solv->featurerules || v >= solv->featurerules_end)
3496 disabled.elements[j++] = v;
3501 if (disabled.count == disabledcnt + 1)
3503 /* just one suggestion, add it to refined list */
3504 v = disabled.elements[disabledcnt];
3506 queue_push(refined, v); /* do not record feature rules */
3507 disableproblem(solv, v);
3508 if (v >= solv->updaterules && v < solv->updaterules_end)
3510 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
3512 enablerule(solv, r); /* enable corresponding feature rule */
3515 reenablepolicyrules(solv, job, -(v + 1));
3519 /* more than one solution, disable all */
3520 /* do not push anything on refine list, as we do not know which solution to choose */
3521 /* thus, the user will get another problem if he selects this solution, where he
3522 * can choose the right one */
3523 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
3525 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
3526 for (i = disabledcnt; i < disabled.count; i++)
3527 solver_printproblem(solv, disabled.elements[i]);
3529 for (i = disabledcnt; i < disabled.count; i++)
3531 v = disabled.elements[i];
3532 disableproblem(solv, v);
3533 if (v >= solv->updaterules && v < solv->updaterules_end)
3535 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
3537 enablerule(solv, r);
3542 /* all done, get us back into the same state as before */
3543 /* enable refined rules again */
3544 for (i = 0; i < disabled.count; i++)
3545 enableproblem(solv, disabled.elements[i]);
3546 queue_free(&disabled);
3547 /* reset policy rules */
3548 for (i = 0; problem[i]; i++)
3549 enableproblem(solv, problem[i]);
3550 disablepolicyrules(solv, job);
3551 /* disable problem rules again */
3552 for (i = 0; problem[i]; i++)
3553 disableproblem(solv, problem[i]);
3554 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
3558 /*-------------------------------------------------------------------
3559 * sorting helper for problems
3561 * bring update rules before job rules
3562 * make essential job rules last
3565 Queue *problems_sort_data;
3568 problems_sortcmp(const void *ap, const void *bp)
3570 Id a = *(Id *)ap, b = *(Id *)bp;
3577 Queue *job = problems_sort_data;
3578 int af = job->elements[-a - 1] & SOLVER_ESSENTIAL;
3579 int bf = job->elements[-b - 1] & SOLVER_ESSENTIAL;
3588 * convert a solution rule into a job modifier
3591 convertsolution(Solver *solv, Id why, Queue *solutionq)
3593 Pool *pool = solv->pool;
3596 queue_push(solutionq, 0);
3597 queue_push(solutionq, -why);
3600 if (why >= solv->infarchrules && why < solv->infarchrules_end)
3603 /* infarch rule, find replacement */
3604 assert(solv->rules[why].p < 0);
3605 name = pool->solvables[-solv->rules[why].p].name;
3606 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
3609 for (; why < solv->infarchrules_end && pool->solvables[-solv->rules[why].p].name == name; why++)
3610 if (solv->decisionmap[-solv->rules[why].p] > 0)
3612 p = -solv->rules[why].p;
3616 p = -solv->rules[why].p; /* XXX: what to do here? */
3617 queue_push(solutionq, SOLVER_SOLUTION_INFARCH);
3618 queue_push(solutionq, p);
3621 if (why >= solv->duprules && why < solv->duprules_end)
3624 /* dist upgrade rule, find replacement */
3625 assert(solv->rules[why].p < 0);
3626 name = pool->solvables[-solv->rules[why].p].name;
3627 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
3630 for (; why < solv->duprules_end && pool->solvables[-solv->rules[why].p].name == name; why++)
3631 if (solv->decisionmap[-solv->rules[why].p] > 0)
3633 p = -solv->rules[why].p;
3637 p = -solv->rules[why].p; /* XXX: what to do here? */
3638 queue_push(solutionq, SOLVER_SOLUTION_DISTUPGRADE);
3639 queue_push(solutionq, p);
3642 if (why >= solv->updaterules && why < solv->updaterules_end)
3644 /* update rule, find replacement package */
3648 assert(why >= solv->updaterules && why < solv->updaterules_end);
3649 /* check if this is a false positive, i.e. the update rule is fulfilled */
3650 rr = solv->rules + why;
3651 FOR_RULELITERALS(p, dp, rr)
3652 if (p > 0 && solv->decisionmap[p] > 0)
3655 return; /* false alarm */
3657 p = solv->installed->start + (why - solv->updaterules);
3658 rr = solv->rules + solv->featurerules + (why - solv->updaterules);
3660 rr = solv->rules + why;
3661 if (solv->distupgrade && solv->rules[why].p != p && solv->decisionmap[p] > 0)
3663 /* distupgrade case, allow to keep old package */
3664 queue_push(solutionq, p);
3665 queue_push(solutionq, p);
3668 if (solv->decisionmap[p] > 0)
3669 return; /* false alarm, turned out we can keep the package */
3672 int mvrp = 0; /* multi-version replacement */
3673 FOR_RULELITERALS(rp, dp, rr)
3675 if (rp > 0 && solv->decisionmap[rp] > 0 && pool->solvables[rp].repo != solv->installed)
3678 if (!(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, rp)))
3684 /* found only multi-version replacements */
3685 /* have to split solution into two parts */
3686 queue_push(solutionq, p);
3687 queue_push(solutionq, mvrp);
3690 queue_push(solutionq, p);
3691 queue_push(solutionq, rp);
3697 * refine the simple solution rule list provided by
3698 * the solver into multiple lists of job modifiers.
3701 create_solutions(Solver *solv, int probnr, int solidx)
3703 Pool *pool = solv->pool;
3705 Queue problem, solution, problems_save;
3711 now = sat_timems(0);
3712 recocount = solv->recommendations.count;
3713 solv->recommendations.count = 0; /* so that revert() doesn't mess with it */
3715 /* save decisionq, decisionq_why, decisionmap */
3716 for (i = 0; i < solv->decisionq.count; i++)
3718 Id p = solv->decisionq.elements[i];
3719 queue_push(&redoq, p);
3720 queue_push(&redoq, solv->decisionq_why.elements[i]);
3721 queue_push(&redoq, solv->decisionmap[p > 0 ? p : -p]);
3723 /* save problems queue */
3724 problems_save = solv->problems;
3725 memset(&solv->problems, 0, sizeof(solv->problems));
3727 /* extract problem from queue */
3728 queue_init(&problem);
3729 for (i = solidx + 1; i < solv->solutions.count; i++)
3731 Id v = solv->solutions.elements[i];
3734 queue_push(&problem, v);
3736 problems_sort_data = &solv->job;
3737 if (problem.count > 1)
3738 qsort(problem.elements, problem.count, sizeof(Id), problems_sortcmp);
3739 queue_push(&problem, 0); /* mark end for refine_suggestion */
3742 for (i = 0; i < problem.count; i++)
3743 printf("PP %d %d\n", i, problem.elements[i]);
3746 /* refine each solution element */
3749 queue_init(&solution);
3750 for (i = 0; i < problem.count; i++)
3752 int solstart = solv->solutions.count;
3753 refine_suggestion(solv, &solv->job, problem.elements, problem.elements[i], &solution, essentialok);
3754 queue_push(&solv->solutions, 0); /* reserve room for number of elements */
3755 for (j = 0; j < solution.count; j++)
3756 convertsolution(solv, solution.elements[j], &solv->solutions);
3757 if (solv->solutions.count == solstart + 1)
3759 solv->solutions.count--;
3760 if (!essentialok && i + 1 == problem.count)
3762 /* nothing found, start over */
3768 /* patch in number of solution elements */
3769 solv->solutions.elements[solstart] = (solv->solutions.count - (solstart + 1)) / 2;
3770 queue_push(&solv->solutions, 0); /* add end marker */
3771 queue_push(&solv->solutions, 0); /* add end marker */
3772 solv->solutions.elements[solidx + 1 + nsol++] = solstart;
3774 solv->solutions.elements[solidx + 1 + nsol] = 0; /* end marker */
3775 solv->solutions.elements[solidx] = nsol;
3776 queue_free(&problem);
3777 queue_free(&solution);
3779 /* restore decisions */
3780 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
3781 queue_empty(&solv->decisionq);
3782 queue_empty(&solv->decisionq_why);
3783 for (i = 0; i < redoq.count; i += 3)
3785 Id p = redoq.elements[i];
3786 queue_push(&solv->decisionq, p);
3787 queue_push(&solv->decisionq_why, redoq.elements[i + 1]);
3788 solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
3790 solv->recommendations.count = recocount;
3792 /* restore problems */
3793 queue_free(&solv->problems);
3794 solv->problems = problems_save;
3795 POOL_DEBUG(SAT_DEBUG_STATS, "create_solutions for problem #%d took %d ms\n", probnr, sat_timems(now));
3799 /**************************************************************************/
3802 solver_problem_count(Solver *solv)
3804 return solv->problems.count / 2;
3808 solver_next_problem(Solver *solv, Id problem)
3811 return solv->problems.count ? 1 : 0;
3812 return (problem + 1) * 2 - 1 < solv->problems.count ? problem + 1 : 0;
3816 solver_solution_count(Solver *solv, Id problem)
3818 Id solidx = solv->problems.elements[problem * 2 - 1];
3819 if (solv->solutions.elements[solidx] < 0)
3820 create_solutions(solv, problem, solidx);
3821 return solv->solutions.elements[solidx];
3825 solver_next_solution(Solver *solv, Id problem, Id solution)
3827 Id solidx = solv->problems.elements[problem * 2 - 1];
3828 if (solv->solutions.elements[solidx] < 0)
3829 create_solutions(solv, problem, solidx);
3830 return solv->solutions.elements[solidx + solution + 1] ? solution + 1 : 0;
3834 solver_solutionelement_count(Solver *solv, Id problem, Id solution)
3836 Id solidx = solv->problems.elements[problem * 2 - 1];
3837 solidx = solv->solutions.elements[solidx + solution];
3838 return solv->solutions.elements[solidx];
3842 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
3844 Id solidx = solv->problems.elements[problem * 2 - 1];
3845 solidx = solv->solutions.elements[solidx + solution];
3848 solidx += 1 + element * 2;
3849 if (!solv->solutions.elements[solidx] && !solv->solutions.elements[solidx + 1])
3851 *p = solv->solutions.elements[solidx];
3852 *rp = solv->solutions.elements[solidx + 1];
3856 /*-------------------------------------------------------------------
3862 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3865 Id lreqr, lconr, lsysr, ljobr;
3869 lreqr = lconr = lsysr = ljobr = 0;
3870 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3873 if (rid >= solv->learntrules)
3874 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3875 else if ((rid >= solv->jobrules && rid < solv->jobrules_end) || (rid >= solv->infarchrules && rid < solv->infarchrules_end) || (rid >= solv->duprules && rid < solv->duprules_end))
3880 else if (rid >= solv->updaterules && rid < solv->updaterules_end)
3887 assert(rid < solv->rpmrules_end);
3888 r = solv->rules + rid;
3889 d = r->d < 0 ? -r->d - 1 : r->d;
3890 if (!d && r->w2 < 0)
3897 if (!d && r->w2 == 0 && !reqassert)
3899 if (*reqrp > 0 && r->p < -1)
3901 Id op = -solv->rules[*reqrp].p;
3902 if (op > 1 && solv->pool->solvables[op].arch != solv->pool->solvables[-r->p].arch)
3903 continue; /* different arch, skip */
3905 /* prefer assertions */
3911 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed && !reqassert)
3913 /* prefer rules of installed packages */
3919 if (!*reqrp && lreqr)
3921 if (!*conrp && lconr)
3923 if (!*jobrp && ljobr)
3925 if (!*sysrp && lsysr)
3930 /*-------------------------------------------------------------------
3934 * search for a rule that describes the problem to the
3935 * user. A pretty hopeless task, actually. We currently
3936 * prefer simple requires.
3940 solver_findproblemrule(Solver *solv, Id problem)
3942 Id reqr, conr, sysr, jobr;
3943 Id idx = solv->problems.elements[2 * problem - 2];
3944 reqr = conr = sysr = jobr = 0;
3945 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3958 findallproblemrules_internal(Solver *solv, Id idx, Queue *rules)
3961 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3963 if (rid >= solv->learntrules)
3965 findallproblemrules_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], rules);
3968 queue_pushunique(rules, rid);
3973 solver_findallproblemrules(Solver *solv, Id problem, Queue *rules)
3976 findallproblemrules_internal(solv, solv->problems.elements[2 * problem - 2], rules);
3980 /*-------------------------------------------------------------------
3982 * create reverse obsoletes map for installed solvables
3984 * for each installed solvable find which packages with *different* names
3985 * obsolete the solvable.
3986 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3990 create_obsolete_index(Solver *solv)
3992 Pool *pool = solv->pool;
3994 Repo *installed = solv->installed;
3995 Id p, pp, obs, *obsp, *obsoletes, *obsoletes_data;
3998 if (!installed || !installed->nsolvables)
4000 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
4001 for (i = 1; i < pool->nsolvables; i++)
4003 s = pool->solvables + i;
4006 if (!pool_installable(pool, s))
4008 obsp = s->repo->idarraydata + s->obsoletes;
4009 while ((obs = *obsp++) != 0)
4011 FOR_PROVIDES(p, pp, obs)
4013 if (pool->solvables[p].repo != installed)
4015 if (pool->solvables[p].name == s->name)
4017 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
4019 obsoletes[p - installed->start]++;
4024 for (i = 0; i < installed->nsolvables; i++)
4027 n += obsoletes[i] + 1;
4030 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
4031 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
4032 for (i = pool->nsolvables - 1; i > 0; i--)
4034 s = pool->solvables + i;
4037 if (!pool_installable(pool, s))
4039 obsp = s->repo->idarraydata + s->obsoletes;
4040 while ((obs = *obsp++) != 0)
4042 FOR_PROVIDES(p, pp, obs)
4044 if (pool->solvables[p].repo != installed)
4046 if (pool->solvables[p].name == s->name)
4048 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
4050 p -= installed->start;
4051 if (obsoletes_data[obsoletes[p]] != i)
4052 obsoletes_data[--obsoletes[p]] = i;
4059 /*-------------------------------------------------------------------
4061 * remove disabled conflicts
4063 * purpose: update the decisionmap after some rules were disabled.
4064 * this is used to calculate the suggested/recommended package list.
4065 * Also returns a "removed" list to undo the discisionmap changes.
4069 removedisabledconflicts(Solver *solv, Queue *removed)
4071 Pool *pool = solv->pool;
4076 Id *decisionmap = solv->decisionmap;
4078 POOL_DEBUG(SAT_DEBUG_SCHUBI, "removedisabledconflicts\n");
4079 queue_empty(removed);
4080 for (i = 0; i < solv->decisionq.count; i++)
4082 p = solv->decisionq.elements[i];
4085 /* a conflict. we never do conflicts on free decisions, so there
4086 * must have been an unit rule */
4087 why = solv->decisionq_why.elements[i];
4089 r = solv->rules + why;
4090 if (r->d < 0 && decisionmap[-p])
4092 /* rule is now disabled, remove from decisionmap */
4093 POOL_DEBUG(SAT_DEBUG_SCHUBI, "removing conflict for package %s[%d]\n", solvable2str(pool, pool->solvables - p), -p);
4094 queue_push(removed, -p);
4095 queue_push(removed, decisionmap[-p]);
4096 decisionmap[-p] = 0;
4099 if (!removed->count)
4101 /* we removed some confliced packages. some of them might still
4102 * be in conflict, so search for unit rules and re-conflict */
4104 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
4106 if (i == solv->nrules)
4109 r = solv->rules + i;
4115 if (r->p < 0 && !decisionmap[-r->p])
4121 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
4123 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
4128 if (r->p < 0 && decisionmap[-r->p] == 0)
4130 if (new || DECISIONMAP_FALSE(r->p))
4132 dp = pool->whatprovidesdata + r->d;
4133 while ((p = *dp++) != 0)
4135 if (new && p == new)
4137 if (p < 0 && decisionmap[-p] == 0)
4146 else if (!DECISIONMAP_FALSE(p))
4156 POOL_DEBUG(SAT_DEBUG_SCHUBI, "re-conflicting package %s[%d]\n", solvable2str(pool, pool->solvables - new), -new);
4157 decisionmap[-new] = -1;
4159 n = 0; /* redo all rules */
4165 undo_removedisabledconflicts(Solver *solv, Queue *removed)
4168 for (i = 0; i < removed->count; i += 2)
4169 solv->decisionmap[removed->elements[i]] = removed->elements[i + 1];
4173 /*-------------------------------------------------------------------
4175 * weaken solvable dependencies
4179 weaken_solvable_deps(Solver *solv, Id p)
4184 for (i = 1, r = solv->rules + i; i < solv->rpmrules_end; i++, r++)
4188 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
4189 continue; /* conflict */
4190 queue_push(&solv->weakruleq, i);
4194 /********************************************************************/
4199 addinfarchrules(Solver *solv, Map *addedmap)
4201 Pool *pool = solv->pool;
4203 Id p, pp, a, aa, bestarch;
4204 Solvable *s, *ps, *bests;
4205 Queue badq, allowedarchs;
4208 queue_init(&allowedarchs);
4209 solv->infarchrules = solv->nrules;
4210 for (i = 1; i < pool->nsolvables; i++)
4212 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
4214 s = pool->solvables + i;
4218 queue_empty(&allowedarchs);
4219 FOR_PROVIDES(p, pp, s->name)
4221 ps = pool->solvables + p;
4222 if (ps->name != s->name || !MAPTST(addedmap, p))
4229 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
4230 if (a != 1 && pool->installed && ps->repo == pool->installed)
4232 if (!solv->distupgrade)
4233 queue_pushunique(&allowedarchs, ps->arch); /* also ok to keep this architecture */
4234 continue; /* ignore installed solvables when calculating the best arch */
4236 if (a && a != 1 && (!bestarch || a < bestarch))
4244 /* speed up common case where installed package already has best arch */
4245 if (allowedarchs.count == 1 && bests && allowedarchs.elements[0] == bests->arch)
4246 allowedarchs.count--; /* installed arch is best */
4248 FOR_PROVIDES(p, pp, s->name)
4250 ps = pool->solvables + p;
4251 if (ps->name != s->name || !MAPTST(addedmap, p))
4254 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
4255 if (a != 1 && bestarch && ((a ^ bestarch) & 0xffff0000) != 0)
4257 for (j = 0; j < allowedarchs.count; j++)
4259 aa = allowedarchs.elements[j];
4262 aa = (aa <= pool->lastarch) ? pool->id2arch[aa] : 0;
4263 if (aa && ((a ^ aa) & 0xffff0000) == 0)
4264 break; /* compatible */
4266 if (j == allowedarchs.count)
4267 queue_push(&badq, p);
4272 /* block all solvables in the badq! */
4273 for (j = 0; j < badq.count; j++)
4275 p = badq.elements[j];
4276 addrule(solv, -p, 0);
4280 queue_free(&allowedarchs);
4281 solv->infarchrules_end = solv->nrules;
4285 createdupmaps(Solver *solv, Queue *job)
4287 Pool *pool = solv->pool;
4289 Id how, what, p, pi, pp, obs, *obsp;
4293 map_init(&solv->dupmap, pool->nsolvables);
4294 map_init(&solv->dupinvolvedmap, pool->nsolvables);
4295 for (i = 0; i < job->count; i += 2)
4297 how = job->elements[i];
4298 what = job->elements[i + 1];
4299 switch (how & SOLVER_JOBMASK)
4301 case SOLVER_DISTUPGRADE:
4302 if (what < 0 || what > pool->nrepos)
4304 repo = pool->repos[what];
4305 FOR_REPO_SOLVABLES(repo, p, s)
4307 MAPSET(&solv->dupmap, p);
4308 FOR_PROVIDES(pi, pp, s->name)
4310 ps = pool->solvables + pi;
4311 if (ps->name != s->name)
4313 MAPSET(&solv->dupinvolvedmap, pi);
4317 /* FIXME: check obsoletes/provides combination */
4318 obsp = s->repo->idarraydata + s->obsoletes;
4319 while ((obs = *obsp++) != 0)
4321 FOR_PROVIDES(pi, pp, obs)
4323 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + pi, obs))
4325 MAPSET(&solv->dupinvolvedmap, pi);
4335 MAPCLR(&solv->dupinvolvedmap, SYSTEMSOLVABLE);
4339 freedupmaps(Solver *solv)
4341 map_free(&solv->dupmap);
4342 map_free(&solv->dupinvolvedmap);
4346 addduprules(Solver *solv, Map *addedmap)
4348 Pool *pool = solv->pool;
4353 solv->duprules = solv->nrules;
4354 for (i = 1; i < pool->nsolvables; i++)
4356 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
4358 s = pool->solvables + i;
4360 FOR_PROVIDES(p, pp, s->name)
4362 ps = pool->solvables + p;
4363 if (ps->name != s->name || !MAPTST(addedmap, p))
4369 if (!MAPTST(&solv->dupinvolvedmap, p))
4371 if (solv->installed && ps->repo == solv->installed)
4373 if (!solv->updatemap.size)
4374 map_init(&solv->updatemap, pool->nsolvables);
4375 MAPSET(&solv->updatemap, p);
4376 if (!MAPTST(&solv->dupmap, p))
4379 /* is installed identical to a good one? */
4380 FOR_PROVIDES(ip, ipp, s->name)
4382 Solvable *is = pool->solvables + ip;
4383 if (!MAPTST(&solv->dupmap, ip))
4385 if (is->evr == s->evr && solvable_identical(s, is))
4389 addrule(solv, -p, 0); /* no match, sorry */
4392 else if (!MAPTST(&solv->dupmap, p))
4393 addrule(solv, -p, 0);
4396 solv->duprules_end = solv->nrules;
4401 findrecommendedsuggested(Solver *solv)
4403 Pool *pool = solv->pool;
4404 Queue redoq, disabledq;
4410 map_init(&obsmap, pool->nsolvables);
4411 if (solv->installed)
4413 Id obs, *obsp, p, po, ppo;
4414 for (p = solv->installed->start; p < solv->installed->end; p++)
4416 s = pool->solvables + p;
4417 if (s->repo != solv->installed || !s->obsoletes)
4419 if (solv->decisionmap[p] <= 0)
4421 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p))
4423 obsp = s->repo->idarraydata + s->obsoletes;
4424 /* foreach obsoletes */
4425 while ((obs = *obsp++) != 0)
4426 FOR_PROVIDES(po, ppo, obs)
4427 MAPSET(&obsmap, po);
4432 queue_init(&disabledq);
4434 /* disable all erase jobs (including weak "keep uninstalled" rules) */
4435 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
4437 if (r->d < 0) /* disabled ? */
4439 if (r->p >= 0) /* install job? */
4441 queue_push(&disabledq, i);
4442 disablerule(solv, r);
4448 enabledisablelearntrules(solv);
4449 removedisabledconflicts(solv, &redoq);
4453 * find recommended packages
4456 /* if redoq.count == 0 we already found all recommended in the
4458 if (redoq.count || solv->dontinstallrecommended || !solv->dontshowinstalledrecommended || solv->ignorealreadyrecommended)
4460 Id rec, *recp, p, pp;
4462 /* create map of all recommened packages */
4463 solv->recommends_index = -1;
4464 MAPZERO(&solv->recommendsmap);
4465 for (i = 0; i < solv->decisionq.count; i++)
4467 p = solv->decisionq.elements[i];
4470 s = pool->solvables + p;
4473 recp = s->repo->idarraydata + s->recommends;
4474 while ((rec = *recp++) != 0)
4476 FOR_PROVIDES(p, pp, rec)
4477 if (solv->decisionmap[p] > 0)
4481 if (!solv->dontshowinstalledrecommended)
4483 FOR_PROVIDES(p, pp, rec)
4484 if (solv->decisionmap[p] > 0)
4485 MAPSET(&solv->recommendsmap, p);
4487 continue; /* p != 0: already fulfilled */
4489 FOR_PROVIDES(p, pp, rec)
4490 MAPSET(&solv->recommendsmap, p);
4494 for (i = 1; i < pool->nsolvables; i++)
4496 if (solv->decisionmap[i] < 0)
4498 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
4500 if (MAPTST(&obsmap, i))
4502 s = pool->solvables + i;
4503 if (!MAPTST(&solv->recommendsmap, i))
4505 if (!s->supplements)
4507 if (!pool_installable(pool, s))
4509 if (!solver_is_supplementing(solv, s))
4512 if (solv->dontinstallrecommended)
4513 queue_push(&solv->recommendations, i);
4515 queue_pushunique(&solv->recommendations, i);
4517 /* we use MODE_SUGGEST here so that repo prio is ignored */
4518 policy_filter_unwanted(solv, &solv->recommendations, POLICY_MODE_SUGGEST);
4522 * find suggested packages
4527 Id sug, *sugp, p, pp;
4529 /* create map of all suggests that are still open */
4530 solv->recommends_index = -1;
4531 MAPZERO(&solv->suggestsmap);
4532 for (i = 0; i < solv->decisionq.count; i++)
4534 p = solv->decisionq.elements[i];
4537 s = pool->solvables + p;
4540 sugp = s->repo->idarraydata + s->suggests;
4541 while ((sug = *sugp++) != 0)
4543 FOR_PROVIDES(p, pp, sug)
4544 if (solv->decisionmap[p] > 0)
4548 if (!solv->dontshowinstalledrecommended)
4550 FOR_PROVIDES(p, pp, sug)
4551 if (solv->decisionmap[p] > 0)
4552 MAPSET(&solv->suggestsmap, p);
4554 continue; /* already fulfilled */
4556 FOR_PROVIDES(p, pp, sug)
4557 MAPSET(&solv->suggestsmap, p);
4561 for (i = 1; i < pool->nsolvables; i++)
4563 if (solv->decisionmap[i] < 0)
4565 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
4567 if (MAPTST(&obsmap, i))
4569 s = pool->solvables + i;
4570 if (!MAPTST(&solv->suggestsmap, i))
4574 if (!pool_installable(pool, s))
4576 if (!solver_is_enhancing(solv, s))
4579 queue_push(&solv->suggestions, i);
4581 policy_filter_unwanted(solv, &solv->suggestions, POLICY_MODE_SUGGEST);
4584 /* undo removedisabledconflicts */
4586 undo_removedisabledconflicts(solv, &redoq);
4589 /* undo job rule disabling */
4590 for (i = 0; i < disabledq.count; i++)
4591 enablerule(solv, solv->rules + disabledq.elements[i]);
4592 queue_free(&disabledq);
4597 Solver *obsq_sortcmp_data;
4600 obsq_sortcmp(const void *ap, const void *bp)
4603 Solver *solv = obsq_sortcmp_data;
4604 Pool *pool = solv->pool;
4605 Solvable *s, *oas, *obs;
4616 s = pool->solvables + a;
4617 oas = pool->solvables + oa;
4618 obs = pool->solvables + ob;
4619 if (oas->name != obs->name)
4621 if (oas->name == s->name)
4623 if (obs->name == s->name)
4625 return strcmp(id2str(pool, oas->name), id2str(pool, obs->name));
4627 r = evrcmp(pool, oas->evr, obs->evr, EVRCMP_COMPARE);
4629 return -r; /* highest version first */
4634 solver_transaction_info(Solver *solv, Id p, Queue *out)
4636 Pool *pool = solv->pool;
4637 Solvable *s = pool->solvables + p;
4638 Queue *ti = &solv->transaction_info;
4642 if (p <= 0 || !s->repo)
4644 if (s->repo == solv->installed)
4646 /* find which packages obsolete us */
4647 for (i = 0; i < ti->count; i += 2)
4648 if (ti->elements[i + 1] == p)
4651 queue_push(out, ti->elements[i]);
4655 /* sort obsoleters */
4656 obsq_sortcmp_data = solv;
4657 qsort(out->elements, out->count / 2, 2 * sizeof(Id), obsq_sortcmp);
4659 for (i = 0; i < out->count; i += 2)
4660 out->elements[i] = out->elements[i / 2 + 1];
4665 /* find the packages we obsolete */
4666 for (i = 0; i < ti->count; i += 2)
4668 if (ti->elements[i] == p)
4669 queue_push(out, ti->elements[i + 1]);
4670 else if (out->count)
4677 solver_transaction_pkg(Solver *solv, Id p)
4682 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
4683 solver_transaction_info(solv, p, &ti);
4684 p = ti.count ? ti.elements[0] : 0;
4690 create_transaction(Solver *solv)
4692 Pool *pool = solv->pool;
4693 Repo *installed = solv->installed;
4694 Queue *ti = &solv->transaction_info;
4699 queue_empty(&solv->transaction);
4702 /* first create obsoletes index */
4705 for (i = 0; i < solv->decisionq.count; i++)
4707 p = solv->decisionq.elements[i];
4708 if (p <= 0 || p == SYSTEMSOLVABLE)
4710 s = pool->solvables + p;
4711 if (s->repo == installed)
4713 noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p);
4714 FOR_PROVIDES(p2, pp2, s->name)
4716 if (solv->decisionmap[p2] > 0)
4718 s2 = pool->solvables + p2;
4719 if (s2->repo != installed)
4721 if (noobs && (s->name != s2->name || s->evr != s2->evr || s->arch != s2->arch))
4723 if (!solv->implicitobsoleteusesprovides && s->name != s2->name)
4728 if (s->obsoletes && !noobs)
4730 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4731 while ((obs = *obsp++) != 0)
4733 FOR_PROVIDES(p2, pp2, obs)
4735 s2 = pool->solvables + p2;
4736 if (s2->repo != installed)
4738 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
4746 obsq_sortcmp_data = solv;
4747 qsort(ti->elements, ti->count / 2, 2 * sizeof(Id), obsq_sortcmp);
4749 for (i = j = 0; i < ti->count; i += 2)
4751 if (j && ti->elements[i] == ti->elements[j - 2] && ti->elements[i + 1] == ti->elements[j - 1])
4753 ti->elements[j++] = ti->elements[i];
4754 ti->elements[j++] = ti->elements[i + 1];
4761 FOR_REPO_SOLVABLES(installed, p, s)
4763 if (solv->decisionmap[p] > 0)
4765 p2 = solver_transaction_pkg(solv, p);
4767 queue_push(&solv->transaction, SOLVER_TRANSACTION_ERASE);
4770 s2 = pool->solvables + p2;
4771 if (s->name == s2->name)
4773 if (s->evr == s2->evr && solvable_identical(s, s2))
4774 queue_push(&solv->transaction, SOLVER_TRANSACTION_REINSTALLED);
4777 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
4779 queue_push(&solv->transaction, SOLVER_TRANSACTION_UPGRADED);
4781 queue_push(&solv->transaction, SOLVER_TRANSACTION_DOWNGRADED);
4783 queue_push(&solv->transaction, SOLVER_TRANSACTION_CHANGED);
4787 queue_push(&solv->transaction, SOLVER_TRANSACTION_OBSOLETED);
4789 queue_push(&solv->transaction, p);
4792 for (i = 0; i < solv->decisionq.count; i++)
4794 p = solv->decisionq.elements[i];
4795 if (p < 0 || p == SYSTEMSOLVABLE)
4797 s = pool->solvables + p;
4798 if (solv->installed && s->repo == solv->installed)
4800 noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p);
4801 p2 = solver_transaction_pkg(solv, p);
4803 queue_push(&solv->transaction, p2 ? SOLVER_TRANSACTION_MULTIREINSTALL : SOLVER_TRANSACTION_MULTIINSTALL);
4805 queue_push(&solv->transaction, SOLVER_TRANSACTION_INSTALL);
4808 s2 = pool->solvables + p2;
4809 if (s->name == s2->name)
4811 if (s->evr == s2->evr && solvable_identical(s, s2))
4812 queue_push(&solv->transaction, SOLVER_TRANSACTION_REINSTALL);
4815 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
4817 queue_push(&solv->transaction, SOLVER_TRANSACTION_UPGRADE);
4819 queue_push(&solv->transaction, SOLVER_TRANSACTION_DOWNGRADE);
4821 queue_push(&solv->transaction, SOLVER_TRANSACTION_CHANGE);
4825 queue_push(&solv->transaction, SOLVER_TRANSACTION_RENAME);
4827 queue_push(&solv->transaction, p);
4838 solver_solve(Solver *solv, Queue *job)
4840 Pool *pool = solv->pool;
4841 Repo *installed = solv->installed;
4844 Map addedmap; /* '1' == have rpm-rules for solvable */
4845 Map installcandidatemap;
4846 Id how, what, select, name, weak, p, pp, d;
4850 int now, solve_start;
4853 solve_start = sat_timems(0);
4855 /* log solver options */
4856 POOL_DEBUG(SAT_DEBUG_STATS, "solver started\n");
4857 POOL_DEBUG(SAT_DEBUG_STATS, "fixsystem=%d updatesystem=%d dosplitprovides=%d, noupdateprovide=%d noinfarchcheck=%d\n", solv->fixsystem, solv->updatesystem, solv->dosplitprovides, solv->noupdateprovide, solv->noinfarchcheck);
4858 POOL_DEBUG(SAT_DEBUG_STATS, "distupgrade=%d distupgrade_removeunsupported=%d\n", solv->distupgrade, solv->distupgrade_removeunsupported);
4859 POOL_DEBUG(SAT_DEBUG_STATS, "allowuninstall=%d, allowdowngrade=%d, allowarchchange=%d, allowvendorchange=%d\n", solv->allowuninstall, solv->allowdowngrade, solv->allowarchchange, solv->allowvendorchange);
4860 POOL_DEBUG(SAT_DEBUG_STATS, "promoteepoch=%d, allowvirtualconflicts=%d, allowselfconflicts=%d\n", pool->promoteepoch, solv->allowvirtualconflicts, solv->allowselfconflicts);
4861 POOL_DEBUG(SAT_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d\n", solv->obsoleteusesprovides, solv->implicitobsoleteusesprovides);
4862 POOL_DEBUG(SAT_DEBUG_STATS, "dontinstallrecommended=%d, ignorealreadyrecommended=%d, dontshowinstalledrecommended=%d\n", solv->dontinstallrecommended, solv->ignorealreadyrecommended, solv->dontshowinstalledrecommended);
4864 /* create whatprovides if not already there */
4865 if (!pool->whatprovides)
4866 pool_createwhatprovides(pool);
4868 /* create obsolete index */
4869 create_obsolete_index(solv);
4872 queue_free(&solv->job);
4873 queue_clone(&solv->job, job);
4876 * create basic rule set of all involved packages
4877 * use addedmap bitmap to make sure we don't create rules twice
4880 /* create noobsolete map if needed */
4881 for (i = 0; i < job->count; i += 2)
4883 how = job->elements[i] & ~SOLVER_WEAK;
4884 if ((how & SOLVER_JOBMASK) != SOLVER_NOOBSOLETES)
4886 what = job->elements[i + 1];
4887 select = how & SOLVER_SELECTMASK;
4888 if (!solv->noobsoletes.size)
4889 map_init(&solv->noobsoletes, pool->nsolvables);
4890 FOR_JOB_SELECT(p, pp, select, what)
4891 MAPSET(&solv->noobsoletes, p);
4894 map_init(&addedmap, pool->nsolvables);
4895 map_init(&installcandidatemap, pool->nsolvables);
4899 * always install our system solvable
4901 MAPSET(&addedmap, SYSTEMSOLVABLE);
4902 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
4903 queue_push(&solv->decisionq_why, 0);
4904 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
4906 now = sat_timems(0);
4908 * create rules for all package that could be involved with the solving
4909 * so called: rpm rules
4914 oldnrules = solv->nrules;
4915 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
4916 FOR_REPO_SOLVABLES(installed, p, s)
4917 addrpmrulesforsolvable(solv, s, &addedmap);
4918 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
4919 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
4920 oldnrules = solv->nrules;
4921 FOR_REPO_SOLVABLES(installed, p, s)
4922 addrpmrulesforupdaters(solv, s, &addedmap, 1);
4923 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
4927 * create rules for all packages involved in the job
4928 * (to be installed or removed)
4931 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
4932 oldnrules = solv->nrules;
4933 for (i = 0; i < job->count; i += 2)
4935 how = job->elements[i];
4936 what = job->elements[i + 1];
4937 select = how & SOLVER_SELECTMASK;
4939 switch (how & SOLVER_JOBMASK)
4941 case SOLVER_INSTALL:
4942 FOR_JOB_SELECT(p, pp, select, what)
4944 MAPSET(&installcandidatemap, p);
4945 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
4948 case SOLVER_DISTUPGRADE:
4949 if (!solv->distupgrade)
4956 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
4958 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
4960 oldnrules = solv->nrules;
4963 * add rules for suggests, enhances
4965 addrpmrulesforweak(solv, &addedmap);
4966 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
4968 IF_POOLDEBUG (SAT_DEBUG_STATS)
4970 int possible = 0, installable = 0;
4971 for (i = 1; i < pool->nsolvables; i++)
4973 if (pool_installable(pool, pool->solvables + i))
4975 if (MAPTST(&addedmap, i))
4978 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
4982 * first pass done, we now have all the rpm rules we need.
4983 * unify existing rules before going over all job rules and
4985 * at this point the system is always solvable,
4986 * as an empty system (remove all packages) is a valid solution
4989 unifyrules(solv); /* remove duplicate rpm rules */
4991 solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
4993 solv->directdecisions = solv->decisionq.count;
4994 POOL_DEBUG(SAT_DEBUG_STATS, "rpm rule memory usage: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
4995 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
4996 POOL_DEBUG(SAT_DEBUG_STATS, "rpm rule creation took %d ms\n", sat_timems(now));
4998 /* create dup maps if needed. We need the maps early to create our
5001 createdupmaps(solv, job);
5004 * create feature rules
5006 * foreach installed:
5007 * create assertion (keep installed, if no update available)
5009 * create update rule (A|update1(A)|update2(A)|...)
5011 * those are used later on to keep a version of the installed packages in
5015 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add feature rules ***\n");
5016 solv->featurerules = solv->nrules; /* mark start of feature rules */
5019 /* foreach possibly installed solvable */
5020 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
5022 if (s->repo != installed)
5024 addrule(solv, 0, 0); /* create dummy rule */
5027 addupdaterule(solv, s, 1); /* allow s to be updated */
5030 * assert one rule per installed solvable,
5031 * either an assertion (A)
5032 * or a possible update (A|update1(A)|update2(A)|...)
5034 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
5036 solv->featurerules_end = solv->nrules;
5039 * Add update rules for installed solvables
5041 * almost identical to feature rules
5042 * except that downgrades/archchanges/vendorchanges are not allowed
5045 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add update rules ***\n");
5046 solv->updaterules = solv->nrules;
5049 { /* foreach installed solvables */
5050 /* we create all update rules, but disable some later on depending on the job */
5051 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
5055 if (s->repo != installed)
5057 addrule(solv, 0, 0); /* create dummy rule */
5060 addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
5062 * check for and remove duplicate
5064 r = solv->rules + solv->nrules - 1; /* r: update rule */
5065 sr = r - (installed->end - installed->start); /* sr: feature rule */
5066 /* it's orphaned if there is no feature rule or the feature rule
5067 * consists just of the installed package */
5068 if (!sr->p || (sr->p == i && !sr->d && !sr->w2))
5069 queue_push(&solv->orphaned, i);
5072 assert(solv->distupgrade && !sr->p);
5075 unifyrules_sortcmp_data = pool;
5076 if (!unifyrules_sortcmp(r, sr))
5078 /* identical rule, kill unneeded one */
5079 if (solv->allowuninstall)
5081 /* keep feature rule, make it weak */
5082 memset(r, 0, sizeof(*r));
5083 queue_push(&solv->weakruleq, sr - solv->rules);
5087 /* keep update rule */
5088 memset(sr, 0, sizeof(*sr));
5091 else if (solv->allowuninstall)
5093 /* make both feature and update rule weak */
5094 queue_push(&solv->weakruleq, r - solv->rules);
5095 queue_push(&solv->weakruleq, sr - solv->rules);
5098 disablerule(solv, sr);
5100 /* consistency check: we added a rule for _every_ installed solvable */
5101 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
5103 solv->updaterules_end = solv->nrules;
5107 * now add all job rules
5110 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
5112 solv->jobrules = solv->nrules;
5113 for (i = 0; i < job->count; i += 2)
5115 oldnrules = solv->nrules;
5117 how = job->elements[i];
5118 what = job->elements[i + 1];
5119 weak = how & SOLVER_WEAK;
5120 select = how & SOLVER_SELECTMASK;
5121 switch (how & SOLVER_JOBMASK)
5123 case SOLVER_INSTALL:
5124 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
5125 if (select == SOLVER_SOLVABLE)
5133 FOR_JOB_SELECT(p, pp, select, what)
5137 /* no candidate found, make this an impossible rule */
5138 queue_push(&q, -SYSTEMSOLVABLE);
5140 p = queue_shift(&q); /* get first candidate */
5141 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
5143 addrule(solv, p, d); /* add install rule */
5144 queue_push(&solv->ruletojob, i);
5146 queue_push(&solv->weakruleq, solv->nrules - 1);
5149 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
5150 if (select == SOLVER_SOLVABLE && solv->installed && pool->solvables[what].repo == solv->installed)
5152 /* special case for "erase a specific solvable": we also
5153 * erase all other solvables with that name, so that they
5154 * don't get picked up as replacement */
5155 name = pool->solvables[what].name;
5156 FOR_PROVIDES(p, pp, name)
5160 s = pool->solvables + p;
5161 if (s->name != name)
5163 /* keep other versions installed */
5164 if (s->repo == solv->installed)
5166 /* keep installcandidates of other jobs */
5167 if (MAPTST(&installcandidatemap, p))
5169 addrule(solv, -p, 0); /* remove by Id */
5170 queue_push(&solv->ruletojob, i);
5172 queue_push(&solv->weakruleq, solv->nrules - 1);
5175 FOR_JOB_SELECT(p, pp, select, what)
5177 addrule(solv, -p, 0);
5178 queue_push(&solv->ruletojob, i);
5180 queue_push(&solv->weakruleq, solv->nrules - 1);
5185 POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
5186 FOR_JOB_SELECT(p, pp, select, what)
5188 s = pool->solvables + p;
5189 if (!solv->installed || s->repo != solv->installed)
5191 if (!solv->updatemap.size)
5192 map_init(&solv->updatemap, pool->nsolvables);
5193 MAPSET(&solv->updatemap, p);
5196 case SOLVER_WEAKENDEPS:
5197 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
5198 if (select != SOLVER_SOLVABLE)
5200 s = pool->solvables + what;
5201 weaken_solvable_deps(solv, what);
5203 case SOLVER_NOOBSOLETES:
5204 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sno obsolete %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
5207 POOL_DEBUG(SAT_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
5208 FOR_JOB_SELECT(p, pp, select, what)
5210 s = pool->solvables + p;
5211 if (installed && s->repo == installed)
5212 addrule(solv, p, 0);
5214 addrule(solv, -p, 0);
5215 queue_push(&solv->ruletojob, i);
5217 queue_push(&solv->weakruleq, solv->nrules - 1);
5220 case SOLVER_DISTUPGRADE:
5221 POOL_DEBUG(SAT_DEBUG_JOB, "job: distupgrade repo #%d\n", what);
5224 POOL_DEBUG(SAT_DEBUG_JOB, "job: unknown job\n");
5232 IF_POOLDEBUG (SAT_DEBUG_JOB)
5235 if (solv->nrules == oldnrules)
5236 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created\n");
5237 for (j = oldnrules; j < solv->nrules; j++)
5239 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
5240 solver_printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
5244 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
5245 solv->jobrules_end = solv->nrules;
5247 /* now create infarch and dup rules */
5248 if (!solv->noinfarchcheck)
5249 addinfarchrules(solv, &addedmap);
5251 solv->infarchrules = solv->infarchrules_end = solv->nrules;
5255 addduprules(solv, &addedmap);
5256 freedupmaps(solv); /* no longer needed */
5259 solv->duprules = solv->duprules_end = solv->nrules;
5262 /* all rules created
5263 * --------------------------------------------------------------
5264 * prepare for solving
5267 /* free unneeded memory */
5268 map_free(&addedmap);
5269 map_free(&installcandidatemap);
5272 POOL_DEBUG(SAT_DEBUG_STATS, "%d rpm rules, %d job rules, %d infarch rules, %d dup rules\n", solv->rpmrules_end - 1, solv->jobrules_end - solv->jobrules, solv->infarchrules_end - solv->infarchrules, solv->duprules_end - solv->duprules);
5274 /* create weak map */
5275 map_init(&solv->weakrulemap, solv->nrules);
5276 for (i = 0; i < solv->weakruleq.count; i++)
5278 p = solv->weakruleq.elements[i];
5279 MAPSET(&solv->weakrulemap, p);
5282 /* all new rules are learnt after this point */
5283 solv->learntrules = solv->nrules;
5285 /* create assertion index. it is only used to speed up
5286 * makeruledecsions() a bit */
5287 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
5288 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
5289 queue_push(&solv->ruleassertions, i);
5291 /* disable update rules that conflict with our job */
5292 disablepolicyrules(solv, job);
5294 /* make decisions based on job/update assertions */
5295 makeruledecisions(solv);
5297 /* create watches chains */
5300 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
5303 * ********************************************
5305 * ********************************************
5308 now = sat_timems(0);
5309 run_solver(solv, 1, solv->dontinstallrecommended ? 0 : 1);
5310 POOL_DEBUG(SAT_DEBUG_STATS, "solver took %d ms\n", sat_timems(now));
5313 * calculate recommended/suggested packages
5315 findrecommendedsuggested(solv);
5318 * if unsolvable, prepare solution queue
5320 if (solv->problems.count)
5323 queue_push(&solv->solutions, 0);
5324 queue_push(&solv->solutions, -1); /* unrefined */
5325 for (i = 1; i < solv->problems.count; i++)
5327 Id p = solv->problems.elements[i];
5328 queue_push(&solv->solutions, p);
5331 solv->problems.elements[j++] = idx;
5332 if (i + 1 >= solv->problems.count)
5334 solv->problems.elements[j++] = solv->problems.elements[++i]; /* copy proofidx */
5335 idx = solv->solutions.count;
5336 queue_push(&solv->solutions, -1);
5338 solv->problems.count = j;
5342 * finally prepare transaction info
5344 create_transaction(solv);
5346 POOL_DEBUG(SAT_DEBUG_STATS, "final solver statistics: %d problems, %d learned rules, %d unsolvable\n", solv->problems.count / 2, solv->stats_learned, solv->stats_unsolvable);
5347 POOL_DEBUG(SAT_DEBUG_STATS, "solver_solve took %d ms\n", sat_timems(solve_start));
5350 /***********************************************************************/
5351 /* disk usage computations */
5353 /*-------------------------------------------------------------------
5355 * calculate DU changes
5359 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
5363 solver_create_state_maps(solv, &installedmap, 0);
5364 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
5365 map_free(&installedmap);
5369 /*-------------------------------------------------------------------
5371 * calculate changes in install size
5375 solver_calc_installsizechange(Solver *solv)
5380 solver_create_state_maps(solv, &installedmap, 0);
5381 change = pool_calc_installsizechange(solv->pool, &installedmap);
5382 map_free(&installedmap);
5387 solver_trivial_installable(Solver *solv, Queue *pkgs, Queue *res)
5390 solver_create_state_maps(solv, &installedmap, 0);
5391 pool_trivial_installable_noobsoletesmap(solv->pool, &installedmap, pkgs, res, solv->noobsoletes.size ? &solv->noobsoletes : 0);
5392 map_free(&installedmap);
5396 #define FIND_INVOLVED_DEBUG 0
5398 solver_find_involved(Solver *solv, Queue *installedq, Solvable *ts, Queue *q)
5400 Pool *pool = solv->pool;
5405 Queue installedq_internal;
5406 Id tp, ip, p, pp, req, *reqp, sup, *supp;
5409 tp = ts - pool->solvables;
5411 queue_init(&installedq_internal);
5412 map_init(&im, pool->nsolvables);
5413 map_init(&installedm, pool->nsolvables);
5417 installedq = &installedq_internal;
5418 if (solv->installed)
5420 for (ip = solv->installed->start; ip < solv->installed->end; ip++)
5422 s = pool->solvables + ip;
5423 if (s->repo != solv->installed)
5425 queue_push(installedq, ip);
5429 for (i = 0; i < installedq->count; i++)
5431 ip = installedq->elements[i];
5432 MAPSET(&installedm, ip);
5436 queue_push(&iq, ts - pool->solvables);
5439 ip = queue_shift(&iq);
5440 if (!MAPTST(&im, ip))
5442 if (!MAPTST(&installedm, ip))
5445 s = pool->solvables + ip;
5446 #if FIND_INVOLVED_DEBUG
5447 printf("hello %s\n", solvable2str(pool, s));
5451 reqp = s->repo->idarraydata + s->requires;
5452 while ((req = *reqp++) != 0)
5454 if (req == SOLVABLE_PREREQMARKER)
5456 /* count number of installed packages that match */
5458 FOR_PROVIDES(p, pp, req)
5459 if (MAPTST(&installedm, p))
5463 FOR_PROVIDES(p, pp, req)
5467 #if FIND_INVOLVED_DEBUG
5468 printf("%s requires %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
5477 reqp = s->repo->idarraydata + s->recommends;
5478 while ((req = *reqp++) != 0)
5481 FOR_PROVIDES(p, pp, req)
5482 if (MAPTST(&installedm, p))
5486 FOR_PROVIDES(p, pp, req)
5490 #if FIND_INVOLVED_DEBUG
5491 printf("%s recommends %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
5500 /* supplements pass */
5501 for (i = 0; i < installedq->count; i++)
5503 ip = installedq->elements[i];
5504 s = pool->solvables + ip;
5505 if (!s->supplements)
5507 if (!MAPTST(&im, ip))
5509 supp = s->repo->idarraydata + s->supplements;
5510 while ((sup = *supp++) != 0)
5511 if (!dep_possible(solv, sup, &im) && dep_possible(solv, sup, &installedm))
5513 /* no longer supplemented, also erase */
5516 #if FIND_INVOLVED_DEBUG
5517 printf("%s supplemented\n", solvable2str(pool, pool->solvables + ip));
5519 queue_push(&iq, ip);
5525 for (i = 0; i < installedq->count; i++)
5527 ip = installedq->elements[i];
5528 if (MAPTST(&im, ip))
5529 queue_push(&iq, ip);
5534 ip = queue_shift(&iq);
5535 if (!MAPTST(&installedm, ip))
5537 s = pool->solvables + ip;
5538 #if FIND_INVOLVED_DEBUG
5539 printf("bye %s\n", solvable2str(pool, s));
5543 reqp = s->repo->idarraydata + s->requires;
5544 while ((req = *reqp++) != 0)
5546 FOR_PROVIDES(p, pp, req)
5548 if (!MAPTST(&im, p))
5552 #if FIND_INVOLVED_DEBUG
5553 printf("%s requires %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
5563 reqp = s->repo->idarraydata + s->recommends;
5564 while ((req = *reqp++) != 0)
5566 FOR_PROVIDES(p, pp, req)
5568 if (!MAPTST(&im, p))
5572 #if FIND_INVOLVED_DEBUG
5573 printf("%s recommends %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
5583 /* supplements pass */
5584 for (i = 0; i < installedq->count; i++)
5586 ip = installedq->elements[i];
5589 s = pool->solvables + ip;
5590 if (!s->supplements)
5592 if (MAPTST(&im, ip))
5594 supp = s->repo->idarraydata + s->supplements;
5595 while ((sup = *supp++) != 0)
5596 if (dep_possible(solv, sup, &im))
5600 #if FIND_INVOLVED_DEBUG
5601 printf("%s supplemented\n", solvable2str(pool, pool->solvables + ip));
5604 queue_push(&iq, ip);
5612 /* convert map into result */
5613 for (i = 0; i < installedq->count; i++)
5615 ip = installedq->elements[i];
5616 if (MAPTST(&im, ip))
5618 if (ip == ts - pool->solvables)
5623 map_free(&installedm);
5624 queue_free(&installedq_internal);
5629 addrpmruleinfo(Solver *solv, Id p, Id d, int type, Id dep)
5631 Pool *pool = solv->pool;
5635 /* check if this creates the rule we're searching for */
5636 r = solv->rules + solv->ruleinfoq->elements[0];
5638 od = r->d < 0 ? -r->d - 1 : r->d;
5643 if (p < 0 && d > 0 && (!pool->whatprovidesdata[d] || !pool->whatprovidesdata[d + 1]))
5645 w2 = pool->whatprovidesdata[d];
5649 if (p > 0 && d < 0) /* this hack is used for buddy deps */
5661 Id *dp = pool->whatprovidesdata + d;
5662 Id *odp = pool->whatprovidesdata + od;
5664 if (*dp++ != *odp++)
5670 /* handle multiversion conflict rules */
5671 if (p < 0 && pool->whatprovidesdata[d] < 0)
5673 w2 = pool->whatprovidesdata[d];
5674 /* XXX: free memory */
5684 if (w2 != op || p != ow2)
5689 if (p != op || w2 != ow2)
5693 /* yep, rule matches. record info */
5694 queue_push(solv->ruleinfoq, type);
5695 if (type == SOLVER_RULE_RPM_SAME_NAME)
5697 /* we normalize same name order */
5698 queue_push(solv->ruleinfoq, op < 0 ? -op : 0);
5699 queue_push(solv->ruleinfoq, ow2 < 0 ? -ow2 : 0);
5703 queue_push(solv->ruleinfoq, p < 0 ? -p : 0);
5704 queue_push(solv->ruleinfoq, w2 < 0 ? -w2 : 0);
5706 queue_push(solv->ruleinfoq, dep);
5710 solver_allruleinfos_cmp(const void *ap, const void *bp)
5712 const Id *a = ap, *b = bp;
5731 solver_allruleinfos(Solver *solv, Id rid, Queue *rq)
5733 Pool *pool = solv->pool;
5734 Rule *r = solv->rules + rid;
5738 if (rid <= 0 || rid >= solv->rpmrules_end)
5740 Id type, from, to, dep;
5741 type = solver_ruleinfo(solv, rid, &from, &to, &dep);
5742 queue_push(rq, type);
5743 queue_push(rq, from);
5745 queue_push(rq, dep);
5750 queue_push(rq, rid);
5751 solv->ruleinfoq = rq;
5752 addrpmrulesforsolvable(solv, pool->solvables - r->p, 0);
5753 /* also try reverse direction for conflicts */
5754 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
5755 addrpmrulesforsolvable(solv, pool->solvables - r->w2, 0);
5756 solv->ruleinfoq = 0;
5758 /* now sort & unify em */
5761 qsort(rq->elements, rq->count / 4, 4 * sizeof(Id), solver_allruleinfos_cmp);
5762 /* throw out identical entries */
5763 for (i = j = 0; i < rq->count; i += 4)
5767 if (rq->elements[i] == rq->elements[j - 4] &&
5768 rq->elements[i + 1] == rq->elements[j - 3] &&
5769 rq->elements[i + 2] == rq->elements[j - 2] &&
5770 rq->elements[i + 3] == rq->elements[j - 1])
5773 rq->elements[j++] = rq->elements[i];
5774 rq->elements[j++] = rq->elements[i + 1];
5775 rq->elements[j++] = rq->elements[i + 2];
5776 rq->elements[j++] = rq->elements[i + 3];
5783 solver_ruleinfo(Solver *solv, Id rid, Id *fromp, Id *top, Id *depp)
5785 Pool *pool = solv->pool;
5786 Rule *r = solv->rules + rid;
5787 SolverRuleinfo type = SOLVER_RULE_UNKNOWN;
5795 if (rid > 0 && rid < solv->rpmrules_end)
5801 return SOLVER_RULE_RPM;
5805 queue_push(&rq, rid);
5806 solv->ruleinfoq = &rq;
5807 addrpmrulesforsolvable(solv, pool->solvables - r->p, 0);
5808 /* also try reverse direction for conflicts */
5809 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
5810 addrpmrulesforsolvable(solv, pool->solvables - r->w2, 0);
5811 solv->ruleinfoq = 0;
5812 type = SOLVER_RULE_RPM;
5813 for (i = 1; i < rq.count; i += 4)
5816 qt = rq.elements[i];
5817 qp = rq.elements[i + 1];
5818 qo = rq.elements[i + 2];
5819 qd = rq.elements[i + 3];
5820 if (type == SOLVER_RULE_RPM || type > qt)
5834 if (rid >= solv->jobrules && rid < solv->jobrules_end)
5836 Id jidx = solv->ruletojob.elements[rid - solv->jobrules];
5840 *top = solv->job.elements[jidx];
5842 *depp = solv->job.elements[jidx + 1];
5843 if ((r->d == 0 || r->d == -1) && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && (solv->job.elements[jidx] & SOLVER_SELECTMASK) != SOLVER_SOLVABLE_ONE_OF)
5844 return SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP;
5845 return SOLVER_RULE_JOB;
5847 if (rid >= solv->updaterules && rid < solv->updaterules_end)
5850 *fromp = solv->installed->start + (rid - solv->updaterules);
5851 return SOLVER_RULE_UPDATE;
5853 if (rid >= solv->featurerules && rid < solv->featurerules_end)
5856 *fromp = solv->installed->start + (rid - solv->featurerules);
5857 return SOLVER_RULE_FEATURE;
5859 if (rid >= solv->duprules && rid < solv->duprules_end)
5864 *depp = pool->solvables[-r->p].name;
5865 return SOLVER_RULE_DISTUPGRADE;
5867 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
5872 *depp = pool->solvables[-r->p].name;
5873 return SOLVER_RULE_INFARCH;
5875 if (rid >= solv->learntrules)
5877 return SOLVER_RULE_LEARNT;
5879 return SOLVER_RULE_UNKNOWN;
5882 /* obsolete function */
5884 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
5886 return solver_ruleinfo(solv, rid, sourcep, targetp, depp);