2 * Copyright (c) 2007-2008, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * SAT based dependency solver
26 #include "solverdebug.h"
28 #define RULES_BLOCK 63
30 static void disableupdaterules(Solver *solv, Queue *job, int jobidx);
32 /********************************************************************
34 * dependency check helpers
38 /*-------------------------------------------------------------------
39 * handle split provides
43 solver_splitprovides(Solver *solv, Id dep)
45 Pool *pool = solv->pool;
50 if (!solv->dosplitprovides || !solv->installed)
54 rd = GETRELDEP(pool, dep);
55 if (rd->flags != REL_WITH)
57 FOR_PROVIDES(p, pp, dep)
59 s = pool->solvables + p;
60 if (s->repo == solv->installed && s->name == rd->name)
67 /*-------------------------------------------------------------------
68 * solver_dep_installed
72 solver_dep_installed(Solver *solv, Id dep)
75 Pool *pool = solv->pool;
80 Reldep *rd = GETRELDEP(pool, dep);
81 if (rd->flags == REL_AND)
83 if (!solver_dep_installed(solv, rd->name))
85 return solver_dep_installed(solv, rd->evr);
87 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
88 return solver_dep_installed(solv, rd->evr);
90 FOR_PROVIDES(p, pp, dep)
92 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
100 /*-------------------------------------------------------------------
101 * Check if dependenc is possible
103 * this mirrors solver_dep_fulfilled
104 * but uses map m instead of the decisionmap
108 dep_possible(Solver *solv, Id dep, Map *m)
110 Pool *pool = solv->pool;
115 Reldep *rd = GETRELDEP(pool, dep);
116 if (rd->flags == REL_AND)
118 if (!dep_possible(solv, rd->name, m))
120 return dep_possible(solv, rd->evr, m);
122 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
123 return solver_splitprovides(solv, rd->evr);
124 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
125 return solver_dep_installed(solv, rd->evr);
127 FOR_PROVIDES(p, pp, dep)
135 /********************************************************************
139 * - unify rules, remove duplicates
142 static Pool *unifyrules_sortcmp_data;
144 /*-------------------------------------------------------------------
146 * compare rules for unification sort
151 unifyrules_sortcmp(const void *ap, const void *bp)
153 Pool *pool = unifyrules_sortcmp_data;
154 Rule *a = (Rule *)ap;
155 Rule *b = (Rule *)bp;
161 return x; /* p differs */
164 if (a->d == 0 && b->d == 0)
165 return a->w2 - b->w2; /* assertion: return w2 diff */
167 if (a->d == 0) /* a is assertion, b not */
169 x = a->w2 - pool->whatprovidesdata[b->d];
173 if (b->d == 0) /* b is assertion, a not */
175 x = pool->whatprovidesdata[a->d] - b->w2;
179 /* compare whatprovidesdata */
180 ad = pool->whatprovidesdata + a->d;
181 bd = pool->whatprovidesdata + b->d;
183 if ((x = *ad++ - *bd++) != 0)
189 /*-------------------------------------------------------------------
192 * go over all rules and remove duplicates
196 unifyrules(Solver *solv)
198 Pool *pool = solv->pool;
202 if (solv->nrules <= 1) /* nothing to unify */
205 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
207 /* sort rules first */
208 unifyrules_sortcmp_data = solv->pool;
209 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
216 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
218 if (jr && !unifyrules_sortcmp(ir, jr))
219 continue; /* prune! */
220 jr = solv->rules + j++; /* keep! */
225 /* reduced count from nrules to j rules */
226 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
228 /* adapt rule buffer */
230 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
234 IF_POOLDEBUG (SAT_DEBUG_STATS)
241 for (i = 1; i < solv->nrules; i++)
248 dp = solv->pool->whatprovidesdata + r->d;
253 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
254 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
256 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
266 hashrule(Solver *solv, Id p, Id d, int n)
268 unsigned int x = (unsigned int)p;
272 return (x * 37) ^ (unsigned int)d;
273 dp = solv->pool->whatprovidesdata + d;
275 x = (x * 37) ^ (unsigned int)*dp++;
281 /*-------------------------------------------------------------------
287 * p = direct literal; always < 0 for installed rpm rules
288 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
291 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
293 * p < 0 : pkg id of A
294 * d > 0 : Offset in whatprovidesdata (list of providers of b)
296 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
297 * p < 0 : pkg id of A
298 * d < 0 : Id of solvable (e.g. B1)
300 * d == 0: unary rule, assertion => (A) or (-A)
302 * Install: p > 0, d = 0 (A) user requested install
303 * Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
304 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
305 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
306 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
307 * also used for obsoletes
308 * ?: p > 0, d < 0 (A|-B)
309 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
313 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
314 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
315 * every other : w1 = p, w2 = whatprovidesdata[d];
316 * Disabled rule: w1 = 0
318 * always returns a rule for non-rpm rules
322 addrule(Solver *solv, Id p, Id d)
324 Pool *pool = solv->pool;
328 int n = 0; /* number of literals in rule - 1
329 0 = direct assertion (single literal)
334 /* it often happenes that requires lead to adding the same rpm rule
335 * multiple times, so we prune those duplicates right away to make
336 * the work for unifyrules a bit easier */
338 if (solv->nrules /* we already have rules */
339 && !solv->rpmrules_end) /* but are not done with rpm rules */
341 r = solv->rules + solv->nrules - 1; /* get the last added rule */
342 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
347 * compute number of literals (n) in rule
352 /* always a binary rule */
354 return 0; /* ignore self conflict */
359 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
361 return 0; /* rule is self-fulfilling */
363 if (n == 1) /* have single provider */
364 d = dp[-1]; /* take single literal */
367 if (n == 1 && p > d && !solv->rpmrules_end)
369 /* smallest literal first so we can find dups */
370 n = p; p = d; d = n; /* p <-> d */
371 n = 1; /* re-set n, was used as temp var */
375 * check for duplicate
378 /* check if the last added rule (r) is exactly the same as what we're looking for. */
379 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
380 return r; /* binary rule */
382 /* have n-ary rule with same first literal, check other literals */
383 if (r && n > 1 && r->d && r->p == p)
385 /* Rule where d is an offset in whatprovidesdata */
389 dp2 = pool->whatprovidesdata + r->d;
390 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
401 /* extend rule buffer */
402 solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
403 r = solv->rules + solv->nrules++; /* point to rule space */
412 /* direct assertion, no watch needed */
428 r->w2 = pool->whatprovidesdata[d];
433 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
435 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
436 solver_printrule(solv, SAT_DEBUG_RULE_CREATION, r);
442 /*-------------------------------------------------------------------
447 disablerule(Solver *solv, Rule *r)
453 /*-------------------------------------------------------------------
458 enablerule(Solver *solv, Rule *r)
465 /**********************************************************************************/
467 /* a problem is an item on the solver's problem list. It can either be >0, in that
468 * case it is a update rule, or it can be <0, which makes it refer to a job
469 * consisting of multiple job rules.
473 disableproblem(Solver *solv, Id v)
481 if (v >= solv->infarchrules && v < solv->infarchrules_end)
483 Pool *pool = solv->pool;
484 Id name = pool->solvables[-solv->rules[v].p].name;
485 while (v > solv->infarchrules && pool->solvables[-solv->rules[v - 1].p].name == name)
487 for (; v < solv->infarchrules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
488 disablerule(solv, solv->rules + v);
491 if (v >= solv->duprules && v < solv->duprules_end)
493 Pool *pool = solv->pool;
494 Id name = pool->solvables[-solv->rules[v].p].name;
495 while (v > solv->duprules && pool->solvables[-solv->rules[v - 1].p].name == name)
497 for (; v < solv->duprules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
498 disablerule(solv, solv->rules + v);
501 disablerule(solv, solv->rules + v);
505 jp = solv->ruletojob.elements;
506 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
508 disablerule(solv, r);
511 /*-------------------------------------------------------------------
516 enableproblem(Solver *solv, Id v)
524 if (v >= solv->infarchrules && v < solv->infarchrules_end)
526 Pool *pool = solv->pool;
527 Id name = pool->solvables[-solv->rules[v].p].name;
528 while (v > solv->infarchrules && pool->solvables[-solv->rules[v - 1].p].name == name)
530 for (; v < solv->infarchrules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
531 enablerule(solv, solv->rules + v);
534 if (v >= solv->duprules && v < solv->duprules_end)
536 Pool *pool = solv->pool;
537 Id name = pool->solvables[-solv->rules[v].p].name;
538 while (v > solv->duprules && pool->solvables[-solv->rules[v - 1].p].name == name)
540 for (; v < solv->duprules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
541 enablerule(solv, solv->rules + v);
544 if (v >= solv->featurerules && v < solv->featurerules_end)
546 /* do not enable feature rule if update rule is enabled */
547 r = solv->rules + (v - solv->featurerules + solv->updaterules);
551 enablerule(solv, solv->rules + v);
552 if (v >= solv->updaterules && v < solv->updaterules_end)
554 /* disable feature rule when enabling update rule */
555 r = solv->rules + (v - solv->updaterules + solv->featurerules);
557 disablerule(solv, r);
562 jp = solv->ruletojob.elements;
563 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
569 /************************************************************************/
572 * make assertion rules into decisions
574 * go through update and job rules and add direct assertions
575 * to the decisionqueue. If we find a conflict, disable rules and
576 * add them to problem queue.
580 makeruledecisions(Solver *solv)
582 Pool *pool = solv->pool;
588 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
590 decisionstart = solv->decisionq.count;
591 for (ii = 0; ii < solv->ruleassertions.count; ii++)
593 ri = solv->ruleassertions.elements[ii];
594 r = solv->rules + ri;
596 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
598 /* do weak rules in phase 2 */
599 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
605 if (!solv->decisionmap[vv]) /* if not yet decided */
610 queue_push(&solv->decisionq, v);
611 queue_push(&solv->decisionq_why, r - solv->rules);
612 solv->decisionmap[vv] = v > 0 ? 1 : -1;
613 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
615 Solvable *s = solv->pool->solvables + vv;
617 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
619 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
624 * check previous decision: is it sane ?
627 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
629 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
635 * The rule (r) we're currently processing says something
636 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
640 if (ri >= solv->learntrules)
642 /* conflict with a learnt rule */
643 /* can happen when packages cannot be installed for
644 * multiple reasons. */
645 /* we disable the learnt rule in this case */
646 disablerule(solv, r);
651 * find the decision which is the "opposite" of the rule
654 for (i = 0; i < solv->decisionq.count; i++)
655 if (solv->decisionq.elements[i] == -v)
657 assert(i < solv->decisionq.count); /* assert that we found it */
660 * conflict with system solvable ?
663 if (v == -SYSTEMSOLVABLE) {
664 /* conflict with system solvable */
665 queue_push(&solv->problems, solv->learnt_pool.count);
666 queue_push(&solv->learnt_pool, ri);
667 queue_push(&solv->learnt_pool, 0);
668 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
669 if (ri >= solv->jobrules && ri < solv->jobrules_end)
670 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
673 queue_push(&solv->problems, v);
674 queue_push(&solv->problems, 0);
675 disableproblem(solv, v);
679 assert(solv->decisionq_why.elements[i] > 0);
682 * conflict with an rpm rule ?
685 if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
687 /* conflict with rpm rule assertion */
688 queue_push(&solv->problems, solv->learnt_pool.count);
689 queue_push(&solv->learnt_pool, ri);
690 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
691 queue_push(&solv->learnt_pool, 0);
692 assert(v > 0 || v == -SYSTEMSOLVABLE);
693 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
694 if (ri >= solv->jobrules && ri < solv->jobrules_end)
695 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
698 queue_push(&solv->problems, v);
699 queue_push(&solv->problems, 0);
700 disableproblem(solv, v);
705 * conflict with another job or update/feature rule
709 queue_push(&solv->problems, solv->learnt_pool.count);
710 queue_push(&solv->learnt_pool, ri);
711 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
712 queue_push(&solv->learnt_pool, 0);
714 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
717 * push all of our rules (can only be feature or job rules)
718 * asserting this literal on the problem stack
721 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
723 if (rr->d < 0 /* disabled */
724 || rr->w2) /* or no assertion */
726 if (rr->p != vv /* not affecting the literal */
729 if (MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
732 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
734 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, solv->rules + i);
737 /* is is a job rule ? */
738 if (i >= solv->jobrules && i < solv->jobrules_end)
739 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
741 queue_push(&solv->problems, v);
742 disableproblem(solv, v);
744 queue_push(&solv->problems, 0);
748 * (back up from decisions)
750 while (solv->decisionq.count > decisionstart)
752 v = solv->decisionq.elements[--solv->decisionq.count];
753 --solv->decisionq_why.count;
755 solv->decisionmap[vv] = 0;
757 ii = -1; /* restarts loop at 0 */
761 * phase 2: now do the weak assertions
763 for (ii = 0; ii < solv->ruleassertions.count; ii++)
765 ri = solv->ruleassertions.elements[ii];
766 r = solv->rules + ri;
767 if (r->d < 0 || r->w2) /* disabled or no assertion */
769 if (ri >= solv->learntrules || !MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
775 * (if not yet decided)
777 if (!solv->decisionmap[vv])
779 queue_push(&solv->decisionq, v);
780 queue_push(&solv->decisionq_why, r - solv->rules);
781 solv->decisionmap[vv] = v > 0 ? 1 : -1;
782 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
784 Solvable *s = solv->pool->solvables + vv;
786 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", solvable2str(solv->pool, s));
788 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", solvable2str(solv->pool, s));
793 * previously decided, sane ?
795 if (v > 0 && solv->decisionmap[vv] > 0)
797 if (v < 0 && solv->decisionmap[vv] < 0)
800 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
801 solver_printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
803 if (ri >= solv->jobrules && ri < solv->jobrules_end)
804 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
807 disableproblem(solv, v);
809 disableupdaterules(solv, solv->job, -(v + 1));
812 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
816 /*-------------------------------------------------------------------
817 * enable/disable learnt rules
819 * we have enabled or disabled some of our rules. We now reenable all
820 * of our learnt rules except the ones that were learnt from rules that
824 enabledisablelearntrules(Solver *solv)
826 Pool *pool = solv->pool;
831 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
832 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
834 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
835 while ((why = *whyp++) != 0)
837 assert(why > 0 && why < i);
838 if (solv->rules[why].d < 0)
841 /* why != 0: we found a disabled rule, disable the learnt rule */
842 if (why && r->d >= 0)
844 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
846 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling ");
847 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
849 disablerule(solv, r);
851 else if (!why && r->d < 0)
853 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
855 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling ");
856 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
864 /*-------------------------------------------------------------------
867 * Enable all rules, except learnt rules, which are
868 * - disabled and weak (set in weakrulemap)
873 enableweakrules(Solver *solv)
878 for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
880 if (r->d >= 0) /* already enabled? */
882 if (!MAPTST(&solv->weakrulemap, i))
889 /* FIXME: bad code ahead, replace as soon as possible */
890 /* FIXME: maybe also look at SOLVER_INSTALL|SOLVABLE_ONE_OF */
892 /*-------------------------------------------------------------------
893 * disable update rules depending on enabled job
894 * if jobidx is set we just disabled this job, so we may want
895 * to re-enable some rules
896 * otherwise we disable all update rules that conflict with some job.
900 disableupdaterules(Solver *solv, Queue *job, int jobidx)
902 Pool *pool = solv->pool;
904 Id how, select, what, p, pp;
911 installed = solv->installed;
915 how = job->elements[jobidx];
916 select = how & SOLVER_SELECTMASK;
917 switch (how & SOLVER_JOBMASK)
922 if (select != SOLVER_SOLVABLE)
929 /* go through all enabled job rules */
930 map_init(&nolockrules, pool->nsolvables);
931 MAPZERO(&solv->noupdate);
932 for (i = solv->jobrules; i < solv->jobrules_end; i++)
935 if (r->d < 0) /* disabled? */
937 j = solv->ruletojob.elements[i - solv->jobrules];
941 how = job->elements[j];
942 what = job->elements[j + 1];
943 select = how & SOLVER_SELECTMASK;
944 switch (how & SOLVER_JOBMASK)
947 if (select != SOLVER_SOLVABLE)
949 s = pool->solvables + what;
950 FOR_PROVIDES(p, pp, s->name)
952 Solvable *ps = pool->solvables + p;
953 if (ps->name == s->name)
954 MAPSET(&nolockrules, p);
958 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, what))
960 if (s->repo == installed)
962 MAPSET(&solv->noupdate, what - installed->start);
968 obsp = s->repo->idarraydata + s->obsoletes;
969 while ((obs = *obsp++) != 0)
970 FOR_PROVIDES(p, pp, obs)
972 Solvable *ps = pool->solvables + p;
973 if (ps->repo != installed)
975 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
977 MAPSET(&solv->noupdate, p - installed->start);
980 FOR_PROVIDES(p, pp, s->name)
982 Solvable *ps = pool->solvables + p;
983 if (ps->repo != installed)
985 if (!solv->implicitobsoleteusesprovides && ps->name != s->name)
987 MAPSET(&solv->noupdate, p - installed->start);
993 FOR_JOB_SELECT(p, pp, select, what)
994 if (pool->solvables[p].repo == installed)
995 MAPSET(&solv->noupdate, p - installed->start);
1002 /* fixup update rule status */
1005 /* we just disabled job #jobidx. enable all update rules
1006 * that aren't disabled by the remaining job rules */
1007 how = job->elements[jobidx];
1008 what = job->elements[jobidx + 1];
1009 select = how & SOLVER_SELECTMASK;
1010 if ((how & SOLVER_JOBMASK) == SOLVER_INSTALL && select == SOLVER_SOLVABLE)
1012 /* check if we need to enable some lock rule */
1013 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1015 if (r->p != -what || r->d >= 0 || !MAPTST(&nolockrules, -r->p))
1017 enablerule(solv, r);
1018 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1020 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1021 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
1024 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1026 if (r->p != -what || r->d >= 0 || !MAPTST(&nolockrules, -r->p))
1028 enablerule(solv, r);
1029 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1031 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1032 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
1036 map_free(&nolockrules);
1039 switch (how & SOLVER_JOBMASK)
1041 case SOLVER_INSTALL:
1042 if (select != SOLVER_SOLVABLE)
1044 s = pool->solvables + what;
1045 if (s->repo == installed)
1047 if (MAPTST(&solv->noupdate, what - installed->start))
1049 r = solv->rules + solv->updaterules + (what - installed->start);
1052 enablerule(solv, r);
1053 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1055 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1056 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
1063 obsp = s->repo->idarraydata + s->obsoletes;
1064 while ((obs = *obsp++) != 0)
1065 FOR_PROVIDES(p, pp, obs)
1067 if (pool->solvables[p].repo != installed)
1069 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
1071 if (MAPTST(&solv->noupdate, p - installed->start))
1073 r = solv->rules + solv->updaterules + (p - installed->start);
1076 enablerule(solv, r);
1077 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1079 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1080 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
1084 FOR_PROVIDES(p, pp, s->name)
1086 if (!solv->implicitobsoleteusesprovides && pool->solvables[p].name != s->name)
1088 if (pool->solvables[p].repo != installed)
1090 if (MAPTST(&solv->noupdate, p - installed->start))
1092 r = solv->rules + solv->updaterules + (p - installed->start);
1095 enablerule(solv, r);
1096 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1098 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1099 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
1104 FOR_JOB_SELECT(p, pp, select, what)
1106 if (pool->solvables[p].repo != installed)
1108 if (MAPTST(&solv->noupdate, p - installed->start))
1110 r = solv->rules + solv->updaterules + (p - installed->start);
1113 enablerule(solv, r);
1114 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1116 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1117 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
1127 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1129 if (r->p < 0 && r->d >= 0 && MAPTST(&nolockrules, -r->p))
1130 disablerule(solv, r); /* was enabled, need to disable */
1132 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1134 if (r->p < 0 && r->d >= 0 && MAPTST(&nolockrules, -r->p))
1135 disablerule(solv, r); /* was enabled, need to disable */
1137 map_free(&nolockrules);
1140 for (i = 0; i < installed->nsolvables; i++)
1142 r = solv->rules + solv->updaterules + i;
1143 if (r->d >= 0 && MAPTST(&solv->noupdate, i))
1144 disablerule(solv, r); /* was enabled, need to disable */
1145 r = solv->rules + solv->featurerules + i;
1146 if (r->d >= 0 && MAPTST(&solv->noupdate, i))
1147 disablerule(solv, r); /* was enabled, need to disable */
1154 * special multiversion patch conflict handling:
1155 * a patch conflict is also satisfied, if some other
1156 * version with the same name/arch that doesn't conflict
1157 * get's installed. The generated rule is thus:
1158 * -patch|-cpack|opack1|opack2|...
1161 makemultiversionconflict(Solver *solv, Id n, Id con)
1163 Pool *pool = solv->pool;
1168 sn = pool->solvables + n;
1169 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1171 FOR_PROVIDES(p, pp, sn->name)
1173 s = pool->solvables + p;
1174 if (s->name != sn->name || s->arch != sn->arch)
1176 if (!MAPTST(&solv->noobsoletes, p))
1178 if (pool_match_nevr(pool, pool->solvables + p, con))
1180 /* here we have a multiversion solvable that doesn't conflict */
1181 /* thus we're not in conflict if it is installed */
1185 return -n; /* no other package found, generate normal conflict */
1186 return pool_queuetowhatprovides(pool, &q);
1190 /*-------------------------------------------------------------------
1192 * add (install) rules for solvable
1194 * s: Solvable for which to add rules
1195 * m: m[s] = 1 for solvables which have rules, prevent rule duplication
1197 * Algorithm: 'visit all nodes of a graph'. The graph nodes are
1198 * solvables, the edges their dependencies.
1199 * Starting from an installed solvable, this will create all rules
1200 * representing the graph created by the solvables dependencies.
1202 * for unfulfilled requirements, conflicts, obsoletes,....
1203 * add a negative assertion for solvables that are not installable
1205 * It will also create rules for all solvables referenced by 's'
1206 * i.e. descend to all providers of requirements of 's'
1211 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
1213 Pool *pool = solv->pool;
1214 Repo *installed = solv->installed;
1216 /* 'work' queue. keeps Ids of solvables we still have to work on.
1217 And buffer for it. */
1222 /* if to add rules for broken deps ('rpm -V' functionality)
1226 /* Id var and pointer for each dependency
1227 * (not used in parallel)
1234 /* var and ptr for loops */
1236 /* ptr to 'whatprovides' */
1238 /* Id for current solvable 's' */
1241 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
1243 queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
1244 queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
1246 /* loop until there's no more work left */
1251 * s: Pointer to solvable
1254 n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
1255 if (MAPTST(m, n)) /* continue if already visited */
1258 MAPSET(m, n); /* mark as visited */
1259 s = pool->solvables + n; /* s = Solvable in question */
1262 if (installed /* Installed system available */
1263 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
1264 && s->repo == installed) /* solvable is installed? */
1266 dontfix = 1; /* dont care about broken rpm deps */
1270 && s->arch != ARCH_SRC
1271 && s->arch != ARCH_NOSRC
1272 && !pool_installable(pool, s))
1274 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
1275 addrule(solv, -n, 0); /* uninstallable */
1278 /* yet another SUSE hack, sigh */
1279 if (pool->nscallback && !strncmp("product:", id2str(pool, s->name), 8))
1281 Id buddy = pool->nscallback(pool, pool->nscallbackdata, NAMESPACE_PRODUCTBUDDY, n);
1282 if (buddy > 0 && buddy != SYSTEMSOLVABLE && buddy != n && buddy < pool->nsolvables)
1284 addrule(solv, n, -buddy);
1285 addrule(solv, buddy, -n);
1286 if (!MAPTST(m, buddy))
1287 queue_push(&workq, buddy);
1291 /*-----------------------------------------
1292 * check requires of s
1297 reqp = s->repo->idarraydata + s->requires;
1298 while ((req = *reqp++) != 0) /* go through all requires */
1300 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
1303 /* find list of solvables providing 'req' */
1304 dp = pool_whatprovides_ptr(pool, req);
1306 if (*dp == SYSTEMSOLVABLE) /* always installed */
1311 /* the strategy here is to not insist on dependencies
1312 * that are already broken. so if we find one provider
1313 * that was already installed, we know that the
1314 * dependency was not broken before so we enforce it */
1316 /* check if any of the providers for 'req' is installed */
1317 for (i = 0; (p = dp[i]) != 0; i++)
1319 if (pool->solvables[p].repo == installed)
1320 break; /* provider was installed */
1322 /* didn't find an installed provider: previously broken dependency */
1325 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1332 /* nothing provides req! */
1333 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1334 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1338 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1340 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1341 for (i = 0; dp[i]; i++)
1342 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1345 /* add 'requires' dependency */
1346 /* rule: (-requestor|provider1|provider2|...|providerN) */
1347 addrule(solv, -n, dp - pool->whatprovidesdata);
1349 /* descend the dependency tree
1350 push all non-visited providers on the work queue */
1353 if (!MAPTST(m, *dp))
1354 queue_push(&workq, *dp);
1357 } /* while, requirements of n */
1359 } /* if, requirements */
1361 /* that's all we check for src packages */
1362 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1365 /*-----------------------------------------
1366 * check conflicts of s
1373 /* we treat conflicts in patches a bit differen:
1375 * - multiversion handling
1376 * XXX: we should really handle this different, looking
1377 * at the name is a bad hack
1379 if (!strncmp("patch:", id2str(pool, s->name), 6))
1381 conp = s->repo->idarraydata + s->conflicts;
1382 /* foreach conflicts of 's' */
1383 while ((con = *conp++) != 0)
1385 /* foreach providers of a conflict of 's' */
1386 FOR_PROVIDES(p, pp, con)
1388 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
1390 /* dontfix: dont care about conflicts with already installed packs */
1391 if (dontfix && pool->solvables[p].repo == installed)
1393 /* p == n: self conflict */
1394 if (p == n && !solv->allowselfconflicts)
1398 Reldep *rd = GETRELDEP(pool, con);
1399 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
1402 p = 0; /* make it a negative assertion, aka 'uninstallable' */
1404 if (p && ispatch && solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p) && ISRELDEP(con))
1406 /* our patch conflicts with a noobsoletes (aka multiversion) package */
1407 p = -makemultiversionconflict(solv, p, con);
1409 /* rule: -n|-p: either solvable _or_ provider of conflict */
1410 addrule(solv, -n, -p);
1415 /*-----------------------------------------
1416 * check obsoletes if not installed
1417 * (only installation will trigger the obsoletes in rpm)
1419 if (!installed || pool->solvables[n].repo != installed)
1420 { /* not installed */
1421 int noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
1422 if (s->obsoletes && !noobs)
1424 obsp = s->repo->idarraydata + s->obsoletes;
1425 /* foreach obsoletes */
1426 while ((obs = *obsp++) != 0)
1428 /* foreach provider of an obsoletes of 's' */
1429 FOR_PROVIDES(p, pp, obs)
1431 if (!solv->obsoleteusesprovides /* obsoletes are matched names, not provides */
1432 && !pool_match_nevr(pool, pool->solvables + p, obs))
1434 addrule(solv, -n, -p);
1438 FOR_PROVIDES(p, pp, s->name)
1440 Solvable *ps = pool->solvables + p;
1441 /* we still obsolete packages with same nevra, like rpm does */
1442 /* (actually, rpm mixes those packages. yuck...) */
1443 if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
1445 if (!solv->implicitobsoleteusesprovides && s->name != ps->name)
1447 addrule(solv, -n, -p);
1451 /*-----------------------------------------
1452 * add recommends to the work queue
1456 recp = s->repo->idarraydata + s->recommends;
1457 while ((rec = *recp++) != 0)
1459 FOR_PROVIDES(p, pp, rec)
1461 queue_push(&workq, p);
1466 sugp = s->repo->idarraydata + s->suggests;
1467 while ((sug = *sugp++) != 0)
1469 FOR_PROVIDES(p, pp, sug)
1471 queue_push(&workq, p);
1476 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1480 /*-------------------------------------------------------------------
1482 * Add package rules for weak rules
1484 * m: visited solvables
1488 addrpmrulesforweak(Solver *solv, Map *m)
1490 Pool *pool = solv->pool;
1495 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1496 /* foreach solvable in pool */
1497 for (i = n = 1; n < pool->nsolvables; i++, n++)
1499 if (i == pool->nsolvables) /* wrap i */
1501 if (MAPTST(m, i)) /* been there */
1504 s = pool->solvables + i;
1505 if (!pool_installable(pool, s)) /* only look at installable ones */
1511 /* find possible supplements */
1512 supp = s->repo->idarraydata + s->supplements;
1513 while ((sup = *supp++) != ID_NULL)
1514 if (dep_possible(solv, sup, m))
1518 /* if nothing found, check for enhances */
1519 if (!sup && s->enhances)
1521 supp = s->repo->idarraydata + s->enhances;
1522 while ((sup = *supp++) != ID_NULL)
1523 if (dep_possible(solv, sup, m))
1526 /* if nothing found, goto next solvables */
1529 addrpmrulesforsolvable(solv, s, m);
1532 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1536 /*-------------------------------------------------------------------
1538 * add package rules for possible updates
1541 * m: map of already visited solvables
1542 * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
1546 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
1548 Pool *pool = solv->pool;
1550 /* queue and buffer for it */
1554 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1556 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1557 /* find update candidates for 's' */
1558 policy_findupdatepackages(solv, s, &qs, allow_all);
1559 /* add rule for 's' if not already done */
1560 if (!MAPTST(m, s - pool->solvables))
1561 addrpmrulesforsolvable(solv, s, m);
1562 /* foreach update candidate, add rule if not already done */
1563 for (i = 0; i < qs.count; i++)
1564 if (!MAPTST(m, qs.elements[i]))
1565 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1568 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1572 finddistupgradepackages(Solver *solv, Solvable *s, Queue *qs, int allow_all)
1574 Pool *pool = solv->pool;
1577 policy_findupdatepackages(solv, s, qs, allow_all);
1581 return 0; /* orphaned, don't create feature rule */
1582 /* check if this is an orphaned package */
1583 policy_findupdatepackages(solv, s, qs, 1);
1585 return 0; /* orphaned, don't create update rule */
1587 return -SYSTEMSOLVABLE; /* supported but not installable */
1590 return s - pool->solvables;
1591 /* check if it is ok to keep the installed package */
1592 for (i = 0; i < qs->count; i++)
1594 Solvable *ns = pool->solvables + qs->elements[i];
1595 if (s->evr == ns->evr && solvable_identical(s, ns))
1596 return s - pool->solvables;
1598 /* nope, it must be some other package */
1599 return -SYSTEMSOLVABLE;
1602 /* add packages from the dup repositories to the update candidates
1603 * this isn't needed for the global dup mode as all packages are
1604 * from dup repos in that case */
1606 addduppackages(Solver *solv, Solvable *s, Queue *qs)
1611 int oldnoupdateprovide = solv->noupdateprovide;
1613 queue_init_buffer(&dupqs, dupqsbuf, sizeof(dupqsbuf)/sizeof(*dupqsbuf));
1614 solv->noupdateprovide = 1;
1615 policy_findupdatepackages(solv, s, &dupqs, 2);
1616 solv->noupdateprovide = oldnoupdateprovide;
1617 for (i = 0; i < dupqs.count; i++)
1619 p = dupqs.elements[i];
1620 if (MAPTST(&solv->dupmap, p))
1621 queue_pushunique(qs, p);
1626 /*-------------------------------------------------------------------
1628 * add rule for update
1629 * (A|A1|A2|A3...) An = update candidates for A
1631 * s = (installed) solvable
1635 addupdaterule(Solver *solv, Solvable *s, int allow_all)
1637 /* installed packages get a special upgrade allowed rule */
1638 Pool *pool = solv->pool;
1643 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1644 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1645 p = s - pool->solvables;
1646 /* find update candidates for 's' */
1647 if (solv->distupgrade)
1648 p = finddistupgradepackages(solv, s, &qs, allow_all);
1650 policy_findupdatepackages(solv, s, &qs, allow_all);
1651 if (!allow_all && !solv->distupgrade && solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
1652 addduppackages(solv, s, &qs);
1654 if (!allow_all && qs.count && solv->noobsoletes.size)
1658 d = pool_queuetowhatprovides(pool, &qs);
1659 /* filter out all noobsoletes packages as they don't update */
1660 for (i = j = 0; i < qs.count; i++)
1662 if (MAPTST(&solv->noobsoletes, qs.elements[i]))
1664 /* it's ok if they have same nevra */
1665 Solvable *ps = pool->solvables + qs.elements[i];
1666 if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
1669 qs.elements[j++] = qs.elements[i];
1671 if (j == 0 && p == -SYSTEMSOLVABLE && solv->distupgrade)
1673 queue_push(&solv->orphaned, s - pool->solvables); /* treat as orphaned */
1678 if (d && solv->updatesystem && solv->installed && s->repo == solv->installed)
1680 if (!solv->multiversionupdaters)
1681 solv->multiversionupdaters = sat_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
1682 solv->multiversionupdaters[s - pool->solvables - solv->installed->start] = d;
1687 if (qs.count && p == -SYSTEMSOLVABLE)
1688 p = queue_shift(&qs);
1689 d = qs.count ? pool_queuetowhatprovides(pool, &qs) : 0;
1691 addrule(solv, p, d); /* allow update of s */
1692 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1696 /********************************************************************/
1700 /*-------------------------------------------------------------------
1703 * initial setup for all watches
1707 makewatches(Solver *solv)
1711 int nsolvables = solv->pool->nsolvables;
1713 sat_free(solv->watches);
1714 /* lower half for removals, upper half for installs */
1715 solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
1717 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
1718 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1720 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1723 if (!r->w2) /* assertions do not need watches */
1726 /* see addwatches_rule(solv, r) */
1727 r->n1 = solv->watches[nsolvables + r->w1];
1728 solv->watches[nsolvables + r->w1] = r - solv->rules;
1730 r->n2 = solv->watches[nsolvables + r->w2];
1731 solv->watches[nsolvables + r->w2] = r - solv->rules;
1736 /*-------------------------------------------------------------------
1738 * add watches (for rule)
1739 * sets up watches for a single rule
1741 * see also makewatches()
1745 addwatches_rule(Solver *solv, Rule *r)
1747 int nsolvables = solv->pool->nsolvables;
1749 r->n1 = solv->watches[nsolvables + r->w1];
1750 solv->watches[nsolvables + r->w1] = r - solv->rules;
1752 r->n2 = solv->watches[nsolvables + r->w2];
1753 solv->watches[nsolvables + r->w2] = r - solv->rules;
1757 /********************************************************************/
1763 /* shortcuts to check if a literal (positive or negative) assignment
1764 * evaluates to 'true' or 'false'
1766 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1767 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
1768 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
1770 /*-------------------------------------------------------------------
1774 * make decision and propagate to all rules
1776 * Evaluate each term affected by the decision (linked through watches)
1777 * If we find unit rules we make new decisions based on them
1779 * Everything's fixed there, it's just finding rules that are
1782 * return : 0 = everything is OK
1783 * rule = conflict found in this rule
1787 propagate(Solver *solv, int level)
1789 Pool *pool = solv->pool;
1790 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
1792 Id p, pkg, other_watch;
1794 Id *decisionmap = solv->decisionmap;
1796 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
1798 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1800 /* foreach non-propagated decision */
1801 while (solv->propagate_index < solv->decisionq.count)
1804 * 'pkg' was just decided
1805 * negate because our watches trigger if literal goes FALSE
1807 pkg = -solv->decisionq.elements[solv->propagate_index++];
1809 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1811 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
1812 solver_printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1815 /* foreach rule where 'pkg' is now FALSE */
1816 for (rp = watches + pkg; *rp; rp = next_rp)
1818 r = solv->rules + *rp;
1821 /* rule is disabled, goto next */
1829 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1831 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1832 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
1835 /* 'pkg' was just decided (was set to FALSE)
1837 * now find other literal watch, check clause
1838 * and advance on linked list
1842 other_watch = r->w2;
1847 other_watch = r->w1;
1852 * This term is already true (through the other literal)
1853 * so we have nothing to do
1855 if (DECISIONMAP_TRUE(other_watch))
1859 * The other literal is FALSE or UNDEF
1865 /* Not a binary clause, try to move our watch.
1867 * Go over all literals and find one that is
1871 * (TRUE is also ok, in that case the rule is fulfilled)
1873 if (r->p /* we have a 'p' */
1874 && r->p != other_watch /* which is not watched */
1875 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
1879 else /* go find a 'd' to make 'true' */
1882 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
1884 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1886 if (p != other_watch /* which is not watched */
1887 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
1895 * if we found some p that is UNDEF or TRUE, move
1898 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1901 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1903 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1919 watches[p] = r - solv->rules;
1922 /* search failed, thus all unwatched literals are FALSE */
1927 * unit clause found, set literal other_watch to TRUE
1930 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
1931 return r; /* eek, a conflict! */
1933 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1935 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
1936 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
1939 if (other_watch > 0)
1940 decisionmap[other_watch] = level; /* install! */
1942 decisionmap[-other_watch] = -level; /* remove! */
1944 queue_push(&solv->decisionq, other_watch);
1945 queue_push(&solv->decisionq_why, r - solv->rules);
1947 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1949 Solvable *s = pool->solvables + (other_watch > 0 ? other_watch : -other_watch);
1950 if (other_watch > 0)
1951 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
1953 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
1956 } /* foreach rule involving 'pkg' */
1958 } /* while we have non-decided decisions */
1960 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
1962 return 0; /* all is well */
1966 /********************************************************************/
1969 /*-------------------------------------------------------------------
1976 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
1978 Pool *pool = solv->pool;
1981 Map seen; /* global? */
1982 Id d, v, vv, *dp, why;
1984 int num = 0, l1num = 0;
1985 int learnt_why = solv->learnt_pool.count;
1986 Id *decisionmap = solv->decisionmap;
1990 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
1991 map_init(&seen, pool->nsolvables);
1992 idx = solv->decisionq.count;
1995 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1996 solver_printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1997 queue_push(&solv->learnt_pool, c - solv->rules);
1998 d = c->d < 0 ? -c->d - 1 : c->d;
1999 dp = d ? pool->whatprovidesdata + d : 0;
2000 /* go through all literals of the rule */
2012 if (DECISIONMAP_TRUE(v)) /* the one true literal */
2014 vv = v > 0 ? v : -v;
2015 if (MAPTST(&seen, vv))
2017 l = solv->decisionmap[vv];
2022 l1num++; /* need to do this one in level1 pass */
2023 else if (l == level)
2024 num++; /* need to do this one as well */
2027 queue_push(&r, v); /* not level1 or conflict level, add to new rule */
2033 if (!num && !--l1num)
2034 break; /* all level 1 literals done */
2038 v = solv->decisionq.elements[--idx];
2039 vv = v > 0 ? v : -v;
2040 if (MAPTST(&seen, vv))
2044 if (num && --num == 0)
2046 *pr = -v; /* so that v doesn't get lost */
2049 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
2050 for (i = 0; i < r.count; i++)
2053 MAPCLR(&seen, v > 0 ? v : -v);
2055 /* only level 1 marks left */
2059 why = solv->decisionq_why.elements[idx];
2060 if (why <= 0) /* just in case, maybe for SYSTEMSOLVABLE */
2062 c = solv->rules + why;
2068 else if (r.count == 1 && r.elements[0] < 0)
2069 *dr = r.elements[0];
2071 *dr = pool_queuetowhatprovides(pool, &r);
2072 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
2074 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
2075 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
2076 for (i = 0; i < r.count; i++)
2077 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
2079 /* push end marker on learnt reasons stack */
2080 queue_push(&solv->learnt_pool, 0);
2083 solv->stats_learned++;
2088 /*-------------------------------------------------------------------
2092 * reset the solver decisions to right after the rpm rules.
2093 * called after rules have been enabled/disabled
2097 reset_solver(Solver *solv)
2099 Pool *pool = solv->pool;
2103 /* rewind decisions to direct rpm rule assertions */
2104 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
2106 v = solv->decisionq.elements[i];
2107 solv->decisionmap[v > 0 ? v : -v] = 0;
2110 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
2112 solv->decisionq_why.count = solv->directdecisions;
2113 solv->decisionq.count = solv->directdecisions;
2114 solv->recommends_index = -1;
2115 solv->propagate_index = 0;
2117 /* adapt learnt rule status to new set of enabled/disabled rules */
2118 enabledisablelearntrules(solv);
2120 /* redo all job/update decisions */
2121 makeruledecisions(solv);
2122 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
2126 /*-------------------------------------------------------------------
2128 * analyze_unsolvable_rule
2132 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
2134 Pool *pool = solv->pool;
2136 Id why = r - solv->rules;
2138 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
2139 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
2140 if (solv->learntrules && why >= solv->learntrules)
2142 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
2143 if (solv->learnt_pool.elements[i] > 0)
2144 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp);
2147 if (MAPTST(&solv->weakrulemap, why))
2148 if (!*lastweakp || why > *lastweakp)
2150 /* do not add rpm rules to problem */
2151 if (why < solv->rpmrules_end)
2153 /* turn rule into problem */
2154 if (why >= solv->jobrules && why < solv->jobrules_end)
2155 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
2156 /* normalize dup/infarch rules */
2157 if (why > solv->infarchrules && why < solv->infarchrules_end)
2159 Id name = pool->solvables[-solv->rules[why].p].name;
2160 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
2163 if (why > solv->duprules && why < solv->duprules_end)
2165 Id name = pool->solvables[-solv->rules[why].p].name;
2166 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
2170 /* return if problem already countains our rule */
2171 if (solv->problems.count)
2173 for (i = solv->problems.count - 1; i >= 0; i--)
2174 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
2176 else if (solv->problems.elements[i] == why)
2179 queue_push(&solv->problems, why);
2183 /*-------------------------------------------------------------------
2185 * analyze_unsolvable
2187 * return: 1 - disabled some rules, try again
2192 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
2194 Pool *pool = solv->pool;
2196 Map seen; /* global to speed things up? */
2197 Id d, v, vv, *dp, why;
2199 Id *decisionmap = solv->decisionmap;
2200 int oldproblemcount;
2201 int oldlearntpoolcount;
2204 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
2205 solv->stats_unsolvable++;
2206 oldproblemcount = solv->problems.count;
2207 oldlearntpoolcount = solv->learnt_pool.count;
2209 /* make room for proof index */
2210 /* must update it later, as analyze_unsolvable_rule would confuse
2211 * it with a rule index if we put the real value in already */
2212 queue_push(&solv->problems, 0);
2215 map_init(&seen, pool->nsolvables);
2216 queue_push(&solv->learnt_pool, r - solv->rules);
2218 analyze_unsolvable_rule(solv, r, &lastweak);
2219 d = r->d < 0 ? -r->d - 1 : r->d;
2220 dp = d ? pool->whatprovidesdata + d : 0;
2231 if (DECISIONMAP_TRUE(v)) /* the one true literal */
2233 vv = v > 0 ? v : -v;
2234 l = solv->decisionmap[vv];
2239 idx = solv->decisionq.count;
2242 v = solv->decisionq.elements[--idx];
2243 vv = v > 0 ? v : -v;
2244 if (!MAPTST(&seen, vv))
2246 why = solv->decisionq_why.elements[idx];
2248 queue_push(&solv->learnt_pool, why);
2249 r = solv->rules + why;
2250 analyze_unsolvable_rule(solv, r, &lastweak);
2251 d = r->d < 0 ? -r->d - 1 : r->d;
2252 dp = d ? pool->whatprovidesdata + d : 0;
2263 if (DECISIONMAP_TRUE(v)) /* the one true literal */
2265 vv = v > 0 ? v : -v;
2266 l = solv->decisionmap[vv];
2273 queue_push(&solv->problems, 0); /* mark end of this problem */
2278 /* disable last weak rule */
2279 solv->problems.count = oldproblemcount;
2280 solv->learnt_pool.count = oldlearntpoolcount;
2281 if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
2282 v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
2285 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling ");
2286 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, solv->rules + lastweak);
2287 disableproblem(solv, v);
2289 disableupdaterules(solv, solv->job, -(v + 1));
2295 queue_push(&solv->learnt_pool, 0);
2296 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
2300 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
2301 disableproblem(solv, solv->problems.elements[i]);
2302 /* XXX: might want to enable all weak rules again */
2306 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
2311 /********************************************************************/
2312 /* Decision revert */
2314 /*-------------------------------------------------------------------
2317 * revert decision at level
2321 revert(Solver *solv, int level)
2323 Pool *pool = solv->pool;
2325 while (solv->decisionq.count)
2327 v = solv->decisionq.elements[solv->decisionq.count - 1];
2328 vv = v > 0 ? v : -v;
2329 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
2331 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
2332 if (v > 0 && solv->recommendations.count && v == solv->recommendations.elements[solv->recommendations.count - 1])
2333 solv->recommendations.count--;
2334 solv->decisionmap[vv] = 0;
2335 solv->decisionq.count--;
2336 solv->decisionq_why.count--;
2337 solv->propagate_index = solv->decisionq.count;
2339 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
2341 solv->branches.count--;
2342 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
2343 solv->branches.count--;
2345 solv->recommends_index = -1;
2349 /*-------------------------------------------------------------------
2351 * watch2onhighest - put watch2 on literal with highest level
2355 watch2onhighest(Solver *solv, Rule *r)
2360 d = r->d < 0 ? -r->d - 1 : r->d;
2362 return; /* binary rule, both watches are set */
2363 dp = solv->pool->whatprovidesdata + d;
2364 while ((v = *dp++) != 0)
2366 l = solv->decisionmap[v < 0 ? -v : v];
2378 /*-------------------------------------------------------------------
2382 * add free decision (solvable to install) to decisionq
2383 * increase level and propagate decision
2384 * return if no conflict.
2386 * in conflict case, analyze conflict rule, add resulting
2387 * rule to learnt rule set, make decision from learnt
2388 * rule (always unit) and re-propagate.
2390 * returns the new solver level or 0 if unsolvable
2395 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules, Id ruleid)
2397 Pool *pool = solv->pool;
2402 assert(ruleid >= 0);
2407 solv->decisionmap[decision] = level;
2409 solv->decisionmap[-decision] = -level;
2410 queue_push(&solv->decisionq, decision);
2411 queue_push(&solv->decisionq_why, -ruleid); /* <= 0 -> free decision */
2415 r = propagate(solv, level);
2419 return analyze_unsolvable(solv, r, disablerules);
2420 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
2421 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
2422 assert(l > 0 && l < level);
2423 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
2425 revert(solv, level);
2426 r = addrule(solv, p, d);
2428 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
2429 queue_push(&solv->learnt_why, why);
2432 /* at least 2 literals, needs watches */
2433 watch2onhighest(solv, r);
2434 addwatches_rule(solv, r);
2438 /* learnt rule is an assertion */
2439 queue_push(&solv->ruleassertions, r - solv->rules);
2441 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
2442 queue_push(&solv->decisionq, p);
2443 queue_push(&solv->decisionq_why, r - solv->rules);
2444 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
2446 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
2447 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
2448 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
2449 solver_printrule(solv, SAT_DEBUG_ANALYZE, r);
2456 /*-------------------------------------------------------------------
2458 * select and install
2460 * install best package from the queue. We add an extra package, inst, if
2461 * provided. See comment in weak install section.
2463 * returns the new solver level or 0 if unsolvable
2468 selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid)
2470 Pool *pool = solv->pool;
2475 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
2478 /* XXX: didn't we already do that? */
2479 /* XXX: shouldn't we prefer installed packages? */
2480 /* XXX: move to policy.c? */
2481 /* choose the supplemented one */
2482 for (i = 0; i < dq->count; i++)
2483 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
2485 dq->elements[0] = dq->elements[i];
2492 /* multiple candidates, open a branch */
2493 for (i = 1; i < dq->count; i++)
2494 queue_push(&solv->branches, dq->elements[i]);
2495 queue_push(&solv->branches, -level);
2497 p = dq->elements[0];
2499 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
2501 return setpropagatelearn(solv, level, p, disablerules, ruleid);
2505 /********************************************************************/
2506 /* Main solver interface */
2509 /*-------------------------------------------------------------------
2512 * create solver structure
2514 * pool: all available solvables
2515 * installed: installed Solvables
2518 * Upon solving, rules are created to flag the Solvables
2519 * of the 'installed' Repo as installed.
2523 solver_create(Pool *pool)
2526 solv = (Solver *)sat_calloc(1, sizeof(Solver));
2528 solv->installed = pool->installed;
2530 queue_init(&solv->ruletojob);
2531 queue_init(&solv->decisionq);
2532 queue_init(&solv->decisionq_why);
2533 queue_init(&solv->problems);
2534 queue_init(&solv->suggestions);
2535 queue_init(&solv->recommendations);
2536 queue_init(&solv->orphaned);
2537 queue_init(&solv->learnt_why);
2538 queue_init(&solv->learnt_pool);
2539 queue_init(&solv->branches);
2540 queue_init(&solv->covenantq);
2541 queue_init(&solv->weakruleq);
2542 queue_init(&solv->ruleassertions);
2544 map_init(&solv->recommendsmap, pool->nsolvables);
2545 map_init(&solv->suggestsmap, pool->nsolvables);
2546 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
2547 solv->recommends_index = 0;
2549 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2551 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
2552 memset(solv->rules, 0, sizeof(Rule));
2558 /*-------------------------------------------------------------------
2564 solver_free(Solver *solv)
2566 queue_free(&solv->ruletojob);
2567 queue_free(&solv->decisionq);
2568 queue_free(&solv->decisionq_why);
2569 queue_free(&solv->learnt_why);
2570 queue_free(&solv->learnt_pool);
2571 queue_free(&solv->problems);
2572 queue_free(&solv->suggestions);
2573 queue_free(&solv->recommendations);
2574 queue_free(&solv->orphaned);
2575 queue_free(&solv->branches);
2576 queue_free(&solv->covenantq);
2577 queue_free(&solv->weakruleq);
2578 queue_free(&solv->ruleassertions);
2580 map_free(&solv->recommendsmap);
2581 map_free(&solv->suggestsmap);
2582 map_free(&solv->noupdate);
2583 map_free(&solv->weakrulemap);
2584 map_free(&solv->noobsoletes);
2586 map_free(&solv->updatemap);
2587 map_free(&solv->dupmap);
2588 map_free(&solv->dupinvolvedmap);
2590 sat_free(solv->decisionmap);
2591 sat_free(solv->rules);
2592 sat_free(solv->watches);
2593 sat_free(solv->obsoletes);
2594 sat_free(solv->obsoletes_data);
2595 sat_free(solv->multiversionupdaters);
2600 /*-------------------------------------------------------------------
2604 * all rules have been set up, now actually run the solver
2609 run_solver(Solver *solv, int disablerules, int doweak)
2611 Queue dq; /* local decisionqueue */
2612 Queue dqs; /* local decisionqueue for supplements */
2618 Pool *pool = solv->pool;
2620 int minimizationsteps;
2622 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2624 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2625 for (i = 1; i < solv->nrules; i++)
2626 solver_printruleclass(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2629 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2631 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2632 solver_printdecisions(solv);
2634 /* start SAT algorithm */
2636 systemlevel = level + 1;
2637 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2643 * here's the main loop:
2644 * 1) propagate new decisions (only needed for level 1)
2645 * 2) try to keep installed packages
2646 * 3) fulfill all unresolved rules
2647 * 4) install recommended packages
2648 * 5) minimalize solution if we had choices
2649 * if we encounter a problem, we rewind to a safe level and restart
2653 minimizationsteps = 0;
2662 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2663 if ((r = propagate(solv, level)) != 0)
2665 if (analyze_unsolvable(solv, r, disablerules))
2673 if (level < systemlevel)
2675 POOL_DEBUG(SAT_DEBUG_STATS, "resolving job rules\n");
2676 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
2679 if (r->d < 0) /* ignore disabled rules */
2682 FOR_RULELITERALS(l, dp, r)
2686 if (solv->decisionmap[-l] <= 0)
2691 if (solv->decisionmap[l] > 0)
2693 if (solv->decisionmap[l] == 0)
2699 /* prune to installed if not updating */
2700 if (!solv->updatesystem && solv->installed && dq.count > 1)
2703 for (j = k = 0; j < dq.count; j++)
2705 Solvable *s = pool->solvables + dq.elements[j];
2706 if (s->repo == solv->installed)
2707 dq.elements[k++] = dq.elements[j];
2713 level = selectandinstall(solv, level, &dq, disablerules, i);
2720 if (level <= olevel)
2723 systemlevel = level + 1;
2724 if (i < solv->jobrules_end)
2730 * installed packages
2733 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2735 Repo *installed = solv->installed;
2738 /* we use two passes if we need to update packages
2739 * to create a better user experience */
2740 for (pass = solv->updatemap.size ? 0 : 1; pass < 2; pass++)
2742 FOR_REPO_SOLVABLES(installed, i, s)
2747 if (MAPTST(&solv->noupdate, i - installed->start))
2749 if (solv->decisionmap[i] > 0)
2751 if (!pass && solv->updatemap.size && !MAPTST(&solv->updatemap, i - installed->start))
2752 continue; /* updates first */
2753 r = solv->rules + solv->updaterules + (i - installed->start);
2755 if (!rr->p || rr->d < 0) /* disabled -> look at feature rule */
2756 rr -= solv->installed->end - solv->installed->start;
2757 if (!rr->p) /* identical to update rule? */
2760 continue; /* orpaned package */
2763 if (solv->decisionmap[i] < 0 || solv->updatesystem || (solv->updatemap.size && MAPTST(&solv->updatemap, i - installed->start)) || rr->p != i)
2765 if (solv->noobsoletes.size && solv->multiversionupdaters
2766 && (d = solv->multiversionupdaters[i - installed->start]) != 0)
2768 /* special multiversion handling, make sure best version is chosen */
2770 while ((p = pool->whatprovidesdata[d++]) != 0)
2771 if (solv->decisionmap[p] >= 0)
2773 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2775 if (p != i && solv->decisionmap[p] == 0)
2777 rr = solv->rules + solv->featurerules + (i - solv->installed->start);
2778 if (!rr->p) /* update rule == feature rule? */
2779 rr = rr - solv->featurerules + solv->updaterules;
2787 /* update to best package */
2788 FOR_RULELITERALS(p, dp, rr)
2790 if (solv->decisionmap[p] > 0)
2792 dq.count = 0; /* already fulfilled */
2795 if (!solv->decisionmap[p])
2800 /* install best version */
2804 level = selectandinstall(solv, level, &dq, disablerules, rr - solv->rules);
2811 if (level <= olevel)
2814 /* if still undecided keep package */
2815 if (solv->decisionmap[i] == 0)
2818 POOL_DEBUG(SAT_DEBUG_POLICY, "keeping %s\n", solvable2str(pool, pool->solvables + i));
2819 level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules);
2826 if (level <= olevel)
2830 if (i < installed->end)
2833 systemlevel = level + 1;
2835 continue; /* had trouble, retry */
2838 if (level < systemlevel)
2839 systemlevel = level;
2845 POOL_DEBUG(SAT_DEBUG_POLICY, "deciding unresolved rules\n");
2846 for (i = 1, n = 1; ; i++, n++)
2848 if (n == solv->nrules)
2850 if (i == solv->nrules)
2852 r = solv->rules + i;
2853 if (r->d < 0) /* ignore disabled rules */
2858 /* binary or unary rule */
2859 /* need two positive undecided literals */
2860 if (r->p < 0 || r->w2 <= 0)
2862 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2864 queue_push(&dq, r->p);
2865 queue_push(&dq, r->w2);
2870 * all negative literals are installed
2871 * no positive literal is installed
2872 * i.e. the rule is not fulfilled and we
2873 * just need to decide on the positive literals
2877 if (solv->decisionmap[-r->p] <= 0)
2882 if (solv->decisionmap[r->p] > 0)
2884 if (solv->decisionmap[r->p] == 0)
2885 queue_push(&dq, r->p);
2887 dp = pool->whatprovidesdata + r->d;
2888 while ((p = *dp++) != 0)
2892 if (solv->decisionmap[-p] <= 0)
2897 if (solv->decisionmap[p] > 0)
2899 if (solv->decisionmap[p] == 0)
2906 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2908 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2909 solver_printruleclass(solv, SAT_DEBUG_PROPAGATE, r);
2911 /* dq.count < 2 cannot happen as this means that
2912 * the rule is unit */
2913 assert(dq.count > 1);
2916 level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
2923 if (level < systemlevel)
2926 } /* for(), decide */
2928 if (n != solv->nrules) /* continue if level < systemlevel */
2935 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended packages\n");
2936 queue_empty(&dq); /* recommended packages */
2937 queue_empty(&dqs); /* supplemented packages */
2938 for (i = 1; i < pool->nsolvables; i++)
2940 if (solv->decisionmap[i] < 0)
2942 if (solv->decisionmap[i] > 0)
2944 /* installed, check for recommends */
2945 Id *recp, rec, pp, p;
2946 s = pool->solvables + i;
2947 if (solv->ignorealreadyrecommended && s->repo == solv->installed)
2949 /* XXX need to special case AND ? */
2952 recp = s->repo->idarraydata + s->recommends;
2953 while ((rec = *recp++) != 0)
2956 FOR_PROVIDES(p, pp, rec)
2958 if (solv->decisionmap[p] > 0)
2963 else if (solv->decisionmap[p] == 0)
2965 queue_pushunique(&dq, p);
2973 s = pool->solvables + i;
2974 if (!s->supplements)
2976 if (!pool_installable(pool, s))
2978 if (!solver_is_supplementing(solv, s))
2980 queue_push(&dqs, i);
2984 /* filter out all packages obsoleted by installed packages */
2985 /* this is no longer needed if we have reverse obsoletes */
2986 if ((dqs.count || dq.count) && solv->installed)
2989 Id obs, *obsp, po, ppo;
2991 map_init(&obsmap, pool->nsolvables);
2992 for (p = solv->installed->start; p < solv->installed->end; p++)
2994 s = pool->solvables + p;
2995 if (s->repo != solv->installed || !s->obsoletes)
2997 if (solv->decisionmap[p] <= 0)
2999 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p))
3001 obsp = s->repo->idarraydata + s->obsoletes;
3002 /* foreach obsoletes */
3003 while ((obs = *obsp++) != 0)
3004 FOR_PROVIDES(po, ppo, obs)
3005 MAPSET(&obsmap, po);
3007 for (i = j = 0; i < dqs.count; i++)
3008 if (!MAPTST(&obsmap, dqs.elements[i]))
3009 dqs.elements[j++] = dqs.elements[i];
3011 for (i = j = 0; i < dq.count; i++)
3012 if (!MAPTST(&obsmap, dq.elements[i]))
3013 dq.elements[j++] = dq.elements[i];
3018 /* filter out all already supplemented packages if requested */
3019 if (solv->ignorealreadyrecommended && dqs.count)
3021 /* turn off all new packages */
3022 for (i = 0; i < solv->decisionq.count; i++)
3024 p = solv->decisionq.elements[i];
3027 s = pool->solvables + p;
3028 if (s->repo && s->repo != solv->installed)
3029 solv->decisionmap[p] = -solv->decisionmap[p];
3031 /* filter out old supplements */
3032 for (i = j = 0; i < dqs.count; i++)
3034 p = dqs.elements[i];
3035 s = pool->solvables + p;
3036 if (!s->supplements)
3038 if (!solver_is_supplementing(solv, s))
3039 dqs.elements[j++] = p;
3042 /* undo turning off */
3043 for (i = 0; i < solv->decisionq.count; i++)
3045 p = solv->decisionq.elements[i];
3048 s = pool->solvables + p;
3049 if (s->repo && s->repo != solv->installed)
3050 solv->decisionmap[p] = -solv->decisionmap[p];
3054 /* make dq contain both recommended and supplemented pkgs */
3057 for (i = 0; i < dqs.count; i++)
3058 queue_pushunique(&dq, dqs.elements[i]);
3065 int decisioncount = solv->decisionq.count;
3069 /* simple case, just one package. no need to choose */
3072 POOL_DEBUG(SAT_DEBUG_POLICY, "installing supplemented %s\n", solvable2str(pool, pool->solvables + p));
3074 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
3075 queue_push(&solv->recommendations, p);
3076 level = setpropagatelearn(solv, level, p, 0, 0);
3080 /* filter and create a map of result */
3081 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
3082 map_init(&dqmap, pool->nsolvables);
3083 for (i = 0; i < dq.count; i++)
3084 MAPSET(&dqmap, dq.elements[i]);
3086 /* install all supplemented packages */
3087 for (i = 0; i < dqs.count; i++)
3089 p = dqs.elements[i];
3090 if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
3092 POOL_DEBUG(SAT_DEBUG_POLICY, "installing supplemented %s\n", solvable2str(pool, pool->solvables + p));
3093 queue_push(&solv->recommendations, p);
3095 level = setpropagatelearn(solv, level, p, 0, 0);
3096 if (level <= olevel)
3099 if (i < dqs.count || solv->decisionq.count < decisioncount)
3105 /* install all recommended packages */
3106 /* more work as we want to created branches if multiple
3107 * choices are valid */
3108 for (i = 0; i < decisioncount; i++)
3111 p = solv->decisionq.elements[i];
3114 s = pool->solvables + p;
3115 if (!s->repo || (solv->ignorealreadyrecommended && s->repo == solv->installed))
3119 recp = s->repo->idarraydata + s->recommends;
3120 while ((rec = *recp++) != 0)
3123 FOR_PROVIDES(p, pp, rec)
3125 if (solv->decisionmap[p] > 0)
3130 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
3131 queue_pushunique(&dq, p);
3137 /* multiple candidates, open a branch */
3138 for (i = 1; i < dq.count; i++)
3139 queue_push(&solv->branches, dq.elements[i]);
3140 queue_push(&solv->branches, -level);
3143 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
3144 queue_push(&solv->recommendations, p);
3146 level = setpropagatelearn(solv, level, p, 0, 0);
3147 if (level <= olevel || solv->decisionq.count < decisioncount)
3151 break; /* had a problem above, quit loop */
3160 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
3162 /* prefer recommended patterns (bnc#450226) */
3163 /* real fix is to minimize recommended packages as well */
3164 for (i = 0; i < dq.count; i++)
3165 if (!strncmp(id2str(pool, pool->solvables[dq.elements[i]].name), "pattern:", 8))
3170 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
3171 queue_push(&solv->recommendations, p);
3172 level = setpropagatelearn(solv, level, p, 0, 0);
3178 if (solv->distupgrade && solv->installed)
3180 int installedone = 0;
3182 /* let's see if we can install some unsupported package */
3183 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unsupported packages\n");
3184 for (i = 0; i < solv->orphaned.count; i++)
3186 p = solv->orphaned.elements[i];
3187 if (solv->decisionmap[p])
3188 continue; /* already decided */
3190 if (solv->distupgrade_removeunsupported)
3192 POOL_DEBUG(SAT_DEBUG_STATS, "removing unsupported %s\n", solvable2str(pool, pool->solvables + p));
3193 level = setpropagatelearn(solv, level, -p, 0, 0);
3197 POOL_DEBUG(SAT_DEBUG_STATS, "keeping unsupported %s\n", solvable2str(pool, pool->solvables + p));
3198 level = setpropagatelearn(solv, level, p, 0, 0);
3204 if (installedone || i < solv->orphaned.count)
3208 if (solv->solution_callback)
3210 solv->solution_callback(solv, solv->solution_callback_data);
3211 if (solv->branches.count)
3213 int i = solv->branches.count - 1;
3214 int l = -solv->branches.elements[i];
3218 if (solv->branches.elements[i - 1] < 0)
3220 p = solv->branches.elements[i];
3221 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
3223 for (j = i + 1; j < solv->branches.count; j++)
3224 queue_push(&dq, solv->branches.elements[j]);
3225 solv->branches.count = i;
3227 revert(solv, level);
3229 for (j = 0; j < dq.count; j++)
3230 queue_push(&solv->branches, dq.elements[j]);
3232 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
3234 level = setpropagatelearn(solv, level, p, disablerules, why);
3243 /* all branches done, we're finally finished */
3247 /* minimization step */
3248 if (solv->branches.count)
3250 int l = 0, lasti = -1, lastl = -1;
3254 for (i = solv->branches.count - 1; i >= 0; i--)
3256 p = solv->branches.elements[i];
3259 else if (p > 0 && solv->decisionmap[p] > l + 1)
3267 /* kill old solvable so that we do not loop */
3268 p = solv->branches.elements[lasti];
3269 solv->branches.elements[lasti] = 0;
3270 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], lastl, solvable2str(pool, pool->solvables + p));
3271 minimizationsteps++;
3274 revert(solv, level);
3275 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
3278 level = setpropagatelearn(solv, level, p, disablerules, why);
3290 POOL_DEBUG(SAT_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
3292 POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
3298 /*-------------------------------------------------------------------
3302 * at this point, all rules that led to conflicts are disabled.
3303 * we re-enable all rules of a problem set but rule "sug", then
3304 * continue to disable more rules until there as again a solution.
3307 /* FIXME: think about conflicting assertions */
3310 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
3312 Pool *pool = solv->pool;
3318 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
3320 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
3321 for (i = 0; problem[i]; i++)
3323 if (problem[i] == sug)
3324 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
3325 solver_printproblem(solv, problem[i]);
3328 queue_init(&disabled);
3329 queue_empty(refined);
3330 queue_push(refined, sug);
3332 /* re-enable all problem rules with the exception of "sug"(gestion) */
3336 for (i = 0; problem[i]; i++)
3337 if (problem[i] != sug)
3338 enableproblem(solv, problem[i]);
3341 disableupdaterules(solv, job, -(sug + 1));
3342 else if (sug >= solv->updaterules && sug < solv->updaterules_end)
3344 /* enable feature rule */
3345 Rule *r = solv->rules + solv->featurerules + (sug - solv->updaterules);
3347 enablerule(solv, r);
3350 enableweakrules(solv);
3354 int njob, nfeature, nupdate;
3355 queue_empty(&solv->problems);
3356 revert(solv, 1); /* XXX no longer needed? */
3359 if (!solv->problems.count)
3360 run_solver(solv, 0, 0);
3362 if (!solv->problems.count)
3364 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
3365 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3366 solver_printdecisions(solv);
3367 break; /* great, no more problems */
3369 disabledcnt = disabled.count;
3370 /* start with 1 to skip over proof index */
3371 njob = nfeature = nupdate = 0;
3372 for (i = 1; i < solv->problems.count - 1; i++)
3374 /* ignore solutions in refined */
3375 v = solv->problems.elements[i];
3377 break; /* end of problem reached */
3378 for (j = 0; problem[j]; j++)
3379 if (problem[j] != sug && problem[j] == v)
3383 if (v >= solv->featurerules && v < solv->featurerules_end)
3389 if ((job->elements[-v -1] & SOLVER_ESSENTIAL) != 0)
3390 continue; /* not that one! */
3393 queue_push(&disabled, v);
3395 if (disabled.count == disabledcnt)
3397 /* no solution found, this was an invalid suggestion! */
3398 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
3402 if (!njob && nupdate && nfeature)
3404 /* got only update rules, filter out feature rules */
3405 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "throwing away feature rules\n");
3406 for (i = j = disabledcnt; i < disabled.count; i++)
3408 v = disabled.elements[i];
3409 if (v < solv->featurerules || v >= solv->featurerules_end)
3410 disabled.elements[j++] = v;
3415 if (disabled.count == disabledcnt + 1)
3417 /* just one suggestion, add it to refined list */
3418 v = disabled.elements[disabledcnt];
3420 queue_push(refined, v); /* do not record feature rules */
3421 disableproblem(solv, v);
3422 if (v >= solv->updaterules && v < solv->updaterules_end)
3424 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
3426 enablerule(solv, r); /* enable corresponding feature rule */
3429 disableupdaterules(solv, job, -(v + 1));
3433 /* more than one solution, disable all */
3434 /* do not push anything on refine list, as we do not know which solution to choose */
3435 /* thus, the user will get another problem if he selects this solution, where he
3436 * can choose the right one */
3437 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
3439 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
3440 for (i = disabledcnt; i < disabled.count; i++)
3441 solver_printproblem(solv, disabled.elements[i]);
3443 for (i = disabledcnt; i < disabled.count; i++)
3445 v = disabled.elements[i];
3446 disableproblem(solv, v);
3447 if (v >= solv->updaterules && v < solv->updaterules_end)
3449 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
3451 enablerule(solv, r);
3456 /* all done, get us back into the same state as before */
3457 /* enable refined rules again */
3458 for (i = 0; i < disabled.count; i++)
3459 enableproblem(solv, disabled.elements[i]);
3460 queue_free(&disabled);
3461 /* disable problem rules again */
3464 for (i = 0; problem[i]; i++)
3465 enableproblem(solv, problem[i]);
3466 disableupdaterules(solv, job, -1);
3468 /* disable problem rules again */
3469 for (i = 0; problem[i]; i++)
3470 disableproblem(solv, problem[i]);
3471 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
3475 /*-------------------------------------------------------------------
3476 * sorting helper for problems
3478 * bring update rules before job rules
3479 * make essential job rules last
3482 Queue *problems_sort_data;
3485 problems_sortcmp(const void *ap, const void *bp)
3487 Id a = *(Id *)ap, b = *(Id *)bp;
3494 Queue *job = problems_sort_data;
3495 int af = job->elements[-a - 1] & SOLVER_ESSENTIAL;
3496 int bf = job->elements[-b - 1] & SOLVER_ESSENTIAL;
3505 /*-------------------------------------------------------------------
3510 problems_sort(Solver *solv, Queue *job)
3513 if (!solv->problems.count)
3515 for (i = j = 1; i < solv->problems.count; i++)
3517 if (!solv->problems.elements[i])
3521 problems_sort_data = job;
3522 qsort(solv->problems.elements + j, i - j, sizeof(Id), problems_sortcmp);
3524 if (++i == solv->problems.count)
3532 /*-------------------------------------------------------------------
3533 * convert problems to solutions
3537 problems_to_solutions(Solver *solv, Queue *job)
3539 Pool *pool = solv->pool;
3545 int i, j, nsol, probsolved;
3546 unsigned int now, refnow;
3548 if (!solv->problems.count)
3550 now = sat_timems(0);
3551 problems_sort(solv, job);
3552 queue_clone(&problems, &solv->problems);
3553 queue_init(&solution);
3554 queue_init(&solutions);
3555 /* copy over proof index */
3556 queue_push(&solutions, problems.elements[0]);
3557 problem = problems.elements + 1;
3559 refnow = sat_timems(0);
3560 for (i = 1; i < problems.count; i++)
3562 Id v = problems.elements[i];
3565 /* mark end of this problem */
3566 queue_push(&solutions, 0);
3567 queue_push(&solutions, 0);
3568 POOL_DEBUG(SAT_DEBUG_STATS, "refining took %d ms\n", sat_timems(refnow));
3569 if (i + 1 == problems.count)
3571 /* copy over proof of next problem */
3572 queue_push(&solutions, problems.elements[i + 1]);
3574 problem = problems.elements + i + 1;
3575 refnow = sat_timems(0);
3579 if (v < 0 && (job->elements[-v - 1] & SOLVER_ESSENTIAL))
3581 /* essential job, skip if we already have a non-essential
3585 probsolved = -1; /* show all solutions */
3587 refine_suggestion(solv, job, problem, v, &solution);
3588 if (!solution.count)
3589 continue; /* this solution didn't work out */
3592 for (j = 0; j < solution.count; j++)
3594 why = solution.elements[j];
3595 /* must be either job descriptor or update rule */
3597 solver_printproblem(solv, why);
3601 /* job descriptor */
3602 queue_push(&solutions, 0);
3603 queue_push(&solutions, -why);
3605 else if (why >= solv->infarchrules && why < solv->infarchrules_end)
3608 /* infarch rule, find replacement */
3609 assert(solv->rules[why].p < 0);
3610 name = pool->solvables[-solv->rules[why].p].name;
3611 while (why >= solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
3614 for (; why < solv->infarchrules_end && pool->solvables[-solv->rules[why].p].name == name; why++)
3615 if (solv->decisionmap[-solv->rules[why].p] > 0)
3617 p = -solv->rules[why].p;
3621 p = -solv->rules[why].p; /* XXX: what to do here? */
3622 queue_push(&solutions, SOLVER_SOLUTION_INFARCH);
3623 queue_push(&solutions, p);
3625 else if (why >= solv->duprules && why < solv->duprules_end)
3628 /* dist upgrade rule, find replacement */
3629 assert(solv->rules[why].p < 0);
3630 name = pool->solvables[-solv->rules[why].p].name;
3631 while (why >= solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
3634 for (; why < solv->infarchrules_end && pool->solvables[-solv->rules[why].p].name == name; why++)
3635 if (solv->decisionmap[-solv->rules[why].p] > 0)
3637 p = -solv->rules[why].p;
3641 p = -solv->rules[why].p; /* XXX: what to do here? */
3642 queue_push(&solutions, SOLVER_SOLUTION_DISTUPGRADE);
3643 queue_push(&solutions, p);
3647 /* update rule, find replacement package */
3651 assert(why >= solv->updaterules && why < solv->updaterules_end);
3652 /* check if this is a false positive, i.e. the update rule is fulfilled */
3653 rr = solv->rules + why;
3654 FOR_RULELITERALS(p, dp, rr)
3655 if (p > 0 && solv->decisionmap[p] > 0)
3658 continue; /* false alarm */
3660 p = solv->installed->start + (why - solv->updaterules);
3661 rr = solv->rules + solv->featurerules + (why - solv->updaterules);
3663 rr = solv->rules + why;
3664 if (solv->distupgrade && solv->rules[why].p != p && solv->decisionmap[p] > 0)
3666 /* distupgrade case, allow to keep old package */
3667 queue_push(&solutions, p);
3668 queue_push(&solutions, p);
3672 if (solv->decisionmap[p] > 0)
3673 continue; /* false alarm, turned out we can keep the package */
3676 int mvrp = 0; /* multi-version replacement */
3677 FOR_RULELITERALS(rp, dp, rr)
3679 if (rp > 0 && solv->decisionmap[rp] > 0 && pool->solvables[rp].repo != solv->installed)
3682 if (!(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, rp)))
3688 /* found only multi-version replacements */
3689 /* have to split solution into two parts */
3690 queue_push(&solutions, p);
3691 queue_push(&solutions, mvrp);
3695 queue_push(&solutions, p);
3696 queue_push(&solutions, rp);
3700 /* mark end of this solution */
3705 queue_push(&solutions, 0);
3706 queue_push(&solutions, 0);
3710 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "Oops, everything was fine?\n");
3713 queue_free(&solution);
3714 queue_free(&problems);
3715 /* copy queue over to solutions */
3716 queue_free(&solv->problems);
3717 queue_clone(&solv->problems, &solutions);
3719 /* bring solver back into problem state */
3720 revert(solv, 1); /* XXX move to reset_solver? */
3723 assert(solv->problems.count == solutions.count);
3724 queue_free(&solutions);
3725 POOL_DEBUG(SAT_DEBUG_STATS, "problems_to_solutions took %d ms\n", sat_timems(now));
3729 /*-------------------------------------------------------------------
3733 * advance to next problem
3737 solver_next_problem(Solver *solv, Id problem)
3741 return solv->problems.count ? 1 : 0;
3742 pp = solv->problems.elements + problem;
3743 while (pp[0] || pp[1])
3747 while (pp[0] || pp[1])
3752 problem = pp - solv->problems.elements;
3753 if (problem >= solv->problems.count)
3759 /*-------------------------------------------------------------------
3765 solver_next_solution(Solver *solv, Id problem, Id solution)
3771 pp = solv->problems.elements + solution;
3772 return pp[0] || pp[1] ? solution : 0;
3774 pp = solv->problems.elements + solution;
3775 while (pp[0] || pp[1])
3778 solution = pp - solv->problems.elements;
3779 return pp[0] || pp[1] ? solution : 0;
3783 /*-------------------------------------------------------------------
3785 * solution element iterator
3789 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
3792 element = element ? element + 2 : solution;
3793 pp = solv->problems.elements + element;
3794 if (!(pp[0] || pp[1]))
3802 /*-------------------------------------------------------------------
3804 * Retrieve information about a problematic rule
3806 * this is basically the reverse of addrpmrulesforsolvable
3810 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
3812 Pool *pool = solv->pool;
3813 Repo *installed = solv->installed;
3817 Id p, d, w2, pp, req, *reqp, con, *conp, obs, *obsp, *dp;
3820 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
3822 r = solv->rules + rid;
3823 *depp = r->p < 0 ? pool->solvables[-r->p].name : 0;
3824 *sourcep = r->p < 0 ? -r->p : 0;
3826 return SOLVER_PROBLEM_INFARCH_RULE;
3828 if (rid >= solv->duprules && rid < solv->duprules_end)
3830 r = solv->rules + rid;
3831 *depp = r->p < 0 ? pool->solvables[-r->p].name : 0;
3832 *sourcep = r->p < 0 ? -r->p : 0;
3834 return SOLVER_PROBLEM_DISTUPGRADE_RULE;
3836 if (rid >= solv->jobrules && rid < solv->jobrules_end)
3839 r = solv->rules + rid;
3840 p = solv->ruletojob.elements[rid - solv->jobrules];
3841 *depp = job->elements[p + 1];
3843 *targetp = job->elements[p];
3844 d = r->d < 0 ? -r->d - 1 : r->d;
3845 if (d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && (job->elements[p] & SOLVER_SELECTMASK) != SOLVER_SOLVABLE_ONE_OF)
3846 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
3847 return SOLVER_PROBLEM_JOB_RULE;
3849 if (rid >= solv->updaterules && rid < solv->updaterules_end)
3852 *sourcep = solv->installed->start + (rid - solv->updaterules);
3854 return SOLVER_PROBLEM_UPDATE_RULE;
3856 assert(rid < solv->rpmrules_end);
3857 r = solv->rules + rid;
3859 d = r->d < 0 ? -r->d - 1 : r->d;
3860 if (d == 0 && r->w2 == 0)
3862 /* a rpm rule assertion */
3863 s = pool->solvables - r->p;
3864 if (installed && !solv->fixsystem && s->repo == installed)
3866 assert(!dontfix); /* dontfix packages never have a neg assertion */
3869 /* see why the package is not installable */
3870 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
3873 return SOLVER_PROBLEM_NOT_INSTALLABLE;
3875 /* check requires */
3878 reqp = s->repo->idarraydata + s->requires;
3879 while ((req = *reqp++) != 0)
3881 if (req == SOLVABLE_PREREQMARKER)
3883 dp = pool_whatprovides_ptr(pool, req);
3890 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
3893 if (!solv->allowselfconflicts && s->conflicts)
3895 conp = s->repo->idarraydata + s->conflicts;
3896 while ((con = *conp++) != 0)
3897 FOR_PROVIDES(p, pp, con)
3901 return SOLVER_PROBLEM_SELF_CONFLICT;
3904 /* should never happen */
3906 return SOLVER_PROBLEM_RPM_RULE;
3908 s = pool->solvables - r->p;
3909 if (installed && !solv->fixsystem && s->repo == installed)
3912 if (d && pool->whatprovidesdata[d] < 0)
3914 /* rule looks like -p|-c|x|x|x..., we only create this for patches with multiversion */
3915 /* reduce it to -p|-c case */
3917 w2 = pool->whatprovidesdata[d];
3919 if (d == 0 && w2 < 0)
3921 /* a package conflict */
3922 Solvable *s2 = pool->solvables - w2;
3925 if (installed && !solv->fixsystem && s2->repo == installed)
3928 /* if both packages have the same name and at least one of them
3929 * is not installed, they conflict */
3930 if (s->name == s2->name && !(installed && s->repo == installed && s2->repo == installed))
3932 /* also check noobsoletes map */
3933 if ((s->evr == s2->evr && s->arch == s2->arch) || !solv->noobsoletes.size
3934 || ((!installed || s->repo != installed) && !MAPTST(&solv->noobsoletes, -r->p))
3935 || ((!installed || s2->repo != installed) && !MAPTST(&solv->noobsoletes, -w2)))
3940 return SOLVER_PROBLEM_SAME_NAME;
3944 /* check conflicts in both directions */
3947 conp = s->repo->idarraydata + s->conflicts;
3948 while ((con = *conp++) != 0)
3950 FOR_PROVIDES(p, pp, con)
3952 if (dontfix && pool->solvables[p].repo == installed)
3959 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3965 conp = s2->repo->idarraydata + s2->conflicts;
3966 while ((con = *conp++) != 0)
3968 FOR_PROVIDES(p, pp, con)
3970 if (dontfix2 && pool->solvables[p].repo == installed)
3977 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3981 /* check obsoletes in both directions */
3982 if ((!installed || s->repo != installed) && s->obsoletes && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->p)))
3984 obsp = s->repo->idarraydata + s->obsoletes;
3985 while ((obs = *obsp++) != 0)
3987 FOR_PROVIDES(p, pp, obs)
3991 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
3996 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
4000 if ((!installed || s2->repo != installed) && s2->obsoletes && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -w2)))
4002 obsp = s2->repo->idarraydata + s2->obsoletes;
4003 while ((obs = *obsp++) != 0)
4005 FOR_PROVIDES(p, pp, obs)
4009 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
4014 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
4018 if (solv->implicitobsoleteusesprovides && (!installed || s->repo != installed) && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->p)))
4020 FOR_PROVIDES(p, pp, s->name)
4027 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
4030 if (solv->implicitobsoleteusesprovides && (!installed || s2->repo != installed) && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -w2)))
4032 FOR_PROVIDES(p, pp, s2->name)
4039 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
4042 /* all cases checked, can't happen */
4046 return SOLVER_PROBLEM_RPM_RULE;
4048 /* simple requires */
4051 reqp = s->repo->idarraydata + s->requires;
4052 while ((req = *reqp++) != 0)
4054 if (req == SOLVABLE_PREREQMARKER)
4056 dp = pool_whatprovides_ptr(pool, req);
4059 if (*dp == r->w2 && dp[1] == 0)
4062 else if (dp - pool->whatprovidesdata == d)
4070 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
4074 /* check for product buddy requires */
4075 if (d == 0 && w2 > 0 && pool->nscallback)
4078 s = pool->solvables - r->p;
4079 if (!strncmp("product:", id2str(pool, s->name), 8))
4081 buddy = pool->nscallback(pool, pool->nscallbackdata, NAMESPACE_PRODUCTBUDDY, -r->p);
4087 s = pool->solvables + w2;
4088 if (!strncmp("product:", id2str(pool, s->name), 8))
4090 buddy = pool->nscallback(pool, pool->nscallbackdata, NAMESPACE_PRODUCTBUDDY, w2);
4097 /* have buddy relation, now fake requires */
4098 s = pool->solvables + w2;
4100 if (s->repo && s->provides)
4103 provp = s->repo->idarraydata + s->provides;
4104 while ((prov = *provp++) != 0)
4106 if (!ISRELDEP(prov))
4108 rd = GETRELDEP(pool, prov);
4109 if (rd->name == s->name && rd->evr == s->evr && rd->flags == REL_EQ)
4114 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
4121 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
4125 /* all cases checked, can't happen */
4129 return SOLVER_PROBLEM_RPM_RULE;
4133 /*-------------------------------------------------------------------
4139 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
4142 Id lreqr, lconr, lsysr, ljobr;
4146 lreqr = lconr = lsysr = ljobr = 0;
4147 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
4150 if (rid >= solv->learntrules)
4151 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
4152 else if ((rid >= solv->jobrules && rid < solv->jobrules_end) || (rid >= solv->infarchrules && rid < solv->infarchrules_end) || (rid >= solv->duprules && rid < solv->duprules_end))
4157 else if (rid >= solv->updaterules && rid < solv->updaterules_end)
4164 assert(rid < solv->rpmrules_end);
4165 r = solv->rules + rid;
4166 d = r->d < 0 ? -r->d - 1 : r->d;
4167 if (!d && r->w2 < 0)
4174 if (!d && r->w2 == 0 && !reqassert)
4176 if (*reqrp > 0 && r->p < -1)
4178 Id op = -solv->rules[*reqrp].p;
4179 if (op > 1 && solv->pool->solvables[op].arch != solv->pool->solvables[-r->p].arch)
4180 continue; /* different arch, skip */
4182 /* prefer assertions */
4188 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed && !reqassert)
4190 /* prefer rules of installed packages */
4196 if (!*reqrp && lreqr)
4198 if (!*conrp && lconr)
4200 if (!*jobrp && ljobr)
4202 if (!*sysrp && lsysr)
4207 /*-------------------------------------------------------------------
4211 * search for a rule that describes the problem to the
4212 * user. A pretty hopeless task, actually. We currently
4213 * prefer simple requires.
4217 solver_findproblemrule(Solver *solv, Id problem)
4219 Id reqr, conr, sysr, jobr;
4220 Id idx = solv->problems.elements[problem - 1];
4221 reqr = conr = sysr = jobr = 0;
4222 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
4235 findallproblemrules_internal(Solver *solv, Id idx, Queue *rules)
4238 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
4240 if (rid >= solv->learntrules)
4242 findallproblemrules_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], rules);
4245 queue_pushunique(rules, rid);
4250 solver_findallproblemrules(Solver *solv, Id problem, Queue *rules)
4253 findallproblemrules_internal(solv, solv->problems.elements[problem - 1], rules);
4257 /*-------------------------------------------------------------------
4259 * create reverse obsoletes map for installed solvables
4261 * for each installed solvable find which packages with *different* names
4262 * obsolete the solvable.
4263 * this index is used in policy_findupdatepackages if noupdateprovide is set.
4267 create_obsolete_index(Solver *solv)
4269 Pool *pool = solv->pool;
4271 Repo *installed = solv->installed;
4272 Id p, pp, obs, *obsp, *obsoletes, *obsoletes_data;
4275 if (!installed || !installed->nsolvables)
4277 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
4278 for (i = 1; i < pool->nsolvables; i++)
4280 s = pool->solvables + i;
4283 if (!pool_installable(pool, s))
4285 obsp = s->repo->idarraydata + s->obsoletes;
4286 while ((obs = *obsp++) != 0)
4288 FOR_PROVIDES(p, pp, obs)
4290 if (pool->solvables[p].repo != installed)
4292 if (pool->solvables[p].name == s->name)
4294 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
4296 obsoletes[p - installed->start]++;
4301 for (i = 0; i < installed->nsolvables; i++)
4304 n += obsoletes[i] + 1;
4307 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
4308 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
4309 for (i = pool->nsolvables - 1; i > 0; i--)
4311 s = pool->solvables + i;
4314 if (!pool_installable(pool, s))
4316 obsp = s->repo->idarraydata + s->obsoletes;
4317 while ((obs = *obsp++) != 0)
4319 FOR_PROVIDES(p, pp, obs)
4321 if (pool->solvables[p].repo != installed)
4323 if (pool->solvables[p].name == s->name)
4325 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
4327 p -= installed->start;
4328 if (obsoletes_data[obsoletes[p]] != i)
4329 obsoletes_data[--obsoletes[p]] = i;
4336 /*-------------------------------------------------------------------
4338 * remove disabled conflicts
4342 removedisabledconflicts(Solver *solv, Queue *removed)
4344 Pool *pool = solv->pool;
4349 Id *decisionmap = solv->decisionmap;
4351 POOL_DEBUG(SAT_DEBUG_SCHUBI, "removedisabledconflicts\n");
4352 queue_empty(removed);
4353 for (i = 0; i < solv->decisionq.count; i++)
4355 p = solv->decisionq.elements[i];
4358 /* a conflict. we never do conflicts on free decisions, so there
4359 * must have been an unit rule */
4360 why = solv->decisionq_why.elements[i];
4362 r = solv->rules + why;
4363 if (r->d < 0 && decisionmap[-p])
4365 /* rule is now disabled, remove from decisionmap */
4366 POOL_DEBUG(SAT_DEBUG_SCHUBI, "removing conflict for package %s[%d]\n", solvable2str(pool, pool->solvables - p), -p);
4367 queue_push(removed, -p);
4368 queue_push(removed, decisionmap[-p]);
4369 decisionmap[-p] = 0;
4372 if (!removed->count)
4374 /* we removed some confliced packages. some of them might still
4375 * be in conflict, so search for unit rules and re-conflict */
4377 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
4379 if (i == solv->nrules)
4382 r = solv->rules + i;
4388 if (r->p < 0 && !decisionmap[-r->p])
4394 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
4396 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
4401 if (r->p < 0 && decisionmap[-r->p] == 0)
4403 if (new || DECISIONMAP_FALSE(r->p))
4405 dp = pool->whatprovidesdata + r->d;
4406 while ((p = *dp++) != 0)
4408 if (new && p == new)
4410 if (p < 0 && decisionmap[-p] == 0)
4419 else if (!DECISIONMAP_FALSE(p))
4429 POOL_DEBUG(SAT_DEBUG_SCHUBI, "re-conflicting package %s[%d]\n", solvable2str(pool, pool->solvables - new), -new);
4430 decisionmap[-new] = -1;
4432 n = 0; /* redo all rules */
4438 /*-------------------------------------------------------------------
4440 * weaken solvable dependencies
4444 weaken_solvable_deps(Solver *solv, Id p)
4449 for (i = 1, r = solv->rules + i; i < solv->rpmrules_end; i++, r++)
4453 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
4454 continue; /* conflict */
4455 queue_push(&solv->weakruleq, i);
4459 /********************************************************************/
4464 addinfarchrules(Solver *solv, Map *addedmap)
4466 Pool *pool = solv->pool;
4468 Id p, pp, a, aa, bestarch;
4469 Solvable *s, *ps, *bests;
4470 Queue badq, allowedarchs;
4473 queue_init(&allowedarchs);
4474 solv->infarchrules = solv->nrules;
4475 for (i = 1; i < pool->nsolvables; i++)
4477 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
4479 s = pool->solvables + i;
4483 queue_empty(&allowedarchs);
4484 FOR_PROVIDES(p, pp, s->name)
4486 ps = pool->solvables + p;
4487 if (ps->name != s->name || !MAPTST(addedmap, p))
4494 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
4495 if (a != 1 && pool->installed && ps->repo == pool->installed && !solv->distupgrade)
4497 queue_pushunique(&allowedarchs, ps->arch); /* also ok to keep this architecture */
4498 continue; /* ignore installed solvables when calculating the best arch */
4500 if (a && a != 1 && (!bestarch || a < bestarch))
4508 /* speed up common case where installed package already has best arch */
4509 if (allowedarchs.count == 1 && bests && allowedarchs.elements[0] == bests->arch)
4510 allowedarchs.count--; /* installed arch is best */
4512 FOR_PROVIDES(p, pp, s->name)
4514 ps = pool->solvables + p;
4515 if (ps->name != s->name || !MAPTST(addedmap, p))
4518 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
4519 if (a != 1 && bestarch && ((a ^ bestarch) & 0xffff0000) != 0)
4521 for (j = 0; j < allowedarchs.count; j++)
4523 aa = allowedarchs.elements[j];
4526 aa = (aa <= pool->lastarch) ? pool->id2arch[aa] : 0;
4527 if (aa && ((a ^ aa) & 0xffff0000) == 0)
4528 break; /* compatible */
4530 if (j == allowedarchs.count)
4531 queue_push(&badq, p);
4536 /* block all solvables in the badq! */
4537 for (j = 0; j < badq.count; j++)
4539 p = badq.elements[j];
4540 addrule(solv, -p, 0);
4544 queue_free(&allowedarchs);
4545 solv->infarchrules_end = solv->nrules;
4549 createdupmaps(Solver *solv, Queue *job)
4551 Pool *pool = solv->pool;
4553 Id how, what, p, pi, pp, obs, *obsp;
4557 map_init(&solv->dupmap, pool->nsolvables);
4558 map_init(&solv->dupinvolvedmap, pool->nsolvables);
4559 for (i = 0; i < job->count; i += 2)
4561 how = job->elements[i];
4562 what = job->elements[i + 1];
4563 switch (how & SOLVER_JOBMASK)
4565 case SOLVER_DISTUPGRADE:
4566 if (what < 0 || what > pool->nrepos)
4568 repo = pool->repos[what];
4569 FOR_REPO_SOLVABLES(repo, p, s)
4571 MAPSET(&solv->dupmap, p);
4572 FOR_PROVIDES(pi, pp, s->name)
4574 ps = pool->solvables + pi;
4575 if (ps->name != s->name)
4577 MAPSET(&solv->dupinvolvedmap, pi);
4581 /* FIXME: check obsoletes/provides combination */
4582 obsp = s->repo->idarraydata + s->obsoletes;
4583 while ((obs = *obsp++) != 0)
4585 FOR_PROVIDES(pi, pp, obs)
4587 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + pi, obs))
4589 MAPSET(&solv->dupinvolvedmap, pi);
4599 MAPCLR(&solv->dupinvolvedmap, SYSTEMSOLVABLE);
4603 freedupmaps(Solver *solv)
4605 map_free(&solv->dupmap);
4606 map_free(&solv->dupinvolvedmap);
4610 addduprules(Solver *solv, Map *addedmap)
4612 Pool *pool = solv->pool;
4617 solv->duprules = solv->nrules;
4618 for (i = 1; i < pool->nsolvables; i++)
4620 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
4622 s = pool->solvables + i;
4624 FOR_PROVIDES(p, pp, s->name)
4626 ps = pool->solvables + p;
4627 if (ps->name != s->name || !MAPTST(addedmap, p))
4633 if (!MAPTST(&solv->dupinvolvedmap, p))
4635 if (solv->installed && ps->repo == solv->installed)
4637 if (!solv->updatemap.size)
4638 map_init(&solv->updatemap, pool->nsolvables);
4639 MAPSET(&solv->updatemap, p);
4640 if (!MAPTST(&solv->dupmap, p))
4643 /* is installed identical to a good one? */
4644 FOR_PROVIDES(ip, ipp, s->name)
4646 Solvable *is = pool->solvables + ip;
4647 if (!MAPTST(&solv->dupmap, ip))
4649 if (is->evr == s->evr && solvable_identical(s, is))
4653 addrule(solv, -p, 0); /* no match, sorry */
4656 else if (!MAPTST(&solv->dupmap, p))
4657 addrule(solv, -p, 0);
4660 solv->duprules_end = solv->nrules;
4670 solver_solve(Solver *solv, Queue *job)
4672 Pool *pool = solv->pool;
4673 Repo *installed = solv->installed;
4676 Map addedmap; /* '1' == have rpm-rules for solvable */
4677 Map installcandidatemap;
4678 Id how, what, select, name, weak, p, pp, d;
4683 int now, solve_start;
4686 solve_start = sat_timems(0);
4687 POOL_DEBUG(SAT_DEBUG_STATS, "solver started\n");
4688 POOL_DEBUG(SAT_DEBUG_STATS, "fixsystem=%d updatesystem=%d dosplitprovides=%d, noupdateprovide=%d\n", solv->fixsystem, solv->updatesystem, solv->dosplitprovides, solv->noupdateprovide);
4689 POOL_DEBUG(SAT_DEBUG_STATS, "distupgrade=%d distupgrade_removeunsupported=%d\n", solv->distupgrade, solv->distupgrade_removeunsupported);
4690 POOL_DEBUG(SAT_DEBUG_STATS, "allowuninstall=%d, allowdowngrade=%d, allowarchchange=%d, allowvendorchange=%d\n", solv->allowuninstall, solv->allowdowngrade, solv->allowarchchange, solv->allowvendorchange);
4691 POOL_DEBUG(SAT_DEBUG_STATS, "promoteepoch=%d, allowvirtualconflicts=%d, allowselfconflicts=%d\n", pool->promoteepoch, solv->allowvirtualconflicts, solv->allowselfconflicts);
4692 POOL_DEBUG(SAT_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d\n", solv->obsoleteusesprovides, solv->implicitobsoleteusesprovides);
4693 POOL_DEBUG(SAT_DEBUG_STATS, "dontinstallrecommended=%d, ignorealreadyrecommended=%d, dontshowinstalledrecommended=%d\n", solv->dontinstallrecommended, solv->ignorealreadyrecommended, solv->dontshowinstalledrecommended);
4694 /* create whatprovides if not already there */
4695 if (!pool->whatprovides)
4696 pool_createwhatprovides(pool);
4698 /* create obsolete index */
4699 create_obsolete_index(solv);
4705 * create basic rule set of all involved packages
4706 * use addedmap bitmap to make sure we don't create rules twice
4710 /* create noobsolete map if needed */
4711 for (i = 0; i < job->count; i += 2)
4713 how = job->elements[i] & ~SOLVER_WEAK;
4714 if ((how & SOLVER_JOBMASK) != SOLVER_NOOBSOLETES)
4716 what = job->elements[i + 1];
4717 select = how & SOLVER_SELECTMASK;
4718 if (!solv->noobsoletes.size)
4719 map_init(&solv->noobsoletes, pool->nsolvables);
4720 FOR_JOB_SELECT(p, pp, select, what)
4721 MAPSET(&solv->noobsoletes, p);
4724 map_init(&addedmap, pool->nsolvables);
4725 map_init(&installcandidatemap, pool->nsolvables);
4729 * always install our system solvable
4731 MAPSET(&addedmap, SYSTEMSOLVABLE);
4732 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
4733 queue_push(&solv->decisionq_why, 0);
4734 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
4736 now = sat_timems(0);
4738 * create rules for all package that could be involved with the solving
4739 * so called: rpm rules
4744 oldnrules = solv->nrules;
4745 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
4746 FOR_REPO_SOLVABLES(installed, p, s)
4747 addrpmrulesforsolvable(solv, s, &addedmap);
4748 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
4749 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
4750 oldnrules = solv->nrules;
4751 FOR_REPO_SOLVABLES(installed, p, s)
4752 addrpmrulesforupdaters(solv, s, &addedmap, 1);
4753 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
4757 * create rules for all packages involved in the job
4758 * (to be installed or removed)
4761 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
4762 oldnrules = solv->nrules;
4763 for (i = 0; i < job->count; i += 2)
4765 how = job->elements[i];
4766 what = job->elements[i + 1];
4767 select = how & SOLVER_SELECTMASK;
4769 switch (how & SOLVER_JOBMASK)
4771 case SOLVER_INSTALL:
4772 FOR_JOB_SELECT(p, pp, select, what)
4774 MAPSET(&installcandidatemap, p);
4775 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
4778 case SOLVER_DISTUPGRADE:
4779 if (!solv->distupgrade)
4786 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
4788 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
4790 oldnrules = solv->nrules;
4793 * add rules for suggests, enhances
4795 addrpmrulesforweak(solv, &addedmap);
4796 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
4798 IF_POOLDEBUG (SAT_DEBUG_STATS)
4800 int possible = 0, installable = 0;
4801 for (i = 1; i < pool->nsolvables; i++)
4803 if (pool_installable(pool, pool->solvables + i))
4805 if (MAPTST(&addedmap, i))
4808 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
4812 * first pass done, we now have all the rpm rules we need.
4813 * unify existing rules before going over all job rules and
4815 * at this point the system is always solvable,
4816 * as an empty system (remove all packages) is a valid solution
4819 unifyrules(solv); /* remove duplicate rpm rules */
4821 solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
4823 solv->directdecisions = solv->decisionq.count;
4824 POOL_DEBUG(SAT_DEBUG_STATS, "rpm rule memory usage: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
4825 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
4826 POOL_DEBUG(SAT_DEBUG_STATS, "rpm rule creation took %d ms\n", sat_timems(now));
4828 /* create dup maps if needed. We need the maps to create our
4831 createdupmaps(solv, job);
4834 * create feature rules
4836 * foreach installed:
4837 * create assertion (keep installed, if no update available)
4839 * create update rule (A|update1(A)|update2(A)|...)
4841 * those are used later on to keep a version of the installed packages in
4845 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add feature rules ***\n");
4846 solv->featurerules = solv->nrules; /* mark start of feature rules */
4849 /* foreach possibly installed solvable */
4850 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
4852 if (s->repo != installed)
4854 addrule(solv, 0, 0); /* create dummy rule */
4857 addupdaterule(solv, s, 1); /* allow s to be updated */
4860 * assert one rule per installed solvable,
4861 * either an assertion (A)
4862 * or a possible update (A|update1(A)|update2(A)|...)
4864 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
4866 solv->featurerules_end = solv->nrules;
4869 * Add update rules for installed solvables
4871 * almost identical to feature rules
4872 * except that downgrades/archchanges/vendorchanges are not allowed
4875 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add update rules ***\n");
4876 solv->updaterules = solv->nrules;
4879 { /* foreach installed solvables */
4880 /* we create all update rules, but disable some later on depending on the job */
4881 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
4885 if (s->repo != installed)
4887 addrule(solv, 0, 0); /* create dummy rule */
4890 addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
4892 * check for and remove duplicate
4894 r = solv->rules + solv->nrules - 1; /* r: update rule */
4895 sr = r - (installed->end - installed->start); /* sr: feature rule */
4896 /* it's orphaned if there is no feature rule or the feature rule
4897 * consists just of the installed package */
4898 if (!sr->p || (sr->p == i && !sr->d && !sr->w2))
4899 queue_push(&solv->orphaned, i);
4902 assert(solv->distupgrade && !sr->p);
4905 unifyrules_sortcmp_data = pool;
4906 if (!unifyrules_sortcmp(r, sr))
4908 /* identical rule, kill unneeded one */
4909 if (solv->allowuninstall)
4911 /* keep feature rule, make it weak */
4912 memset(r, 0, sizeof(*r));
4913 queue_push(&solv->weakruleq, sr - solv->rules);
4917 /* keep update rule */
4918 memset(sr, 0, sizeof(*sr));
4921 else if (solv->allowuninstall)
4923 /* make both feature and update rule weak */
4924 queue_push(&solv->weakruleq, r - solv->rules);
4925 queue_push(&solv->weakruleq, sr - solv->rules);
4928 disablerule(solv, sr);
4930 /* consistency check: we added a rule for _every_ installed solvable */
4931 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
4933 solv->updaterules_end = solv->nrules;
4937 * now add all job rules
4940 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
4942 solv->jobrules = solv->nrules;
4943 for (i = 0; i < job->count; i += 2)
4945 oldnrules = solv->nrules;
4947 how = job->elements[i];
4948 what = job->elements[i + 1];
4949 weak = how & SOLVER_WEAK;
4950 select = how & SOLVER_SELECTMASK;
4951 switch (how & SOLVER_JOBMASK)
4953 case SOLVER_INSTALL:
4954 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4955 if (select == SOLVER_SOLVABLE)
4963 FOR_JOB_SELECT(p, pp, select, what)
4967 /* no candidate found, make this an impossible rule */
4968 queue_push(&q, -SYSTEMSOLVABLE);
4970 p = queue_shift(&q); /* get first candidate */
4971 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
4973 addrule(solv, p, d); /* add install rule */
4974 queue_push(&solv->ruletojob, i);
4976 queue_push(&solv->weakruleq, solv->nrules - 1);
4979 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4980 if (select == SOLVER_SOLVABLE && solv->installed && pool->solvables[what].repo == solv->installed)
4982 /* special case for "erase a specific solvable": we also
4983 * erase all other solvables with that name, so that they
4984 * don't get picked up as replacement */
4985 name = pool->solvables[what].name;
4986 FOR_PROVIDES(p, pp, name)
4990 s = pool->solvables + p;
4991 if (s->name != name)
4993 /* keep other versions installed */
4994 if (s->repo == solv->installed)
4996 /* keep installcandidates of other jobs */
4997 if (MAPTST(&installcandidatemap, p))
4999 addrule(solv, -p, 0); /* remove by Id */
5000 queue_push(&solv->ruletojob, i);
5002 queue_push(&solv->weakruleq, solv->nrules - 1);
5005 FOR_JOB_SELECT(p, pp, select, what)
5007 addrule(solv, -p, 0);
5008 queue_push(&solv->ruletojob, i);
5010 queue_push(&solv->weakruleq, solv->nrules - 1);
5015 POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
5016 FOR_JOB_SELECT(p, pp, select, what)
5018 s = pool->solvables + p;
5019 if (!solv->installed || s->repo != solv->installed)
5021 if (!solv->updatemap.size)
5022 map_init(&solv->updatemap, pool->nsolvables);
5023 MAPSET(&solv->updatemap, p);
5026 case SOLVER_WEAKENDEPS:
5027 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
5028 if (select != SOLVER_SOLVABLE)
5030 s = pool->solvables + what;
5031 weaken_solvable_deps(solv, what);
5033 case SOLVER_NOOBSOLETES:
5034 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sno obsolete %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
5037 POOL_DEBUG(SAT_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
5038 FOR_JOB_SELECT(p, pp, select, what)
5040 s = pool->solvables + p;
5041 if (installed && s->repo == installed)
5042 addrule(solv, p, 0);
5044 addrule(solv, -p, 0);
5045 queue_push(&solv->ruletojob, i);
5047 queue_push(&solv->weakruleq, solv->nrules - 1);
5050 case SOLVER_DISTUPGRADE:
5051 POOL_DEBUG(SAT_DEBUG_JOB, "job: distupgrade repo #%d\n", what);
5054 POOL_DEBUG(SAT_DEBUG_JOB, "job: unknown job\n");
5062 IF_POOLDEBUG (SAT_DEBUG_JOB)
5065 if (solv->nrules == oldnrules)
5066 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created\n");
5067 for (j = oldnrules; j < solv->nrules; j++)
5069 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
5070 solver_printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
5074 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
5075 solv->jobrules_end = solv->nrules;
5077 /* now create infarch and dup rules */
5078 addinfarchrules(solv, &addedmap);
5081 addduprules(solv, &addedmap);
5082 freedupmaps(solv); /* no longer needed */
5085 solv->duprules = solv->duprules_end = solv->nrules;
5087 /* all rules created
5088 * --------------------------------------------------------------
5089 * prepare for solving
5092 /* free unneeded memory */
5093 map_free(&addedmap);
5094 map_free(&installcandidatemap);
5097 POOL_DEBUG(SAT_DEBUG_STATS, "%d rpm rules, %d job rules, %d infarch rules, %d dup rules\n", solv->rpmrules_end - 1, solv->jobrules_end - solv->jobrules, solv->infarchrules_end - solv->infarchrules, solv->duprules_end - solv->duprules);
5099 /* create weak map */
5100 map_init(&solv->weakrulemap, solv->nrules);
5101 for (i = 0; i < solv->weakruleq.count; i++)
5103 p = solv->weakruleq.elements[i];
5104 MAPSET(&solv->weakrulemap, p);
5107 /* all new rules are learnt after this point */
5108 solv->learntrules = solv->nrules;
5110 /* create assertion index. it is only used to speed up
5111 * makeruledecsions() a bit */
5112 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
5113 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
5114 queue_push(&solv->ruleassertions, i);
5116 /* disable update rules that conflict with our job */
5117 disableupdaterules(solv, job, -1);
5119 /* make decisions based on job/update assertions */
5120 makeruledecisions(solv);
5122 /* create watches chains */
5125 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
5128 * ********************************************
5130 * ********************************************
5133 now = sat_timems(0);
5134 run_solver(solv, 1, solv->dontinstallrecommended ? 0 : 1);
5135 POOL_DEBUG(SAT_DEBUG_STATS, "solver took %d ms\n", sat_timems(now));
5139 /* disable all erase jobs (including weak "keep uninstalled" rules) */
5140 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
5142 if (r->d < 0) /* disabled ? */
5144 if (r->p > 0) /* install job? */
5146 disablerule(solv, r);
5152 enabledisablelearntrules(solv);
5153 removedisabledconflicts(solv, &redoq);
5157 * find recommended packages
5160 /* if redoq.count == 0 we already found all recommended in the
5162 if (redoq.count || solv->dontinstallrecommended || !solv->dontshowinstalledrecommended || solv->ignorealreadyrecommended)
5164 Id rec, *recp, p, pp;
5166 /* create map of all recommened packages */
5167 solv->recommends_index = -1;
5168 MAPZERO(&solv->recommendsmap);
5169 for (i = 0; i < solv->decisionq.count; i++)
5171 p = solv->decisionq.elements[i];
5174 s = pool->solvables + p;
5177 recp = s->repo->idarraydata + s->recommends;
5178 while ((rec = *recp++) != 0)
5180 FOR_PROVIDES(p, pp, rec)
5181 if (solv->decisionmap[p] > 0)
5185 if (!solv->dontshowinstalledrecommended)
5187 FOR_PROVIDES(p, pp, rec)
5188 if (solv->decisionmap[p] > 0)
5189 MAPSET(&solv->recommendsmap, p);
5191 continue; /* p != 0: already fulfilled */
5193 FOR_PROVIDES(p, pp, rec)
5194 MAPSET(&solv->recommendsmap, p);
5198 for (i = 1; i < pool->nsolvables; i++)
5200 if (solv->decisionmap[i] < 0)
5202 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
5204 s = pool->solvables + i;
5205 if (!MAPTST(&solv->recommendsmap, i))
5207 if (!s->supplements)
5209 if (!pool_installable(pool, s))
5211 if (!solver_is_supplementing(solv, s))
5214 if (solv->dontinstallrecommended)
5215 queue_push(&solv->recommendations, i);
5217 queue_pushunique(&solv->recommendations, i);
5219 /* we use MODE_SUGGEST here so that repo prio is ignored */
5220 policy_filter_unwanted(solv, &solv->recommendations, POLICY_MODE_SUGGEST);
5224 * find suggested packages
5229 Id sug, *sugp, p, pp;
5231 /* create map of all suggests that are still open */
5232 solv->recommends_index = -1;
5233 MAPZERO(&solv->suggestsmap);
5234 for (i = 0; i < solv->decisionq.count; i++)
5236 p = solv->decisionq.elements[i];
5239 s = pool->solvables + p;
5242 sugp = s->repo->idarraydata + s->suggests;
5243 while ((sug = *sugp++) != 0)
5245 FOR_PROVIDES(p, pp, sug)
5246 if (solv->decisionmap[p] > 0)
5250 if (!solv->dontshowinstalledrecommended)
5252 FOR_PROVIDES(p, pp, sug)
5253 if (solv->decisionmap[p] > 0)
5254 MAPSET(&solv->suggestsmap, p);
5256 continue; /* already fulfilled */
5258 FOR_PROVIDES(p, pp, sug)
5259 MAPSET(&solv->suggestsmap, p);
5263 for (i = 1; i < pool->nsolvables; i++)
5265 if (solv->decisionmap[i] < 0)
5267 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
5269 s = pool->solvables + i;
5270 if (!MAPTST(&solv->suggestsmap, i))
5274 if (!pool_installable(pool, s))
5276 if (!solver_is_enhancing(solv, s))
5279 queue_push(&solv->suggestions, i);
5281 policy_filter_unwanted(solv, &solv->suggestions, POLICY_MODE_SUGGEST);
5286 /* restore decisionmap */
5287 for (i = 0; i < redoq.count; i += 2)
5288 solv->decisionmap[redoq.elements[i]] = redoq.elements[i + 1];
5292 * if unsolvable, prepare solutions
5295 if (solv->problems.count)
5297 int recocount = solv->recommendations.count;
5298 solv->recommendations.count = 0; /* so that revert() doesn't mess with it */
5299 queue_empty(&redoq);
5300 for (i = 0; i < solv->decisionq.count; i++)
5302 Id p = solv->decisionq.elements[i];
5303 queue_push(&redoq, p);
5304 queue_push(&redoq, solv->decisionq_why.elements[i]);
5305 queue_push(&redoq, solv->decisionmap[p > 0 ? p : -p]);
5307 problems_to_solutions(solv, job);
5308 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
5309 queue_empty(&solv->decisionq);
5310 queue_empty(&solv->decisionq_why);
5311 for (i = 0; i < redoq.count; i += 3)
5313 Id p = redoq.elements[i];
5314 queue_push(&solv->decisionq, p);
5315 queue_push(&solv->decisionq_why, redoq.elements[i + 1]);
5316 solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
5318 solv->recommendations.count = recocount;
5322 POOL_DEBUG(SAT_DEBUG_STATS, "final solver statistics: %d learned rules, %d unsolvable\n", solv->stats_learned, solv->stats_unsolvable);
5323 POOL_DEBUG(SAT_DEBUG_STATS, "solver_solve took %d ms\n", sat_timems(solve_start));
5327 /***********************************************************************/
5328 /* disk usage computations */
5330 /*-------------------------------------------------------------------
5332 * calculate DU changes
5336 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
5340 solver_create_state_maps(solv, &installedmap, 0);
5341 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
5342 map_free(&installedmap);
5346 /*-------------------------------------------------------------------
5348 * calculate changes in install size
5352 solver_calc_installsizechange(Solver *solv)
5357 solver_create_state_maps(solv, &installedmap, 0);
5358 change = pool_calc_installsizechange(solv->pool, &installedmap);
5359 map_free(&installedmap);
5363 #define FIND_INVOLVED_DEBUG 0
5365 solver_find_involved(Solver *solv, Queue *installedq, Solvable *ts, Queue *q)
5367 Pool *pool = solv->pool;
5372 Queue installedq_internal;
5373 Id tp, ip, p, pp, req, *reqp, sup, *supp;
5376 tp = ts - pool->solvables;
5378 queue_init(&installedq_internal);
5379 map_init(&im, pool->nsolvables);
5380 map_init(&installedm, pool->nsolvables);
5384 installedq = &installedq_internal;
5385 if (solv->installed)
5387 for (ip = solv->installed->start; ip < solv->installed->end; ip++)
5389 s = pool->solvables + ip;
5390 if (s->repo != solv->installed)
5392 queue_push(installedq, ip);
5396 for (i = 0; i < installedq->count; i++)
5398 ip = installedq->elements[i];
5399 MAPSET(&installedm, ip);
5403 queue_push(&iq, ts - pool->solvables);
5406 ip = queue_shift(&iq);
5407 if (!MAPTST(&im, ip))
5409 if (!MAPTST(&installedm, ip))
5412 s = pool->solvables + ip;
5413 #if FIND_INVOLVED_DEBUG
5414 printf("hello %s\n", solvable2str(pool, s));
5418 reqp = s->repo->idarraydata + s->requires;
5419 while ((req = *reqp++) != 0)
5421 if (req == SOLVABLE_PREREQMARKER)
5423 /* count number of installed packages that match */
5425 FOR_PROVIDES(p, pp, req)
5426 if (MAPTST(&installedm, p))
5430 FOR_PROVIDES(p, pp, req)
5434 #if FIND_INVOLVED_DEBUG
5435 printf("%s requires %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
5444 reqp = s->repo->idarraydata + s->recommends;
5445 while ((req = *reqp++) != 0)
5448 FOR_PROVIDES(p, pp, req)
5449 if (MAPTST(&installedm, p))
5453 FOR_PROVIDES(p, pp, req)
5457 #if FIND_INVOLVED_DEBUG
5458 printf("%s recommends %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
5467 /* supplements pass */
5468 for (i = 0; i < installedq->count; i++)
5470 ip = installedq->elements[i];
5471 s = pool->solvables + ip;
5472 if (!s->supplements)
5474 if (!MAPTST(&im, ip))
5476 supp = s->repo->idarraydata + s->supplements;
5477 while ((sup = *supp++) != 0)
5478 if (!dep_possible(solv, sup, &im) && dep_possible(solv, sup, &installedm))
5480 /* no longer supplemented, also erase */
5483 #if FIND_INVOLVED_DEBUG
5484 printf("%s supplemented\n", solvable2str(pool, pool->solvables + ip));
5486 queue_push(&iq, ip);
5492 for (i = 0; i < installedq->count; i++)
5494 ip = installedq->elements[i];
5495 if (MAPTST(&im, ip))
5496 queue_push(&iq, ip);
5501 ip = queue_shift(&iq);
5502 if (!MAPTST(&installedm, ip))
5504 s = pool->solvables + ip;
5505 #if FIND_INVOLVED_DEBUG
5506 printf("bye %s\n", solvable2str(pool, s));
5510 reqp = s->repo->idarraydata + s->requires;
5511 while ((req = *reqp++) != 0)
5513 FOR_PROVIDES(p, pp, req)
5515 if (!MAPTST(&im, p))
5519 #if FIND_INVOLVED_DEBUG
5520 printf("%s requires %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
5530 reqp = s->repo->idarraydata + s->recommends;
5531 while ((req = *reqp++) != 0)
5533 FOR_PROVIDES(p, pp, req)
5535 if (!MAPTST(&im, p))
5539 #if FIND_INVOLVED_DEBUG
5540 printf("%s recommends %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
5550 /* supplements pass */
5551 for (i = 0; i < installedq->count; i++)
5553 ip = installedq->elements[i];
5556 s = pool->solvables + ip;
5557 if (!s->supplements)
5559 if (MAPTST(&im, ip))
5561 supp = s->repo->idarraydata + s->supplements;
5562 while ((sup = *supp++) != 0)
5563 if (dep_possible(solv, sup, &im))
5567 #if FIND_INVOLVED_DEBUG
5568 printf("%s supplemented\n", solvable2str(pool, pool->solvables + ip));
5571 queue_push(&iq, ip);
5579 /* convert map into result */
5580 for (i = 0; i < installedq->count; i++)
5582 ip = installedq->elements[i];
5583 if (MAPTST(&im, ip))
5585 if (ip == ts - pool->solvables)
5590 map_free(&installedm);
5591 queue_free(&installedq_internal);