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 /********************************************************************
32 * dependency check helpers
36 /*-------------------------------------------------------------------
37 * handle split provides
41 solver_splitprovides(Solver *solv, Id dep)
43 Pool *pool = solv->pool;
48 if (!solv->dosplitprovides || !solv->installed)
52 rd = GETRELDEP(pool, dep);
53 if (rd->flags != REL_WITH)
55 FOR_PROVIDES(p, pp, dep)
57 s = pool->solvables + p;
58 if (s->repo == solv->installed && s->name == rd->name)
65 /*-------------------------------------------------------------------
66 * solver_dep_installed
70 solver_dep_installed(Solver *solv, Id dep)
73 Pool *pool = solv->pool;
78 Reldep *rd = GETRELDEP(pool, dep);
79 if (rd->flags == REL_AND)
81 if (!solver_dep_installed(solv, rd->name))
83 return solver_dep_installed(solv, rd->evr);
85 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
86 return solver_dep_installed(solv, rd->evr);
88 FOR_PROVIDES(p, pp, dep)
90 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
98 /*-------------------------------------------------------------------
99 * Check if dependenc is possible
101 * this mirrors solver_dep_fulfilled
102 * but uses map m instead of the decisionmap
106 dep_possible(Solver *solv, Id dep, Map *m)
108 Pool *pool = solv->pool;
113 Reldep *rd = GETRELDEP(pool, dep);
114 if (rd->flags == REL_AND)
116 if (!dep_possible(solv, rd->name, m))
118 return dep_possible(solv, rd->evr, m);
120 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
121 return solver_splitprovides(solv, rd->evr);
122 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
123 return solver_dep_installed(solv, rd->evr);
125 FOR_PROVIDES(p, pp, dep)
133 /********************************************************************
137 * - unify rules, remove duplicates
140 static Pool *unifyrules_sortcmp_data;
142 /*-------------------------------------------------------------------
144 * compare rules for unification sort
149 unifyrules_sortcmp(const void *ap, const void *bp)
151 Pool *pool = unifyrules_sortcmp_data;
152 Rule *a = (Rule *)ap;
153 Rule *b = (Rule *)bp;
159 return x; /* p differs */
162 if (a->d == 0 && b->d == 0)
163 return a->w2 - b->w2; /* assertion: return w2 diff */
165 if (a->d == 0) /* a is assertion, b not */
167 x = a->w2 - pool->whatprovidesdata[b->d];
171 if (b->d == 0) /* b is assertion, a not */
173 x = pool->whatprovidesdata[a->d] - b->w2;
177 /* compare whatprovidesdata */
178 ad = pool->whatprovidesdata + a->d;
179 bd = pool->whatprovidesdata + b->d;
181 if ((x = *ad++ - *bd++) != 0)
187 /*-------------------------------------------------------------------
190 * go over all rules and remove duplicates
194 unifyrules(Solver *solv)
196 Pool *pool = solv->pool;
200 if (solv->nrules <= 1) /* nothing to unify */
203 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
205 /* sort rules first */
206 unifyrules_sortcmp_data = solv->pool;
207 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
214 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
216 if (jr && !unifyrules_sortcmp(ir, jr))
217 continue; /* prune! */
218 jr = solv->rules + j++; /* keep! */
223 /* reduced count from nrules to j rules */
224 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
226 /* adapt rule buffer */
228 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
232 IF_POOLDEBUG (SAT_DEBUG_STATS)
239 for (i = 1; i < solv->nrules; i++)
246 dp = solv->pool->whatprovidesdata + r->d;
251 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
252 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
254 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
264 hashrule(Solver *solv, Id p, Id d, int n)
266 unsigned int x = (unsigned int)p;
270 return (x * 37) ^ (unsigned int)d;
271 dp = solv->pool->whatprovidesdata + d;
273 x = (x * 37) ^ (unsigned int)*dp++;
279 /*-------------------------------------------------------------------
285 * p = direct literal; always < 0 for installed rpm rules
286 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
289 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
291 * p < 0 : pkg id of A
292 * d > 0 : Offset in whatprovidesdata (list of providers of b)
294 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
295 * p < 0 : pkg id of A
296 * d < 0 : Id of solvable (e.g. B1)
298 * d == 0: unary rule, assertion => (A) or (-A)
300 * Install: p > 0, d = 0 (A) user requested install
301 * Remove: p < 0, d = 0 (-A) user requested remove
302 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
303 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
304 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
305 * ? p > 0, d < 0 (A|-B)
306 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
310 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
311 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
312 * every other : w1 = p, w2 = whatprovidesdata[d];
313 * Disabled rule: w1 = 0
315 * always returns a rule for non-rpm rules
319 addrule(Solver *solv, Id p, Id d)
321 Pool *pool = solv->pool;
325 int n = 0; /* number of literals in rule - 1
326 0 = direct assertion (single literal)
331 /* it often happenes that requires lead to adding the same rpm rule
332 * multiple times, so we prune those duplicates right away to make
333 * the work for unifyrules a bit easier */
335 if (solv->nrules /* we already have rules */
336 && !solv->rpmrules_end) /* but are not done with rpm rules */
338 r = solv->rules + solv->nrules - 1; /* get the last added rule */
339 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
344 * compute number of literals (n) in rule
349 /* always a binary rule */
351 return 0; /* ignore self conflict */
356 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
358 return 0; /* rule is self-fulfilling */
360 if (n == 1) /* have single provider */
361 d = dp[-1]; /* take single literal */
365 if (n == 0 && !solv->rpmrules_end)
367 /* this is a rpm rule assertion, we do not have to allocate it */
368 /* it can be identified by a level of 1 and a zero reason */
369 /* we must not drop those rules from the decisionq when rewinding! */
371 assert(solv->decisionmap[-p] == 0 || solv->decisionmap[-p] == -1);
372 if (solv->decisionmap[-p])
373 return 0; /* already got that one */
374 queue_push(&solv->decisionq, p);
375 queue_push(&solv->decisionq_why, 0);
376 solv->decisionmap[-p] = -1;
381 if (n == 1 && p > d && !solv->rpmrules_end)
383 /* smallest literal first so we can find dups */
384 n = p; p = d; d = n; /* p <-> d */
385 n = 1; /* re-set n, was used as temp var */
389 * check for duplicate
392 /* check if the last added rule (r) is exactly the same as what we're looking for. */
393 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
394 return r; /* binary rule */
396 /* have n-ary rule with same first literal, check other literals */
397 if (r && n > 1 && r->d && r->p == p)
399 /* Rule where d is an offset in whatprovidesdata */
403 dp2 = pool->whatprovidesdata + r->d;
404 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
415 /* extend rule buffer */
416 solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
417 r = solv->rules + solv->nrules++; /* point to rule space */
426 /* direct assertion, no watch needed */
442 r->w2 = pool->whatprovidesdata[d];
447 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
449 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
450 solver_printrule(solv, SAT_DEBUG_RULE_CREATION, r);
456 /*-------------------------------------------------------------------
461 disablerule(Solver *solv, Rule *r)
467 /*-------------------------------------------------------------------
472 enablerule(Solver *solv, Rule *r)
479 /**********************************************************************************/
481 /* a problem is an item on the solver's problem list. It can either be >0, in that
482 * case it is a update rule, or it can be <0, which makes it refer to a job
483 * consisting of multiple job rules.
487 disableproblem(Solver *solv, Id v)
495 disablerule(solv, solv->rules + v);
499 jp = solv->ruletojob.elements;
500 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
502 disablerule(solv, r);
505 /*-------------------------------------------------------------------
510 enableproblem(Solver *solv, Id v)
518 if (v >= solv->featurerules && v < solv->featurerules_end)
520 /* do not enable feature rule if update rule is enabled */
521 r = solv->rules + (v - solv->featurerules + solv->updaterules);
525 enablerule(solv, solv->rules + v);
526 if (v >= solv->updaterules && v < solv->updaterules_end)
528 /* disable feature rule when enabling update rule */
529 r = solv->rules + (v - solv->updaterules + solv->featurerules);
531 disablerule(solv, r);
536 jp = solv->ruletojob.elements;
537 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
543 /************************************************************************/
546 * make assertion rules into decisions
548 * go through update and job rules and add direct assertions
549 * to the decisionqueue. If we find a conflict, disable rules and
550 * add them to problem queue.
554 makeruledecisions(Solver *solv)
556 Pool *pool = solv->pool;
562 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
564 decisionstart = solv->decisionq.count;
565 for (ii = 0; ii < solv->ruleassertions.count; ii++)
567 ri = solv->ruleassertions.elements[ii];
568 r = solv->rules + ri;
570 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
572 /* do weak rules in phase 2 */
573 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
579 if (!solv->decisionmap[vv]) /* if not yet decided */
584 queue_push(&solv->decisionq, v);
585 queue_push(&solv->decisionq_why, r - solv->rules);
586 solv->decisionmap[vv] = v > 0 ? 1 : -1;
587 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
589 Solvable *s = solv->pool->solvables + vv;
591 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
593 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
598 * check previous decision: is it sane ?
601 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
603 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
609 * The rule (r) we're currently processing says something
610 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
614 if (ri >= solv->learntrules)
616 /* conflict with a learnt rule */
617 /* can happen when packages cannot be installed for
618 * multiple reasons. */
619 /* we disable the learnt rule in this case */
620 disablerule(solv, r);
625 * find the decision which is the "opposite" of the rule
628 for (i = 0; i < solv->decisionq.count; i++)
629 if (solv->decisionq.elements[i] == -v)
631 assert(i < solv->decisionq.count); /* assert that we found it */
634 * conflict with system solvable ?
637 if (v == -SYSTEMSOLVABLE) {
638 /* conflict with system solvable */
639 queue_push(&solv->problems, solv->learnt_pool.count);
640 queue_push(&solv->learnt_pool, ri);
641 queue_push(&solv->learnt_pool, 0);
642 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
643 if (ri >= solv->jobrules && ri < solv->jobrules_end)
644 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
647 queue_push(&solv->problems, v);
648 queue_push(&solv->problems, 0);
649 disableproblem(solv, v);
653 assert(solv->decisionq_why.elements[i]);
656 * conflict with an rpm rule ?
659 if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
661 /* conflict with rpm rule assertion */
662 queue_push(&solv->problems, solv->learnt_pool.count);
663 queue_push(&solv->learnt_pool, ri);
664 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
665 queue_push(&solv->learnt_pool, 0);
666 assert(v > 0 || v == -SYSTEMSOLVABLE);
667 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
668 if (ri >= solv->jobrules && ri < solv->jobrules_end)
669 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
672 queue_push(&solv->problems, v);
673 queue_push(&solv->problems, 0);
674 disableproblem(solv, v);
679 * conflict with another job or update/feature rule
683 queue_push(&solv->problems, solv->learnt_pool.count);
684 queue_push(&solv->learnt_pool, ri);
685 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
686 queue_push(&solv->learnt_pool, 0);
688 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
691 * push all of our rules (can only be feature or job rules)
692 * asserting this literal on the problem stack
695 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
697 if (rr->d < 0 /* disabled */
698 || rr->w2) /* or no assertion */
700 if (rr->p != vv /* not affecting the literal */
703 if (MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
706 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
708 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, solv->rules + i);
711 /* is is a job rule ? */
712 if (i >= solv->jobrules && i < solv->jobrules_end)
713 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
715 queue_push(&solv->problems, v);
716 disableproblem(solv, v);
718 queue_push(&solv->problems, 0);
722 * (back up from decisions)
724 while (solv->decisionq.count > decisionstart)
726 v = solv->decisionq.elements[--solv->decisionq.count];
727 --solv->decisionq_why.count;
729 solv->decisionmap[vv] = 0;
731 ii = -1; /* restarts loop at 0 */
735 * phase 2: now do the weak assertions
737 for (ii = 0; ii < solv->ruleassertions.count; ii++)
739 ri = solv->ruleassertions.elements[ii];
740 r = solv->rules + ri;
741 if (r->d < 0 || r->w2) /* disabled or no assertion */
743 if (!MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
749 * (if not yet decided)
751 if (!solv->decisionmap[vv])
753 queue_push(&solv->decisionq, v);
754 queue_push(&solv->decisionq_why, r - solv->rules);
755 solv->decisionmap[vv] = v > 0 ? 1 : -1;
756 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
758 Solvable *s = solv->pool->solvables + vv;
760 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", solvable2str(solv->pool, s));
762 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", solvable2str(solv->pool, s));
767 * previously decided, sane ?
769 if (v > 0 && solv->decisionmap[vv] > 0)
771 if (v < 0 && solv->decisionmap[vv] < 0)
774 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
775 solver_printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
776 disablerule(solv, r);
779 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
783 /*-------------------------------------------------------------------
784 * enable/disable learnt rules
786 * we have enabled or disabled some of our rules. We now reenable all
787 * of our learnt rules but the ones that were learnt from rules that
791 enabledisablelearntrules(Solver *solv)
793 Pool *pool = solv->pool;
798 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
799 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
801 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
802 while ((why = *whyp++) != 0)
804 assert(why > 0 && why < i);
805 if (solv->rules[why].d < 0)
808 /* why != 0: we found a disabled rule, disable the learnt rule */
809 if (why && r->d >= 0)
811 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
813 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling ");
814 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
816 disablerule(solv, r);
818 else if (!why && r->d < 0)
820 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
822 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling ");
823 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
831 /*-------------------------------------------------------------------
834 * Enable all rules, except learnt rules, which are
835 * - disabled and weak (set in weakrulemap)
840 enableweakrules(Solver *solv)
845 for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
847 if (r->d >= 0) /* skip non-direct literals */
849 if (!MAPTST(&solv->weakrulemap, i))
856 /* FIXME: bad code ahead, replace as soon as possible */
857 /* FIXME: should probably look at SOLVER_INSTALL|SOLVABLE_ONE_OF */
859 /*-------------------------------------------------------------------
860 * disable update rules
864 disableupdaterules(Solver *solv, Queue *job, int jobidx)
866 Pool *pool = solv->pool;
868 Id how, select, what, p, pp;
874 installed = solv->installed;
880 how = job->elements[jobidx];
881 select = how & SOLVER_SELECTMASK;
882 switch (how & SOLVER_JOBMASK)
887 if (select != SOLVER_SOLVABLE)
894 /* go through all enabled job rules */
895 MAPZERO(&solv->noupdate);
896 for (i = solv->jobrules; i < solv->jobrules_end; i++)
899 if (r->d < 0) /* disabled? */
901 j = solv->ruletojob.elements[i - solv->jobrules];
905 how = job->elements[j];
906 what = job->elements[j + 1];
907 select = how & SOLVER_SELECTMASK;
908 switch (how & SOLVER_JOBMASK)
911 if (select != SOLVER_SOLVABLE)
913 s = pool->solvables + what;
914 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, what))
916 if (s->repo == installed)
921 obsp = s->repo->idarraydata + s->obsoletes;
922 while ((obs = *obsp++) != 0)
923 FOR_PROVIDES(p, pp, obs)
925 if (pool->solvables[p].repo != installed)
927 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
929 MAPSET(&solv->noupdate, p - installed->start);
932 FOR_PROVIDES(p, pp, s->name)
934 if (!solv->implicitobsoleteusesprovides && pool->solvables[p].name != s->name)
936 if (pool->solvables[p].repo == installed)
937 MAPSET(&solv->noupdate, p - installed->start);
941 FOR_JOB_SELECT(p, pp, select, what)
942 if (pool->solvables[p].repo == installed)
943 MAPSET(&solv->noupdate, p - installed->start);
950 /* fixup update rule status */
953 /* we just disabled job #jobidx. enable all update rules
954 * that aren't disabled by the remaining job rules */
955 how = job->elements[jobidx];
956 what = job->elements[jobidx + 1];
957 select = how & SOLVER_SELECTMASK;
958 switch (how & SOLVER_JOBMASK)
961 if (select != SOLVER_SOLVABLE)
963 s = pool->solvables + what;
964 if (s->repo == installed)
969 obsp = s->repo->idarraydata + s->obsoletes;
970 while ((obs = *obsp++) != 0)
971 FOR_PROVIDES(p, pp, obs)
973 if (pool->solvables[p].repo != installed)
975 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
977 if (MAPTST(&solv->noupdate, p - installed->start))
979 r = solv->rules + solv->updaterules + (p - installed->start);
983 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
985 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
986 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
990 FOR_PROVIDES(p, pp, s->name)
992 if (!solv->implicitobsoleteusesprovides && pool->solvables[p].name != s->name)
994 if (pool->solvables[p].repo != installed)
996 if (MAPTST(&solv->noupdate, p - installed->start))
998 r = solv->rules + solv->updaterules + (p - installed->start);
1001 enablerule(solv, r);
1002 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1004 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1005 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
1010 FOR_JOB_SELECT(p, pp, select, what)
1012 if (pool->solvables[p].repo != installed)
1014 if (MAPTST(&solv->noupdate, p - installed->start))
1016 r = solv->rules + solv->updaterules + (p - installed->start);
1019 enablerule(solv, r);
1020 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1022 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1023 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
1033 for (i = 0; i < installed->nsolvables; i++)
1035 r = solv->rules + solv->updaterules + i;
1036 if (r->d >= 0 && MAPTST(&solv->noupdate, i))
1037 disablerule(solv, r); /* was enabled, need to disable */
1038 r = solv->rules + solv->featurerules + i;
1039 if (r->d >= 0 && MAPTST(&solv->noupdate, i))
1040 disablerule(solv, r); /* was enabled, need to disable */
1046 * special multiversion patch conflict handling:
1047 * a patch conflict is also satisfied, if some other
1048 * version with the same name/arch that doesn't conflict
1049 * get's installed. The generated rule is thus:
1050 * -patch|-cpack|opack1|opack2|...
1053 makemultiversionconflict(Solver *solv, Id n, Id con)
1055 Pool *pool = solv->pool;
1060 sn = pool->solvables + n;
1061 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1063 FOR_PROVIDES(p, pp, sn->name)
1065 s = pool->solvables + p;
1066 if (s->name != sn->name || s->arch != sn->arch)
1068 if (!MAPTST(&solv->noobsoletes, p))
1070 if (pool_match_nevr(pool, pool->solvables + p, con))
1072 /* here we have a multiversion solvable that doesn't conflict */
1073 /* thus we're not in conflict if it is installed */
1077 return -n; /* no other package found, generate normal conflict */
1078 return pool_queuetowhatprovides(pool, &q);
1082 /*-------------------------------------------------------------------
1084 * add (install) rules for solvable
1086 * s: Solvable for which to add rules
1087 * m: m[s] = 1 for solvables which have rules, prevent rule duplication
1089 * Algorithm: 'visit all nodes of a graph'. The graph nodes are
1090 * solvables, the edges their dependencies.
1091 * Starting from an installed solvable, this will create all rules
1092 * representing the graph created by the solvables dependencies.
1094 * for unfulfilled requirements, conflicts, obsoletes,....
1095 * add a negative assertion for solvables that are not installable
1097 * It will also create rules for all solvables referenced by 's'
1098 * i.e. descend to all providers of requirements of 's'
1103 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
1105 Pool *pool = solv->pool;
1106 Repo *installed = solv->installed;
1108 /* 'work' queue. keeps Ids of solvables we still have to work on.
1109 And buffer for it. */
1114 /* if to add rules for broken deps ('rpm -V' functionality)
1118 /* Id var and pointer for each dependency
1119 * (not used in parallel)
1126 /* var and ptr for loops */
1128 /* ptr to 'whatprovides' */
1130 /* Id for current solvable 's' */
1133 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
1135 queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
1136 queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
1138 /* loop until there's no more work left */
1143 * s: Pointer to solvable
1146 n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
1147 if (MAPTST(m, n)) /* continue if already visited */
1150 MAPSET(m, n); /* mark as visited */
1151 s = pool->solvables + n; /* s = Solvable in question */
1154 if (installed /* Installed system available */
1155 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
1156 && s->repo == installed) /* solvable is installed? */
1158 dontfix = 1; /* dont care about broken rpm deps */
1162 && s->arch != ARCH_SRC
1163 && s->arch != ARCH_NOSRC
1164 && !pool_installable(pool, s))
1166 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
1167 addrule(solv, -n, 0); /* uninstallable */
1170 /*-----------------------------------------
1171 * check requires of s
1176 reqp = s->repo->idarraydata + s->requires;
1177 while ((req = *reqp++) != 0) /* go through all requires */
1179 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
1182 /* find list of solvables providing 'req' */
1183 dp = pool->whatprovidesdata + pool_whatprovides(pool, req);
1185 if (*dp == SYSTEMSOLVABLE) /* always installed */
1190 /* the strategy here is to not insist on dependencies
1191 * that are already broken. so if we find one provider
1192 * that was already installed, we know that the
1193 * dependency was not broken before so we enforce it */
1195 /* check if any of the providers for 'req' is installed */
1196 for (i = 0; (p = dp[i]) != 0; i++)
1198 if (pool->solvables[p].repo == installed)
1199 break; /* provider was installed */
1201 /* didn't find an installed provider: previously broken dependency */
1204 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1211 /* nothing provides req! */
1212 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1213 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1217 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1219 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1220 for (i = 0; dp[i]; i++)
1221 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1224 /* add 'requires' dependency */
1225 /* rule: (-requestor|provider1|provider2|...|providerN) */
1226 addrule(solv, -n, dp - pool->whatprovidesdata);
1228 /* descend the dependency tree
1229 push all non-visited providers on the work queue */
1232 if (!MAPTST(m, *dp))
1233 queue_push(&workq, *dp);
1236 } /* while, requirements of n */
1238 } /* if, requirements */
1240 /* that's all we check for src packages */
1241 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1244 /*-----------------------------------------
1245 * check conflicts of s
1252 /* we treat conflicts in patches a bit differen:
1254 * - multiversion handling
1255 * XXX: we should really handle this different, looking
1256 * at the name is a bad hack
1258 if (!strncmp("patch:", id2str(pool, s->name), 6))
1260 conp = s->repo->idarraydata + s->conflicts;
1261 /* foreach conflicts of 's' */
1262 while ((con = *conp++) != 0)
1264 /* foreach providers of a conflict of 's' */
1265 FOR_PROVIDES(p, pp, con)
1267 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
1269 /* dontfix: dont care about conflicts with already installed packs */
1270 if (dontfix && pool->solvables[p].repo == installed)
1272 /* p == n: self conflict */
1273 if (p == n && !solv->allowselfconflicts)
1277 Reldep *rd = GETRELDEP(pool, con);
1278 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
1281 p = 0; /* make it a negative assertion, aka 'uninstallable' */
1283 if (p && ispatch && solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p) && ISRELDEP(con))
1285 /* our patch conflicts with a noobsoletes (aka multiversion) package */
1286 p = -makemultiversionconflict(solv, p, con);
1288 /* rule: -n|-p: either solvable _or_ provider of conflict */
1289 addrule(solv, -n, -p);
1294 /*-----------------------------------------
1295 * check obsoletes if not installed
1296 * (only installation will trigger the obsoletes in rpm)
1298 if (!installed || pool->solvables[n].repo != installed)
1299 { /* not installed */
1300 int noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
1301 if (s->obsoletes && !noobs)
1303 obsp = s->repo->idarraydata + s->obsoletes;
1304 /* foreach obsoletes */
1305 while ((obs = *obsp++) != 0)
1307 /* foreach provider of an obsoletes of 's' */
1308 FOR_PROVIDES(p, pp, obs)
1310 if (!solv->obsoleteusesprovides /* obsoletes are matched names, not provides */
1311 && !pool_match_nevr(pool, pool->solvables + p, obs))
1313 addrule(solv, -n, -p);
1317 FOR_PROVIDES(p, pp, s->name)
1319 Solvable *ps = pool->solvables + p;
1320 /* we still obsolete packages with same nevra, like rpm does */
1321 /* (actually, rpm mixes those packages. yuck...) */
1322 if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
1324 if (!solv->implicitobsoleteusesprovides && s->name != ps->name)
1326 addrule(solv, -n, -p);
1330 /*-----------------------------------------
1331 * add recommends to the work queue
1335 recp = s->repo->idarraydata + s->recommends;
1336 while ((rec = *recp++) != 0)
1338 FOR_PROVIDES(p, pp, rec)
1340 queue_push(&workq, p);
1345 sugp = s->repo->idarraydata + s->suggests;
1346 while ((sug = *sugp++) != 0)
1348 FOR_PROVIDES(p, pp, sug)
1350 queue_push(&workq, p);
1355 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1359 /*-------------------------------------------------------------------
1361 * Add package rules for weak rules
1363 * m: visited solvables
1367 addrpmrulesforweak(Solver *solv, Map *m)
1369 Pool *pool = solv->pool;
1374 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1375 /* foreach solvable in pool */
1376 for (i = n = 1; n < pool->nsolvables; i++, n++)
1378 if (i == pool->nsolvables) /* wrap i */
1380 if (MAPTST(m, i)) /* been there */
1383 s = pool->solvables + i;
1384 if (!pool_installable(pool, s)) /* only look at installable ones */
1390 /* find possible supplements */
1391 supp = s->repo->idarraydata + s->supplements;
1392 while ((sup = *supp++) != ID_NULL)
1393 if (dep_possible(solv, sup, m))
1397 /* if nothing found, check for enhances */
1398 if (!sup && s->enhances)
1400 supp = s->repo->idarraydata + s->enhances;
1401 while ((sup = *supp++) != ID_NULL)
1402 if (dep_possible(solv, sup, m))
1405 /* if nothing found, goto next solvables */
1408 addrpmrulesforsolvable(solv, s, m);
1411 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1415 /*-------------------------------------------------------------------
1417 * add package rules for possible updates
1420 * m: map of already visited solvables
1421 * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
1425 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
1427 Pool *pool = solv->pool;
1429 /* queue and buffer for it */
1433 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1435 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1436 /* find update candidates for 's' */
1437 policy_findupdatepackages(solv, s, &qs, allow_all);
1438 /* add rule for 's' if not already done */
1439 if (!MAPTST(m, s - pool->solvables))
1440 addrpmrulesforsolvable(solv, s, m);
1441 /* foreach update candidate, add rule if not already done */
1442 for (i = 0; i < qs.count; i++)
1443 if (!MAPTST(m, qs.elements[i]))
1444 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1447 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1451 finddistupgradepackages(Solver *solv, Solvable *s, Queue *qs, int allow_all)
1453 Pool *pool = solv->pool;
1456 policy_findupdatepackages(solv, s, qs, allow_all);
1461 policy_findupdatepackages(solv, s, qs, 1);
1465 return -SYSTEMSOLVABLE;
1468 return s - pool->solvables;
1469 /* check if it is ok to keep the installed package */
1470 for (i = 0; i < qs->count; i++)
1472 Solvable *ns = pool->solvables + qs->elements[i];
1473 if (s->evr == ns->evr && solvable_identical(pool, s, ns))
1474 return s - pool->solvables;
1476 /* nope, it must be some other package */
1477 return queue_shift(qs);
1480 /*-------------------------------------------------------------------
1482 * add rule for update
1483 * (A|A1|A2|A3...) An = update candidates for A
1485 * s = (installed) solvable
1489 addupdaterule(Solver *solv, Solvable *s, int allow_all)
1491 /* installed packages get a special upgrade allowed rule */
1492 Pool *pool = solv->pool;
1497 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1498 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1499 p = s - pool->solvables;
1500 /* find update candidates for 's' */
1501 if (solv->distupgrade)
1502 p = finddistupgradepackages(solv, s, &qs, allow_all);
1504 policy_findupdatepackages(solv, s, &qs, allow_all);
1505 d = qs.count ? pool_queuetowhatprovides(pool, &qs) : 0;
1507 addrule(solv, p, d); /* allow update of s */
1508 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1512 /********************************************************************/
1516 /*-------------------------------------------------------------------
1519 * initial setup for all watches
1523 makewatches(Solver *solv)
1527 int nsolvables = solv->pool->nsolvables;
1529 sat_free(solv->watches);
1530 /* lower half for removals, upper half for installs */
1531 solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
1533 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
1534 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1536 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1539 if (!r->w2) /* assertions do not need watches */
1542 /* see addwatches_rule(solv, r) */
1543 r->n1 = solv->watches[nsolvables + r->w1];
1544 solv->watches[nsolvables + r->w1] = r - solv->rules;
1546 r->n2 = solv->watches[nsolvables + r->w2];
1547 solv->watches[nsolvables + r->w2] = r - solv->rules;
1552 /*-------------------------------------------------------------------
1554 * add watches (for rule)
1555 * sets up watches for a single rule
1557 * see also makewatches()
1561 addwatches_rule(Solver *solv, Rule *r)
1563 int nsolvables = solv->pool->nsolvables;
1565 r->n1 = solv->watches[nsolvables + r->w1];
1566 solv->watches[nsolvables + r->w1] = r - solv->rules;
1568 r->n2 = solv->watches[nsolvables + r->w2];
1569 solv->watches[nsolvables + r->w2] = r - solv->rules;
1573 /********************************************************************/
1579 /* shortcuts to check if a literal (positive or negative) assignment
1580 * evaluates to 'true' or 'false'
1582 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1583 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
1584 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
1586 /*-------------------------------------------------------------------
1590 * make decision and propagate to all rules
1592 * Evaluate each term affected by the decision (linked through watches)
1593 * If we find unit rules we make new decisions based on them
1595 * Everything's fixed there, it's just finding rules that are
1598 * return : 0 = everything is OK
1599 * rule = conflict found in this rule
1603 propagate(Solver *solv, int level)
1605 Pool *pool = solv->pool;
1606 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
1608 Id p, pkg, other_watch;
1610 Id *decisionmap = solv->decisionmap;
1612 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
1614 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1616 /* foreach non-propagated decision */
1617 while (solv->propagate_index < solv->decisionq.count)
1620 * 'pkg' was just decided
1621 * negate because our watches trigger if literal goes FALSE
1623 pkg = -solv->decisionq.elements[solv->propagate_index++];
1625 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1627 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
1628 solver_printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1631 /* foreach rule where 'pkg' is now FALSE */
1632 for (rp = watches + pkg; *rp; rp = next_rp)
1634 r = solv->rules + *rp;
1637 /* rule is disabled, goto next */
1645 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1647 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1648 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
1651 /* 'pkg' was just decided (was set to FALSE)
1653 * now find other literal watch, check clause
1654 * and advance on linked list
1658 other_watch = r->w2;
1663 other_watch = r->w1;
1668 * This term is already true (through the other literal)
1669 * so we have nothing to do
1671 if (DECISIONMAP_TRUE(other_watch))
1675 * The other literal is FALSE or UNDEF
1681 /* Not a binary clause, try to move our watch.
1683 * Go over all literals and find one that is
1687 * (TRUE is also ok, in that case the rule is fulfilled)
1689 if (r->p /* we have a 'p' */
1690 && r->p != other_watch /* which is not watched */
1691 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
1695 else /* go find a 'd' to make 'true' */
1698 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
1700 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1702 if (p != other_watch /* which is not watched */
1703 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
1711 * if we found some p that is UNDEF or TRUE, move
1714 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1717 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1719 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1735 watches[p] = r - solv->rules;
1738 /* search failed, thus all unwatched literals are FALSE */
1743 * unit clause found, set literal other_watch to TRUE
1746 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
1747 return r; /* eek, a conflict! */
1749 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1751 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
1752 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
1755 if (other_watch > 0)
1756 decisionmap[other_watch] = level; /* install! */
1758 decisionmap[-other_watch] = -level; /* remove! */
1760 queue_push(&solv->decisionq, other_watch);
1761 queue_push(&solv->decisionq_why, r - solv->rules);
1763 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1765 Solvable *s = pool->solvables + (other_watch > 0 ? other_watch : -other_watch);
1766 if (other_watch > 0)
1767 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
1769 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
1772 } /* foreach rule involving 'pkg' */
1774 } /* while we have non-decided decisions */
1776 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
1778 return 0; /* all is well */
1782 /********************************************************************/
1785 /*-------------------------------------------------------------------
1792 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
1794 Pool *pool = solv->pool;
1797 Map seen; /* global? */
1798 Id d, v, vv, *dp, why;
1800 int num = 0, l1num = 0;
1801 int learnt_why = solv->learnt_pool.count;
1802 Id *decisionmap = solv->decisionmap;
1806 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
1807 map_init(&seen, pool->nsolvables);
1808 idx = solv->decisionq.count;
1811 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1812 solver_printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1813 queue_push(&solv->learnt_pool, c - solv->rules);
1814 d = c->d < 0 ? -c->d - 1 : c->d;
1815 dp = d ? pool->whatprovidesdata + d : 0;
1816 /* go through all literals of the rule */
1828 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1830 vv = v > 0 ? v : -v;
1831 if (MAPTST(&seen, vv))
1833 l = solv->decisionmap[vv];
1838 l1num++; /* need to do this one in level1 pass */
1839 else if (l == level)
1840 num++; /* need to do this one as well */
1843 queue_push(&r, v); /* not level1 or conflict level, add to new rule */
1849 if (!num && !--l1num)
1850 break; /* all level 1 literals done */
1854 v = solv->decisionq.elements[--idx];
1855 vv = v > 0 ? v : -v;
1856 if (MAPTST(&seen, vv))
1860 if (num && --num == 0)
1862 *pr = -v; /* so that v doesn't get lost */
1865 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1866 for (i = 0; i < r.count; i++)
1869 MAPCLR(&seen, v > 0 ? v : -v);
1871 /* only level 1 marks left */
1875 why = solv->decisionq_why.elements[idx];
1876 if (!why) /* just in case, maybe for SYSTEMSOLVABLE */
1878 c = solv->rules + why;
1884 else if (r.count == 1 && r.elements[0] < 0)
1885 *dr = r.elements[0];
1887 *dr = pool_queuetowhatprovides(pool, &r);
1888 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1890 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1891 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
1892 for (i = 0; i < r.count; i++)
1893 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
1895 /* push end marker on learnt reasons stack */
1896 queue_push(&solv->learnt_pool, 0);
1899 solv->stats_learned++;
1904 /*-------------------------------------------------------------------
1908 * reset the solver decisions to right after the rpm rules.
1909 * called after rules have been enabled/disabled
1913 reset_solver(Solver *solv)
1915 Pool *pool = solv->pool;
1919 /* rewind decisions to direct rpm rule assertions */
1920 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
1922 v = solv->decisionq.elements[i];
1923 solv->decisionmap[v > 0 ? v : -v] = 0;
1926 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
1928 solv->decisionq_why.count = solv->directdecisions;
1929 solv->decisionq.count = solv->directdecisions;
1930 solv->recommends_index = -1;
1931 solv->propagate_index = 0;
1933 /* adapt learnt rule status to new set of enabled/disabled rules */
1934 enabledisablelearntrules(solv);
1936 /* redo all job/update decisions */
1937 makeruledecisions(solv);
1938 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
1942 /*-------------------------------------------------------------------
1944 * analyze_unsolvable_rule
1948 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
1950 Pool *pool = solv->pool;
1952 Id why = r - solv->rules;
1954 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1955 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1956 if (solv->learntrules && why >= solv->learntrules)
1958 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1959 if (solv->learnt_pool.elements[i] > 0)
1960 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp);
1963 if (MAPTST(&solv->weakrulemap, why))
1964 if (!*lastweakp || why > *lastweakp)
1966 /* do not add rpm rules to problem */
1967 if (why < solv->rpmrules_end)
1969 /* turn rule into problem */
1970 if (why >= solv->jobrules && why < solv->jobrules_end)
1971 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1972 /* return if problem already countains our rule */
1973 if (solv->problems.count)
1975 for (i = solv->problems.count - 1; i >= 0; i--)
1976 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1978 else if (solv->problems.elements[i] == why)
1981 queue_push(&solv->problems, why);
1985 /*-------------------------------------------------------------------
1987 * analyze_unsolvable
1989 * return: 1 - disabled some rules, try again
1994 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1996 Pool *pool = solv->pool;
1998 Map seen; /* global to speed things up? */
1999 Id d, v, vv, *dp, why;
2001 Id *decisionmap = solv->decisionmap;
2002 int oldproblemcount;
2003 int oldlearntpoolcount;
2006 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
2007 solv->stats_unsolvable++;
2008 oldproblemcount = solv->problems.count;
2009 oldlearntpoolcount = solv->learnt_pool.count;
2011 /* make room for proof index */
2012 /* must update it later, as analyze_unsolvable_rule would confuse
2013 * it with a rule index if we put the real value in already */
2014 queue_push(&solv->problems, 0);
2017 map_init(&seen, pool->nsolvables);
2018 queue_push(&solv->learnt_pool, r - solv->rules);
2020 analyze_unsolvable_rule(solv, r, &lastweak);
2021 d = r->d < 0 ? -r->d - 1 : r->d;
2022 dp = d ? pool->whatprovidesdata + d : 0;
2033 if (DECISIONMAP_TRUE(v)) /* the one true literal */
2035 vv = v > 0 ? v : -v;
2036 l = solv->decisionmap[vv];
2041 idx = solv->decisionq.count;
2044 v = solv->decisionq.elements[--idx];
2045 vv = v > 0 ? v : -v;
2046 if (!MAPTST(&seen, vv))
2048 why = solv->decisionq_why.elements[idx];
2049 queue_push(&solv->learnt_pool, why);
2050 r = solv->rules + why;
2051 analyze_unsolvable_rule(solv, r, &lastweak);
2052 d = r->d < 0 ? -r->d - 1 : r->d;
2053 dp = d ? pool->whatprovidesdata + d : 0;
2064 if (DECISIONMAP_TRUE(v)) /* the one true literal */
2066 vv = v > 0 ? v : -v;
2067 l = solv->decisionmap[vv];
2074 queue_push(&solv->problems, 0); /* mark end of this problem */
2078 /* disable last weak rule */
2079 solv->problems.count = oldproblemcount;
2080 solv->learnt_pool.count = oldlearntpoolcount;
2081 r = solv->rules + lastweak;
2082 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling ");
2083 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
2084 disablerule(solv, r);
2090 queue_push(&solv->learnt_pool, 0);
2091 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
2095 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
2096 disableproblem(solv, solv->problems.elements[i]);
2097 /* XXX: might want to enable all weak rules again */
2101 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
2106 /********************************************************************/
2107 /* Decision revert */
2109 /*-------------------------------------------------------------------
2112 * revert decision at level
2116 revert(Solver *solv, int level)
2118 Pool *pool = solv->pool;
2120 while (solv->decisionq.count)
2122 v = solv->decisionq.elements[solv->decisionq.count - 1];
2123 vv = v > 0 ? v : -v;
2124 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
2126 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
2127 if (v > 0 && solv->recommendations.count && v == solv->recommendations.elements[solv->recommendations.count - 1])
2128 solv->recommendations.count--;
2129 solv->decisionmap[vv] = 0;
2130 solv->decisionq.count--;
2131 solv->decisionq_why.count--;
2132 solv->propagate_index = solv->decisionq.count;
2134 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
2136 solv->branches.count--;
2137 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
2138 solv->branches.count--;
2140 solv->recommends_index = -1;
2144 /*-------------------------------------------------------------------
2146 * watch2onhighest - put watch2 on literal with highest level
2150 watch2onhighest(Solver *solv, Rule *r)
2155 d = r->d < 0 ? -r->d - 1 : r->d;
2157 return; /* binary rule, both watches are set */
2158 dp = solv->pool->whatprovidesdata + d;
2159 while ((v = *dp++) != 0)
2161 l = solv->decisionmap[v < 0 ? -v : v];
2173 /*-------------------------------------------------------------------
2177 * add free decision (solvable to install) to decisionq
2178 * increase level and propagate decision
2179 * return if no conflict.
2181 * in conflict case, analyze conflict rule, add resulting
2182 * rule to learnt rule set, make decision from learnt
2183 * rule (always unit) and re-propagate.
2185 * returns the new solver level or 0 if unsolvable
2190 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
2192 Pool *pool = solv->pool;
2201 solv->decisionmap[decision] = level;
2203 solv->decisionmap[-decision] = -level;
2204 queue_push(&solv->decisionq, decision);
2205 queue_push(&solv->decisionq_why, 0);
2209 r = propagate(solv, level);
2213 return analyze_unsolvable(solv, r, disablerules);
2214 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
2215 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
2216 assert(l > 0 && l < level);
2217 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
2219 revert(solv, level);
2220 r = addrule(solv, p, d); /* p requires d */
2222 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
2223 queue_push(&solv->learnt_why, why);
2226 /* at least 2 literals, needs watches */
2227 watch2onhighest(solv, r);
2228 addwatches_rule(solv, r);
2232 /* learnt rule is an assertion */
2233 queue_push(&solv->ruleassertions, r - solv->rules);
2235 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
2236 queue_push(&solv->decisionq, p);
2237 queue_push(&solv->decisionq_why, r - solv->rules);
2238 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
2240 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
2241 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
2242 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
2243 solver_printrule(solv, SAT_DEBUG_ANALYZE, r);
2250 /*-------------------------------------------------------------------
2252 * select and install
2254 * install best package from the queue. We add an extra package, inst, if
2255 * provided. See comment in weak install section.
2257 * returns the new solver level or 0 if unsolvable
2262 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
2264 Pool *pool = solv->pool;
2268 /* FIXME: do we really need that inst handling? */
2269 if (solv->distupgrade && inst && dq->count)
2271 policy_filter_unwanted(solv, dq, 0, POLICY_MODE_CHOOSE);
2272 for (i = 0; i < dq->count; i++)
2273 if (solvable_identical(pool, pool->solvables + inst, pool->solvables + dq->elements[i]))
2274 dq->elements[i] = inst;
2278 if (dq->count > 1 || inst)
2279 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
2285 /* choose the supplemented one */
2286 for (i = 0; i < dq->count; i++)
2287 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
2291 for (i = 1; i < dq->count; i++)
2292 queue_push(&solv->branches, dq->elements[i]);
2293 queue_push(&solv->branches, -level);
2297 p = dq->elements[i];
2299 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
2301 return setpropagatelearn(solv, level, p, disablerules);
2305 /********************************************************************/
2306 /* Main solver interface */
2309 /*-------------------------------------------------------------------
2312 * create solver structure
2314 * pool: all available solvables
2315 * installed: installed Solvables
2318 * Upon solving, rules are created to flag the Solvables
2319 * of the 'installed' Repo as installed.
2323 solver_create(Pool *pool, Repo *installed)
2326 solv = (Solver *)sat_calloc(1, sizeof(Solver));
2328 solv->installed = installed;
2330 queue_init(&solv->ruletojob);
2331 queue_init(&solv->decisionq);
2332 queue_init(&solv->decisionq_why);
2333 queue_init(&solv->problems);
2334 queue_init(&solv->suggestions);
2335 queue_init(&solv->recommendations);
2336 queue_init(&solv->orphaned);
2337 queue_init(&solv->learnt_why);
2338 queue_init(&solv->learnt_pool);
2339 queue_init(&solv->branches);
2340 queue_init(&solv->covenantq);
2341 queue_init(&solv->weakruleq);
2342 queue_init(&solv->ruleassertions);
2344 map_init(&solv->recommendsmap, pool->nsolvables);
2345 map_init(&solv->suggestsmap, pool->nsolvables);
2346 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
2347 solv->recommends_index = 0;
2349 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2351 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
2352 memset(solv->rules, 0, sizeof(Rule));
2358 /*-------------------------------------------------------------------
2364 solver_free(Solver *solv)
2366 queue_free(&solv->ruletojob);
2367 queue_free(&solv->decisionq);
2368 queue_free(&solv->decisionq_why);
2369 queue_free(&solv->learnt_why);
2370 queue_free(&solv->learnt_pool);
2371 queue_free(&solv->problems);
2372 queue_free(&solv->suggestions);
2373 queue_free(&solv->recommendations);
2374 queue_free(&solv->orphaned);
2375 queue_free(&solv->branches);
2376 queue_free(&solv->covenantq);
2377 queue_free(&solv->weakruleq);
2378 queue_free(&solv->ruleassertions);
2380 map_free(&solv->recommendsmap);
2381 map_free(&solv->suggestsmap);
2382 map_free(&solv->noupdate);
2383 map_free(&solv->weakrulemap);
2384 map_free(&solv->noobsoletes);
2386 sat_free(solv->decisionmap);
2387 sat_free(solv->rules);
2388 sat_free(solv->watches);
2389 sat_free(solv->obsoletes);
2390 sat_free(solv->obsoletes_data);
2395 /*-------------------------------------------------------------------
2399 * all rules have been set up, now actually run the solver
2404 run_solver(Solver *solv, int disablerules, int doweak)
2406 Queue dq; /* local decisionqueue */
2407 Queue dqs; /* local decisionqueue for supplements */
2413 Pool *pool = solv->pool;
2416 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2418 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2419 for (i = 1; i < solv->nrules; i++)
2420 solver_printruleclass(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2423 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2425 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2426 solver_printdecisions(solv);
2428 /* start SAT algorithm */
2430 systemlevel = level + 1;
2431 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2437 * here's the main loop:
2438 * 1) propagate new decisions (only needed for level 1)
2439 * 2) try to keep installed packages
2440 * 3) fulfill all unresolved rules
2441 * 4) install recommended packages
2442 * 5) minimalize solution if we had choices
2443 * if we encounter a problem, we rewind to a safe level and restart
2455 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2456 if ((r = propagate(solv, level)) != 0)
2458 if (analyze_unsolvable(solv, r, disablerules))
2465 if (level < systemlevel)
2467 POOL_DEBUG(SAT_DEBUG_STATS, "resolving job rules\n");
2468 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
2471 if (r->d < 0) /* ignore disabled rules */
2474 FOR_RULELITERALS(l, dp, r)
2478 if (solv->decisionmap[-l] <= 0)
2483 if (solv->decisionmap[l] > 0)
2485 if (solv->decisionmap[l] == 0)
2491 /* prune to installed if not updating */
2492 if (!solv->updatesystem && solv->installed && dq.count > 1)
2495 for (j = k = 0; j < dq.count; j++)
2497 Solvable *s = pool->solvables + dq.elements[j];
2498 if (s->repo == solv->installed)
2499 dq.elements[k++] = dq.elements[j];
2505 level = selectandinstall(solv, level, &dq, 0, disablerules);
2511 if (level <= olevel)
2514 systemlevel = level + 1;
2515 if (i < solv->jobrules_end)
2521 * installed packages
2524 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2526 if (!solv->updatesystem)
2529 * Normal run (non-updating)
2530 * Keep as many packages installed as possible
2532 POOL_DEBUG(SAT_DEBUG_STATS, "installing old packages\n");
2534 for (i = solv->installed->start; i < solv->installed->end; i++)
2536 s = pool->solvables + i;
2538 /* skip if not installed */
2539 if (s->repo != solv->installed)
2542 /* skip if already decided */
2543 if (solv->decisionmap[i] != 0)
2546 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2549 level = setpropagatelearn(solv, level, i, disablerules);
2551 if (level == 0) /* unsolvable */
2556 if (level <= olevel)
2559 if (i < solv->installed->end)
2563 POOL_DEBUG(SAT_DEBUG_STATS, "resolving update/feature rules\n");
2565 for (i = solv->installed->start, r = solv->rules + solv->updaterules; i < solv->installed->end; i++, r++)
2569 s = pool->solvables + i;
2571 /* skip if not installed (can't update) */
2572 if (s->repo != solv->installed)
2574 /* skip if already decided */
2575 if (solv->decisionmap[i] > 0)
2578 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2579 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2585 if (rr->d < 0) /* disabled -> look at feature rule ? */
2586 rr -= solv->installed->end - solv->installed->start;
2587 if (!rr->p) /* identical to update rule? */
2592 FOR_RULELITERALS(p, dp, rr)
2594 if (solv->decisionmap[p] > 0)
2596 if (solv->decisionmap[p] == 0)
2599 if (p || !dq.count) /* already fulfilled or empty */
2601 if (dq.elements[0] == i)
2602 inst = queue_shift(&dq);
2606 /* FIXME: it is handled a bit different because we do not want
2607 * to have it pruned just because it is not recommened.
2608 * we should not prune installed packages instead.
2610 level = selectandinstall(solv, level, &dq, inst, disablerules);
2616 if (level <= olevel)
2619 systemlevel = level + 1;
2620 if (i < solv->installed->end)
2624 if (level < systemlevel)
2625 systemlevel = level;
2631 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unresolved rules\n");
2632 for (i = 1, n = 1; ; i++, n++)
2634 if (n == solv->nrules)
2636 if (i == solv->nrules)
2638 r = solv->rules + i;
2639 if (r->d < 0) /* ignore disabled rules */
2644 /* binary or unary rule */
2645 /* need two positive undecided literals */
2646 if (r->p < 0 || r->w2 <= 0)
2648 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2650 queue_push(&dq, r->p);
2651 queue_push(&dq, r->w2);
2656 * all negative literals are installed
2657 * no positive literal is installed
2658 * i.e. the rule is not fulfilled and we
2659 * just need to decide on the positive literals
2663 if (solv->decisionmap[-r->p] <= 0)
2668 if (solv->decisionmap[r->p] > 0)
2670 if (solv->decisionmap[r->p] == 0)
2671 queue_push(&dq, r->p);
2673 dp = pool->whatprovidesdata + r->d;
2674 while ((p = *dp++) != 0)
2678 if (solv->decisionmap[-p] <= 0)
2683 if (solv->decisionmap[p] > 0)
2685 if (solv->decisionmap[p] == 0)
2692 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2694 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2695 solver_printruleclass(solv, SAT_DEBUG_PROPAGATE, r);
2697 /* dq.count < 2 cannot happen as this means that
2698 * the rule is unit */
2699 assert(dq.count > 1);
2702 level = selectandinstall(solv, level, &dq, 0, disablerules);
2708 if (level < systemlevel)
2711 } /* for(), decide */
2713 if (n != solv->nrules) /* continue if level < systemlevel */
2720 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
2723 for (i = 1; i < pool->nsolvables; i++)
2725 if (solv->decisionmap[i] < 0)
2727 if (solv->decisionmap[i] > 0)
2729 /* installed, check for recommends */
2730 Id *recp, rec, pp, p;
2731 s = pool->solvables + i;
2732 if (solv->ignorealreadyrecommended && s->repo == solv->installed)
2734 /* XXX need to special case AND ? */
2737 recp = s->repo->idarraydata + s->recommends;
2738 while ((rec = *recp++) != 0)
2741 FOR_PROVIDES(p, pp, rec)
2743 if (solv->decisionmap[p] > 0)
2748 else if (solv->decisionmap[p] == 0)
2750 queue_pushunique(&dq, p);
2758 s = pool->solvables + i;
2759 if (!s->supplements)
2761 if (!pool_installable(pool, s))
2763 if (!solver_is_supplementing(solv, s))
2765 if (solv->ignorealreadyrecommended && solv->installed)
2766 queue_pushunique(&dqs, i); /* needs filter */
2768 queue_pushunique(&dq, i);
2771 if (solv->ignorealreadyrecommended && dqs.count)
2773 /* turn off all new packages */
2774 for (i = 0; i < solv->decisionq.count; i++)
2776 p = solv->decisionq.elements[i];
2779 s = pool->solvables + p;
2780 if (s->repo && s->repo != solv->installed)
2781 solv->decisionmap[p] = -solv->decisionmap[p];
2783 /* filter out old supplements */
2784 for (i = 0; i < dqs.count; i++)
2786 p = dqs.elements[i];
2787 s = pool->solvables + p;
2788 if (!s->supplements)
2790 if (!solver_is_supplementing(solv, s))
2791 queue_pushunique(&dq, p);
2793 /* undo turning off */
2794 for (i = 0; i < solv->decisionq.count; i++)
2796 p = solv->decisionq.elements[i];
2799 s = pool->solvables + p;
2800 if (s->repo && s->repo != solv->installed)
2801 solv->decisionmap[p] = -solv->decisionmap[p];
2807 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2809 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2810 queue_push(&solv->recommendations, p);
2811 level = setpropagatelearn(solv, level, p, 0);
2816 if (solv->distupgrade && solv->installed)
2818 /* let's see if we can install some unsupported package */
2820 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unsupported packages\n");
2821 for (i = solv->installed->start, ri = 0; i < solv->installed->end; i++, ri++)
2823 s = pool->solvables + i;
2824 if (s->repo != solv->installed)
2826 if (solv->decisionmap[i])
2828 if (!solv->rules[solv->updaterules + ri].p && !solv->rules[solv->featurerules + ri].p)
2831 if (i < solv->installed->end)
2833 if (solv->distupgrade_removeunsupported)
2835 POOL_DEBUG(SAT_DEBUG_STATS, "removing unsupported %s\n", solvable2str(pool, pool->solvables + i));
2836 level = setpropagatelearn(solv, level, -i, 0);
2840 POOL_DEBUG(SAT_DEBUG_STATS, "keeping unsupported %s\n", solvable2str(pool, pool->solvables + i));
2841 level = setpropagatelearn(solv, level, i, 0);
2847 if (solv->solution_callback)
2849 solv->solution_callback(solv, solv->solution_callback_data);
2850 if (solv->branches.count)
2852 int i = solv->branches.count - 1;
2853 int l = -solv->branches.elements[i];
2855 if (solv->branches.elements[i - 1] < 0)
2857 p = solv->branches.elements[i];
2858 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
2860 for (j = i + 1; j < solv->branches.count; j++)
2861 queue_push(&dq, solv->branches.elements[j]);
2862 solv->branches.count = i;
2864 revert(solv, level);
2866 for (j = 0; j < dq.count; j++)
2867 queue_push(&solv->branches, dq.elements[j]);
2869 level = setpropagatelearn(solv, level, p, disablerules);
2877 /* all branches done, we're finally finished */
2881 /* minimization step */
2882 if (solv->branches.count)
2884 int l = 0, lasti = -1, lastl = -1;
2886 for (i = solv->branches.count - 1; i >= 0; i--)
2888 p = solv->branches.elements[i];
2891 else if (p > 0 && solv->decisionmap[p] > l + 1)
2899 /* kill old solvable so that we do not loop */
2900 p = solv->branches.elements[lasti];
2901 solv->branches.elements[lasti] = 0;
2902 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
2905 revert(solv, level);
2907 level = setpropagatelearn(solv, level, p, disablerules);
2918 POOL_DEBUG(SAT_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable\n", solv->stats_learned, solv->stats_unsolvable);
2920 POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
2926 /*-------------------------------------------------------------------
2930 * at this point, all rules that led to conflicts are disabled.
2931 * we re-enable all rules of a problem set but rule "sug", then
2932 * continue to disable more rules until there as again a solution.
2935 /* FIXME: think about conflicting assertions */
2938 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2940 Pool *pool = solv->pool;
2946 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2948 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
2949 for (i = 0; problem[i]; i++)
2951 if (problem[i] == sug)
2952 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
2953 solver_printproblem(solv, problem[i]);
2956 queue_init(&disabled);
2957 queue_empty(refined);
2958 queue_push(refined, sug);
2960 /* re-enable all problem rules with the exception of "sug"(gestion) */
2964 for (i = 0; problem[i]; i++)
2965 if (problem[i] != sug)
2966 enableproblem(solv, problem[i]);
2969 disableupdaterules(solv, job, -(sug + 1));
2970 else if (sug >= solv->updaterules && sug < solv->updaterules_end)
2972 /* enable feature rule */
2973 Rule *r = solv->rules + solv->featurerules + (sug - solv->updaterules);
2975 enablerule(solv, r);
2978 enableweakrules(solv);
2982 int njob, nfeature, nupdate;
2983 queue_empty(&solv->problems);
2984 revert(solv, 1); /* XXX no longer needed? */
2987 if (!solv->problems.count)
2988 run_solver(solv, 0, 0);
2990 if (!solv->problems.count)
2992 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
2993 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2994 solver_printdecisions(solv);
2995 break; /* great, no more problems */
2997 disabledcnt = disabled.count;
2998 /* start with 1 to skip over proof index */
2999 njob = nfeature = nupdate = 0;
3000 for (i = 1; i < solv->problems.count - 1; i++)
3002 /* ignore solutions in refined */
3003 v = solv->problems.elements[i];
3005 break; /* end of problem reached */
3006 for (j = 0; problem[j]; j++)
3007 if (problem[j] != sug && problem[j] == v)
3011 if (v >= solv->featurerules && v < solv->featurerules_end)
3017 queue_push(&disabled, v);
3019 if (disabled.count == disabledcnt)
3021 /* no solution found, this was an invalid suggestion! */
3022 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
3026 if (!njob && nupdate && nfeature)
3028 /* got only update rules, filter out feature rules */
3029 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "throwing away feature rules\n");
3030 for (i = j = disabledcnt; i < disabled.count; i++)
3032 v = disabled.elements[i];
3033 if (v < solv->featurerules || v >= solv->featurerules_end)
3034 disabled.elements[j++] = v;
3039 if (disabled.count == disabledcnt + 1)
3041 /* just one suggestion, add it to refined list */
3042 v = disabled.elements[disabledcnt];
3044 queue_push(refined, v); /* do not record feature rules */
3045 disableproblem(solv, v);
3046 if (v >= solv->updaterules && v < solv->updaterules_end)
3048 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
3050 enablerule(solv, r); /* enable corresponding feature rule */
3053 disableupdaterules(solv, job, -(v + 1));
3057 /* more than one solution, disable all */
3058 /* do not push anything on refine list, as we do not know which solution to choose */
3059 /* thus, the user will get another problem if he selects this solution, where he
3060 * can choose the right one */
3061 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
3063 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
3064 for (i = disabledcnt; i < disabled.count; i++)
3065 solver_printproblem(solv, disabled.elements[i]);
3067 for (i = disabledcnt; i < disabled.count; i++)
3069 v = disabled.elements[i];
3070 disableproblem(solv, v);
3071 if (v >= solv->updaterules && v < solv->updaterules_end)
3073 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
3075 enablerule(solv, r);
3080 /* all done, get us back into the same state as before */
3081 /* enable refined rules again */
3082 for (i = 0; i < disabled.count; i++)
3083 enableproblem(solv, disabled.elements[i]);
3084 /* disable problem rules again */
3087 for (i = 0; problem[i]; i++)
3088 enableproblem(solv, problem[i]);
3089 disableupdaterules(solv, job, -1);
3091 /* disable problem rules again */
3092 for (i = 0; problem[i]; i++)
3093 disableproblem(solv, problem[i]);
3094 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
3098 /*-------------------------------------------------------------------
3099 * sorting helper for problems
3103 problems_sortcmp(const void *ap, const void *bp)
3105 Id a = *(Id *)ap, b = *(Id *)bp;
3114 /*-------------------------------------------------------------------
3119 problems_sort(Solver *solv)
3122 if (!solv->problems.count)
3124 for (i = j = 1; i < solv->problems.count; i++)
3126 if (!solv->problems.elements[i])
3129 qsort(solv->problems.elements + j, i - j, sizeof(Id), problems_sortcmp);
3130 if (++i == solv->problems.count)
3138 /*-------------------------------------------------------------------
3139 * convert problems to solutions
3143 problems_to_solutions(Solver *solv, Queue *job)
3145 Pool *pool = solv->pool;
3153 if (!solv->problems.count)
3155 problems_sort(solv);
3156 queue_clone(&problems, &solv->problems);
3157 queue_init(&solution);
3158 queue_init(&solutions);
3159 /* copy over proof index */
3160 queue_push(&solutions, problems.elements[0]);
3161 problem = problems.elements + 1;
3162 for (i = 1; i < problems.count; i++)
3164 Id v = problems.elements[i];
3167 /* mark end of this problem */
3168 queue_push(&solutions, 0);
3169 queue_push(&solutions, 0);
3170 if (i + 1 == problems.count)
3172 /* copy over proof of next problem */
3173 queue_push(&solutions, problems.elements[i + 1]);
3175 problem = problems.elements + i + 1;
3178 refine_suggestion(solv, job, problem, v, &solution);
3179 if (!solution.count)
3180 continue; /* this solution didn't work out */
3183 for (j = 0; j < solution.count; j++)
3185 why = solution.elements[j];
3186 /* must be either job descriptor or update rule */
3187 assert(why < 0 || (why >= solv->updaterules && why < solv->updaterules_end));
3189 solver_printproblem(solv, why);
3193 /* job descriptor */
3194 queue_push(&solutions, 0);
3195 queue_push(&solutions, -why);
3199 /* update rule, find replacement package */
3200 Id p, d, *dp, rp = 0;
3202 p = solv->installed->start + (why - solv->updaterules);
3203 rr = solv->rules + solv->featurerules + (why - solv->updaterules);
3205 rr = solv->rules + why;
3206 if (solv->distupgrade && solv->rules[why].p != p && solv->decisionmap[p] > 0)
3208 /* distupgrade case, allow to keep old package */
3209 queue_push(&solutions, p);
3210 queue_push(&solutions, p);
3214 if (solv->decisionmap[p] > 0)
3215 continue; /* false alarm, turned out we can keep the package */
3218 d = rr->d < 0 ? -rr->d - 1 : rr->d;
3221 if (solv->decisionmap[rr->w2] > 0 && pool->solvables[rr->w2].repo != solv->installed)
3226 for (dp = pool->whatprovidesdata + d; *dp; dp++)
3228 if (solv->decisionmap[*dp] > 0 && pool->solvables[*dp].repo != solv->installed)
3236 queue_push(&solutions, p);
3237 queue_push(&solutions, rp);
3241 /* mark end of this solution */
3244 queue_push(&solutions, 0);
3245 queue_push(&solutions, 0);
3249 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "Oops, everything was fine?\n");
3252 queue_free(&solution);
3253 queue_free(&problems);
3254 /* copy queue over to solutions */
3255 queue_free(&solv->problems);
3256 queue_clone(&solv->problems, &solutions);
3258 /* bring solver back into problem state */
3259 revert(solv, 1); /* XXX move to reset_solver? */
3262 assert(solv->problems.count == solutions.count);
3263 queue_free(&solutions);
3267 /*-------------------------------------------------------------------
3271 * advance to next problem
3275 solver_next_problem(Solver *solv, Id problem)
3279 return solv->problems.count ? 1 : 0;
3280 pp = solv->problems.elements + problem;
3281 while (pp[0] || pp[1])
3285 while (pp[0] || pp[1])
3290 problem = pp - solv->problems.elements;
3291 if (problem >= solv->problems.count)
3297 /*-------------------------------------------------------------------
3303 solver_next_solution(Solver *solv, Id problem, Id solution)
3309 pp = solv->problems.elements + solution;
3310 return pp[0] || pp[1] ? solution : 0;
3312 pp = solv->problems.elements + solution;
3313 while (pp[0] || pp[1])
3316 solution = pp - solv->problems.elements;
3317 return pp[0] || pp[1] ? solution : 0;
3321 /*-------------------------------------------------------------------
3323 * solution element iterator
3327 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
3330 element = element ? element + 2 : solution;
3331 pp = solv->problems.elements + element;
3332 if (!(pp[0] || pp[1]))
3340 /*-------------------------------------------------------------------
3342 * Retrieve information about a problematic rule
3344 * this is basically the reverse of addrpmrulesforsolvable
3348 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
3350 Pool *pool = solv->pool;
3351 Repo *installed = solv->installed;
3355 Id p, d, w2, pp, req, *reqp, con, *conp, obs, *obsp, *dp;
3358 if (rid >= solv->jobrules && rid < solv->jobrules_end)
3361 r = solv->rules + rid;
3362 p = solv->ruletojob.elements[rid - solv->jobrules];
3363 *depp = job->elements[p + 1];
3365 *targetp = job->elements[p];
3366 d = r->d < 0 ? -r->d - 1 : r->d;
3367 if (d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && (job->elements[p] & SOLVER_SELECTMASK) != SOLVER_SOLVABLE_ONE_OF)
3368 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
3369 return SOLVER_PROBLEM_JOB_RULE;
3371 if (rid >= solv->updaterules && rid < solv->updaterules_end)
3374 *sourcep = solv->installed->start + (rid - solv->updaterules);
3376 return SOLVER_PROBLEM_UPDATE_RULE;
3378 assert(rid < solv->rpmrules_end);
3379 r = solv->rules + rid;
3381 d = r->d < 0 ? -r->d - 1 : r->d;
3382 if (d == 0 && r->w2 == 0)
3384 /* a rpm rule assertion */
3385 s = pool->solvables - r->p;
3386 if (installed && !solv->fixsystem && s->repo == installed)
3388 assert(!dontfix); /* dontfix packages never have a neg assertion */
3391 /* see why the package is not installable */
3392 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
3395 return SOLVER_PROBLEM_NOT_INSTALLABLE;
3397 /* check requires */
3400 reqp = s->repo->idarraydata + s->requires;
3401 while ((req = *reqp++) != 0)
3403 if (req == SOLVABLE_PREREQMARKER)
3405 dp = pool->whatprovidesdata + pool_whatprovides(pool, req);
3412 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
3415 if (!solv->allowselfconflicts && s->conflicts)
3417 conp = s->repo->idarraydata + s->conflicts;
3418 while ((con = *conp++) != 0)
3419 FOR_PROVIDES(p, pp, con)
3423 return SOLVER_PROBLEM_SELF_CONFLICT;
3426 /* should never happen */
3428 return SOLVER_PROBLEM_RPM_RULE;
3430 s = pool->solvables - r->p;
3431 if (installed && !solv->fixsystem && s->repo == installed)
3434 if (d && pool->whatprovidesdata[d] < 0)
3436 /* rule looks like -p|-c|x|x|x..., we only create this for patches with multiversion */
3437 /* reduce it to -p|-c case */
3438 w2 = pool->whatprovidesdata[d];
3440 if (d == 0 && w2 < 0)
3442 /* a package conflict */
3443 Solvable *s2 = pool->solvables - w2;
3446 if (installed && !solv->fixsystem && s2->repo == installed)
3449 /* if both packages have the same name and at least one of them
3450 * is not installed, they conflict */
3451 if (s->name == s2->name && !(installed && s->repo == installed && s2->repo == installed))
3453 /* also check noobsoletes map */
3454 if ((s->evr == s2->evr && s->arch == s2->arch) || !solv->noobsoletes.size
3455 || ((!installed || s->repo != installed) && !MAPTST(&solv->noobsoletes, -r->p))
3456 || ((!installed || s2->repo != installed) && !MAPTST(&solv->noobsoletes, -w2)))
3461 return SOLVER_PROBLEM_SAME_NAME;
3465 /* check conflicts in both directions */
3468 conp = s->repo->idarraydata + s->conflicts;
3469 while ((con = *conp++) != 0)
3471 FOR_PROVIDES(p, pp, con)
3473 if (dontfix && pool->solvables[p].repo == installed)
3480 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3486 conp = s2->repo->idarraydata + s2->conflicts;
3487 while ((con = *conp++) != 0)
3489 FOR_PROVIDES(p, pp, con)
3491 if (dontfix2 && pool->solvables[p].repo == installed)
3498 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3502 /* check obsoletes in both directions */
3503 if ((!installed || s->repo != installed) && s->obsoletes && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->p)))
3505 obsp = s->repo->idarraydata + s->obsoletes;
3506 while ((obs = *obsp++) != 0)
3508 FOR_PROVIDES(p, pp, obs)
3512 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
3517 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3521 if ((!installed || s2->repo != installed) && s2->obsoletes && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -w2)))
3523 obsp = s2->repo->idarraydata + s2->obsoletes;
3524 while ((obs = *obsp++) != 0)
3526 FOR_PROVIDES(p, pp, obs)
3530 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
3535 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3539 if (solv->implicitobsoleteusesprovides && (!installed || s->repo != installed) && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->p)))
3541 FOR_PROVIDES(p, pp, s->name)
3548 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3551 if (solv->implicitobsoleteusesprovides && (!installed || s2->repo != installed) && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -w2)))
3553 FOR_PROVIDES(p, pp, s2->name)
3560 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3563 /* all cases checked, can't happen */
3567 return SOLVER_PROBLEM_RPM_RULE;
3569 /* simple requires */
3572 reqp = s->repo->idarraydata + s->requires;
3573 while ((req = *reqp++) != 0)
3575 if (req == SOLVABLE_PREREQMARKER)
3577 dp = pool->whatprovidesdata + pool_whatprovides(pool, req);
3580 if (*dp == r->w2 && dp[1] == 0)
3583 else if (dp - pool->whatprovidesdata == d)
3591 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
3594 /* all cases checked, can't happen */
3598 return SOLVER_PROBLEM_RPM_RULE;
3602 /*-------------------------------------------------------------------
3608 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3611 Id lreqr, lconr, lsysr, ljobr;
3615 lreqr = lconr = lsysr = ljobr = 0;
3616 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3619 if (rid >= solv->learntrules)
3620 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3621 else if (rid >= solv->jobrules && rid < solv->jobrules_end)
3626 else if (rid >= solv->updaterules && rid < solv->updaterules_end)
3633 assert(rid < solv->rpmrules_end);
3634 r = solv->rules + rid;
3635 d = r->d < 0 ? -r->d - 1 : r->d;
3636 if (!d && r->w2 < 0)
3643 if (!d && r->w2 == 0 && !reqassert)
3645 /* prefer assertions (XXX: bad idea?) */
3651 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed)
3653 /* prefer rules of installed packages */
3654 Id op = *reqrp >= 0 ? solv->rules[*reqrp].p : -*reqrp;
3655 if (op <= 0 || solv->pool->solvables[op].repo != solv->installed)
3661 if (!*reqrp && lreqr)
3663 if (!*conrp && lconr)
3665 if (!*jobrp && ljobr)
3667 if (!*sysrp && lsysr)
3672 /*-------------------------------------------------------------------
3676 * search for a rule that describes the problem to the
3677 * user. A pretty hopeless task, actually. We currently
3678 * prefer simple requires.
3682 solver_findproblemrule(Solver *solv, Id problem)
3684 Id reqr, conr, sysr, jobr;
3685 Id idx = solv->problems.elements[problem - 1];
3686 reqr = conr = sysr = jobr = 0;
3687 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3700 /*-------------------------------------------------------------------
3702 * create reverse obsoletes map for installed solvables
3704 * for each installed solvable find which packages with *different* names
3705 * obsolete the solvable.
3706 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3710 create_obsolete_index(Solver *solv)
3712 Pool *pool = solv->pool;
3714 Repo *installed = solv->installed;
3715 Id p, pp, obs, *obsp, *obsoletes, *obsoletes_data;
3718 if (!installed || !installed->nsolvables)
3720 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
3721 for (i = 1; i < pool->nsolvables; i++)
3723 s = pool->solvables + i;
3726 if (!pool_installable(pool, s))
3728 obsp = s->repo->idarraydata + s->obsoletes;
3729 while ((obs = *obsp++) != 0)
3731 FOR_PROVIDES(p, pp, obs)
3733 if (pool->solvables[p].repo != installed)
3735 if (pool->solvables[p].name == s->name)
3737 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
3739 obsoletes[p - installed->start]++;
3744 for (i = 0; i < installed->nsolvables; i++)
3747 n += obsoletes[i] + 1;
3750 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
3751 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
3752 for (i = pool->nsolvables - 1; i > 0; i--)
3754 s = pool->solvables + i;
3757 if (!pool_installable(pool, s))
3759 obsp = s->repo->idarraydata + s->obsoletes;
3760 while ((obs = *obsp++) != 0)
3762 FOR_PROVIDES(p, pp, obs)
3764 if (pool->solvables[p].repo != installed)
3766 if (pool->solvables[p].name == s->name)
3768 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
3770 p -= installed->start;
3771 if (obsoletes_data[obsoletes[p]] != i)
3772 obsoletes_data[--obsoletes[p]] = i;
3779 /*-------------------------------------------------------------------
3781 * remove disabled conflicts
3785 removedisabledconflicts(Solver *solv, Queue *removed)
3787 Pool *pool = solv->pool;
3792 Id *decisionmap = solv->decisionmap;
3794 POOL_DEBUG(SAT_DEBUG_STATS, "removedisabledconflicts\n");
3795 queue_empty(removed);
3796 for (i = 0; i < solv->decisionq.count; i++)
3798 p = solv->decisionq.elements[i];
3801 /* a conflict. we never do conflicts on free decisions, so there
3802 * must have been an unit rule */
3803 why = solv->decisionq_why.elements[i];
3805 r = solv->rules + why;
3806 if (r->d < 0 && decisionmap[-p])
3808 /* rule is now disabled, remove from decisionmap */
3809 POOL_DEBUG(SAT_DEBUG_STATS, "removing conflict for package %s[%d]\n", solvable2str(pool, pool->solvables - p), -p);
3810 queue_push(removed, -p);
3811 queue_push(removed, decisionmap[-p]);
3812 decisionmap[-p] = 0;
3815 if (!removed->count)
3817 /* we removed some confliced packages. some of them might still
3818 * be in conflict, so search for unit rules and re-conflict */
3820 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
3822 if (i == solv->nrules)
3825 r = solv->rules + i;
3831 if (r->p < 0 && !decisionmap[-r->p])
3837 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
3839 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
3844 if (r->p < 0 && decisionmap[-r->p] == 0)
3846 if (new || DECISIONMAP_FALSE(r->p))
3848 dp = pool->whatprovidesdata + r->d;
3849 while ((p = *dp++) != 0)
3851 if (new && p == new)
3853 if (p < 0 && decisionmap[-p] == 0)
3862 else if (!DECISIONMAP_FALSE(p))
3872 POOL_DEBUG(SAT_DEBUG_STATS, "re-conflicting package %s[%d]\n", solvable2str(pool, pool->solvables - new), -new);
3873 decisionmap[-new] = -1;
3875 n = 0; /* redo all rules */
3881 /*-------------------------------------------------------------------
3883 * weaken solvable dependencies
3887 weaken_solvable_deps(Solver *solv, Id p)
3892 for (i = 1, r = solv->rules + i; i < solv->rpmrules_end; i++, r++)
3896 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3897 continue; /* conflict */
3898 queue_push(&solv->weakruleq, i);
3902 /********************************************************************/
3912 solver_solve(Solver *solv, Queue *job)
3914 Pool *pool = solv->pool;
3915 Repo *installed = solv->installed;
3918 Map addedmap; /* '1' == have rpm-rules for solvable */
3919 Map installcandidatemap;
3920 Id how, what, select, name, weak, p, pp, d;
3926 POOL_DEBUG(SAT_DEBUG_STATS, "solver started\n");
3927 POOL_DEBUG(SAT_DEBUG_STATS, "fixsystem=%d updatesystem=%d dosplitprovides=%d, noupdateprovide=%d\n", solv->fixsystem, solv->updatesystem, solv->dosplitprovides, solv->noupdateprovide);
3928 POOL_DEBUG(SAT_DEBUG_STATS, "distupgrade=%d distupgrade_removeunsupported=%d\n", solv->distupgrade, solv->distupgrade_removeunsupported);
3929 POOL_DEBUG(SAT_DEBUG_STATS, "allowuninstall=%d, allowdowngrade=%d, allowarchchange=%d, allowvendorchange=%d\n", solv->allowuninstall, solv->allowdowngrade, solv->allowarchchange, solv->allowvendorchange);
3930 POOL_DEBUG(SAT_DEBUG_STATS, "promoteepoch=%d, allowvirtualconflicts=%d, allowselfconflicts=%d\n", pool->promoteepoch, solv->allowvirtualconflicts, solv->allowselfconflicts);
3931 POOL_DEBUG(SAT_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d\n", solv->obsoleteusesprovides, solv->implicitobsoleteusesprovides);
3932 POOL_DEBUG(SAT_DEBUG_STATS, "dontinstallrecommended=%d, ignorealreadyrecommended=%d, dontshowinstalledrecommended=%d\n", solv->dontinstallrecommended, solv->ignorealreadyrecommended, solv->dontshowinstalledrecommended);
3933 /* create whatprovides if not already there */
3934 if (!pool->whatprovides)
3935 pool_createwhatprovides(pool);
3937 /* create obsolete index if needed */
3938 create_obsolete_index(solv);
3941 * create basic rule set of all involved packages
3942 * use addedmap bitmap to make sure we don't create rules twice
3946 /* create noobsolete map if needed */
3947 for (i = 0; i < job->count; i += 2)
3949 how = job->elements[i] & ~SOLVER_WEAK;
3950 if ((how & SOLVER_JOBMASK) != SOLVER_NOOBSOLETES)
3952 what = job->elements[i + 1];
3953 select = how & SOLVER_SELECTMASK;
3954 if (!solv->noobsoletes.size)
3955 map_init(&solv->noobsoletes, pool->nsolvables);
3956 FOR_JOB_SELECT(p, pp, select, what)
3957 MAPSET(&solv->noobsoletes, p);
3960 map_init(&addedmap, pool->nsolvables);
3961 map_init(&installcandidatemap, pool->nsolvables);
3965 * always install our system solvable
3967 MAPSET(&addedmap, SYSTEMSOLVABLE);
3968 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3969 queue_push(&solv->decisionq_why, 0);
3970 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
3973 * create rules for all package that could be involved with the solving
3974 * so called: rpm rules
3979 oldnrules = solv->nrules;
3980 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
3981 FOR_REPO_SOLVABLES(installed, p, s)
3982 addrpmrulesforsolvable(solv, s, &addedmap);
3983 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3984 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
3985 oldnrules = solv->nrules;
3986 FOR_REPO_SOLVABLES(installed, p, s)
3987 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3988 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3992 * create rules for all packages involved in the job
3993 * (to be installed or removed)
3996 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
3997 oldnrules = solv->nrules;
3998 for (i = 0; i < job->count; i += 2)
4000 how = job->elements[i];
4001 what = job->elements[i + 1];
4002 select = how & SOLVER_SELECTMASK;
4004 switch (how & SOLVER_JOBMASK)
4006 case SOLVER_INSTALL:
4007 FOR_JOB_SELECT(p, pp, select, what)
4009 MAPSET(&installcandidatemap, p);
4010 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
4014 /* FIXME: semantics? */
4015 FOR_JOB_SELECT(p, pp, select, what)
4016 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
4020 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
4022 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
4024 oldnrules = solv->nrules;
4027 * add rules for suggests, enhances
4029 addrpmrulesforweak(solv, &addedmap);
4030 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
4032 IF_POOLDEBUG (SAT_DEBUG_STATS)
4034 int possible = 0, installable = 0;
4035 for (i = 1; i < pool->nsolvables; i++)
4037 if (pool_installable(pool, pool->solvables + i))
4039 if (MAPTST(&addedmap, i))
4042 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
4046 * first pass done, we now have all the rpm rules we need.
4047 * unify existing rules before going over all job rules and
4049 * at this point the system is always solvable,
4050 * as an empty system (remove all packages) is a valid solution
4053 unifyrules(solv); /* remove duplicate rpm rules */
4055 solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
4057 solv->directdecisions = solv->decisionq.count;
4058 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
4061 * create feature rules
4063 * foreach installed:
4064 * create assertion (keep installed, if no update available)
4066 * create update rule (A|update1(A)|update2(A)|...)
4068 * those are used later on to keep a version of the installed packages in
4072 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add feature rules ***\n");
4073 solv->featurerules = solv->nrules; /* mark start of feature rules */
4076 /* foreach possibly installed solvable */
4077 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
4079 if (s->repo != installed)
4081 addrule(solv, 0, 0); /* create dummy rule */
4084 addupdaterule(solv, s, 1); /* allow s to be updated */
4087 * assert one rule per installed solvable,
4088 * either an assertion (A)
4089 * or a possible update (A|update1(A)|update2(A)|...)
4091 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
4093 solv->featurerules_end = solv->nrules;
4096 * Add update rules for installed solvables
4098 * almost identical to feature rules
4099 * except that downgrades/archchanges/vendorchanges are not allowed
4102 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add update rules ***\n");
4103 solv->updaterules = solv->nrules;
4106 { /* foreach installed solvables */
4107 /* we create all update rules, but disable some later on depending on the job */
4108 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
4112 if (s->repo != installed)
4114 addrule(solv, 0, 0); /* create dummy rule */
4117 addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
4119 * check for and remove duplicate
4121 r = solv->rules + solv->nrules - 1; /* r: update rule */
4122 sr = r - (installed->end - installed->start); /* sr: feature rule */
4123 /* it's orphaned if there is no feature rule or the feature rule
4124 * consists just of the installed package */
4125 if (!sr->p || (sr->p == i && !sr->d && !sr->w2))
4126 queue_push(&solv->orphaned, i);
4129 assert(!sr->p); /* can't have feature rule and no update rule */
4132 unifyrules_sortcmp_data = pool;
4133 if (!unifyrules_sortcmp(r, sr))
4135 /* identical rule, kill unneeded rule */
4136 if (solv->allowuninstall)
4138 /* keep feature rule, make it weak */
4139 memset(r, 0, sizeof(*r));
4140 queue_push(&solv->weakruleq, sr - solv->rules);
4144 /* keep update rule */
4145 memset(sr, 0, sizeof(*sr));
4148 else if (solv->allowuninstall)
4150 /* make both feature and update rule weak */
4151 queue_push(&solv->weakruleq, r - solv->rules);
4152 queue_push(&solv->weakruleq, sr - solv->rules);
4155 disablerule(solv, sr);
4157 /* consistency check: we added a rule for _every_ installed solvable */
4158 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
4160 solv->updaterules_end = solv->nrules;
4164 * now add all job rules
4167 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
4169 solv->jobrules = solv->nrules;
4170 for (i = 0; i < job->count; i += 2)
4172 oldnrules = solv->nrules;
4174 how = job->elements[i];
4175 what = job->elements[i + 1];
4176 weak = how & SOLVER_WEAK;
4177 select = how & SOLVER_SELECTMASK;
4178 switch (how & SOLVER_JOBMASK)
4180 case SOLVER_INSTALL:
4181 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4182 if (select == SOLVER_SOLVABLE)
4190 FOR_JOB_SELECT(p, pp, select, what)
4194 /* no candidate found, make this an impossible rule */
4195 queue_push(&q, -SYSTEMSOLVABLE);
4197 p = queue_shift(&q); /* get first candidate */
4198 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
4200 addrule(solv, p, d); /* add install rule */
4201 queue_push(&solv->ruletojob, i);
4203 queue_push(&solv->weakruleq, solv->nrules - 1);
4206 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4207 if (select == SOLVER_SOLVABLE && solv->installed && pool->solvables[what].repo == solv->installed)
4209 /* special case for "erase a specific solvable": we also
4210 * erase all other solvables with that name, so that they
4211 * don't get picked up as replacement */
4212 name = pool->solvables[what].name;
4213 FOR_PROVIDES(p, pp, name)
4217 s = pool->solvables + p;
4218 if (s->name != name)
4220 /* keep other versions installed */
4221 if (s->repo == solv->installed)
4223 /* keep installcandidates of other jobs */
4224 if (MAPTST(&installcandidatemap, p))
4226 addrule(solv, -p, 0); /* remove by Id */
4227 queue_push(&solv->ruletojob, i);
4229 queue_push(&solv->weakruleq, solv->nrules - 1);
4232 FOR_JOB_SELECT(p, pp, select, what)
4234 addrule(solv, -p, 0);
4235 queue_push(&solv->ruletojob, i);
4237 queue_push(&solv->weakruleq, solv->nrules - 1);
4242 POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4243 if (select != SOLVER_SOLVABLE)
4245 s = pool->solvables + what;
4246 POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solvable2str(pool, s));
4247 addupdaterule(solv, s, 0);
4248 queue_push(&solv->ruletojob, i);
4250 queue_push(&solv->weakruleq, solv->nrules - 1);
4252 case SOLVER_WEAKENDEPS:
4253 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4254 if (select != SOLVER_SOLVABLE)
4256 s = pool->solvables + what;
4257 weaken_solvable_deps(solv, what);
4259 case SOLVER_NOOBSOLETES:
4260 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sno obsolete %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4263 POOL_DEBUG(SAT_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4264 FOR_JOB_SELECT(p, pp, select, what)
4266 s = pool->solvables + p;
4267 if (installed && s->repo == installed)
4268 addrule(solv, p, 0);
4270 addrule(solv, -p, 0);
4271 queue_push(&solv->ruletojob, i);
4273 queue_push(&solv->weakruleq, solv->nrules - 1);
4277 POOL_DEBUG(SAT_DEBUG_JOB, "job: unknown job\n");
4285 IF_POOLDEBUG (SAT_DEBUG_JOB)
4288 if (solv->nrules == oldnrules)
4289 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created\n");
4290 for (j = oldnrules; j < solv->nrules; j++)
4292 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
4293 solver_printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
4297 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
4298 solv->jobrules_end = solv->nrules;
4300 /* all rules created
4301 * --------------------------------------------------------------
4302 * prepare for solving
4305 /* free unneeded memory */
4306 map_free(&addedmap);
4307 map_free(&installcandidatemap);
4310 /* create weak map */
4311 map_init(&solv->weakrulemap, solv->nrules);
4312 for (i = 0; i < solv->weakruleq.count; i++)
4314 p = solv->weakruleq.elements[i];
4315 MAPSET(&solv->weakrulemap, p);
4318 /* all new rules are learnt after this point */
4319 solv->learntrules = solv->nrules;
4321 /* create assertion index. it is only used to speed up
4322 * makeruledecsions() a bit */
4323 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
4324 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
4325 queue_push(&solv->ruleassertions, i);
4327 /* disable update rules that conflict with our job */
4328 disableupdaterules(solv, job, -1);
4330 /* make decisions based on job/update assertions */
4331 makeruledecisions(solv);
4333 /* create watches chains */
4336 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
4339 * ********************************************
4341 * ********************************************
4344 run_solver(solv, 1, solv->dontinstallrecommended ? 0 : 1);
4348 /* disable all erase jobs (including weak "keep uninstalled" rules) */
4349 for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++)
4351 if (r->d < 0) /* disabled ? */
4353 if (r->p > 0) /* install job? */
4355 disablerule(solv, r);
4361 enabledisablelearntrules(solv);
4362 removedisabledconflicts(solv, &redoq);
4366 * find recommended packages
4369 /* if redoq.count == 0 we already found all recommended in the
4371 if (redoq.count || solv->dontinstallrecommended || !solv->dontshowinstalledrecommended || solv->ignorealreadyrecommended)
4373 Id rec, *recp, p, pp;
4375 /* create map of all recommened packages */
4376 solv->recommends_index = -1;
4377 MAPZERO(&solv->recommendsmap);
4378 for (i = 0; i < solv->decisionq.count; i++)
4380 p = solv->decisionq.elements[i];
4383 s = pool->solvables + p;
4386 recp = s->repo->idarraydata + s->recommends;
4387 while ((rec = *recp++) != 0)
4389 FOR_PROVIDES(p, pp, rec)
4390 if (solv->decisionmap[p] > 0)
4394 if (!solv->dontshowinstalledrecommended)
4396 FOR_PROVIDES(p, pp, rec)
4397 if (solv->decisionmap[p] > 0)
4398 MAPSET(&solv->recommendsmap, p);
4400 continue; /* p != 0: already fulfilled */
4402 FOR_PROVIDES(p, pp, rec)
4403 MAPSET(&solv->recommendsmap, p);
4407 for (i = 1; i < pool->nsolvables; i++)
4409 if (solv->decisionmap[i] < 0)
4411 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
4413 s = pool->solvables + i;
4414 if (!MAPTST(&solv->recommendsmap, i))
4416 if (!s->supplements)
4418 if (!pool_installable(pool, s))
4420 if (!solver_is_supplementing(solv, s))
4423 if (solv->dontinstallrecommended)
4424 queue_push(&solv->recommendations, i);
4426 queue_pushunique(&solv->recommendations, i);
4428 /* we use MODE_SUGGEST here so that repo prio is ignored */
4429 policy_filter_unwanted(solv, &solv->recommendations, 0, POLICY_MODE_SUGGEST);
4433 * find suggested packages
4438 Id sug, *sugp, p, pp;
4440 /* create map of all suggests that are still open */
4441 solv->recommends_index = -1;
4442 MAPZERO(&solv->suggestsmap);
4443 for (i = 0; i < solv->decisionq.count; i++)
4445 p = solv->decisionq.elements[i];
4448 s = pool->solvables + p;
4451 sugp = s->repo->idarraydata + s->suggests;
4452 while ((sug = *sugp++) != 0)
4454 FOR_PROVIDES(p, pp, sug)
4455 if (solv->decisionmap[p] > 0)
4459 if (!solv->dontshowinstalledrecommended)
4461 FOR_PROVIDES(p, pp, sug)
4462 if (solv->decisionmap[p] > 0)
4463 MAPSET(&solv->suggestsmap, p);
4465 continue; /* already fulfilled */
4467 FOR_PROVIDES(p, pp, sug)
4468 MAPSET(&solv->suggestsmap, p);
4472 for (i = 1; i < pool->nsolvables; i++)
4474 if (solv->decisionmap[i] < 0)
4476 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
4478 s = pool->solvables + i;
4479 if (!MAPTST(&solv->suggestsmap, i))
4483 if (!pool_installable(pool, s))
4485 if (!solver_is_enhancing(solv, s))
4488 queue_push(&solv->suggestions, i);
4490 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
4495 /* restore decisionmap */
4496 for (i = 0; i < redoq.count; i += 2)
4497 solv->decisionmap[redoq.elements[i]] = redoq.elements[i + 1];
4501 * if unsolvable, prepare solutions
4504 if (solv->problems.count)
4506 int recocount = solv->recommendations.count;
4507 solv->recommendations.count = 0; /* so that revert() doesn't mess with it */
4508 queue_empty(&redoq);
4509 for (i = 0; i < solv->decisionq.count; i++)
4511 Id p = solv->decisionq.elements[i];
4512 queue_push(&redoq, p);
4513 queue_push(&redoq, solv->decisionq_why.elements[i]);
4514 queue_push(&redoq, solv->decisionmap[p > 0 ? p : -p]);
4516 problems_to_solutions(solv, job);
4517 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
4518 queue_empty(&solv->decisionq);
4519 queue_empty(&solv->decisionq_why);
4520 for (i = 0; i < redoq.count; i += 3)
4522 Id p = redoq.elements[i];
4523 queue_push(&solv->decisionq, p);
4524 queue_push(&solv->decisionq_why, redoq.elements[i + 1]);
4525 solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
4527 solv->recommendations.count = recocount;
4530 POOL_DEBUG(SAT_DEBUG_STATS, "final solver statistics: %d learned rules, %d unsolvable\n", solv->stats_learned, solv->stats_unsolvable);
4534 /***********************************************************************/
4535 /* disk usage computations */
4537 /*-------------------------------------------------------------------
4539 * calculate DU changes
4543 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
4547 solver_create_state_maps(solv, &installedmap, 0);
4548 pool_calc_duchanges(solv->pool, solv->installed, &installedmap, mps, nmps);
4549 map_free(&installedmap);
4553 /*-------------------------------------------------------------------
4555 * calculate changes in install size
4559 solver_calc_installsizechange(Solver *solv)
4564 solver_create_state_maps(solv, &installedmap, 0);
4565 change = pool_calc_installsizechange(solv->pool, solv->installed, &installedmap);
4566 map_free(&installedmap);
4570 #define FIND_INVOLVED_DEBUG 0
4572 solver_find_involved(Solver *solv, Queue *installedq, Solvable *ts, Queue *q)
4574 Pool *pool = solv->pool;
4579 Queue installedq_internal;
4580 Id tp, ip, p, pp, req, *reqp, sup, *supp;
4583 tp = ts - pool->solvables;
4585 queue_init(&installedq_internal);
4586 map_init(&im, pool->nsolvables);
4587 map_init(&installedm, pool->nsolvables);
4591 installedq = &installedq_internal;
4592 if (solv->installed)
4594 for (ip = solv->installed->start; ip < solv->installed->end; ip++)
4596 s = pool->solvables + ip;
4597 if (s->repo != solv->installed)
4599 queue_push(installedq, ip);
4603 for (i = 0; i < installedq->count; i++)
4605 ip = installedq->elements[i];
4606 MAPSET(&installedm, ip);
4610 queue_push(&iq, ts - pool->solvables);
4613 ip = queue_shift(&iq);
4614 if (!MAPTST(&im, ip))
4616 if (!MAPTST(&installedm, ip))
4619 s = pool->solvables + ip;
4620 #if FIND_INVOLVED_DEBUG
4621 printf("hello %s\n", solvable2str(pool, s));
4625 reqp = s->repo->idarraydata + s->requires;
4626 while ((req = *reqp++) != 0)
4628 if (req == SOLVABLE_PREREQMARKER)
4630 /* count number of installed packages that match */
4632 FOR_PROVIDES(p, pp, req)
4633 if (MAPTST(&installedm, p))
4637 FOR_PROVIDES(p, pp, req)
4641 #if FIND_INVOLVED_DEBUG
4642 printf("%s requires %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
4651 reqp = s->repo->idarraydata + s->recommends;
4652 while ((req = *reqp++) != 0)
4655 FOR_PROVIDES(p, pp, req)
4656 if (MAPTST(&installedm, p))
4660 FOR_PROVIDES(p, pp, req)
4664 #if FIND_INVOLVED_DEBUG
4665 printf("%s recommends %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
4674 /* supplements pass */
4675 for (i = 0; i < installedq->count; i++)
4677 ip = installedq->elements[i];
4678 s = pool->solvables + ip;
4679 if (!s->supplements)
4681 if (!MAPTST(&im, ip))
4683 supp = s->repo->idarraydata + s->supplements;
4684 while ((sup = *supp++) != 0)
4685 if (!dep_possible(solv, sup, &im) && dep_possible(solv, sup, &installedm))
4687 /* no longer supplemented, also erase */
4690 #if FIND_INVOLVED_DEBUG
4691 printf("%s supplemented\n", solvable2str(pool, pool->solvables + ip));
4693 queue_push(&iq, ip);
4699 for (i = 0; i < installedq->count; i++)
4701 ip = installedq->elements[i];
4702 if (MAPTST(&im, ip))
4703 queue_push(&iq, ip);
4708 ip = queue_shift(&iq);
4709 if (!MAPTST(&installedm, ip))
4711 s = pool->solvables + ip;
4712 #if FIND_INVOLVED_DEBUG
4713 printf("bye %s\n", solvable2str(pool, s));
4717 reqp = s->repo->idarraydata + s->requires;
4718 while ((req = *reqp++) != 0)
4720 FOR_PROVIDES(p, pp, req)
4722 if (!MAPTST(&im, p))
4726 #if FIND_INVOLVED_DEBUG
4727 printf("%s requires %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
4737 reqp = s->repo->idarraydata + s->recommends;
4738 while ((req = *reqp++) != 0)
4740 FOR_PROVIDES(p, pp, req)
4742 if (!MAPTST(&im, p))
4746 #if FIND_INVOLVED_DEBUG
4747 printf("%s recommends %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
4757 /* supplements pass */
4758 for (i = 0; i < installedq->count; i++)
4760 ip = installedq->elements[i];
4763 s = pool->solvables + ip;
4764 if (!s->supplements)
4766 if (MAPTST(&im, ip))
4768 supp = s->repo->idarraydata + s->supplements;
4769 while ((sup = *supp++) != 0)
4770 if (dep_possible(solv, sup, &im))
4774 #if FIND_INVOLVED_DEBUG
4775 printf("%s supplemented\n", solvable2str(pool, pool->solvables + ip));
4778 queue_push(&iq, ip);
4786 /* convert map into result */
4787 for (i = 0; i < installedq->count; i++)
4789 ip = installedq->elements[i];
4790 if (MAPTST(&im, ip))
4792 if (ip == ts - pool->solvables)
4797 map_free(&installedm);
4798 queue_free(&installedq_internal);