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 */
368 if (n == 0 && !solv->rpmrules_end)
370 /* this is a rpm rule assertion, we do not have to allocate it */
371 /* it can be identified by a level of 1 and a zero reason */
372 /* we must not drop those rules from the decisionq when rewinding! */
374 assert(solv->decisionmap[-p] == 0 || solv->decisionmap[-p] == -1);
375 if (solv->decisionmap[-p])
376 return 0; /* already got that one */
377 queue_push(&solv->decisionq, p);
378 queue_push(&solv->decisionq_why, 0);
379 solv->decisionmap[-p] = -1;
384 if (n == 1 && p > d && !solv->rpmrules_end)
386 /* smallest literal first so we can find dups */
387 n = p; p = d; d = n; /* p <-> d */
388 n = 1; /* re-set n, was used as temp var */
392 * check for duplicate
395 /* check if the last added rule (r) is exactly the same as what we're looking for. */
396 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
397 return r; /* binary rule */
399 /* have n-ary rule with same first literal, check other literals */
400 if (r && n > 1 && r->d && r->p == p)
402 /* Rule where d is an offset in whatprovidesdata */
406 dp2 = pool->whatprovidesdata + r->d;
407 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
418 /* extend rule buffer */
419 solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
420 r = solv->rules + solv->nrules++; /* point to rule space */
429 /* direct assertion, no watch needed */
445 r->w2 = pool->whatprovidesdata[d];
450 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
452 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
453 solver_printrule(solv, SAT_DEBUG_RULE_CREATION, r);
459 /*-------------------------------------------------------------------
464 disablerule(Solver *solv, Rule *r)
470 /*-------------------------------------------------------------------
475 enablerule(Solver *solv, Rule *r)
482 /**********************************************************************************/
484 /* a problem is an item on the solver's problem list. It can either be >0, in that
485 * case it is a update rule, or it can be <0, which makes it refer to a job
486 * consisting of multiple job rules.
490 disableproblem(Solver *solv, Id v)
498 disablerule(solv, solv->rules + v);
502 jp = solv->ruletojob.elements;
503 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
505 disablerule(solv, r);
508 /*-------------------------------------------------------------------
513 enableproblem(Solver *solv, Id v)
521 if (v >= solv->featurerules && v < solv->featurerules_end)
523 /* do not enable feature rule if update rule is enabled */
524 r = solv->rules + (v - solv->featurerules + solv->updaterules);
528 enablerule(solv, solv->rules + v);
529 if (v >= solv->updaterules && v < solv->updaterules_end)
531 /* disable feature rule when enabling update rule */
532 r = solv->rules + (v - solv->updaterules + solv->featurerules);
534 disablerule(solv, r);
539 jp = solv->ruletojob.elements;
540 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
546 /************************************************************************/
549 * make assertion rules into decisions
551 * go through update and job rules and add direct assertions
552 * to the decisionqueue. If we find a conflict, disable rules and
553 * add them to problem queue.
557 makeruledecisions(Solver *solv)
559 Pool *pool = solv->pool;
565 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
567 decisionstart = solv->decisionq.count;
568 for (ii = 0; ii < solv->ruleassertions.count; ii++)
570 ri = solv->ruleassertions.elements[ii];
571 r = solv->rules + ri;
573 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
575 /* do weak rules in phase 2 */
576 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
582 if (!solv->decisionmap[vv]) /* if not yet decided */
587 queue_push(&solv->decisionq, v);
588 queue_push(&solv->decisionq_why, r - solv->rules);
589 solv->decisionmap[vv] = v > 0 ? 1 : -1;
590 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
592 Solvable *s = solv->pool->solvables + vv;
594 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
596 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
601 * check previous decision: is it sane ?
604 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
606 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
612 * The rule (r) we're currently processing says something
613 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
617 if (ri >= solv->learntrules)
619 /* conflict with a learnt rule */
620 /* can happen when packages cannot be installed for
621 * multiple reasons. */
622 /* we disable the learnt rule in this case */
623 disablerule(solv, r);
628 * find the decision which is the "opposite" of the rule
631 for (i = 0; i < solv->decisionq.count; i++)
632 if (solv->decisionq.elements[i] == -v)
634 assert(i < solv->decisionq.count); /* assert that we found it */
637 * conflict with system solvable ?
640 if (v == -SYSTEMSOLVABLE) {
641 /* conflict with system solvable */
642 queue_push(&solv->problems, solv->learnt_pool.count);
643 queue_push(&solv->learnt_pool, ri);
644 queue_push(&solv->learnt_pool, 0);
645 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
646 if (ri >= solv->jobrules && ri < solv->jobrules_end)
647 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
650 queue_push(&solv->problems, v);
651 queue_push(&solv->problems, 0);
652 disableproblem(solv, v);
656 assert(solv->decisionq_why.elements[i]);
659 * conflict with an rpm rule ?
662 if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
664 /* conflict with rpm rule assertion */
665 queue_push(&solv->problems, solv->learnt_pool.count);
666 queue_push(&solv->learnt_pool, ri);
667 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
668 queue_push(&solv->learnt_pool, 0);
669 assert(v > 0 || v == -SYSTEMSOLVABLE);
670 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
671 if (ri >= solv->jobrules && ri < solv->jobrules_end)
672 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
675 queue_push(&solv->problems, v);
676 queue_push(&solv->problems, 0);
677 disableproblem(solv, v);
682 * conflict with another job or update/feature rule
686 queue_push(&solv->problems, solv->learnt_pool.count);
687 queue_push(&solv->learnt_pool, ri);
688 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
689 queue_push(&solv->learnt_pool, 0);
691 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
694 * push all of our rules (can only be feature or job rules)
695 * asserting this literal on the problem stack
698 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
700 if (rr->d < 0 /* disabled */
701 || rr->w2) /* or no assertion */
703 if (rr->p != vv /* not affecting the literal */
706 if (MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
709 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
711 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, solv->rules + i);
714 /* is is a job rule ? */
715 if (i >= solv->jobrules && i < solv->jobrules_end)
716 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
718 queue_push(&solv->problems, v);
719 disableproblem(solv, v);
721 queue_push(&solv->problems, 0);
725 * (back up from decisions)
727 while (solv->decisionq.count > decisionstart)
729 v = solv->decisionq.elements[--solv->decisionq.count];
730 --solv->decisionq_why.count;
732 solv->decisionmap[vv] = 0;
734 ii = -1; /* restarts loop at 0 */
738 * phase 2: now do the weak assertions
740 for (ii = 0; ii < solv->ruleassertions.count; ii++)
742 ri = solv->ruleassertions.elements[ii];
743 r = solv->rules + ri;
744 if (r->d < 0 || r->w2) /* disabled or no assertion */
746 if (!MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
752 * (if not yet decided)
754 if (!solv->decisionmap[vv])
756 queue_push(&solv->decisionq, v);
757 queue_push(&solv->decisionq_why, r - solv->rules);
758 solv->decisionmap[vv] = v > 0 ? 1 : -1;
759 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
761 Solvable *s = solv->pool->solvables + vv;
763 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", solvable2str(solv->pool, s));
765 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", solvable2str(solv->pool, s));
770 * previously decided, sane ?
772 if (v > 0 && solv->decisionmap[vv] > 0)
774 if (v < 0 && solv->decisionmap[vv] < 0)
777 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
778 solver_printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
780 if (ri >= solv->jobrules && ri < solv->jobrules_end)
781 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
784 disableproblem(solv, v);
786 disableupdaterules(solv, solv->job, -(v + 1));
789 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
793 /*-------------------------------------------------------------------
794 * enable/disable learnt rules
796 * we have enabled or disabled some of our rules. We now reenable all
797 * of our learnt rules but the ones that were learnt from rules that
801 enabledisablelearntrules(Solver *solv)
803 Pool *pool = solv->pool;
808 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
809 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
811 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
812 while ((why = *whyp++) != 0)
814 assert(why > 0 && why < i);
815 if (solv->rules[why].d < 0)
818 /* why != 0: we found a disabled rule, disable the learnt rule */
819 if (why && r->d >= 0)
821 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
823 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling ");
824 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
826 disablerule(solv, r);
828 else if (!why && r->d < 0)
830 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
832 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling ");
833 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
841 /*-------------------------------------------------------------------
844 * Enable all rules, except learnt rules, which are
845 * - disabled and weak (set in weakrulemap)
850 enableweakrules(Solver *solv)
855 for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
857 if (r->d >= 0) /* skip non-direct literals */
859 if (!MAPTST(&solv->weakrulemap, i))
866 /* FIXME: bad code ahead, replace as soon as possible */
867 /* FIXME: should probably look at SOLVER_INSTALL|SOLVABLE_ONE_OF */
869 /*-------------------------------------------------------------------
870 * disable update rules
874 disableupdaterules(Solver *solv, Queue *job, int jobidx)
876 Pool *pool = solv->pool;
878 Id how, select, what, p, pp;
884 installed = solv->installed;
890 how = job->elements[jobidx];
891 select = how & SOLVER_SELECTMASK;
892 switch (how & SOLVER_JOBMASK)
897 if (select != SOLVER_SOLVABLE)
904 /* go through all enabled job rules */
905 MAPZERO(&solv->noupdate);
906 for (i = solv->jobrules; i < solv->jobrules_end; i++)
909 if (r->d < 0) /* disabled? */
911 j = solv->ruletojob.elements[i - solv->jobrules];
915 how = job->elements[j];
916 what = job->elements[j + 1];
917 select = how & SOLVER_SELECTMASK;
918 switch (how & SOLVER_JOBMASK)
921 if (select != SOLVER_SOLVABLE)
923 s = pool->solvables + what;
924 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, what))
926 if (s->repo == installed)
928 MAPSET(&solv->noupdate, what - installed->start);
934 obsp = s->repo->idarraydata + s->obsoletes;
935 while ((obs = *obsp++) != 0)
936 FOR_PROVIDES(p, pp, obs)
938 if (pool->solvables[p].repo != installed)
940 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
942 MAPSET(&solv->noupdate, p - installed->start);
945 FOR_PROVIDES(p, pp, s->name)
947 if (!solv->implicitobsoleteusesprovides && pool->solvables[p].name != s->name)
949 if (pool->solvables[p].repo == installed)
950 MAPSET(&solv->noupdate, p - installed->start);
954 FOR_JOB_SELECT(p, pp, select, what)
955 if (pool->solvables[p].repo == installed)
956 MAPSET(&solv->noupdate, p - installed->start);
963 /* fixup update rule status */
966 /* we just disabled job #jobidx. enable all update rules
967 * that aren't disabled by the remaining job rules */
968 how = job->elements[jobidx];
969 what = job->elements[jobidx + 1];
970 select = how & SOLVER_SELECTMASK;
971 switch (how & SOLVER_JOBMASK)
974 if (select != SOLVER_SOLVABLE)
976 s = pool->solvables + what;
977 if (s->repo == installed)
979 if (MAPTST(&solv->noupdate, what - installed->start))
981 r = solv->rules + solv->updaterules + (what - installed->start);
985 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
987 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
988 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
995 obsp = s->repo->idarraydata + s->obsoletes;
996 while ((obs = *obsp++) != 0)
997 FOR_PROVIDES(p, pp, obs)
999 if (pool->solvables[p].repo != installed)
1001 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
1003 if (MAPTST(&solv->noupdate, p - installed->start))
1005 r = solv->rules + solv->updaterules + (p - installed->start);
1008 enablerule(solv, r);
1009 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1011 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1012 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
1016 FOR_PROVIDES(p, pp, s->name)
1018 if (!solv->implicitobsoleteusesprovides && pool->solvables[p].name != s->name)
1020 if (pool->solvables[p].repo != installed)
1022 if (MAPTST(&solv->noupdate, p - installed->start))
1024 r = solv->rules + solv->updaterules + (p - installed->start);
1027 enablerule(solv, r);
1028 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1030 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1031 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
1036 FOR_JOB_SELECT(p, pp, select, what)
1038 if (pool->solvables[p].repo != installed)
1040 if (MAPTST(&solv->noupdate, p - installed->start))
1042 r = solv->rules + solv->updaterules + (p - installed->start);
1045 enablerule(solv, r);
1046 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1048 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1049 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
1059 for (i = 0; i < installed->nsolvables; i++)
1061 r = solv->rules + solv->updaterules + i;
1062 if (r->d >= 0 && MAPTST(&solv->noupdate, i))
1063 disablerule(solv, r); /* was enabled, need to disable */
1064 r = solv->rules + solv->featurerules + i;
1065 if (r->d >= 0 && MAPTST(&solv->noupdate, i))
1066 disablerule(solv, r); /* was enabled, need to disable */
1072 * special multiversion patch conflict handling:
1073 * a patch conflict is also satisfied, if some other
1074 * version with the same name/arch that doesn't conflict
1075 * get's installed. The generated rule is thus:
1076 * -patch|-cpack|opack1|opack2|...
1079 makemultiversionconflict(Solver *solv, Id n, Id con)
1081 Pool *pool = solv->pool;
1086 sn = pool->solvables + n;
1087 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1089 FOR_PROVIDES(p, pp, sn->name)
1091 s = pool->solvables + p;
1092 if (s->name != sn->name || s->arch != sn->arch)
1094 if (!MAPTST(&solv->noobsoletes, p))
1096 if (pool_match_nevr(pool, pool->solvables + p, con))
1098 /* here we have a multiversion solvable that doesn't conflict */
1099 /* thus we're not in conflict if it is installed */
1103 return -n; /* no other package found, generate normal conflict */
1104 return pool_queuetowhatprovides(pool, &q);
1108 /*-------------------------------------------------------------------
1110 * add (install) rules for solvable
1112 * s: Solvable for which to add rules
1113 * m: m[s] = 1 for solvables which have rules, prevent rule duplication
1115 * Algorithm: 'visit all nodes of a graph'. The graph nodes are
1116 * solvables, the edges their dependencies.
1117 * Starting from an installed solvable, this will create all rules
1118 * representing the graph created by the solvables dependencies.
1120 * for unfulfilled requirements, conflicts, obsoletes,....
1121 * add a negative assertion for solvables that are not installable
1123 * It will also create rules for all solvables referenced by 's'
1124 * i.e. descend to all providers of requirements of 's'
1129 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
1131 Pool *pool = solv->pool;
1132 Repo *installed = solv->installed;
1134 /* 'work' queue. keeps Ids of solvables we still have to work on.
1135 And buffer for it. */
1140 /* if to add rules for broken deps ('rpm -V' functionality)
1144 /* Id var and pointer for each dependency
1145 * (not used in parallel)
1152 /* var and ptr for loops */
1154 /* ptr to 'whatprovides' */
1156 /* Id for current solvable 's' */
1159 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
1161 queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
1162 queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
1164 /* loop until there's no more work left */
1169 * s: Pointer to solvable
1172 n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
1173 if (MAPTST(m, n)) /* continue if already visited */
1176 MAPSET(m, n); /* mark as visited */
1177 s = pool->solvables + n; /* s = Solvable in question */
1180 if (installed /* Installed system available */
1181 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
1182 && s->repo == installed) /* solvable is installed? */
1184 dontfix = 1; /* dont care about broken rpm deps */
1188 && s->arch != ARCH_SRC
1189 && s->arch != ARCH_NOSRC
1190 && !pool_installable(pool, s))
1192 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
1193 addrule(solv, -n, 0); /* uninstallable */
1196 /*-----------------------------------------
1197 * check requires of s
1202 reqp = s->repo->idarraydata + s->requires;
1203 while ((req = *reqp++) != 0) /* go through all requires */
1205 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
1208 /* find list of solvables providing 'req' */
1209 dp = pool->whatprovidesdata + pool_whatprovides(pool, req);
1211 if (*dp == SYSTEMSOLVABLE) /* always installed */
1216 /* the strategy here is to not insist on dependencies
1217 * that are already broken. so if we find one provider
1218 * that was already installed, we know that the
1219 * dependency was not broken before so we enforce it */
1221 /* check if any of the providers for 'req' is installed */
1222 for (i = 0; (p = dp[i]) != 0; i++)
1224 if (pool->solvables[p].repo == installed)
1225 break; /* provider was installed */
1227 /* didn't find an installed provider: previously broken dependency */
1230 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1237 /* nothing provides req! */
1238 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1239 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1243 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1245 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1246 for (i = 0; dp[i]; i++)
1247 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1250 /* add 'requires' dependency */
1251 /* rule: (-requestor|provider1|provider2|...|providerN) */
1252 addrule(solv, -n, dp - pool->whatprovidesdata);
1254 /* descend the dependency tree
1255 push all non-visited providers on the work queue */
1258 if (!MAPTST(m, *dp))
1259 queue_push(&workq, *dp);
1262 } /* while, requirements of n */
1264 } /* if, requirements */
1266 /* that's all we check for src packages */
1267 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1270 /*-----------------------------------------
1271 * check conflicts of s
1278 /* we treat conflicts in patches a bit differen:
1280 * - multiversion handling
1281 * XXX: we should really handle this different, looking
1282 * at the name is a bad hack
1284 if (!strncmp("patch:", id2str(pool, s->name), 6))
1286 conp = s->repo->idarraydata + s->conflicts;
1287 /* foreach conflicts of 's' */
1288 while ((con = *conp++) != 0)
1290 /* foreach providers of a conflict of 's' */
1291 FOR_PROVIDES(p, pp, con)
1293 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
1295 /* dontfix: dont care about conflicts with already installed packs */
1296 if (dontfix && pool->solvables[p].repo == installed)
1298 /* p == n: self conflict */
1299 if (p == n && !solv->allowselfconflicts)
1303 Reldep *rd = GETRELDEP(pool, con);
1304 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
1307 p = 0; /* make it a negative assertion, aka 'uninstallable' */
1309 if (p && ispatch && solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p) && ISRELDEP(con))
1311 /* our patch conflicts with a noobsoletes (aka multiversion) package */
1312 p = -makemultiversionconflict(solv, p, con);
1314 /* rule: -n|-p: either solvable _or_ provider of conflict */
1315 addrule(solv, -n, -p);
1320 /*-----------------------------------------
1321 * check obsoletes if not installed
1322 * (only installation will trigger the obsoletes in rpm)
1324 if (!installed || pool->solvables[n].repo != installed)
1325 { /* not installed */
1326 int noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
1327 if (s->obsoletes && !noobs)
1329 obsp = s->repo->idarraydata + s->obsoletes;
1330 /* foreach obsoletes */
1331 while ((obs = *obsp++) != 0)
1333 /* foreach provider of an obsoletes of 's' */
1334 FOR_PROVIDES(p, pp, obs)
1336 if (!solv->obsoleteusesprovides /* obsoletes are matched names, not provides */
1337 && !pool_match_nevr(pool, pool->solvables + p, obs))
1339 addrule(solv, -n, -p);
1343 FOR_PROVIDES(p, pp, s->name)
1345 Solvable *ps = pool->solvables + p;
1346 /* we still obsolete packages with same nevra, like rpm does */
1347 /* (actually, rpm mixes those packages. yuck...) */
1348 if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
1350 if (!solv->implicitobsoleteusesprovides && s->name != ps->name)
1352 addrule(solv, -n, -p);
1356 /*-----------------------------------------
1357 * add recommends to the work queue
1361 recp = s->repo->idarraydata + s->recommends;
1362 while ((rec = *recp++) != 0)
1364 FOR_PROVIDES(p, pp, rec)
1366 queue_push(&workq, p);
1371 sugp = s->repo->idarraydata + s->suggests;
1372 while ((sug = *sugp++) != 0)
1374 FOR_PROVIDES(p, pp, sug)
1376 queue_push(&workq, p);
1381 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1385 /*-------------------------------------------------------------------
1387 * Add package rules for weak rules
1389 * m: visited solvables
1393 addrpmrulesforweak(Solver *solv, Map *m)
1395 Pool *pool = solv->pool;
1400 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1401 /* foreach solvable in pool */
1402 for (i = n = 1; n < pool->nsolvables; i++, n++)
1404 if (i == pool->nsolvables) /* wrap i */
1406 if (MAPTST(m, i)) /* been there */
1409 s = pool->solvables + i;
1410 if (!pool_installable(pool, s)) /* only look at installable ones */
1416 /* find possible supplements */
1417 supp = s->repo->idarraydata + s->supplements;
1418 while ((sup = *supp++) != ID_NULL)
1419 if (dep_possible(solv, sup, m))
1423 /* if nothing found, check for enhances */
1424 if (!sup && s->enhances)
1426 supp = s->repo->idarraydata + s->enhances;
1427 while ((sup = *supp++) != ID_NULL)
1428 if (dep_possible(solv, sup, m))
1431 /* if nothing found, goto next solvables */
1434 addrpmrulesforsolvable(solv, s, m);
1437 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1441 /*-------------------------------------------------------------------
1443 * add package rules for possible updates
1446 * m: map of already visited solvables
1447 * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
1451 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
1453 Pool *pool = solv->pool;
1455 /* queue and buffer for it */
1459 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1461 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1462 /* find update candidates for 's' */
1463 policy_findupdatepackages(solv, s, &qs, allow_all);
1464 /* add rule for 's' if not already done */
1465 if (!MAPTST(m, s - pool->solvables))
1466 addrpmrulesforsolvable(solv, s, m);
1467 /* foreach update candidate, add rule if not already done */
1468 for (i = 0; i < qs.count; i++)
1469 if (!MAPTST(m, qs.elements[i]))
1470 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1473 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1477 finddistupgradepackages(Solver *solv, Solvable *s, Queue *qs, int allow_all)
1479 Pool *pool = solv->pool;
1482 policy_findupdatepackages(solv, s, qs, allow_all);
1487 policy_findupdatepackages(solv, s, qs, 1);
1489 return 0; /* orphaned */
1491 return -SYSTEMSOLVABLE;
1494 return s - pool->solvables;
1495 /* check if it is ok to keep the installed package */
1496 for (i = 0; i < qs->count; i++)
1498 Solvable *ns = pool->solvables + qs->elements[i];
1499 if (s->evr == ns->evr && solvable_identical(s, ns))
1500 return s - pool->solvables;
1502 /* nope, it must be some other package */
1503 return -SYSTEMSOLVABLE;
1506 /*-------------------------------------------------------------------
1508 * add rule for update
1509 * (A|A1|A2|A3...) An = update candidates for A
1511 * s = (installed) solvable
1515 addupdaterule(Solver *solv, Solvable *s, int allow_all)
1517 /* installed packages get a special upgrade allowed rule */
1518 Pool *pool = solv->pool;
1523 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1524 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1525 p = s - pool->solvables;
1526 /* find update candidates for 's' */
1527 if (solv->distupgrade)
1528 p = finddistupgradepackages(solv, s, &qs, allow_all);
1530 policy_findupdatepackages(solv, s, &qs, allow_all);
1531 if (!allow_all && qs.count && solv->noobsoletes.size)
1535 d = pool_queuetowhatprovides(pool, &qs);
1536 /* filter out all noobsoletes packages as they don't update */
1537 for (i = j = 0; i < qs.count; i++)
1539 if (MAPTST(&solv->noobsoletes, qs.elements[i]))
1541 /* it's ok if they have same nevra */
1542 Solvable *ps = pool->solvables + qs.elements[i];
1543 if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
1546 qs.elements[j++] = qs.elements[i];
1548 if (j == 0 && p == -SYSTEMSOLVABLE && solv->distupgrade)
1550 queue_push(&solv->orphaned, s - pool->solvables); /* treat as orphaned */
1555 if (d && solv->updatesystem && solv->installed && s->repo == solv->installed)
1557 if (!solv->multiversionupdaters)
1558 solv->multiversionupdaters = sat_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
1559 solv->multiversionupdaters[s - pool->solvables - solv->installed->start] = d;
1564 if (qs.count && p == -SYSTEMSOLVABLE)
1565 p = queue_shift(&qs);
1566 d = qs.count ? pool_queuetowhatprovides(pool, &qs) : 0;
1568 addrule(solv, p, d); /* allow update of s */
1569 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1573 /********************************************************************/
1577 /*-------------------------------------------------------------------
1580 * initial setup for all watches
1584 makewatches(Solver *solv)
1588 int nsolvables = solv->pool->nsolvables;
1590 sat_free(solv->watches);
1591 /* lower half for removals, upper half for installs */
1592 solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
1594 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
1595 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1597 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1600 if (!r->w2) /* assertions do not need watches */
1603 /* see addwatches_rule(solv, r) */
1604 r->n1 = solv->watches[nsolvables + r->w1];
1605 solv->watches[nsolvables + r->w1] = r - solv->rules;
1607 r->n2 = solv->watches[nsolvables + r->w2];
1608 solv->watches[nsolvables + r->w2] = r - solv->rules;
1613 /*-------------------------------------------------------------------
1615 * add watches (for rule)
1616 * sets up watches for a single rule
1618 * see also makewatches()
1622 addwatches_rule(Solver *solv, Rule *r)
1624 int nsolvables = solv->pool->nsolvables;
1626 r->n1 = solv->watches[nsolvables + r->w1];
1627 solv->watches[nsolvables + r->w1] = r - solv->rules;
1629 r->n2 = solv->watches[nsolvables + r->w2];
1630 solv->watches[nsolvables + r->w2] = r - solv->rules;
1634 /********************************************************************/
1640 /* shortcuts to check if a literal (positive or negative) assignment
1641 * evaluates to 'true' or 'false'
1643 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1644 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
1645 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
1647 /*-------------------------------------------------------------------
1651 * make decision and propagate to all rules
1653 * Evaluate each term affected by the decision (linked through watches)
1654 * If we find unit rules we make new decisions based on them
1656 * Everything's fixed there, it's just finding rules that are
1659 * return : 0 = everything is OK
1660 * rule = conflict found in this rule
1664 propagate(Solver *solv, int level)
1666 Pool *pool = solv->pool;
1667 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
1669 Id p, pkg, other_watch;
1671 Id *decisionmap = solv->decisionmap;
1673 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
1675 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1677 /* foreach non-propagated decision */
1678 while (solv->propagate_index < solv->decisionq.count)
1681 * 'pkg' was just decided
1682 * negate because our watches trigger if literal goes FALSE
1684 pkg = -solv->decisionq.elements[solv->propagate_index++];
1686 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1688 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
1689 solver_printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1692 /* foreach rule where 'pkg' is now FALSE */
1693 for (rp = watches + pkg; *rp; rp = next_rp)
1695 r = solv->rules + *rp;
1698 /* rule is disabled, goto next */
1706 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1708 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1709 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
1712 /* 'pkg' was just decided (was set to FALSE)
1714 * now find other literal watch, check clause
1715 * and advance on linked list
1719 other_watch = r->w2;
1724 other_watch = r->w1;
1729 * This term is already true (through the other literal)
1730 * so we have nothing to do
1732 if (DECISIONMAP_TRUE(other_watch))
1736 * The other literal is FALSE or UNDEF
1742 /* Not a binary clause, try to move our watch.
1744 * Go over all literals and find one that is
1748 * (TRUE is also ok, in that case the rule is fulfilled)
1750 if (r->p /* we have a 'p' */
1751 && r->p != other_watch /* which is not watched */
1752 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
1756 else /* go find a 'd' to make 'true' */
1759 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
1761 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1763 if (p != other_watch /* which is not watched */
1764 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
1772 * if we found some p that is UNDEF or TRUE, move
1775 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1778 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1780 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1796 watches[p] = r - solv->rules;
1799 /* search failed, thus all unwatched literals are FALSE */
1804 * unit clause found, set literal other_watch to TRUE
1807 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
1808 return r; /* eek, a conflict! */
1810 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1812 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
1813 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
1816 if (other_watch > 0)
1817 decisionmap[other_watch] = level; /* install! */
1819 decisionmap[-other_watch] = -level; /* remove! */
1821 queue_push(&solv->decisionq, other_watch);
1822 queue_push(&solv->decisionq_why, r - solv->rules);
1824 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1826 Solvable *s = pool->solvables + (other_watch > 0 ? other_watch : -other_watch);
1827 if (other_watch > 0)
1828 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
1830 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
1833 } /* foreach rule involving 'pkg' */
1835 } /* while we have non-decided decisions */
1837 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
1839 return 0; /* all is well */
1843 /********************************************************************/
1846 /*-------------------------------------------------------------------
1853 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
1855 Pool *pool = solv->pool;
1858 Map seen; /* global? */
1859 Id d, v, vv, *dp, why;
1861 int num = 0, l1num = 0;
1862 int learnt_why = solv->learnt_pool.count;
1863 Id *decisionmap = solv->decisionmap;
1867 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
1868 map_init(&seen, pool->nsolvables);
1869 idx = solv->decisionq.count;
1872 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1873 solver_printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1874 queue_push(&solv->learnt_pool, c - solv->rules);
1875 d = c->d < 0 ? -c->d - 1 : c->d;
1876 dp = d ? pool->whatprovidesdata + d : 0;
1877 /* go through all literals of the rule */
1889 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1891 vv = v > 0 ? v : -v;
1892 if (MAPTST(&seen, vv))
1894 l = solv->decisionmap[vv];
1899 l1num++; /* need to do this one in level1 pass */
1900 else if (l == level)
1901 num++; /* need to do this one as well */
1904 queue_push(&r, v); /* not level1 or conflict level, add to new rule */
1910 if (!num && !--l1num)
1911 break; /* all level 1 literals done */
1915 v = solv->decisionq.elements[--idx];
1916 vv = v > 0 ? v : -v;
1917 if (MAPTST(&seen, vv))
1921 if (num && --num == 0)
1923 *pr = -v; /* so that v doesn't get lost */
1926 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1927 for (i = 0; i < r.count; i++)
1930 MAPCLR(&seen, v > 0 ? v : -v);
1932 /* only level 1 marks left */
1936 why = solv->decisionq_why.elements[idx];
1937 if (!why) /* just in case, maybe for SYSTEMSOLVABLE */
1939 c = solv->rules + why;
1945 else if (r.count == 1 && r.elements[0] < 0)
1946 *dr = r.elements[0];
1948 *dr = pool_queuetowhatprovides(pool, &r);
1949 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1951 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1952 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
1953 for (i = 0; i < r.count; i++)
1954 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
1956 /* push end marker on learnt reasons stack */
1957 queue_push(&solv->learnt_pool, 0);
1960 solv->stats_learned++;
1965 /*-------------------------------------------------------------------
1969 * reset the solver decisions to right after the rpm rules.
1970 * called after rules have been enabled/disabled
1974 reset_solver(Solver *solv)
1976 Pool *pool = solv->pool;
1980 /* rewind decisions to direct rpm rule assertions */
1981 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
1983 v = solv->decisionq.elements[i];
1984 solv->decisionmap[v > 0 ? v : -v] = 0;
1987 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
1989 solv->decisionq_why.count = solv->directdecisions;
1990 solv->decisionq.count = solv->directdecisions;
1991 solv->recommends_index = -1;
1992 solv->propagate_index = 0;
1994 /* adapt learnt rule status to new set of enabled/disabled rules */
1995 enabledisablelearntrules(solv);
1997 /* redo all job/update decisions */
1998 makeruledecisions(solv);
1999 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
2003 /*-------------------------------------------------------------------
2005 * analyze_unsolvable_rule
2009 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
2011 Pool *pool = solv->pool;
2013 Id why = r - solv->rules;
2015 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
2016 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
2017 if (solv->learntrules && why >= solv->learntrules)
2019 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
2020 if (solv->learnt_pool.elements[i] > 0)
2021 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp);
2024 if (MAPTST(&solv->weakrulemap, why))
2025 if (!*lastweakp || why > *lastweakp)
2027 /* do not add rpm rules to problem */
2028 if (why < solv->rpmrules_end)
2030 /* turn rule into problem */
2031 if (why >= solv->jobrules && why < solv->jobrules_end)
2032 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
2033 /* return if problem already countains our rule */
2034 if (solv->problems.count)
2036 for (i = solv->problems.count - 1; i >= 0; i--)
2037 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
2039 else if (solv->problems.elements[i] == why)
2042 queue_push(&solv->problems, why);
2046 /*-------------------------------------------------------------------
2048 * analyze_unsolvable
2050 * return: 1 - disabled some rules, try again
2055 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
2057 Pool *pool = solv->pool;
2059 Map seen; /* global to speed things up? */
2060 Id d, v, vv, *dp, why;
2062 Id *decisionmap = solv->decisionmap;
2063 int oldproblemcount;
2064 int oldlearntpoolcount;
2067 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
2068 solv->stats_unsolvable++;
2069 oldproblemcount = solv->problems.count;
2070 oldlearntpoolcount = solv->learnt_pool.count;
2072 /* make room for proof index */
2073 /* must update it later, as analyze_unsolvable_rule would confuse
2074 * it with a rule index if we put the real value in already */
2075 queue_push(&solv->problems, 0);
2078 map_init(&seen, pool->nsolvables);
2079 queue_push(&solv->learnt_pool, r - solv->rules);
2081 analyze_unsolvable_rule(solv, r, &lastweak);
2082 d = r->d < 0 ? -r->d - 1 : r->d;
2083 dp = d ? pool->whatprovidesdata + d : 0;
2094 if (DECISIONMAP_TRUE(v)) /* the one true literal */
2096 vv = v > 0 ? v : -v;
2097 l = solv->decisionmap[vv];
2102 idx = solv->decisionq.count;
2105 v = solv->decisionq.elements[--idx];
2106 vv = v > 0 ? v : -v;
2107 if (!MAPTST(&seen, vv))
2109 why = solv->decisionq_why.elements[idx];
2110 queue_push(&solv->learnt_pool, why);
2111 r = solv->rules + why;
2112 analyze_unsolvable_rule(solv, r, &lastweak);
2113 d = r->d < 0 ? -r->d - 1 : r->d;
2114 dp = d ? pool->whatprovidesdata + d : 0;
2125 if (DECISIONMAP_TRUE(v)) /* the one true literal */
2127 vv = v > 0 ? v : -v;
2128 l = solv->decisionmap[vv];
2135 queue_push(&solv->problems, 0); /* mark end of this problem */
2140 /* disable last weak rule */
2141 solv->problems.count = oldproblemcount;
2142 solv->learnt_pool.count = oldlearntpoolcount;
2143 if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
2144 v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
2147 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling ");
2148 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, solv->rules + lastweak);
2149 disableproblem(solv, v);
2151 disableupdaterules(solv, solv->job, -(v + 1));
2157 queue_push(&solv->learnt_pool, 0);
2158 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
2162 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
2163 disableproblem(solv, solv->problems.elements[i]);
2164 /* XXX: might want to enable all weak rules again */
2168 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
2173 /********************************************************************/
2174 /* Decision revert */
2176 /*-------------------------------------------------------------------
2179 * revert decision at level
2183 revert(Solver *solv, int level)
2185 Pool *pool = solv->pool;
2187 while (solv->decisionq.count)
2189 v = solv->decisionq.elements[solv->decisionq.count - 1];
2190 vv = v > 0 ? v : -v;
2191 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
2193 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
2194 if (v > 0 && solv->recommendations.count && v == solv->recommendations.elements[solv->recommendations.count - 1])
2195 solv->recommendations.count--;
2196 solv->decisionmap[vv] = 0;
2197 solv->decisionq.count--;
2198 solv->decisionq_why.count--;
2199 solv->propagate_index = solv->decisionq.count;
2201 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
2203 solv->branches.count--;
2204 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
2205 solv->branches.count--;
2207 solv->recommends_index = -1;
2211 /*-------------------------------------------------------------------
2213 * watch2onhighest - put watch2 on literal with highest level
2217 watch2onhighest(Solver *solv, Rule *r)
2222 d = r->d < 0 ? -r->d - 1 : r->d;
2224 return; /* binary rule, both watches are set */
2225 dp = solv->pool->whatprovidesdata + d;
2226 while ((v = *dp++) != 0)
2228 l = solv->decisionmap[v < 0 ? -v : v];
2240 /*-------------------------------------------------------------------
2244 * add free decision (solvable to install) to decisionq
2245 * increase level and propagate decision
2246 * return if no conflict.
2248 * in conflict case, analyze conflict rule, add resulting
2249 * rule to learnt rule set, make decision from learnt
2250 * rule (always unit) and re-propagate.
2252 * returns the new solver level or 0 if unsolvable
2257 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
2259 Pool *pool = solv->pool;
2268 solv->decisionmap[decision] = level;
2270 solv->decisionmap[-decision] = -level;
2271 queue_push(&solv->decisionq, decision);
2272 queue_push(&solv->decisionq_why, 0);
2276 r = propagate(solv, level);
2280 return analyze_unsolvable(solv, r, disablerules);
2281 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
2282 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
2283 assert(l > 0 && l < level);
2284 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
2286 revert(solv, level);
2287 r = addrule(solv, p, d); /* p requires d */
2289 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
2290 queue_push(&solv->learnt_why, why);
2293 /* at least 2 literals, needs watches */
2294 watch2onhighest(solv, r);
2295 addwatches_rule(solv, r);
2299 /* learnt rule is an assertion */
2300 queue_push(&solv->ruleassertions, r - solv->rules);
2302 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
2303 queue_push(&solv->decisionq, p);
2304 queue_push(&solv->decisionq_why, r - solv->rules);
2305 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
2307 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
2308 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
2309 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
2310 solver_printrule(solv, SAT_DEBUG_ANALYZE, r);
2317 /*-------------------------------------------------------------------
2319 * select and install
2321 * install best package from the queue. We add an extra package, inst, if
2322 * provided. See comment in weak install section.
2324 * returns the new solver level or 0 if unsolvable
2329 selectandinstall(Solver *solv, int level, Queue *dq, int disablerules)
2331 Pool *pool = solv->pool;
2336 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
2339 /* XXX: didn't we already do that? */
2340 /* XXX: shouldn't we prefer installed packages? */
2341 /* XXX: move to policy.c? */
2342 /* choose the supplemented one */
2343 for (i = 0; i < dq->count; i++)
2344 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
2346 dq->elements[0] = dq->elements[i];
2353 /* multiple candidates, open a branch */
2354 for (i = 1; i < dq->count; i++)
2355 queue_push(&solv->branches, dq->elements[i]);
2356 queue_push(&solv->branches, -level);
2358 p = dq->elements[0];
2360 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
2362 return setpropagatelearn(solv, level, p, disablerules);
2366 /********************************************************************/
2367 /* Main solver interface */
2370 /*-------------------------------------------------------------------
2373 * create solver structure
2375 * pool: all available solvables
2376 * installed: installed Solvables
2379 * Upon solving, rules are created to flag the Solvables
2380 * of the 'installed' Repo as installed.
2384 solver_create(Pool *pool)
2387 solv = (Solver *)sat_calloc(1, sizeof(Solver));
2389 solv->installed = pool->installed;
2391 queue_init(&solv->ruletojob);
2392 queue_init(&solv->decisionq);
2393 queue_init(&solv->decisionq_why);
2394 queue_init(&solv->problems);
2395 queue_init(&solv->suggestions);
2396 queue_init(&solv->recommendations);
2397 queue_init(&solv->orphaned);
2398 queue_init(&solv->learnt_why);
2399 queue_init(&solv->learnt_pool);
2400 queue_init(&solv->branches);
2401 queue_init(&solv->covenantq);
2402 queue_init(&solv->weakruleq);
2403 queue_init(&solv->ruleassertions);
2405 map_init(&solv->recommendsmap, pool->nsolvables);
2406 map_init(&solv->suggestsmap, pool->nsolvables);
2407 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
2408 solv->recommends_index = 0;
2410 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2412 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
2413 memset(solv->rules, 0, sizeof(Rule));
2419 /*-------------------------------------------------------------------
2425 solver_free(Solver *solv)
2427 queue_free(&solv->ruletojob);
2428 queue_free(&solv->decisionq);
2429 queue_free(&solv->decisionq_why);
2430 queue_free(&solv->learnt_why);
2431 queue_free(&solv->learnt_pool);
2432 queue_free(&solv->problems);
2433 queue_free(&solv->suggestions);
2434 queue_free(&solv->recommendations);
2435 queue_free(&solv->orphaned);
2436 queue_free(&solv->branches);
2437 queue_free(&solv->covenantq);
2438 queue_free(&solv->weakruleq);
2439 queue_free(&solv->ruleassertions);
2441 map_free(&solv->recommendsmap);
2442 map_free(&solv->suggestsmap);
2443 map_free(&solv->noupdate);
2444 map_free(&solv->weakrulemap);
2445 map_free(&solv->noobsoletes);
2447 sat_free(solv->decisionmap);
2448 sat_free(solv->rules);
2449 sat_free(solv->watches);
2450 sat_free(solv->obsoletes);
2451 sat_free(solv->obsoletes_data);
2452 sat_free(solv->multiversionupdaters);
2457 /*-------------------------------------------------------------------
2461 * all rules have been set up, now actually run the solver
2466 run_solver(Solver *solv, int disablerules, int doweak)
2468 Queue dq; /* local decisionqueue */
2469 Queue dqs; /* local decisionqueue for supplements */
2475 Pool *pool = solv->pool;
2477 int minimizationsteps;
2479 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2481 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2482 for (i = 1; i < solv->nrules; i++)
2483 solver_printruleclass(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2486 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2488 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2489 solver_printdecisions(solv);
2491 /* start SAT algorithm */
2493 systemlevel = level + 1;
2494 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2500 * here's the main loop:
2501 * 1) propagate new decisions (only needed for level 1)
2502 * 2) try to keep installed packages
2503 * 3) fulfill all unresolved rules
2504 * 4) install recommended packages
2505 * 5) minimalize solution if we had choices
2506 * if we encounter a problem, we rewind to a safe level and restart
2510 minimizationsteps = 0;
2519 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2520 if ((r = propagate(solv, level)) != 0)
2522 if (analyze_unsolvable(solv, r, disablerules))
2530 if (level < systemlevel)
2532 POOL_DEBUG(SAT_DEBUG_STATS, "resolving job rules\n");
2533 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
2536 if (r->d < 0) /* ignore disabled rules */
2539 FOR_RULELITERALS(l, dp, r)
2543 if (solv->decisionmap[-l] <= 0)
2548 if (solv->decisionmap[l] > 0)
2550 if (solv->decisionmap[l] == 0)
2556 /* prune to installed if not updating */
2557 if (!solv->updatesystem && solv->installed && dq.count > 1)
2560 for (j = k = 0; j < dq.count; j++)
2562 Solvable *s = pool->solvables + dq.elements[j];
2563 if (s->repo == solv->installed)
2564 dq.elements[k++] = dq.elements[j];
2570 level = selectandinstall(solv, level, &dq, disablerules);
2577 if (level <= olevel)
2580 systemlevel = level + 1;
2581 if (i < solv->jobrules_end)
2587 * installed packages
2590 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2592 if (!solv->updatesystem)
2595 * Normal run (non-updating)
2596 * Keep as many packages installed as possible
2598 POOL_DEBUG(SAT_DEBUG_STATS, "installing old packages\n");
2600 for (i = solv->installed->start; i < solv->installed->end; i++)
2602 s = pool->solvables + i;
2604 /* skip if not installed */
2605 if (s->repo != solv->installed)
2608 /* skip if already decided */
2609 if (solv->decisionmap[i] != 0)
2612 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2615 level = setpropagatelearn(solv, level, i, disablerules);
2617 if (level == 0) /* unsolvable */
2623 if (level <= olevel)
2626 systemlevel = level + 1;
2627 if (i < solv->installed->end)
2630 else if (solv->noobsoletes.size && solv->multiversionupdaters)
2632 /* see if we can multi-version install the newest package */
2633 for (i = solv->installed->start; i < solv->installed->end; i++)
2636 s = pool->solvables + i;
2637 if (s->repo != solv->installed)
2639 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2641 d = solv->multiversionupdaters[i - solv->installed->start];
2646 while ((p = pool->whatprovidesdata[d++]) != 0)
2647 if (solv->decisionmap[p] >= 0)
2649 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2651 if (p != i && solv->decisionmap[p] == 0)
2654 POOL_DEBUG(SAT_DEBUG_POLICY, "installing (multi-version) %s\n", solvable2str(pool, pool->solvables + p));
2655 level = setpropagatelearn(solv, level, p, disablerules);
2662 if (level <= olevel)
2666 /* now that the best version is installed, try to
2667 * keep the original one */
2668 if (solv->decisionmap[p]) /* already decided? */
2670 r = solv->rules + solv->updaterules + (i - solv->installed->start);
2671 if (!r->p) /* update rule == feature rule? */
2672 r = r - solv->updaterules + solv->featurerules;
2673 if (r->p == p) /* allowed to keep package? */
2676 POOL_DEBUG(SAT_DEBUG_POLICY, "keeping (multi-version) %s\n", solvable2str(pool, pool->solvables + p));
2677 level = setpropagatelearn(solv, level, p, disablerules);
2684 if (level <= olevel)
2688 systemlevel = level + 1;
2689 if (i < solv->installed->end)
2693 POOL_DEBUG(SAT_DEBUG_STATS, "resolving update/feature rules\n");
2695 for (i = solv->installed->start, r = solv->rules + solv->updaterules; i < solv->installed->end; i++, r++)
2698 s = pool->solvables + i;
2700 /* skip if not installed (can't update) */
2701 if (s->repo != solv->installed)
2703 /* skip if already decided */
2704 if (solv->decisionmap[i] > 0)
2707 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2708 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2714 if (rr->d < 0) /* disabled -> look at feature rule ? */
2715 rr -= solv->installed->end - solv->installed->start;
2716 if (!rr->p) /* identical to update rule? */
2719 continue; /* no such rule or disabled */
2721 FOR_RULELITERALS(p, dp, rr)
2723 if (solv->decisionmap[p] > 0)
2725 if (solv->decisionmap[p] == 0)
2728 if (p || !dq.count) /* already fulfilled or empty */
2731 level = selectandinstall(solv, level, &dq, disablerules);
2738 if (level <= olevel)
2741 systemlevel = level + 1;
2742 if (i < solv->installed->end)
2746 if (level < systemlevel)
2747 systemlevel = level;
2753 POOL_DEBUG(SAT_DEBUG_POLICY, "deciding unresolved rules\n");
2754 for (i = 1, n = 1; ; i++, n++)
2756 if (n == solv->nrules)
2758 if (i == solv->nrules)
2760 r = solv->rules + i;
2761 if (r->d < 0) /* ignore disabled rules */
2766 /* binary or unary rule */
2767 /* need two positive undecided literals */
2768 if (r->p < 0 || r->w2 <= 0)
2770 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2772 queue_push(&dq, r->p);
2773 queue_push(&dq, r->w2);
2778 * all negative literals are installed
2779 * no positive literal is installed
2780 * i.e. the rule is not fulfilled and we
2781 * just need to decide on the positive literals
2785 if (solv->decisionmap[-r->p] <= 0)
2790 if (solv->decisionmap[r->p] > 0)
2792 if (solv->decisionmap[r->p] == 0)
2793 queue_push(&dq, r->p);
2795 dp = pool->whatprovidesdata + r->d;
2796 while ((p = *dp++) != 0)
2800 if (solv->decisionmap[-p] <= 0)
2805 if (solv->decisionmap[p] > 0)
2807 if (solv->decisionmap[p] == 0)
2814 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2816 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2817 solver_printruleclass(solv, SAT_DEBUG_PROPAGATE, r);
2819 /* dq.count < 2 cannot happen as this means that
2820 * the rule is unit */
2821 assert(dq.count > 1);
2824 level = selectandinstall(solv, level, &dq, disablerules);
2831 if (level < systemlevel)
2834 } /* for(), decide */
2836 if (n != solv->nrules) /* continue if level < systemlevel */
2843 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended packages\n");
2844 queue_empty(&dq); /* recommended packages */
2845 queue_empty(&dqs); /* supplemented packages */
2846 for (i = 1; i < pool->nsolvables; i++)
2848 if (solv->decisionmap[i] < 0)
2850 if (solv->decisionmap[i] > 0)
2852 /* installed, check for recommends */
2853 Id *recp, rec, pp, p;
2854 s = pool->solvables + i;
2855 if (solv->ignorealreadyrecommended && s->repo == solv->installed)
2857 /* XXX need to special case AND ? */
2860 recp = s->repo->idarraydata + s->recommends;
2861 while ((rec = *recp++) != 0)
2864 FOR_PROVIDES(p, pp, rec)
2866 if (solv->decisionmap[p] > 0)
2871 else if (solv->decisionmap[p] == 0)
2873 queue_pushunique(&dq, p);
2881 s = pool->solvables + i;
2882 if (!s->supplements)
2884 if (!pool_installable(pool, s))
2886 if (!solver_is_supplementing(solv, s))
2888 queue_push(&dqs, i);
2892 /* filter out all already supplemented packages if requested */
2893 if (solv->ignorealreadyrecommended && dqs.count)
2895 /* turn off all new packages */
2896 for (i = 0; i < solv->decisionq.count; i++)
2898 p = solv->decisionq.elements[i];
2901 s = pool->solvables + p;
2902 if (s->repo && s->repo != solv->installed)
2903 solv->decisionmap[p] = -solv->decisionmap[p];
2905 /* filter out old supplements */
2906 for (i = j = 0; i < dqs.count; i++)
2908 p = dqs.elements[i];
2909 s = pool->solvables + p;
2910 if (!s->supplements)
2912 if (!solver_is_supplementing(solv, s))
2913 dqs.elements[j++] = p;
2916 /* undo turning off */
2917 for (i = 0; i < solv->decisionq.count; i++)
2919 p = solv->decisionq.elements[i];
2922 s = pool->solvables + p;
2923 if (s->repo && s->repo != solv->installed)
2924 solv->decisionmap[p] = -solv->decisionmap[p];
2928 /* make dq contain both recommended and supplemented pkgs */
2931 for (i = 0; i < dqs.count; i++)
2932 queue_pushunique(&dq, dqs.elements[i]);
2939 int decisioncount = solv->decisionq.count;
2943 /* simple case, just one package. no need to choose */
2946 POOL_DEBUG(SAT_DEBUG_POLICY, "installing supplemented %s\n", solvable2str(pool, pool->solvables + p));
2948 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2949 queue_push(&solv->recommendations, p);
2950 level = setpropagatelearn(solv, level, p, 0);
2954 /* filter and create a map of result */
2955 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
2956 map_init(&dqmap, pool->nsolvables);
2957 for (i = 0; i < dq.count; i++)
2958 MAPSET(&dqmap, dq.elements[i]);
2960 /* install all supplemented packages */
2961 for (i = 0; i < dqs.count; i++)
2963 p = dqs.elements[i];
2964 if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
2966 POOL_DEBUG(SAT_DEBUG_POLICY, "installing supplemented %s\n", solvable2str(pool, pool->solvables + p));
2967 queue_push(&solv->recommendations, p);
2969 level = setpropagatelearn(solv, level, p, 0);
2970 if (level <= olevel)
2973 if (i < dqs.count || solv->decisionq.count < decisioncount)
2979 /* install all recommended packages */
2980 /* more work as we want to created branches if multiple
2981 * choices are valid */
2982 for (i = 0; i < decisioncount; i++)
2985 p = solv->decisionq.elements[i];
2988 s = pool->solvables + p;
2989 if (!s->repo || (solv->ignorealreadyrecommended && s->repo == solv->installed))
2993 recp = s->repo->idarraydata + s->recommends;
2994 while ((rec = *recp++) != 0)
2997 FOR_PROVIDES(p, pp, rec)
2999 if (solv->decisionmap[p] > 0)
3004 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
3005 queue_pushunique(&dq, p);
3011 /* multiple candidates, open a branch */
3012 for (i = 1; i < dq.count; i++)
3013 queue_push(&solv->branches, dq.elements[i]);
3014 queue_push(&solv->branches, -level);
3017 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
3018 queue_push(&solv->recommendations, p);
3020 level = setpropagatelearn(solv, level, p, 0);
3021 if (level <= olevel || solv->decisionq.count < decisioncount)
3025 break; /* had a problem above, quit loop */
3034 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
3036 /* prefer recommended patterns (bnc#450226) */
3037 /* real fix is to minimize recommended packages as well */
3038 for (i = 0; i < dq.count; i++)
3039 if (!strncmp(id2str(pool, pool->solvables[dq.elements[i]].name), "pattern:", 8))
3044 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
3045 queue_push(&solv->recommendations, p);
3046 level = setpropagatelearn(solv, level, p, 0);
3052 if (solv->distupgrade && solv->installed)
3054 /* let's see if we can install some unsupported package */
3055 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unsupported packages\n");
3056 for (i = 0; i < solv->orphaned.count; i++)
3058 p = solv->orphaned.elements[i];
3059 if (!solv->decisionmap[p])
3062 if (i < solv->orphaned.count)
3064 p = solv->orphaned.elements[i];
3065 if (solv->distupgrade_removeunsupported)
3067 POOL_DEBUG(SAT_DEBUG_STATS, "removing unsupported %s\n", solvable2str(pool, pool->solvables + p));
3068 level = setpropagatelearn(solv, level, -p, 0);
3072 POOL_DEBUG(SAT_DEBUG_STATS, "keeping unsupported %s\n", solvable2str(pool, pool->solvables + p));
3073 level = setpropagatelearn(solv, level, p, 0);
3079 if (solv->solution_callback)
3081 solv->solution_callback(solv, solv->solution_callback_data);
3082 if (solv->branches.count)
3084 int i = solv->branches.count - 1;
3085 int l = -solv->branches.elements[i];
3087 if (solv->branches.elements[i - 1] < 0)
3089 p = solv->branches.elements[i];
3090 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
3092 for (j = i + 1; j < solv->branches.count; j++)
3093 queue_push(&dq, solv->branches.elements[j]);
3094 solv->branches.count = i;
3096 revert(solv, level);
3098 for (j = 0; j < dq.count; j++)
3099 queue_push(&solv->branches, dq.elements[j]);
3101 level = setpropagatelearn(solv, level, p, disablerules);
3110 /* all branches done, we're finally finished */
3114 /* minimization step */
3115 if (solv->branches.count)
3117 int l = 0, lasti = -1, lastl = -1;
3119 for (i = solv->branches.count - 1; i >= 0; i--)
3121 p = solv->branches.elements[i];
3124 else if (p > 0 && solv->decisionmap[p] > l + 1)
3132 /* kill old solvable so that we do not loop */
3133 p = solv->branches.elements[lasti];
3134 solv->branches.elements[lasti] = 0;
3135 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], lastl, solvable2str(pool, pool->solvables + p));
3136 minimizationsteps++;
3139 revert(solv, level);
3141 level = setpropagatelearn(solv, level, p, disablerules);
3153 POOL_DEBUG(SAT_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
3155 POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
3161 /*-------------------------------------------------------------------
3165 * at this point, all rules that led to conflicts are disabled.
3166 * we re-enable all rules of a problem set but rule "sug", then
3167 * continue to disable more rules until there as again a solution.
3170 /* FIXME: think about conflicting assertions */
3173 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
3175 Pool *pool = solv->pool;
3181 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
3183 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
3184 for (i = 0; problem[i]; i++)
3186 if (problem[i] == sug)
3187 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
3188 solver_printproblem(solv, problem[i]);
3191 queue_init(&disabled);
3192 queue_empty(refined);
3193 queue_push(refined, sug);
3195 /* re-enable all problem rules with the exception of "sug"(gestion) */
3199 for (i = 0; problem[i]; i++)
3200 if (problem[i] != sug)
3201 enableproblem(solv, problem[i]);
3204 disableupdaterules(solv, job, -(sug + 1));
3205 else if (sug >= solv->updaterules && sug < solv->updaterules_end)
3207 /* enable feature rule */
3208 Rule *r = solv->rules + solv->featurerules + (sug - solv->updaterules);
3210 enablerule(solv, r);
3213 enableweakrules(solv);
3217 int njob, nfeature, nupdate;
3218 queue_empty(&solv->problems);
3219 revert(solv, 1); /* XXX no longer needed? */
3222 if (!solv->problems.count)
3223 run_solver(solv, 0, 0);
3225 if (!solv->problems.count)
3227 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
3228 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3229 solver_printdecisions(solv);
3230 break; /* great, no more problems */
3232 disabledcnt = disabled.count;
3233 /* start with 1 to skip over proof index */
3234 njob = nfeature = nupdate = 0;
3235 for (i = 1; i < solv->problems.count - 1; i++)
3237 /* ignore solutions in refined */
3238 v = solv->problems.elements[i];
3240 break; /* end of problem reached */
3241 for (j = 0; problem[j]; j++)
3242 if (problem[j] != sug && problem[j] == v)
3246 if (v >= solv->featurerules && v < solv->featurerules_end)
3252 if ((job->elements[-v -1] & SOLVER_ESSENTIAL) != 0)
3253 continue; /* not that one! */
3256 queue_push(&disabled, v);
3258 if (disabled.count == disabledcnt)
3260 /* no solution found, this was an invalid suggestion! */
3261 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
3265 if (!njob && nupdate && nfeature)
3267 /* got only update rules, filter out feature rules */
3268 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "throwing away feature rules\n");
3269 for (i = j = disabledcnt; i < disabled.count; i++)
3271 v = disabled.elements[i];
3272 if (v < solv->featurerules || v >= solv->featurerules_end)
3273 disabled.elements[j++] = v;
3278 if (disabled.count == disabledcnt + 1)
3280 /* just one suggestion, add it to refined list */
3281 v = disabled.elements[disabledcnt];
3283 queue_push(refined, v); /* do not record feature rules */
3284 disableproblem(solv, v);
3285 if (v >= solv->updaterules && v < solv->updaterules_end)
3287 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
3289 enablerule(solv, r); /* enable corresponding feature rule */
3292 disableupdaterules(solv, job, -(v + 1));
3296 /* more than one solution, disable all */
3297 /* do not push anything on refine list, as we do not know which solution to choose */
3298 /* thus, the user will get another problem if he selects this solution, where he
3299 * can choose the right one */
3300 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
3302 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
3303 for (i = disabledcnt; i < disabled.count; i++)
3304 solver_printproblem(solv, disabled.elements[i]);
3306 for (i = disabledcnt; i < disabled.count; i++)
3308 v = disabled.elements[i];
3309 disableproblem(solv, v);
3310 if (v >= solv->updaterules && v < solv->updaterules_end)
3312 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
3314 enablerule(solv, r);
3319 /* all done, get us back into the same state as before */
3320 /* enable refined rules again */
3321 for (i = 0; i < disabled.count; i++)
3322 enableproblem(solv, disabled.elements[i]);
3323 /* disable problem rules again */
3326 for (i = 0; problem[i]; i++)
3327 enableproblem(solv, problem[i]);
3328 disableupdaterules(solv, job, -1);
3330 /* disable problem rules again */
3331 for (i = 0; problem[i]; i++)
3332 disableproblem(solv, problem[i]);
3333 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
3337 /*-------------------------------------------------------------------
3338 * sorting helper for problems
3340 * bring update rules before job rules
3341 * make essential job rules last
3344 Queue *problems_sort_data;
3347 problems_sortcmp(const void *ap, const void *bp)
3349 Id a = *(Id *)ap, b = *(Id *)bp;
3356 Queue *job = problems_sort_data;
3357 int af = job->elements[-a - 1] & SOLVER_ESSENTIAL;
3358 int bf = job->elements[-b - 1] & SOLVER_ESSENTIAL;
3367 /*-------------------------------------------------------------------
3372 problems_sort(Solver *solv, Queue *job)
3375 if (!solv->problems.count)
3377 for (i = j = 1; i < solv->problems.count; i++)
3379 if (!solv->problems.elements[i])
3383 problems_sort_data = job;
3384 qsort(solv->problems.elements + j, i - j, sizeof(Id), problems_sortcmp);
3386 if (++i == solv->problems.count)
3394 /*-------------------------------------------------------------------
3395 * convert problems to solutions
3399 problems_to_solutions(Solver *solv, Queue *job)
3401 Pool *pool = solv->pool;
3407 int i, j, nsol, probsolved;
3408 unsigned int now, refnow;
3410 if (!solv->problems.count)
3412 now = sat_timems(0);
3413 problems_sort(solv, job);
3414 queue_clone(&problems, &solv->problems);
3415 queue_init(&solution);
3416 queue_init(&solutions);
3417 /* copy over proof index */
3418 queue_push(&solutions, problems.elements[0]);
3419 problem = problems.elements + 1;
3421 refnow = sat_timems(0);
3422 for (i = 1; i < problems.count; i++)
3424 Id v = problems.elements[i];
3427 /* mark end of this problem */
3428 queue_push(&solutions, 0);
3429 queue_push(&solutions, 0);
3430 POOL_DEBUG(SAT_DEBUG_STATS, "refining took %d ms\n", sat_timems(refnow));
3431 if (i + 1 == problems.count)
3433 /* copy over proof of next problem */
3434 queue_push(&solutions, problems.elements[i + 1]);
3436 problem = problems.elements + i + 1;
3437 refnow = sat_timems(0);
3441 if (v < 0 && (job->elements[-v - 1] & SOLVER_ESSENTIAL))
3443 /* essential job, skip if we already have a non-essential
3447 probsolved = -1; /* show all solutions */
3449 refine_suggestion(solv, job, problem, v, &solution);
3450 if (!solution.count)
3451 continue; /* this solution didn't work out */
3454 for (j = 0; j < solution.count; j++)
3456 why = solution.elements[j];
3457 /* must be either job descriptor or update rule */
3458 assert(why < 0 || (why >= solv->updaterules && why < solv->updaterules_end));
3460 solver_printproblem(solv, why);
3464 /* job descriptor */
3465 queue_push(&solutions, 0);
3466 queue_push(&solutions, -why);
3470 /* update rule, find replacement package */
3473 p = solv->installed->start + (why - solv->updaterules);
3474 rr = solv->rules + solv->featurerules + (why - solv->updaterules);
3476 rr = solv->rules + why;
3477 if (solv->distupgrade && solv->rules[why].p != p && solv->decisionmap[p] > 0)
3479 /* distupgrade case, allow to keep old package */
3480 queue_push(&solutions, p);
3481 queue_push(&solutions, p);
3485 if (solv->decisionmap[p] > 0)
3486 continue; /* false alarm, turned out we can keep the package */
3489 int mvrp = 0; /* multi-version replacement */
3490 FOR_RULELITERALS(rp, dp, rr)
3492 if (rp > 0 && solv->decisionmap[rp] > 0 && pool->solvables[rp].repo != solv->installed)
3495 if (!(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, rp)))
3501 /* found only multi-version replacements */
3502 /* have to split solution into two parts */
3503 queue_push(&solutions, p);
3504 queue_push(&solutions, mvrp);
3508 queue_push(&solutions, p);
3509 queue_push(&solutions, rp);
3513 /* mark end of this solution */
3518 queue_push(&solutions, 0);
3519 queue_push(&solutions, 0);
3523 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "Oops, everything was fine?\n");
3526 queue_free(&solution);
3527 queue_free(&problems);
3528 /* copy queue over to solutions */
3529 queue_free(&solv->problems);
3530 queue_clone(&solv->problems, &solutions);
3532 /* bring solver back into problem state */
3533 revert(solv, 1); /* XXX move to reset_solver? */
3536 assert(solv->problems.count == solutions.count);
3537 queue_free(&solutions);
3538 POOL_DEBUG(SAT_DEBUG_STATS, "problems_to_solutions took %d ms\n", sat_timems(now));
3542 /*-------------------------------------------------------------------
3546 * advance to next problem
3550 solver_next_problem(Solver *solv, Id problem)
3554 return solv->problems.count ? 1 : 0;
3555 pp = solv->problems.elements + problem;
3556 while (pp[0] || pp[1])
3560 while (pp[0] || pp[1])
3565 problem = pp - solv->problems.elements;
3566 if (problem >= solv->problems.count)
3572 /*-------------------------------------------------------------------
3578 solver_next_solution(Solver *solv, Id problem, Id solution)
3584 pp = solv->problems.elements + solution;
3585 return pp[0] || pp[1] ? solution : 0;
3587 pp = solv->problems.elements + solution;
3588 while (pp[0] || pp[1])
3591 solution = pp - solv->problems.elements;
3592 return pp[0] || pp[1] ? solution : 0;
3596 /*-------------------------------------------------------------------
3598 * solution element iterator
3602 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
3605 element = element ? element + 2 : solution;
3606 pp = solv->problems.elements + element;
3607 if (!(pp[0] || pp[1]))
3615 /*-------------------------------------------------------------------
3617 * Retrieve information about a problematic rule
3619 * this is basically the reverse of addrpmrulesforsolvable
3623 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
3625 Pool *pool = solv->pool;
3626 Repo *installed = solv->installed;
3630 Id p, d, w2, pp, req, *reqp, con, *conp, obs, *obsp, *dp;
3633 if (rid >= solv->jobrules && rid < solv->jobrules_end)
3636 r = solv->rules + rid;
3637 p = solv->ruletojob.elements[rid - solv->jobrules];
3638 *depp = job->elements[p + 1];
3640 *targetp = job->elements[p];
3641 d = r->d < 0 ? -r->d - 1 : r->d;
3642 if (d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && (job->elements[p] & SOLVER_SELECTMASK) != SOLVER_SOLVABLE_ONE_OF)
3643 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
3644 return SOLVER_PROBLEM_JOB_RULE;
3646 if (rid >= solv->updaterules && rid < solv->updaterules_end)
3649 *sourcep = solv->installed->start + (rid - solv->updaterules);
3651 return SOLVER_PROBLEM_UPDATE_RULE;
3653 assert(rid < solv->rpmrules_end);
3654 r = solv->rules + rid;
3656 d = r->d < 0 ? -r->d - 1 : r->d;
3657 if (d == 0 && r->w2 == 0)
3659 /* a rpm rule assertion */
3660 s = pool->solvables - r->p;
3661 if (installed && !solv->fixsystem && s->repo == installed)
3663 assert(!dontfix); /* dontfix packages never have a neg assertion */
3666 /* see why the package is not installable */
3667 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
3670 return SOLVER_PROBLEM_NOT_INSTALLABLE;
3672 /* check requires */
3675 reqp = s->repo->idarraydata + s->requires;
3676 while ((req = *reqp++) != 0)
3678 if (req == SOLVABLE_PREREQMARKER)
3680 dp = pool->whatprovidesdata + pool_whatprovides(pool, req);
3687 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
3690 if (!solv->allowselfconflicts && s->conflicts)
3692 conp = s->repo->idarraydata + s->conflicts;
3693 while ((con = *conp++) != 0)
3694 FOR_PROVIDES(p, pp, con)
3698 return SOLVER_PROBLEM_SELF_CONFLICT;
3701 /* should never happen */
3703 return SOLVER_PROBLEM_RPM_RULE;
3705 s = pool->solvables - r->p;
3706 if (installed && !solv->fixsystem && s->repo == installed)
3709 if (d && pool->whatprovidesdata[d] < 0)
3711 /* rule looks like -p|-c|x|x|x..., we only create this for patches with multiversion */
3712 /* reduce it to -p|-c case */
3713 w2 = pool->whatprovidesdata[d];
3715 if (d == 0 && w2 < 0)
3717 /* a package conflict */
3718 Solvable *s2 = pool->solvables - w2;
3721 if (installed && !solv->fixsystem && s2->repo == installed)
3724 /* if both packages have the same name and at least one of them
3725 * is not installed, they conflict */
3726 if (s->name == s2->name && !(installed && s->repo == installed && s2->repo == installed))
3728 /* also check noobsoletes map */
3729 if ((s->evr == s2->evr && s->arch == s2->arch) || !solv->noobsoletes.size
3730 || ((!installed || s->repo != installed) && !MAPTST(&solv->noobsoletes, -r->p))
3731 || ((!installed || s2->repo != installed) && !MAPTST(&solv->noobsoletes, -w2)))
3736 return SOLVER_PROBLEM_SAME_NAME;
3740 /* check conflicts in both directions */
3743 conp = s->repo->idarraydata + s->conflicts;
3744 while ((con = *conp++) != 0)
3746 FOR_PROVIDES(p, pp, con)
3748 if (dontfix && pool->solvables[p].repo == installed)
3755 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3761 conp = s2->repo->idarraydata + s2->conflicts;
3762 while ((con = *conp++) != 0)
3764 FOR_PROVIDES(p, pp, con)
3766 if (dontfix2 && pool->solvables[p].repo == installed)
3773 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3777 /* check obsoletes in both directions */
3778 if ((!installed || s->repo != installed) && s->obsoletes && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->p)))
3780 obsp = s->repo->idarraydata + s->obsoletes;
3781 while ((obs = *obsp++) != 0)
3783 FOR_PROVIDES(p, pp, obs)
3787 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
3792 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3796 if ((!installed || s2->repo != installed) && s2->obsoletes && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -w2)))
3798 obsp = s2->repo->idarraydata + s2->obsoletes;
3799 while ((obs = *obsp++) != 0)
3801 FOR_PROVIDES(p, pp, obs)
3805 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
3810 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3814 if (solv->implicitobsoleteusesprovides && (!installed || s->repo != installed) && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->p)))
3816 FOR_PROVIDES(p, pp, s->name)
3823 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3826 if (solv->implicitobsoleteusesprovides && (!installed || s2->repo != installed) && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -w2)))
3828 FOR_PROVIDES(p, pp, s2->name)
3835 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3838 /* all cases checked, can't happen */
3842 return SOLVER_PROBLEM_RPM_RULE;
3844 /* simple requires */
3847 reqp = s->repo->idarraydata + s->requires;
3848 while ((req = *reqp++) != 0)
3850 if (req == SOLVABLE_PREREQMARKER)
3852 dp = pool->whatprovidesdata + pool_whatprovides(pool, req);
3855 if (*dp == r->w2 && dp[1] == 0)
3858 else if (dp - pool->whatprovidesdata == d)
3866 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
3869 /* all cases checked, can't happen */
3873 return SOLVER_PROBLEM_RPM_RULE;
3877 /*-------------------------------------------------------------------
3883 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3886 Id lreqr, lconr, lsysr, ljobr;
3890 lreqr = lconr = lsysr = ljobr = 0;
3891 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3894 if (rid >= solv->learntrules)
3895 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3896 else if (rid >= solv->jobrules && rid < solv->jobrules_end)
3901 else if (rid >= solv->updaterules && rid < solv->updaterules_end)
3908 assert(rid < solv->rpmrules_end);
3909 r = solv->rules + rid;
3910 d = r->d < 0 ? -r->d - 1 : r->d;
3911 if (!d && r->w2 < 0)
3918 if (!d && r->w2 == 0 && !reqassert)
3920 if (*reqrp > 0 && r->p < -1)
3922 Id op = -solv->rules[*reqrp].p;
3923 if (op > 1 && solv->pool->solvables[op].arch != solv->pool->solvables[-r->p].arch)
3924 continue; /* different arch, skip */
3926 /* prefer assertions */
3932 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed && !reqassert)
3934 /* prefer rules of installed packages */
3940 if (!*reqrp && lreqr)
3942 if (!*conrp && lconr)
3944 if (!*jobrp && ljobr)
3946 if (!*sysrp && lsysr)
3951 /*-------------------------------------------------------------------
3955 * search for a rule that describes the problem to the
3956 * user. A pretty hopeless task, actually. We currently
3957 * prefer simple requires.
3961 solver_findproblemrule(Solver *solv, Id problem)
3963 Id reqr, conr, sysr, jobr;
3964 Id idx = solv->problems.elements[problem - 1];
3965 reqr = conr = sysr = jobr = 0;
3966 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3979 /*-------------------------------------------------------------------
3981 * create reverse obsoletes map for installed solvables
3983 * for each installed solvable find which packages with *different* names
3984 * obsolete the solvable.
3985 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3989 create_obsolete_index(Solver *solv)
3991 Pool *pool = solv->pool;
3993 Repo *installed = solv->installed;
3994 Id p, pp, obs, *obsp, *obsoletes, *obsoletes_data;
3997 if (!installed || !installed->nsolvables)
3999 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
4000 for (i = 1; i < pool->nsolvables; i++)
4002 s = pool->solvables + i;
4005 if (!pool_installable(pool, s))
4007 obsp = s->repo->idarraydata + s->obsoletes;
4008 while ((obs = *obsp++) != 0)
4010 FOR_PROVIDES(p, pp, obs)
4012 if (pool->solvables[p].repo != installed)
4014 if (pool->solvables[p].name == s->name)
4016 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
4018 obsoletes[p - installed->start]++;
4023 for (i = 0; i < installed->nsolvables; i++)
4026 n += obsoletes[i] + 1;
4029 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
4030 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
4031 for (i = pool->nsolvables - 1; i > 0; i--)
4033 s = pool->solvables + i;
4036 if (!pool_installable(pool, s))
4038 obsp = s->repo->idarraydata + s->obsoletes;
4039 while ((obs = *obsp++) != 0)
4041 FOR_PROVIDES(p, pp, obs)
4043 if (pool->solvables[p].repo != installed)
4045 if (pool->solvables[p].name == s->name)
4047 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
4049 p -= installed->start;
4050 if (obsoletes_data[obsoletes[p]] != i)
4051 obsoletes_data[--obsoletes[p]] = i;
4058 /*-------------------------------------------------------------------
4060 * remove disabled conflicts
4064 removedisabledconflicts(Solver *solv, Queue *removed)
4066 Pool *pool = solv->pool;
4071 Id *decisionmap = solv->decisionmap;
4073 POOL_DEBUG(SAT_DEBUG_SCHUBI, "removedisabledconflicts\n");
4074 queue_empty(removed);
4075 for (i = 0; i < solv->decisionq.count; i++)
4077 p = solv->decisionq.elements[i];
4080 /* a conflict. we never do conflicts on free decisions, so there
4081 * must have been an unit rule */
4082 why = solv->decisionq_why.elements[i];
4084 r = solv->rules + why;
4085 if (r->d < 0 && decisionmap[-p])
4087 /* rule is now disabled, remove from decisionmap */
4088 POOL_DEBUG(SAT_DEBUG_SCHUBI, "removing conflict for package %s[%d]\n", solvable2str(pool, pool->solvables - p), -p);
4089 queue_push(removed, -p);
4090 queue_push(removed, decisionmap[-p]);
4091 decisionmap[-p] = 0;
4094 if (!removed->count)
4096 /* we removed some confliced packages. some of them might still
4097 * be in conflict, so search for unit rules and re-conflict */
4099 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
4101 if (i == solv->nrules)
4104 r = solv->rules + i;
4110 if (r->p < 0 && !decisionmap[-r->p])
4116 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
4118 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
4123 if (r->p < 0 && decisionmap[-r->p] == 0)
4125 if (new || DECISIONMAP_FALSE(r->p))
4127 dp = pool->whatprovidesdata + r->d;
4128 while ((p = *dp++) != 0)
4130 if (new && p == new)
4132 if (p < 0 && decisionmap[-p] == 0)
4141 else if (!DECISIONMAP_FALSE(p))
4151 POOL_DEBUG(SAT_DEBUG_SCHUBI, "re-conflicting package %s[%d]\n", solvable2str(pool, pool->solvables - new), -new);
4152 decisionmap[-new] = -1;
4154 n = 0; /* redo all rules */
4160 /*-------------------------------------------------------------------
4162 * weaken solvable dependencies
4166 weaken_solvable_deps(Solver *solv, Id p)
4171 for (i = 1, r = solv->rules + i; i < solv->rpmrules_end; i++, r++)
4175 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
4176 continue; /* conflict */
4177 queue_push(&solv->weakruleq, i);
4181 /********************************************************************/
4191 solver_solve(Solver *solv, Queue *job)
4193 Pool *pool = solv->pool;
4194 Repo *installed = solv->installed;
4197 Map addedmap; /* '1' == have rpm-rules for solvable */
4198 Map installcandidatemap;
4199 Id how, what, select, name, weak, p, pp, d;
4204 int now, solve_start;
4206 solve_start = sat_timems(0);
4207 POOL_DEBUG(SAT_DEBUG_STATS, "solver started\n");
4208 POOL_DEBUG(SAT_DEBUG_STATS, "fixsystem=%d updatesystem=%d dosplitprovides=%d, noupdateprovide=%d\n", solv->fixsystem, solv->updatesystem, solv->dosplitprovides, solv->noupdateprovide);
4209 POOL_DEBUG(SAT_DEBUG_STATS, "distupgrade=%d distupgrade_removeunsupported=%d\n", solv->distupgrade, solv->distupgrade_removeunsupported);
4210 POOL_DEBUG(SAT_DEBUG_STATS, "allowuninstall=%d, allowdowngrade=%d, allowarchchange=%d, allowvendorchange=%d\n", solv->allowuninstall, solv->allowdowngrade, solv->allowarchchange, solv->allowvendorchange);
4211 POOL_DEBUG(SAT_DEBUG_STATS, "promoteepoch=%d, allowvirtualconflicts=%d, allowselfconflicts=%d\n", pool->promoteepoch, solv->allowvirtualconflicts, solv->allowselfconflicts);
4212 POOL_DEBUG(SAT_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d\n", solv->obsoleteusesprovides, solv->implicitobsoleteusesprovides);
4213 POOL_DEBUG(SAT_DEBUG_STATS, "dontinstallrecommended=%d, ignorealreadyrecommended=%d, dontshowinstalledrecommended=%d\n", solv->dontinstallrecommended, solv->ignorealreadyrecommended, solv->dontshowinstalledrecommended);
4214 /* create whatprovides if not already there */
4215 if (!pool->whatprovides)
4216 pool_createwhatprovides(pool);
4218 /* create obsolete index */
4219 create_obsolete_index(solv);
4225 * create basic rule set of all involved packages
4226 * use addedmap bitmap to make sure we don't create rules twice
4230 /* create noobsolete map if needed */
4231 for (i = 0; i < job->count; i += 2)
4233 how = job->elements[i] & ~SOLVER_WEAK;
4234 if ((how & SOLVER_JOBMASK) != SOLVER_NOOBSOLETES)
4236 what = job->elements[i + 1];
4237 select = how & SOLVER_SELECTMASK;
4238 if (!solv->noobsoletes.size)
4239 map_init(&solv->noobsoletes, pool->nsolvables);
4240 FOR_JOB_SELECT(p, pp, select, what)
4241 MAPSET(&solv->noobsoletes, p);
4244 map_init(&addedmap, pool->nsolvables);
4245 map_init(&installcandidatemap, pool->nsolvables);
4249 * always install our system solvable
4251 MAPSET(&addedmap, SYSTEMSOLVABLE);
4252 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
4253 queue_push(&solv->decisionq_why, 0);
4254 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
4256 now = sat_timems(0);
4258 * create rules for all package that could be involved with the solving
4259 * so called: rpm rules
4264 oldnrules = solv->nrules;
4265 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
4266 FOR_REPO_SOLVABLES(installed, p, s)
4267 addrpmrulesforsolvable(solv, s, &addedmap);
4268 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
4269 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
4270 oldnrules = solv->nrules;
4271 FOR_REPO_SOLVABLES(installed, p, s)
4272 addrpmrulesforupdaters(solv, s, &addedmap, 1);
4273 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
4277 * create rules for all packages involved in the job
4278 * (to be installed or removed)
4281 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
4282 oldnrules = solv->nrules;
4283 for (i = 0; i < job->count; i += 2)
4285 how = job->elements[i];
4286 what = job->elements[i + 1];
4287 select = how & SOLVER_SELECTMASK;
4289 switch (how & SOLVER_JOBMASK)
4291 case SOLVER_INSTALL:
4292 FOR_JOB_SELECT(p, pp, select, what)
4294 MAPSET(&installcandidatemap, p);
4295 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
4299 /* FIXME: semantics? */
4300 FOR_JOB_SELECT(p, pp, select, what)
4301 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
4305 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
4307 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
4309 oldnrules = solv->nrules;
4312 * add rules for suggests, enhances
4314 addrpmrulesforweak(solv, &addedmap);
4315 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
4317 IF_POOLDEBUG (SAT_DEBUG_STATS)
4319 int possible = 0, installable = 0;
4320 for (i = 1; i < pool->nsolvables; i++)
4322 if (pool_installable(pool, pool->solvables + i))
4324 if (MAPTST(&addedmap, i))
4327 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
4331 * first pass done, we now have all the rpm rules we need.
4332 * unify existing rules before going over all job rules and
4334 * at this point the system is always solvable,
4335 * as an empty system (remove all packages) is a valid solution
4338 unifyrules(solv); /* remove duplicate rpm rules */
4340 solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
4342 solv->directdecisions = solv->decisionq.count;
4343 POOL_DEBUG(SAT_DEBUG_STATS, "rpm rule memory usage: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
4344 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
4345 POOL_DEBUG(SAT_DEBUG_STATS, "rpm rule creation took %d ms\n", sat_timems(now));
4348 * create feature rules
4350 * foreach installed:
4351 * create assertion (keep installed, if no update available)
4353 * create update rule (A|update1(A)|update2(A)|...)
4355 * those are used later on to keep a version of the installed packages in
4359 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add feature rules ***\n");
4360 solv->featurerules = solv->nrules; /* mark start of feature rules */
4363 /* foreach possibly installed solvable */
4364 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
4366 if (s->repo != installed)
4368 addrule(solv, 0, 0); /* create dummy rule */
4371 addupdaterule(solv, s, 1); /* allow s to be updated */
4374 * assert one rule per installed solvable,
4375 * either an assertion (A)
4376 * or a possible update (A|update1(A)|update2(A)|...)
4378 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
4380 solv->featurerules_end = solv->nrules;
4383 * Add update rules for installed solvables
4385 * almost identical to feature rules
4386 * except that downgrades/archchanges/vendorchanges are not allowed
4389 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add update rules ***\n");
4390 solv->updaterules = solv->nrules;
4393 { /* foreach installed solvables */
4394 /* we create all update rules, but disable some later on depending on the job */
4395 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
4399 if (s->repo != installed)
4401 addrule(solv, 0, 0); /* create dummy rule */
4404 addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
4406 * check for and remove duplicate
4408 r = solv->rules + solv->nrules - 1; /* r: update rule */
4409 sr = r - (installed->end - installed->start); /* sr: feature rule */
4410 /* it's orphaned if there is no feature rule or the feature rule
4411 * consists just of the installed package */
4412 if (!sr->p || (sr->p == i && !sr->d && !sr->w2))
4413 queue_push(&solv->orphaned, i);
4416 assert(solv->distupgrade && !sr->p);
4419 unifyrules_sortcmp_data = pool;
4420 if (!unifyrules_sortcmp(r, sr))
4422 /* identical rule, kill unneeded rule */
4423 if (solv->allowuninstall)
4425 /* keep feature rule, make it weak */
4426 memset(r, 0, sizeof(*r));
4427 queue_push(&solv->weakruleq, sr - solv->rules);
4431 /* keep update rule */
4432 memset(sr, 0, sizeof(*sr));
4435 else if (solv->allowuninstall)
4437 /* make both feature and update rule weak */
4438 queue_push(&solv->weakruleq, r - solv->rules);
4439 queue_push(&solv->weakruleq, sr - solv->rules);
4442 disablerule(solv, sr);
4444 /* consistency check: we added a rule for _every_ installed solvable */
4445 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
4447 solv->updaterules_end = solv->nrules;
4451 * now add all job rules
4454 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
4456 solv->jobrules = solv->nrules;
4457 for (i = 0; i < job->count; i += 2)
4459 oldnrules = solv->nrules;
4461 how = job->elements[i];
4462 what = job->elements[i + 1];
4463 weak = how & SOLVER_WEAK;
4464 select = how & SOLVER_SELECTMASK;
4465 switch (how & SOLVER_JOBMASK)
4467 case SOLVER_INSTALL:
4468 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4469 if (select == SOLVER_SOLVABLE)
4477 FOR_JOB_SELECT(p, pp, select, what)
4481 /* no candidate found, make this an impossible rule */
4482 queue_push(&q, -SYSTEMSOLVABLE);
4484 p = queue_shift(&q); /* get first candidate */
4485 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
4487 addrule(solv, p, d); /* add install rule */
4488 queue_push(&solv->ruletojob, i);
4490 queue_push(&solv->weakruleq, solv->nrules - 1);
4493 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4494 if (select == SOLVER_SOLVABLE && solv->installed && pool->solvables[what].repo == solv->installed)
4496 /* special case for "erase a specific solvable": we also
4497 * erase all other solvables with that name, so that they
4498 * don't get picked up as replacement */
4499 name = pool->solvables[what].name;
4500 FOR_PROVIDES(p, pp, name)
4504 s = pool->solvables + p;
4505 if (s->name != name)
4507 /* keep other versions installed */
4508 if (s->repo == solv->installed)
4510 /* keep installcandidates of other jobs */
4511 if (MAPTST(&installcandidatemap, p))
4513 addrule(solv, -p, 0); /* remove by Id */
4514 queue_push(&solv->ruletojob, i);
4516 queue_push(&solv->weakruleq, solv->nrules - 1);
4519 FOR_JOB_SELECT(p, pp, select, what)
4521 addrule(solv, -p, 0);
4522 queue_push(&solv->ruletojob, i);
4524 queue_push(&solv->weakruleq, solv->nrules - 1);
4529 POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4530 if (select != SOLVER_SOLVABLE)
4532 s = pool->solvables + what;
4533 POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solvable2str(pool, s));
4534 addupdaterule(solv, s, 0);
4535 queue_push(&solv->ruletojob, i);
4537 queue_push(&solv->weakruleq, solv->nrules - 1);
4539 case SOLVER_WEAKENDEPS:
4540 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4541 if (select != SOLVER_SOLVABLE)
4543 s = pool->solvables + what;
4544 weaken_solvable_deps(solv, what);
4546 case SOLVER_NOOBSOLETES:
4547 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sno obsolete %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4550 POOL_DEBUG(SAT_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4551 FOR_JOB_SELECT(p, pp, select, what)
4553 s = pool->solvables + p;
4554 if (installed && s->repo == installed)
4555 addrule(solv, p, 0);
4557 addrule(solv, -p, 0);
4558 queue_push(&solv->ruletojob, i);
4560 queue_push(&solv->weakruleq, solv->nrules - 1);
4564 POOL_DEBUG(SAT_DEBUG_JOB, "job: unknown job\n");
4572 IF_POOLDEBUG (SAT_DEBUG_JOB)
4575 if (solv->nrules == oldnrules)
4576 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created\n");
4577 for (j = oldnrules; j < solv->nrules; j++)
4579 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
4580 solver_printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
4584 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
4585 solv->jobrules_end = solv->nrules;
4587 /* all rules created
4588 * --------------------------------------------------------------
4589 * prepare for solving
4592 /* free unneeded memory */
4593 map_free(&addedmap);
4594 map_free(&installcandidatemap);
4597 /* create weak map */
4598 map_init(&solv->weakrulemap, solv->nrules);
4599 for (i = 0; i < solv->weakruleq.count; i++)
4601 p = solv->weakruleq.elements[i];
4602 MAPSET(&solv->weakrulemap, p);
4605 /* all new rules are learnt after this point */
4606 solv->learntrules = solv->nrules;
4608 /* create assertion index. it is only used to speed up
4609 * makeruledecsions() a bit */
4610 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
4611 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
4612 queue_push(&solv->ruleassertions, i);
4614 /* disable update rules that conflict with our job */
4615 disableupdaterules(solv, job, -1);
4617 /* make decisions based on job/update assertions */
4618 makeruledecisions(solv);
4620 /* create watches chains */
4623 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
4626 * ********************************************
4628 * ********************************************
4631 now = sat_timems(0);
4632 run_solver(solv, 1, solv->dontinstallrecommended ? 0 : 1);
4633 POOL_DEBUG(SAT_DEBUG_STATS, "solver took %d ms\n", sat_timems(now));
4637 /* disable all erase jobs (including weak "keep uninstalled" rules) */
4638 for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++)
4640 if (r->d < 0) /* disabled ? */
4642 if (r->p > 0) /* install job? */
4644 disablerule(solv, r);
4650 enabledisablelearntrules(solv);
4651 removedisabledconflicts(solv, &redoq);
4655 * find recommended packages
4658 /* if redoq.count == 0 we already found all recommended in the
4660 if (redoq.count || solv->dontinstallrecommended || !solv->dontshowinstalledrecommended || solv->ignorealreadyrecommended)
4662 Id rec, *recp, p, pp;
4664 /* create map of all recommened packages */
4665 solv->recommends_index = -1;
4666 MAPZERO(&solv->recommendsmap);
4667 for (i = 0; i < solv->decisionq.count; i++)
4669 p = solv->decisionq.elements[i];
4672 s = pool->solvables + p;
4675 recp = s->repo->idarraydata + s->recommends;
4676 while ((rec = *recp++) != 0)
4678 FOR_PROVIDES(p, pp, rec)
4679 if (solv->decisionmap[p] > 0)
4683 if (!solv->dontshowinstalledrecommended)
4685 FOR_PROVIDES(p, pp, rec)
4686 if (solv->decisionmap[p] > 0)
4687 MAPSET(&solv->recommendsmap, p);
4689 continue; /* p != 0: already fulfilled */
4691 FOR_PROVIDES(p, pp, rec)
4692 MAPSET(&solv->recommendsmap, p);
4696 for (i = 1; i < pool->nsolvables; i++)
4698 if (solv->decisionmap[i] < 0)
4700 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
4702 s = pool->solvables + i;
4703 if (!MAPTST(&solv->recommendsmap, i))
4705 if (!s->supplements)
4707 if (!pool_installable(pool, s))
4709 if (!solver_is_supplementing(solv, s))
4712 if (solv->dontinstallrecommended)
4713 queue_push(&solv->recommendations, i);
4715 queue_pushunique(&solv->recommendations, i);
4717 /* we use MODE_SUGGEST here so that repo prio is ignored */
4718 policy_filter_unwanted(solv, &solv->recommendations, POLICY_MODE_SUGGEST);
4722 * find suggested packages
4727 Id sug, *sugp, p, pp;
4729 /* create map of all suggests that are still open */
4730 solv->recommends_index = -1;
4731 MAPZERO(&solv->suggestsmap);
4732 for (i = 0; i < solv->decisionq.count; i++)
4734 p = solv->decisionq.elements[i];
4737 s = pool->solvables + p;
4740 sugp = s->repo->idarraydata + s->suggests;
4741 while ((sug = *sugp++) != 0)
4743 FOR_PROVIDES(p, pp, sug)
4744 if (solv->decisionmap[p] > 0)
4748 if (!solv->dontshowinstalledrecommended)
4750 FOR_PROVIDES(p, pp, sug)
4751 if (solv->decisionmap[p] > 0)
4752 MAPSET(&solv->suggestsmap, p);
4754 continue; /* already fulfilled */
4756 FOR_PROVIDES(p, pp, sug)
4757 MAPSET(&solv->suggestsmap, p);
4761 for (i = 1; i < pool->nsolvables; i++)
4763 if (solv->decisionmap[i] < 0)
4765 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
4767 s = pool->solvables + i;
4768 if (!MAPTST(&solv->suggestsmap, i))
4772 if (!pool_installable(pool, s))
4774 if (!solver_is_enhancing(solv, s))
4777 queue_push(&solv->suggestions, i);
4779 policy_filter_unwanted(solv, &solv->suggestions, POLICY_MODE_SUGGEST);
4784 /* restore decisionmap */
4785 for (i = 0; i < redoq.count; i += 2)
4786 solv->decisionmap[redoq.elements[i]] = redoq.elements[i + 1];
4790 * if unsolvable, prepare solutions
4793 if (solv->problems.count)
4795 int recocount = solv->recommendations.count;
4796 solv->recommendations.count = 0; /* so that revert() doesn't mess with it */
4797 queue_empty(&redoq);
4798 for (i = 0; i < solv->decisionq.count; i++)
4800 Id p = solv->decisionq.elements[i];
4801 queue_push(&redoq, p);
4802 queue_push(&redoq, solv->decisionq_why.elements[i]);
4803 queue_push(&redoq, solv->decisionmap[p > 0 ? p : -p]);
4805 problems_to_solutions(solv, job);
4806 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
4807 queue_empty(&solv->decisionq);
4808 queue_empty(&solv->decisionq_why);
4809 for (i = 0; i < redoq.count; i += 3)
4811 Id p = redoq.elements[i];
4812 queue_push(&solv->decisionq, p);
4813 queue_push(&solv->decisionq_why, redoq.elements[i + 1]);
4814 solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
4816 solv->recommendations.count = recocount;
4820 POOL_DEBUG(SAT_DEBUG_STATS, "final solver statistics: %d learned rules, %d unsolvable\n", solv->stats_learned, solv->stats_unsolvable);
4821 POOL_DEBUG(SAT_DEBUG_STATS, "solver_solve took %d ms\n", sat_timems(solve_start));
4825 /***********************************************************************/
4826 /* disk usage computations */
4828 /*-------------------------------------------------------------------
4830 * calculate DU changes
4834 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
4838 solver_create_state_maps(solv, &installedmap, 0);
4839 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
4840 map_free(&installedmap);
4844 /*-------------------------------------------------------------------
4846 * calculate changes in install size
4850 solver_calc_installsizechange(Solver *solv)
4855 solver_create_state_maps(solv, &installedmap, 0);
4856 change = pool_calc_installsizechange(solv->pool, &installedmap);
4857 map_free(&installedmap);
4861 #define FIND_INVOLVED_DEBUG 0
4863 solver_find_involved(Solver *solv, Queue *installedq, Solvable *ts, Queue *q)
4865 Pool *pool = solv->pool;
4870 Queue installedq_internal;
4871 Id tp, ip, p, pp, req, *reqp, sup, *supp;
4874 tp = ts - pool->solvables;
4876 queue_init(&installedq_internal);
4877 map_init(&im, pool->nsolvables);
4878 map_init(&installedm, pool->nsolvables);
4882 installedq = &installedq_internal;
4883 if (solv->installed)
4885 for (ip = solv->installed->start; ip < solv->installed->end; ip++)
4887 s = pool->solvables + ip;
4888 if (s->repo != solv->installed)
4890 queue_push(installedq, ip);
4894 for (i = 0; i < installedq->count; i++)
4896 ip = installedq->elements[i];
4897 MAPSET(&installedm, ip);
4901 queue_push(&iq, ts - pool->solvables);
4904 ip = queue_shift(&iq);
4905 if (!MAPTST(&im, ip))
4907 if (!MAPTST(&installedm, ip))
4910 s = pool->solvables + ip;
4911 #if FIND_INVOLVED_DEBUG
4912 printf("hello %s\n", solvable2str(pool, s));
4916 reqp = s->repo->idarraydata + s->requires;
4917 while ((req = *reqp++) != 0)
4919 if (req == SOLVABLE_PREREQMARKER)
4921 /* count number of installed packages that match */
4923 FOR_PROVIDES(p, pp, req)
4924 if (MAPTST(&installedm, p))
4928 FOR_PROVIDES(p, pp, req)
4932 #if FIND_INVOLVED_DEBUG
4933 printf("%s requires %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
4942 reqp = s->repo->idarraydata + s->recommends;
4943 while ((req = *reqp++) != 0)
4946 FOR_PROVIDES(p, pp, req)
4947 if (MAPTST(&installedm, p))
4951 FOR_PROVIDES(p, pp, req)
4955 #if FIND_INVOLVED_DEBUG
4956 printf("%s recommends %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
4965 /* supplements pass */
4966 for (i = 0; i < installedq->count; i++)
4968 ip = installedq->elements[i];
4969 s = pool->solvables + ip;
4970 if (!s->supplements)
4972 if (!MAPTST(&im, ip))
4974 supp = s->repo->idarraydata + s->supplements;
4975 while ((sup = *supp++) != 0)
4976 if (!dep_possible(solv, sup, &im) && dep_possible(solv, sup, &installedm))
4978 /* no longer supplemented, also erase */
4981 #if FIND_INVOLVED_DEBUG
4982 printf("%s supplemented\n", solvable2str(pool, pool->solvables + ip));
4984 queue_push(&iq, ip);
4990 for (i = 0; i < installedq->count; i++)
4992 ip = installedq->elements[i];
4993 if (MAPTST(&im, ip))
4994 queue_push(&iq, ip);
4999 ip = queue_shift(&iq);
5000 if (!MAPTST(&installedm, ip))
5002 s = pool->solvables + ip;
5003 #if FIND_INVOLVED_DEBUG
5004 printf("bye %s\n", solvable2str(pool, s));
5008 reqp = s->repo->idarraydata + s->requires;
5009 while ((req = *reqp++) != 0)
5011 FOR_PROVIDES(p, pp, req)
5013 if (!MAPTST(&im, p))
5017 #if FIND_INVOLVED_DEBUG
5018 printf("%s requires %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
5028 reqp = s->repo->idarraydata + s->recommends;
5029 while ((req = *reqp++) != 0)
5031 FOR_PROVIDES(p, pp, req)
5033 if (!MAPTST(&im, p))
5037 #if FIND_INVOLVED_DEBUG
5038 printf("%s recommends %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
5048 /* supplements pass */
5049 for (i = 0; i < installedq->count; i++)
5051 ip = installedq->elements[i];
5054 s = pool->solvables + ip;
5055 if (!s->supplements)
5057 if (MAPTST(&im, ip))
5059 supp = s->repo->idarraydata + s->supplements;
5060 while ((sup = *supp++) != 0)
5061 if (dep_possible(solv, sup, &im))
5065 #if FIND_INVOLVED_DEBUG
5066 printf("%s supplemented\n", solvable2str(pool, pool->solvables + ip));
5069 queue_push(&iq, ip);
5077 /* convert map into result */
5078 for (i = 0; i < installedq->count; i++)
5080 ip = installedq->elements[i];
5081 if (MAPTST(&im, ip))
5083 if (ip == ts - pool->solvables)
5088 map_free(&installedm);
5089 queue_free(&installedq_internal);