2 * Copyright (c) 2007-2008, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * SAT based dependency solver
26 #include "solverdebug.h"
28 #define RULES_BLOCK 63
30 static void disableupdaterules(Solver *solv, Queue *job, int jobidx);
32 /********************************************************************
34 * dependency check helpers
38 /*-------------------------------------------------------------------
39 * handle split provides
43 solver_splitprovides(Solver *solv, Id dep)
45 Pool *pool = solv->pool;
50 if (!solv->dosplitprovides || !solv->installed)
54 rd = GETRELDEP(pool, dep);
55 if (rd->flags != REL_WITH)
57 FOR_PROVIDES(p, pp, dep)
59 s = pool->solvables + p;
60 if (s->repo == solv->installed && s->name == rd->name)
67 /*-------------------------------------------------------------------
68 * solver_dep_installed
72 solver_dep_installed(Solver *solv, Id dep)
75 Pool *pool = solv->pool;
80 Reldep *rd = GETRELDEP(pool, dep);
81 if (rd->flags == REL_AND)
83 if (!solver_dep_installed(solv, rd->name))
85 return solver_dep_installed(solv, rd->evr);
87 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
88 return solver_dep_installed(solv, rd->evr);
90 FOR_PROVIDES(p, pp, dep)
92 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
100 /*-------------------------------------------------------------------
101 * Check if dependenc is possible
103 * this mirrors solver_dep_fulfilled
104 * but uses map m instead of the decisionmap
108 dep_possible(Solver *solv, Id dep, Map *m)
110 Pool *pool = solv->pool;
115 Reldep *rd = GETRELDEP(pool, dep);
116 if (rd->flags == REL_AND)
118 if (!dep_possible(solv, rd->name, m))
120 return dep_possible(solv, rd->evr, m);
122 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
123 return solver_splitprovides(solv, rd->evr);
124 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
125 return solver_dep_installed(solv, rd->evr);
127 FOR_PROVIDES(p, pp, dep)
135 /********************************************************************
139 * - unify rules, remove duplicates
142 static Pool *unifyrules_sortcmp_data;
144 /*-------------------------------------------------------------------
146 * compare rules for unification sort
151 unifyrules_sortcmp(const void *ap, const void *bp)
153 Pool *pool = unifyrules_sortcmp_data;
154 Rule *a = (Rule *)ap;
155 Rule *b = (Rule *)bp;
161 return x; /* p differs */
164 if (a->d == 0 && b->d == 0)
165 return a->w2 - b->w2; /* assertion: return w2 diff */
167 if (a->d == 0) /* a is assertion, b not */
169 x = a->w2 - pool->whatprovidesdata[b->d];
173 if (b->d == 0) /* b is assertion, a not */
175 x = pool->whatprovidesdata[a->d] - b->w2;
179 /* compare whatprovidesdata */
180 ad = pool->whatprovidesdata + a->d;
181 bd = pool->whatprovidesdata + b->d;
183 if ((x = *ad++ - *bd++) != 0)
189 /*-------------------------------------------------------------------
192 * go over all rules and remove duplicates
196 unifyrules(Solver *solv)
198 Pool *pool = solv->pool;
202 if (solv->nrules <= 1) /* nothing to unify */
205 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
207 /* sort rules first */
208 unifyrules_sortcmp_data = solv->pool;
209 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
216 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
218 if (jr && !unifyrules_sortcmp(ir, jr))
219 continue; /* prune! */
220 jr = solv->rules + j++; /* keep! */
225 /* reduced count from nrules to j rules */
226 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
228 /* adapt rule buffer */
230 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
234 IF_POOLDEBUG (SAT_DEBUG_STATS)
241 for (i = 1; i < solv->nrules; i++)
248 dp = solv->pool->whatprovidesdata + r->d;
253 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
254 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
256 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
266 hashrule(Solver *solv, Id p, Id d, int n)
268 unsigned int x = (unsigned int)p;
272 return (x * 37) ^ (unsigned int)d;
273 dp = solv->pool->whatprovidesdata + d;
275 x = (x * 37) ^ (unsigned int)*dp++;
281 /*-------------------------------------------------------------------
287 * p = direct literal; always < 0 for installed rpm rules
288 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
291 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
293 * p < 0 : pkg id of A
294 * d > 0 : Offset in whatprovidesdata (list of providers of b)
296 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
297 * p < 0 : pkg id of A
298 * d < 0 : Id of solvable (e.g. B1)
300 * d == 0: unary rule, assertion => (A) or (-A)
302 * Install: p > 0, d = 0 (A) user requested install
303 * Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
304 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
305 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
306 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
307 * also used for obsoletes
308 * ?: p > 0, d < 0 (A|-B)
309 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
313 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
314 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
315 * every other : w1 = p, w2 = whatprovidesdata[d];
316 * Disabled rule: w1 = 0
318 * always returns a rule for non-rpm rules
322 addrule(Solver *solv, Id p, Id d)
324 Pool *pool = solv->pool;
328 int n = 0; /* number of literals in rule - 1
329 0 = direct assertion (single literal)
334 /* it often happenes that requires lead to adding the same rpm rule
335 * multiple times, so we prune those duplicates right away to make
336 * the work for unifyrules a bit easier */
338 if (solv->nrules /* we already have rules */
339 && !solv->rpmrules_end) /* but are not done with rpm rules */
341 r = solv->rules + solv->nrules - 1; /* get the last added rule */
342 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
347 * compute number of literals (n) in rule
352 /* always a binary rule */
354 return 0; /* ignore self conflict */
359 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
361 return 0; /* rule is self-fulfilling */
363 if (n == 1) /* have single provider */
364 d = dp[-1]; /* take single literal */
367 if (n == 1 && p > d && !solv->rpmrules_end)
369 /* smallest literal first so we can find dups */
370 n = p; p = d; d = n; /* p <-> d */
371 n = 1; /* re-set n, was used as temp var */
375 * check for duplicate
378 /* check if the last added rule (r) is exactly the same as what we're looking for. */
379 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
380 return r; /* binary rule */
382 /* have n-ary rule with same first literal, check other literals */
383 if (r && n > 1 && r->d && r->p == p)
385 /* Rule where d is an offset in whatprovidesdata */
389 dp2 = pool->whatprovidesdata + r->d;
390 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
401 /* extend rule buffer */
402 solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
403 r = solv->rules + solv->nrules++; /* point to rule space */
412 /* direct assertion, no watch needed */
428 r->w2 = pool->whatprovidesdata[d];
433 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
435 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
436 solver_printrule(solv, SAT_DEBUG_RULE_CREATION, r);
442 /*-------------------------------------------------------------------
447 disablerule(Solver *solv, Rule *r)
453 /*-------------------------------------------------------------------
458 enablerule(Solver *solv, Rule *r)
465 /**********************************************************************************/
467 /* a problem is an item on the solver's problem list. It can either be >0, in that
468 * case it is a update rule, or it can be <0, which makes it refer to a job
469 * consisting of multiple job rules.
473 disableproblem(Solver *solv, Id v)
481 disablerule(solv, solv->rules + v);
485 jp = solv->ruletojob.elements;
486 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
488 disablerule(solv, r);
491 /*-------------------------------------------------------------------
496 enableproblem(Solver *solv, Id v)
504 if (v >= solv->featurerules && v < solv->featurerules_end)
506 /* do not enable feature rule if update rule is enabled */
507 r = solv->rules + (v - solv->featurerules + solv->updaterules);
511 enablerule(solv, solv->rules + v);
512 if (v >= solv->updaterules && v < solv->updaterules_end)
514 /* disable feature rule when enabling update rule */
515 r = solv->rules + (v - solv->updaterules + solv->featurerules);
517 disablerule(solv, r);
522 jp = solv->ruletojob.elements;
523 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
529 /************************************************************************/
532 * make assertion rules into decisions
534 * go through update and job rules and add direct assertions
535 * to the decisionqueue. If we find a conflict, disable rules and
536 * add them to problem queue.
540 makeruledecisions(Solver *solv)
542 Pool *pool = solv->pool;
548 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
550 decisionstart = solv->decisionq.count;
551 for (ii = 0; ii < solv->ruleassertions.count; ii++)
553 ri = solv->ruleassertions.elements[ii];
554 r = solv->rules + ri;
556 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
558 /* do weak rules in phase 2 */
559 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
565 if (!solv->decisionmap[vv]) /* if not yet decided */
570 queue_push(&solv->decisionq, v);
571 queue_push(&solv->decisionq_why, r - solv->rules);
572 solv->decisionmap[vv] = v > 0 ? 1 : -1;
573 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
575 Solvable *s = solv->pool->solvables + vv;
577 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
579 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
584 * check previous decision: is it sane ?
587 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
589 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
595 * The rule (r) we're currently processing says something
596 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
600 if (ri >= solv->learntrules)
602 /* conflict with a learnt rule */
603 /* can happen when packages cannot be installed for
604 * multiple reasons. */
605 /* we disable the learnt rule in this case */
606 disablerule(solv, r);
611 * find the decision which is the "opposite" of the rule
614 for (i = 0; i < solv->decisionq.count; i++)
615 if (solv->decisionq.elements[i] == -v)
617 assert(i < solv->decisionq.count); /* assert that we found it */
620 * conflict with system solvable ?
623 if (v == -SYSTEMSOLVABLE) {
624 /* conflict with system solvable */
625 queue_push(&solv->problems, solv->learnt_pool.count);
626 queue_push(&solv->learnt_pool, ri);
627 queue_push(&solv->learnt_pool, 0);
628 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
629 if (ri >= solv->jobrules && ri < solv->jobrules_end)
630 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
633 queue_push(&solv->problems, v);
634 queue_push(&solv->problems, 0);
635 disableproblem(solv, v);
639 assert(solv->decisionq_why.elements[i] > 0);
642 * conflict with an rpm rule ?
645 if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
647 /* conflict with rpm rule assertion */
648 queue_push(&solv->problems, solv->learnt_pool.count);
649 queue_push(&solv->learnt_pool, ri);
650 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
651 queue_push(&solv->learnt_pool, 0);
652 assert(v > 0 || v == -SYSTEMSOLVABLE);
653 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
654 if (ri >= solv->jobrules && ri < solv->jobrules_end)
655 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
658 queue_push(&solv->problems, v);
659 queue_push(&solv->problems, 0);
660 disableproblem(solv, v);
665 * conflict with another job or update/feature rule
669 queue_push(&solv->problems, solv->learnt_pool.count);
670 queue_push(&solv->learnt_pool, ri);
671 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
672 queue_push(&solv->learnt_pool, 0);
674 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
677 * push all of our rules (can only be feature or job rules)
678 * asserting this literal on the problem stack
681 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
683 if (rr->d < 0 /* disabled */
684 || rr->w2) /* or no assertion */
686 if (rr->p != vv /* not affecting the literal */
689 if (MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
692 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
694 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, solv->rules + i);
697 /* is is a job rule ? */
698 if (i >= solv->jobrules && i < solv->jobrules_end)
699 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
701 queue_push(&solv->problems, v);
702 disableproblem(solv, v);
704 queue_push(&solv->problems, 0);
708 * (back up from decisions)
710 while (solv->decisionq.count > decisionstart)
712 v = solv->decisionq.elements[--solv->decisionq.count];
713 --solv->decisionq_why.count;
715 solv->decisionmap[vv] = 0;
717 ii = -1; /* restarts loop at 0 */
721 * phase 2: now do the weak assertions
723 for (ii = 0; ii < solv->ruleassertions.count; ii++)
725 ri = solv->ruleassertions.elements[ii];
726 r = solv->rules + ri;
727 if (r->d < 0 || r->w2) /* disabled or no assertion */
729 if (!MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
735 * (if not yet decided)
737 if (!solv->decisionmap[vv])
739 queue_push(&solv->decisionq, v);
740 queue_push(&solv->decisionq_why, r - solv->rules);
741 solv->decisionmap[vv] = v > 0 ? 1 : -1;
742 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
744 Solvable *s = solv->pool->solvables + vv;
746 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", solvable2str(solv->pool, s));
748 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", solvable2str(solv->pool, s));
753 * previously decided, sane ?
755 if (v > 0 && solv->decisionmap[vv] > 0)
757 if (v < 0 && solv->decisionmap[vv] < 0)
760 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
761 solver_printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
763 if (ri >= solv->jobrules && ri < solv->jobrules_end)
764 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
767 disableproblem(solv, v);
769 disableupdaterules(solv, solv->job, -(v + 1));
772 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
776 /*-------------------------------------------------------------------
777 * enable/disable learnt rules
779 * we have enabled or disabled some of our rules. We now reenable all
780 * of our learnt rules but the ones that were learnt from rules that
784 enabledisablelearntrules(Solver *solv)
786 Pool *pool = solv->pool;
791 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
792 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
794 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
795 while ((why = *whyp++) != 0)
797 assert(why > 0 && why < i);
798 if (solv->rules[why].d < 0)
801 /* why != 0: we found a disabled rule, disable the learnt rule */
802 if (why && r->d >= 0)
804 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
806 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling ");
807 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
809 disablerule(solv, r);
811 else if (!why && r->d < 0)
813 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
815 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling ");
816 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
824 /*-------------------------------------------------------------------
827 * Enable all rules, except learnt rules, which are
828 * - disabled and weak (set in weakrulemap)
833 enableweakrules(Solver *solv)
838 for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
840 if (r->d >= 0) /* skip non-direct literals */
842 if (!MAPTST(&solv->weakrulemap, i))
849 /* FIXME: bad code ahead, replace as soon as possible */
850 /* FIXME: should probably look at SOLVER_INSTALL|SOLVABLE_ONE_OF */
852 /*-------------------------------------------------------------------
853 * disable update rules
857 disableupdaterules(Solver *solv, Queue *job, int jobidx)
859 Pool *pool = solv->pool;
861 Id how, select, what, p, pp;
867 installed = solv->installed;
873 how = job->elements[jobidx];
874 select = how & SOLVER_SELECTMASK;
875 switch (how & SOLVER_JOBMASK)
880 if (select != SOLVER_SOLVABLE)
887 /* go through all enabled job rules */
888 MAPZERO(&solv->noupdate);
889 for (i = solv->jobrules; i < solv->jobrules_end; i++)
892 if (r->d < 0) /* disabled? */
894 j = solv->ruletojob.elements[i - solv->jobrules];
898 how = job->elements[j];
899 what = job->elements[j + 1];
900 select = how & SOLVER_SELECTMASK;
901 switch (how & SOLVER_JOBMASK)
904 if (select != SOLVER_SOLVABLE)
906 s = pool->solvables + what;
907 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, what))
909 if (s->repo == installed)
911 MAPSET(&solv->noupdate, what - installed->start);
917 obsp = s->repo->idarraydata + s->obsoletes;
918 while ((obs = *obsp++) != 0)
919 FOR_PROVIDES(p, pp, obs)
921 if (pool->solvables[p].repo != installed)
923 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
925 MAPSET(&solv->noupdate, p - installed->start);
928 FOR_PROVIDES(p, pp, s->name)
930 if (!solv->implicitobsoleteusesprovides && pool->solvables[p].name != s->name)
932 if (pool->solvables[p].repo == installed)
933 MAPSET(&solv->noupdate, p - installed->start);
937 FOR_JOB_SELECT(p, pp, select, what)
938 if (pool->solvables[p].repo == installed)
939 MAPSET(&solv->noupdate, p - installed->start);
946 /* fixup update rule status */
949 /* we just disabled job #jobidx. enable all update rules
950 * that aren't disabled by the remaining job rules */
951 how = job->elements[jobidx];
952 what = job->elements[jobidx + 1];
953 select = how & SOLVER_SELECTMASK;
954 switch (how & SOLVER_JOBMASK)
957 if (select != SOLVER_SOLVABLE)
959 s = pool->solvables + what;
960 if (s->repo == installed)
962 if (MAPTST(&solv->noupdate, what - installed->start))
964 r = solv->rules + solv->updaterules + (what - installed->start);
968 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
970 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
971 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
978 obsp = s->repo->idarraydata + s->obsoletes;
979 while ((obs = *obsp++) != 0)
980 FOR_PROVIDES(p, pp, obs)
982 if (pool->solvables[p].repo != installed)
984 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
986 if (MAPTST(&solv->noupdate, p - installed->start))
988 r = solv->rules + solv->updaterules + (p - installed->start);
992 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
994 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
995 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
999 FOR_PROVIDES(p, pp, s->name)
1001 if (!solv->implicitobsoleteusesprovides && pool->solvables[p].name != s->name)
1003 if (pool->solvables[p].repo != installed)
1005 if (MAPTST(&solv->noupdate, p - installed->start))
1007 r = solv->rules + solv->updaterules + (p - installed->start);
1010 enablerule(solv, r);
1011 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1013 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1014 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
1019 FOR_JOB_SELECT(p, pp, select, what)
1021 if (pool->solvables[p].repo != installed)
1023 if (MAPTST(&solv->noupdate, p - installed->start))
1025 r = solv->rules + solv->updaterules + (p - installed->start);
1028 enablerule(solv, r);
1029 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1031 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1032 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
1042 for (i = 0; i < installed->nsolvables; i++)
1044 r = solv->rules + solv->updaterules + i;
1045 if (r->d >= 0 && MAPTST(&solv->noupdate, i))
1046 disablerule(solv, r); /* was enabled, need to disable */
1047 r = solv->rules + solv->featurerules + i;
1048 if (r->d >= 0 && MAPTST(&solv->noupdate, i))
1049 disablerule(solv, r); /* was enabled, need to disable */
1055 * special multiversion patch conflict handling:
1056 * a patch conflict is also satisfied, if some other
1057 * version with the same name/arch that doesn't conflict
1058 * get's installed. The generated rule is thus:
1059 * -patch|-cpack|opack1|opack2|...
1062 makemultiversionconflict(Solver *solv, Id n, Id con)
1064 Pool *pool = solv->pool;
1069 sn = pool->solvables + n;
1070 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1072 FOR_PROVIDES(p, pp, sn->name)
1074 s = pool->solvables + p;
1075 if (s->name != sn->name || s->arch != sn->arch)
1077 if (!MAPTST(&solv->noobsoletes, p))
1079 if (pool_match_nevr(pool, pool->solvables + p, con))
1081 /* here we have a multiversion solvable that doesn't conflict */
1082 /* thus we're not in conflict if it is installed */
1086 return -n; /* no other package found, generate normal conflict */
1087 return pool_queuetowhatprovides(pool, &q);
1091 /*-------------------------------------------------------------------
1093 * add (install) rules for solvable
1095 * s: Solvable for which to add rules
1096 * m: m[s] = 1 for solvables which have rules, prevent rule duplication
1098 * Algorithm: 'visit all nodes of a graph'. The graph nodes are
1099 * solvables, the edges their dependencies.
1100 * Starting from an installed solvable, this will create all rules
1101 * representing the graph created by the solvables dependencies.
1103 * for unfulfilled requirements, conflicts, obsoletes,....
1104 * add a negative assertion for solvables that are not installable
1106 * It will also create rules for all solvables referenced by 's'
1107 * i.e. descend to all providers of requirements of 's'
1112 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
1114 Pool *pool = solv->pool;
1115 Repo *installed = solv->installed;
1117 /* 'work' queue. keeps Ids of solvables we still have to work on.
1118 And buffer for it. */
1123 /* if to add rules for broken deps ('rpm -V' functionality)
1127 /* Id var and pointer for each dependency
1128 * (not used in parallel)
1135 /* var and ptr for loops */
1137 /* ptr to 'whatprovides' */
1139 /* Id for current solvable 's' */
1142 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
1144 queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
1145 queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
1147 /* loop until there's no more work left */
1152 * s: Pointer to solvable
1155 n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
1156 if (MAPTST(m, n)) /* continue if already visited */
1159 MAPSET(m, n); /* mark as visited */
1160 s = pool->solvables + n; /* s = Solvable in question */
1163 if (installed /* Installed system available */
1164 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
1165 && s->repo == installed) /* solvable is installed? */
1167 dontfix = 1; /* dont care about broken rpm deps */
1171 && s->arch != ARCH_SRC
1172 && s->arch != ARCH_NOSRC
1173 && !pool_installable(pool, s))
1175 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
1176 addrule(solv, -n, 0); /* uninstallable */
1179 /*-----------------------------------------
1180 * check requires of s
1185 reqp = s->repo->idarraydata + s->requires;
1186 while ((req = *reqp++) != 0) /* go through all requires */
1188 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
1191 /* find list of solvables providing 'req' */
1192 dp = pool->whatprovidesdata + pool_whatprovides(pool, req);
1194 if (*dp == SYSTEMSOLVABLE) /* always installed */
1199 /* the strategy here is to not insist on dependencies
1200 * that are already broken. so if we find one provider
1201 * that was already installed, we know that the
1202 * dependency was not broken before so we enforce it */
1204 /* check if any of the providers for 'req' is installed */
1205 for (i = 0; (p = dp[i]) != 0; i++)
1207 if (pool->solvables[p].repo == installed)
1208 break; /* provider was installed */
1210 /* didn't find an installed provider: previously broken dependency */
1213 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1220 /* nothing provides req! */
1221 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1222 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1226 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1228 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1229 for (i = 0; dp[i]; i++)
1230 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1233 /* add 'requires' dependency */
1234 /* rule: (-requestor|provider1|provider2|...|providerN) */
1235 addrule(solv, -n, dp - pool->whatprovidesdata);
1237 /* descend the dependency tree
1238 push all non-visited providers on the work queue */
1241 if (!MAPTST(m, *dp))
1242 queue_push(&workq, *dp);
1245 } /* while, requirements of n */
1247 } /* if, requirements */
1249 /* that's all we check for src packages */
1250 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1253 /*-----------------------------------------
1254 * check conflicts of s
1261 /* we treat conflicts in patches a bit differen:
1263 * - multiversion handling
1264 * XXX: we should really handle this different, looking
1265 * at the name is a bad hack
1267 if (!strncmp("patch:", id2str(pool, s->name), 6))
1269 conp = s->repo->idarraydata + s->conflicts;
1270 /* foreach conflicts of 's' */
1271 while ((con = *conp++) != 0)
1273 /* foreach providers of a conflict of 's' */
1274 FOR_PROVIDES(p, pp, con)
1276 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
1278 /* dontfix: dont care about conflicts with already installed packs */
1279 if (dontfix && pool->solvables[p].repo == installed)
1281 /* p == n: self conflict */
1282 if (p == n && !solv->allowselfconflicts)
1286 Reldep *rd = GETRELDEP(pool, con);
1287 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
1290 p = 0; /* make it a negative assertion, aka 'uninstallable' */
1292 if (p && ispatch && solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p) && ISRELDEP(con))
1294 /* our patch conflicts with a noobsoletes (aka multiversion) package */
1295 p = -makemultiversionconflict(solv, p, con);
1297 /* rule: -n|-p: either solvable _or_ provider of conflict */
1298 addrule(solv, -n, -p);
1303 /*-----------------------------------------
1304 * check obsoletes if not installed
1305 * (only installation will trigger the obsoletes in rpm)
1307 if (!installed || pool->solvables[n].repo != installed)
1308 { /* not installed */
1309 int noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
1310 if (s->obsoletes && !noobs)
1312 obsp = s->repo->idarraydata + s->obsoletes;
1313 /* foreach obsoletes */
1314 while ((obs = *obsp++) != 0)
1316 /* foreach provider of an obsoletes of 's' */
1317 FOR_PROVIDES(p, pp, obs)
1319 if (!solv->obsoleteusesprovides /* obsoletes are matched names, not provides */
1320 && !pool_match_nevr(pool, pool->solvables + p, obs))
1322 addrule(solv, -n, -p);
1326 FOR_PROVIDES(p, pp, s->name)
1328 Solvable *ps = pool->solvables + p;
1329 /* we still obsolete packages with same nevra, like rpm does */
1330 /* (actually, rpm mixes those packages. yuck...) */
1331 if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
1333 if (!solv->implicitobsoleteusesprovides && s->name != ps->name)
1335 addrule(solv, -n, -p);
1339 /*-----------------------------------------
1340 * add recommends to the work queue
1344 recp = s->repo->idarraydata + s->recommends;
1345 while ((rec = *recp++) != 0)
1347 FOR_PROVIDES(p, pp, rec)
1349 queue_push(&workq, p);
1354 sugp = s->repo->idarraydata + s->suggests;
1355 while ((sug = *sugp++) != 0)
1357 FOR_PROVIDES(p, pp, sug)
1359 queue_push(&workq, p);
1364 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1368 /*-------------------------------------------------------------------
1370 * Add package rules for weak rules
1372 * m: visited solvables
1376 addrpmrulesforweak(Solver *solv, Map *m)
1378 Pool *pool = solv->pool;
1383 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1384 /* foreach solvable in pool */
1385 for (i = n = 1; n < pool->nsolvables; i++, n++)
1387 if (i == pool->nsolvables) /* wrap i */
1389 if (MAPTST(m, i)) /* been there */
1392 s = pool->solvables + i;
1393 if (!pool_installable(pool, s)) /* only look at installable ones */
1399 /* find possible supplements */
1400 supp = s->repo->idarraydata + s->supplements;
1401 while ((sup = *supp++) != ID_NULL)
1402 if (dep_possible(solv, sup, m))
1406 /* if nothing found, check for enhances */
1407 if (!sup && s->enhances)
1409 supp = s->repo->idarraydata + s->enhances;
1410 while ((sup = *supp++) != ID_NULL)
1411 if (dep_possible(solv, sup, m))
1414 /* if nothing found, goto next solvables */
1417 addrpmrulesforsolvable(solv, s, m);
1420 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1424 /*-------------------------------------------------------------------
1426 * add package rules for possible updates
1429 * m: map of already visited solvables
1430 * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
1434 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
1436 Pool *pool = solv->pool;
1438 /* queue and buffer for it */
1442 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1444 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1445 /* find update candidates for 's' */
1446 policy_findupdatepackages(solv, s, &qs, allow_all);
1447 /* add rule for 's' if not already done */
1448 if (!MAPTST(m, s - pool->solvables))
1449 addrpmrulesforsolvable(solv, s, m);
1450 /* foreach update candidate, add rule if not already done */
1451 for (i = 0; i < qs.count; i++)
1452 if (!MAPTST(m, qs.elements[i]))
1453 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1456 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1460 finddistupgradepackages(Solver *solv, Solvable *s, Queue *qs, int allow_all)
1462 Pool *pool = solv->pool;
1465 policy_findupdatepackages(solv, s, qs, allow_all);
1470 policy_findupdatepackages(solv, s, qs, 1);
1472 return 0; /* orphaned */
1474 return -SYSTEMSOLVABLE;
1477 return s - pool->solvables;
1478 /* check if it is ok to keep the installed package */
1479 for (i = 0; i < qs->count; i++)
1481 Solvable *ns = pool->solvables + qs->elements[i];
1482 if (s->evr == ns->evr && solvable_identical(s, ns))
1483 return s - pool->solvables;
1485 /* nope, it must be some other package */
1486 return -SYSTEMSOLVABLE;
1489 /*-------------------------------------------------------------------
1491 * add rule for update
1492 * (A|A1|A2|A3...) An = update candidates for A
1494 * s = (installed) solvable
1498 addupdaterule(Solver *solv, Solvable *s, int allow_all)
1500 /* installed packages get a special upgrade allowed rule */
1501 Pool *pool = solv->pool;
1506 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1507 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1508 p = s - pool->solvables;
1509 /* find update candidates for 's' */
1510 if (solv->distupgrade)
1511 p = finddistupgradepackages(solv, s, &qs, allow_all);
1513 policy_findupdatepackages(solv, s, &qs, allow_all);
1514 if (!allow_all && qs.count && solv->noobsoletes.size)
1518 d = pool_queuetowhatprovides(pool, &qs);
1519 /* filter out all noobsoletes packages as they don't update */
1520 for (i = j = 0; i < qs.count; i++)
1522 if (MAPTST(&solv->noobsoletes, qs.elements[i]))
1524 /* it's ok if they have same nevra */
1525 Solvable *ps = pool->solvables + qs.elements[i];
1526 if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
1529 qs.elements[j++] = qs.elements[i];
1531 if (j == 0 && p == -SYSTEMSOLVABLE && solv->distupgrade)
1533 queue_push(&solv->orphaned, s - pool->solvables); /* treat as orphaned */
1538 if (d && solv->updatesystem && solv->installed && s->repo == solv->installed)
1540 if (!solv->multiversionupdaters)
1541 solv->multiversionupdaters = sat_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
1542 solv->multiversionupdaters[s - pool->solvables - solv->installed->start] = d;
1547 if (qs.count && p == -SYSTEMSOLVABLE)
1548 p = queue_shift(&qs);
1549 d = qs.count ? pool_queuetowhatprovides(pool, &qs) : 0;
1551 addrule(solv, p, d); /* allow update of s */
1552 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1556 /********************************************************************/
1560 /*-------------------------------------------------------------------
1563 * initial setup for all watches
1567 makewatches(Solver *solv)
1571 int nsolvables = solv->pool->nsolvables;
1573 sat_free(solv->watches);
1574 /* lower half for removals, upper half for installs */
1575 solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
1577 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
1578 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1580 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1583 if (!r->w2) /* assertions do not need watches */
1586 /* see addwatches_rule(solv, r) */
1587 r->n1 = solv->watches[nsolvables + r->w1];
1588 solv->watches[nsolvables + r->w1] = r - solv->rules;
1590 r->n2 = solv->watches[nsolvables + r->w2];
1591 solv->watches[nsolvables + r->w2] = r - solv->rules;
1596 /*-------------------------------------------------------------------
1598 * add watches (for rule)
1599 * sets up watches for a single rule
1601 * see also makewatches()
1605 addwatches_rule(Solver *solv, Rule *r)
1607 int nsolvables = solv->pool->nsolvables;
1609 r->n1 = solv->watches[nsolvables + r->w1];
1610 solv->watches[nsolvables + r->w1] = r - solv->rules;
1612 r->n2 = solv->watches[nsolvables + r->w2];
1613 solv->watches[nsolvables + r->w2] = r - solv->rules;
1617 /********************************************************************/
1623 /* shortcuts to check if a literal (positive or negative) assignment
1624 * evaluates to 'true' or 'false'
1626 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1627 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
1628 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
1630 /*-------------------------------------------------------------------
1634 * make decision and propagate to all rules
1636 * Evaluate each term affected by the decision (linked through watches)
1637 * If we find unit rules we make new decisions based on them
1639 * Everything's fixed there, it's just finding rules that are
1642 * return : 0 = everything is OK
1643 * rule = conflict found in this rule
1647 propagate(Solver *solv, int level)
1649 Pool *pool = solv->pool;
1650 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
1652 Id p, pkg, other_watch;
1654 Id *decisionmap = solv->decisionmap;
1656 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
1658 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1660 /* foreach non-propagated decision */
1661 while (solv->propagate_index < solv->decisionq.count)
1664 * 'pkg' was just decided
1665 * negate because our watches trigger if literal goes FALSE
1667 pkg = -solv->decisionq.elements[solv->propagate_index++];
1669 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1671 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
1672 solver_printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1675 /* foreach rule where 'pkg' is now FALSE */
1676 for (rp = watches + pkg; *rp; rp = next_rp)
1678 r = solv->rules + *rp;
1681 /* rule is disabled, goto next */
1689 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1691 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1692 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
1695 /* 'pkg' was just decided (was set to FALSE)
1697 * now find other literal watch, check clause
1698 * and advance on linked list
1702 other_watch = r->w2;
1707 other_watch = r->w1;
1712 * This term is already true (through the other literal)
1713 * so we have nothing to do
1715 if (DECISIONMAP_TRUE(other_watch))
1719 * The other literal is FALSE or UNDEF
1725 /* Not a binary clause, try to move our watch.
1727 * Go over all literals and find one that is
1731 * (TRUE is also ok, in that case the rule is fulfilled)
1733 if (r->p /* we have a 'p' */
1734 && r->p != other_watch /* which is not watched */
1735 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
1739 else /* go find a 'd' to make 'true' */
1742 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
1744 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1746 if (p != other_watch /* which is not watched */
1747 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
1755 * if we found some p that is UNDEF or TRUE, move
1758 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1761 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1763 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1779 watches[p] = r - solv->rules;
1782 /* search failed, thus all unwatched literals are FALSE */
1787 * unit clause found, set literal other_watch to TRUE
1790 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
1791 return r; /* eek, a conflict! */
1793 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1795 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
1796 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
1799 if (other_watch > 0)
1800 decisionmap[other_watch] = level; /* install! */
1802 decisionmap[-other_watch] = -level; /* remove! */
1804 queue_push(&solv->decisionq, other_watch);
1805 queue_push(&solv->decisionq_why, r - solv->rules);
1807 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1809 Solvable *s = pool->solvables + (other_watch > 0 ? other_watch : -other_watch);
1810 if (other_watch > 0)
1811 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
1813 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
1816 } /* foreach rule involving 'pkg' */
1818 } /* while we have non-decided decisions */
1820 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
1822 return 0; /* all is well */
1826 /********************************************************************/
1829 /*-------------------------------------------------------------------
1836 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
1838 Pool *pool = solv->pool;
1841 Map seen; /* global? */
1842 Id d, v, vv, *dp, why;
1844 int num = 0, l1num = 0;
1845 int learnt_why = solv->learnt_pool.count;
1846 Id *decisionmap = solv->decisionmap;
1850 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
1851 map_init(&seen, pool->nsolvables);
1852 idx = solv->decisionq.count;
1855 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1856 solver_printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1857 queue_push(&solv->learnt_pool, c - solv->rules);
1858 d = c->d < 0 ? -c->d - 1 : c->d;
1859 dp = d ? pool->whatprovidesdata + d : 0;
1860 /* go through all literals of the rule */
1872 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1874 vv = v > 0 ? v : -v;
1875 if (MAPTST(&seen, vv))
1877 l = solv->decisionmap[vv];
1882 l1num++; /* need to do this one in level1 pass */
1883 else if (l == level)
1884 num++; /* need to do this one as well */
1887 queue_push(&r, v); /* not level1 or conflict level, add to new rule */
1893 if (!num && !--l1num)
1894 break; /* all level 1 literals done */
1898 v = solv->decisionq.elements[--idx];
1899 vv = v > 0 ? v : -v;
1900 if (MAPTST(&seen, vv))
1904 if (num && --num == 0)
1906 *pr = -v; /* so that v doesn't get lost */
1909 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1910 for (i = 0; i < r.count; i++)
1913 MAPCLR(&seen, v > 0 ? v : -v);
1915 /* only level 1 marks left */
1919 why = solv->decisionq_why.elements[idx];
1920 if (why <= 0) /* just in case, maybe for SYSTEMSOLVABLE */
1922 c = solv->rules + why;
1928 else if (r.count == 1 && r.elements[0] < 0)
1929 *dr = r.elements[0];
1931 *dr = pool_queuetowhatprovides(pool, &r);
1932 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1934 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1935 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
1936 for (i = 0; i < r.count; i++)
1937 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
1939 /* push end marker on learnt reasons stack */
1940 queue_push(&solv->learnt_pool, 0);
1943 solv->stats_learned++;
1948 /*-------------------------------------------------------------------
1952 * reset the solver decisions to right after the rpm rules.
1953 * called after rules have been enabled/disabled
1957 reset_solver(Solver *solv)
1959 Pool *pool = solv->pool;
1963 /* rewind decisions to direct rpm rule assertions */
1964 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
1966 v = solv->decisionq.elements[i];
1967 solv->decisionmap[v > 0 ? v : -v] = 0;
1970 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
1972 solv->decisionq_why.count = solv->directdecisions;
1973 solv->decisionq.count = solv->directdecisions;
1974 solv->recommends_index = -1;
1975 solv->propagate_index = 0;
1977 /* adapt learnt rule status to new set of enabled/disabled rules */
1978 enabledisablelearntrules(solv);
1980 /* redo all job/update decisions */
1981 makeruledecisions(solv);
1982 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
1986 /*-------------------------------------------------------------------
1988 * analyze_unsolvable_rule
1992 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
1994 Pool *pool = solv->pool;
1996 Id why = r - solv->rules;
1998 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1999 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
2000 if (solv->learntrules && why >= solv->learntrules)
2002 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
2003 if (solv->learnt_pool.elements[i] > 0)
2004 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp);
2007 if (MAPTST(&solv->weakrulemap, why))
2008 if (!*lastweakp || why > *lastweakp)
2010 /* do not add rpm rules to problem */
2011 if (why < solv->rpmrules_end)
2013 /* turn rule into problem */
2014 if (why >= solv->jobrules && why < solv->jobrules_end)
2015 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
2016 /* return if problem already countains our rule */
2017 if (solv->problems.count)
2019 for (i = solv->problems.count - 1; i >= 0; i--)
2020 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
2022 else if (solv->problems.elements[i] == why)
2025 queue_push(&solv->problems, why);
2029 /*-------------------------------------------------------------------
2031 * analyze_unsolvable
2033 * return: 1 - disabled some rules, try again
2038 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
2040 Pool *pool = solv->pool;
2042 Map seen; /* global to speed things up? */
2043 Id d, v, vv, *dp, why;
2045 Id *decisionmap = solv->decisionmap;
2046 int oldproblemcount;
2047 int oldlearntpoolcount;
2050 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
2051 solv->stats_unsolvable++;
2052 oldproblemcount = solv->problems.count;
2053 oldlearntpoolcount = solv->learnt_pool.count;
2055 /* make room for proof index */
2056 /* must update it later, as analyze_unsolvable_rule would confuse
2057 * it with a rule index if we put the real value in already */
2058 queue_push(&solv->problems, 0);
2061 map_init(&seen, pool->nsolvables);
2062 queue_push(&solv->learnt_pool, r - solv->rules);
2064 analyze_unsolvable_rule(solv, r, &lastweak);
2065 d = r->d < 0 ? -r->d - 1 : r->d;
2066 dp = d ? pool->whatprovidesdata + d : 0;
2077 if (DECISIONMAP_TRUE(v)) /* the one true literal */
2079 vv = v > 0 ? v : -v;
2080 l = solv->decisionmap[vv];
2085 idx = solv->decisionq.count;
2088 v = solv->decisionq.elements[--idx];
2089 vv = v > 0 ? v : -v;
2090 if (!MAPTST(&seen, vv))
2092 why = solv->decisionq_why.elements[idx];
2094 queue_push(&solv->learnt_pool, why);
2095 r = solv->rules + why;
2096 analyze_unsolvable_rule(solv, r, &lastweak);
2097 d = r->d < 0 ? -r->d - 1 : r->d;
2098 dp = d ? pool->whatprovidesdata + d : 0;
2109 if (DECISIONMAP_TRUE(v)) /* the one true literal */
2111 vv = v > 0 ? v : -v;
2112 l = solv->decisionmap[vv];
2119 queue_push(&solv->problems, 0); /* mark end of this problem */
2124 /* disable last weak rule */
2125 solv->problems.count = oldproblemcount;
2126 solv->learnt_pool.count = oldlearntpoolcount;
2127 if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
2128 v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
2131 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling ");
2132 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, solv->rules + lastweak);
2133 disableproblem(solv, v);
2135 disableupdaterules(solv, solv->job, -(v + 1));
2141 queue_push(&solv->learnt_pool, 0);
2142 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
2146 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
2147 disableproblem(solv, solv->problems.elements[i]);
2148 /* XXX: might want to enable all weak rules again */
2152 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
2157 /********************************************************************/
2158 /* Decision revert */
2160 /*-------------------------------------------------------------------
2163 * revert decision at level
2167 revert(Solver *solv, int level)
2169 Pool *pool = solv->pool;
2171 while (solv->decisionq.count)
2173 v = solv->decisionq.elements[solv->decisionq.count - 1];
2174 vv = v > 0 ? v : -v;
2175 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
2177 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
2178 if (v > 0 && solv->recommendations.count && v == solv->recommendations.elements[solv->recommendations.count - 1])
2179 solv->recommendations.count--;
2180 solv->decisionmap[vv] = 0;
2181 solv->decisionq.count--;
2182 solv->decisionq_why.count--;
2183 solv->propagate_index = solv->decisionq.count;
2185 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
2187 solv->branches.count--;
2188 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
2189 solv->branches.count--;
2191 solv->recommends_index = -1;
2195 /*-------------------------------------------------------------------
2197 * watch2onhighest - put watch2 on literal with highest level
2201 watch2onhighest(Solver *solv, Rule *r)
2206 d = r->d < 0 ? -r->d - 1 : r->d;
2208 return; /* binary rule, both watches are set */
2209 dp = solv->pool->whatprovidesdata + d;
2210 while ((v = *dp++) != 0)
2212 l = solv->decisionmap[v < 0 ? -v : v];
2224 /*-------------------------------------------------------------------
2228 * add free decision (solvable to install) to decisionq
2229 * increase level and propagate decision
2230 * return if no conflict.
2232 * in conflict case, analyze conflict rule, add resulting
2233 * rule to learnt rule set, make decision from learnt
2234 * rule (always unit) and re-propagate.
2236 * returns the new solver level or 0 if unsolvable
2241 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules, Id ruleid)
2243 Pool *pool = solv->pool;
2248 assert(ruleid >= 0);
2253 solv->decisionmap[decision] = level;
2255 solv->decisionmap[-decision] = -level;
2256 queue_push(&solv->decisionq, decision);
2257 queue_push(&solv->decisionq_why, -ruleid); /* <= 0 -> free decision */
2261 r = propagate(solv, level);
2265 return analyze_unsolvable(solv, r, disablerules);
2266 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
2267 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
2268 assert(l > 0 && l < level);
2269 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
2271 revert(solv, level);
2272 r = addrule(solv, p, d); /* p requires d */
2274 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
2275 queue_push(&solv->learnt_why, why);
2278 /* at least 2 literals, needs watches */
2279 watch2onhighest(solv, r);
2280 addwatches_rule(solv, r);
2284 /* learnt rule is an assertion */
2285 queue_push(&solv->ruleassertions, r - solv->rules);
2287 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
2288 queue_push(&solv->decisionq, p);
2289 queue_push(&solv->decisionq_why, r - solv->rules);
2290 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
2292 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
2293 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
2294 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
2295 solver_printrule(solv, SAT_DEBUG_ANALYZE, r);
2302 /*-------------------------------------------------------------------
2304 * select and install
2306 * install best package from the queue. We add an extra package, inst, if
2307 * provided. See comment in weak install section.
2309 * returns the new solver level or 0 if unsolvable
2314 selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid)
2316 Pool *pool = solv->pool;
2321 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
2324 /* XXX: didn't we already do that? */
2325 /* XXX: shouldn't we prefer installed packages? */
2326 /* XXX: move to policy.c? */
2327 /* choose the supplemented one */
2328 for (i = 0; i < dq->count; i++)
2329 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
2331 dq->elements[0] = dq->elements[i];
2338 /* multiple candidates, open a branch */
2339 for (i = 1; i < dq->count; i++)
2340 queue_push(&solv->branches, dq->elements[i]);
2341 queue_push(&solv->branches, -level);
2343 p = dq->elements[0];
2345 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
2347 return setpropagatelearn(solv, level, p, disablerules, ruleid);
2351 /********************************************************************/
2352 /* Main solver interface */
2355 /*-------------------------------------------------------------------
2358 * create solver structure
2360 * pool: all available solvables
2361 * installed: installed Solvables
2364 * Upon solving, rules are created to flag the Solvables
2365 * of the 'installed' Repo as installed.
2369 solver_create(Pool *pool)
2372 solv = (Solver *)sat_calloc(1, sizeof(Solver));
2374 solv->installed = pool->installed;
2376 queue_init(&solv->ruletojob);
2377 queue_init(&solv->decisionq);
2378 queue_init(&solv->decisionq_why);
2379 queue_init(&solv->problems);
2380 queue_init(&solv->suggestions);
2381 queue_init(&solv->recommendations);
2382 queue_init(&solv->orphaned);
2383 queue_init(&solv->learnt_why);
2384 queue_init(&solv->learnt_pool);
2385 queue_init(&solv->branches);
2386 queue_init(&solv->covenantq);
2387 queue_init(&solv->weakruleq);
2388 queue_init(&solv->ruleassertions);
2390 map_init(&solv->recommendsmap, pool->nsolvables);
2391 map_init(&solv->suggestsmap, pool->nsolvables);
2392 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
2393 solv->recommends_index = 0;
2395 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2397 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
2398 memset(solv->rules, 0, sizeof(Rule));
2404 /*-------------------------------------------------------------------
2410 solver_free(Solver *solv)
2412 queue_free(&solv->ruletojob);
2413 queue_free(&solv->decisionq);
2414 queue_free(&solv->decisionq_why);
2415 queue_free(&solv->learnt_why);
2416 queue_free(&solv->learnt_pool);
2417 queue_free(&solv->problems);
2418 queue_free(&solv->suggestions);
2419 queue_free(&solv->recommendations);
2420 queue_free(&solv->orphaned);
2421 queue_free(&solv->branches);
2422 queue_free(&solv->covenantq);
2423 queue_free(&solv->weakruleq);
2424 queue_free(&solv->ruleassertions);
2426 map_free(&solv->recommendsmap);
2427 map_free(&solv->suggestsmap);
2428 map_free(&solv->noupdate);
2429 map_free(&solv->weakrulemap);
2430 map_free(&solv->noobsoletes);
2432 sat_free(solv->decisionmap);
2433 sat_free(solv->rules);
2434 sat_free(solv->watches);
2435 sat_free(solv->obsoletes);
2436 sat_free(solv->obsoletes_data);
2437 sat_free(solv->multiversionupdaters);
2442 /*-------------------------------------------------------------------
2446 * all rules have been set up, now actually run the solver
2451 run_solver(Solver *solv, int disablerules, int doweak)
2453 Queue dq; /* local decisionqueue */
2454 Queue dqs; /* local decisionqueue for supplements */
2460 Pool *pool = solv->pool;
2462 int minimizationsteps;
2464 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2466 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2467 for (i = 1; i < solv->nrules; i++)
2468 solver_printruleclass(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2471 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2473 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2474 solver_printdecisions(solv);
2476 /* start SAT algorithm */
2478 systemlevel = level + 1;
2479 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2485 * here's the main loop:
2486 * 1) propagate new decisions (only needed for level 1)
2487 * 2) try to keep installed packages
2488 * 3) fulfill all unresolved rules
2489 * 4) install recommended packages
2490 * 5) minimalize solution if we had choices
2491 * if we encounter a problem, we rewind to a safe level and restart
2495 minimizationsteps = 0;
2504 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2505 if ((r = propagate(solv, level)) != 0)
2507 if (analyze_unsolvable(solv, r, disablerules))
2515 if (level < systemlevel)
2517 POOL_DEBUG(SAT_DEBUG_STATS, "resolving job rules\n");
2518 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
2521 if (r->d < 0) /* ignore disabled rules */
2524 FOR_RULELITERALS(l, dp, r)
2528 if (solv->decisionmap[-l] <= 0)
2533 if (solv->decisionmap[l] > 0)
2535 if (solv->decisionmap[l] == 0)
2541 /* prune to installed if not updating */
2542 if (!solv->updatesystem && solv->installed && dq.count > 1)
2545 for (j = k = 0; j < dq.count; j++)
2547 Solvable *s = pool->solvables + dq.elements[j];
2548 if (s->repo == solv->installed)
2549 dq.elements[k++] = dq.elements[j];
2555 level = selectandinstall(solv, level, &dq, disablerules, i);
2562 if (level <= olevel)
2565 systemlevel = level + 1;
2566 if (i < solv->jobrules_end)
2572 * installed packages
2575 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2577 if (!solv->updatesystem)
2580 * Normal run (non-updating)
2581 * Keep as many packages installed as possible
2583 POOL_DEBUG(SAT_DEBUG_STATS, "installing old packages\n");
2585 for (i = solv->installed->start; i < solv->installed->end; i++)
2587 s = pool->solvables + i;
2589 /* skip if not installed */
2590 if (s->repo != solv->installed)
2593 /* skip if already decided */
2594 if (solv->decisionmap[i] != 0)
2597 r = solv->rules + solv->updaterules + (i - solv->installed->start);
2598 if (!r->p) /* update rule == feature rule? */
2599 r = r - solv->updaterules + solv->featurerules;
2600 if (r->p && r->p != i) /* allowed to keep package? */
2603 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2606 level = setpropagatelearn(solv, level, i, disablerules, r->p ? r - solv->rules : 0);
2608 if (level == 0) /* unsolvable */
2614 if (level <= olevel)
2617 systemlevel = level + 1;
2618 if (i < solv->installed->end)
2621 else if (solv->noobsoletes.size && solv->multiversionupdaters)
2623 /* see if we can multi-version install the newest package */
2624 for (i = solv->installed->start; i < solv->installed->end; i++)
2627 s = pool->solvables + i;
2628 if (s->repo != solv->installed)
2630 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2632 d = solv->multiversionupdaters[i - solv->installed->start];
2637 while ((p = pool->whatprovidesdata[d++]) != 0)
2638 if (solv->decisionmap[p] >= 0)
2640 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2642 if (p != i && solv->decisionmap[p] == 0)
2644 r = solv->rules + solv->featurerules + (i - solv->installed->start);
2645 if (!r->p) /* update rule == feature rule? */
2646 r = r - solv->featurerules + solv->updaterules;
2648 POOL_DEBUG(SAT_DEBUG_POLICY, "installing (multi-version) %s\n", solvable2str(pool, pool->solvables + p));
2649 level = setpropagatelearn(solv, level, p, disablerules, r->p ? r - solv->rules : 0);
2656 if (level <= olevel)
2660 /* now that the best version is installed, try to
2661 * keep the original one */
2662 if (solv->decisionmap[p]) /* already decided? */
2664 r = solv->rules + solv->updaterules + (i - solv->installed->start);
2665 if (!r->p) /* update rule == feature rule? */
2666 r = r - solv->updaterules + solv->featurerules;
2667 if (r->p == p) /* allowed to keep package? */
2670 POOL_DEBUG(SAT_DEBUG_POLICY, "keeping (multi-version) %s\n", solvable2str(pool, pool->solvables + p));
2671 level = setpropagatelearn(solv, level, p, disablerules, r - solv->rules);
2678 if (level <= olevel)
2682 systemlevel = level + 1;
2683 if (i < solv->installed->end)
2687 POOL_DEBUG(SAT_DEBUG_STATS, "resolving update/feature rules\n");
2689 for (i = solv->installed->start, r = solv->rules + solv->updaterules; i < solv->installed->end; i++, r++)
2692 s = pool->solvables + i;
2694 /* skip if not installed (can't update) */
2695 if (s->repo != solv->installed)
2697 /* skip if already decided */
2698 if (solv->decisionmap[i] > 0)
2701 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2702 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2708 if (rr->d < 0) /* disabled -> look at feature rule ? */
2709 rr -= solv->installed->end - solv->installed->start;
2710 if (!rr->p) /* identical to update rule? */
2713 continue; /* no such rule or disabled */
2715 FOR_RULELITERALS(p, dp, rr)
2717 if (solv->decisionmap[p] > 0)
2719 if (solv->decisionmap[p] == 0)
2722 if (p || !dq.count) /* already fulfilled or empty */
2725 level = selectandinstall(solv, level, &dq, disablerules, rr - solv->rules);
2732 if (level <= olevel)
2735 systemlevel = level + 1;
2736 if (i < solv->installed->end)
2740 if (level < systemlevel)
2741 systemlevel = level;
2747 POOL_DEBUG(SAT_DEBUG_POLICY, "deciding unresolved rules\n");
2748 for (i = 1, n = 1; ; i++, n++)
2750 if (n == solv->nrules)
2752 if (i == solv->nrules)
2754 r = solv->rules + i;
2755 if (r->d < 0) /* ignore disabled rules */
2760 /* binary or unary rule */
2761 /* need two positive undecided literals */
2762 if (r->p < 0 || r->w2 <= 0)
2764 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2766 queue_push(&dq, r->p);
2767 queue_push(&dq, r->w2);
2772 * all negative literals are installed
2773 * no positive literal is installed
2774 * i.e. the rule is not fulfilled and we
2775 * just need to decide on the positive literals
2779 if (solv->decisionmap[-r->p] <= 0)
2784 if (solv->decisionmap[r->p] > 0)
2786 if (solv->decisionmap[r->p] == 0)
2787 queue_push(&dq, r->p);
2789 dp = pool->whatprovidesdata + r->d;
2790 while ((p = *dp++) != 0)
2794 if (solv->decisionmap[-p] <= 0)
2799 if (solv->decisionmap[p] > 0)
2801 if (solv->decisionmap[p] == 0)
2808 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2810 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2811 solver_printruleclass(solv, SAT_DEBUG_PROPAGATE, r);
2813 /* dq.count < 2 cannot happen as this means that
2814 * the rule is unit */
2815 assert(dq.count > 1);
2818 level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
2825 if (level < systemlevel)
2828 } /* for(), decide */
2830 if (n != solv->nrules) /* continue if level < systemlevel */
2837 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended packages\n");
2838 queue_empty(&dq); /* recommended packages */
2839 queue_empty(&dqs); /* supplemented packages */
2840 for (i = 1; i < pool->nsolvables; i++)
2842 if (solv->decisionmap[i] < 0)
2844 if (solv->decisionmap[i] > 0)
2846 /* installed, check for recommends */
2847 Id *recp, rec, pp, p;
2848 s = pool->solvables + i;
2849 if (solv->ignorealreadyrecommended && s->repo == solv->installed)
2851 /* XXX need to special case AND ? */
2854 recp = s->repo->idarraydata + s->recommends;
2855 while ((rec = *recp++) != 0)
2858 FOR_PROVIDES(p, pp, rec)
2860 if (solv->decisionmap[p] > 0)
2865 else if (solv->decisionmap[p] == 0)
2867 queue_pushunique(&dq, p);
2875 s = pool->solvables + i;
2876 if (!s->supplements)
2878 if (!pool_installable(pool, s))
2880 if (!solver_is_supplementing(solv, s))
2882 queue_push(&dqs, i);
2886 /* filter out all already supplemented packages if requested */
2887 if (solv->ignorealreadyrecommended && dqs.count)
2889 /* turn off all new packages */
2890 for (i = 0; i < solv->decisionq.count; i++)
2892 p = solv->decisionq.elements[i];
2895 s = pool->solvables + p;
2896 if (s->repo && s->repo != solv->installed)
2897 solv->decisionmap[p] = -solv->decisionmap[p];
2899 /* filter out old supplements */
2900 for (i = j = 0; i < dqs.count; i++)
2902 p = dqs.elements[i];
2903 s = pool->solvables + p;
2904 if (!s->supplements)
2906 if (!solver_is_supplementing(solv, s))
2907 dqs.elements[j++] = p;
2910 /* undo turning off */
2911 for (i = 0; i < solv->decisionq.count; i++)
2913 p = solv->decisionq.elements[i];
2916 s = pool->solvables + p;
2917 if (s->repo && s->repo != solv->installed)
2918 solv->decisionmap[p] = -solv->decisionmap[p];
2922 /* make dq contain both recommended and supplemented pkgs */
2925 for (i = 0; i < dqs.count; i++)
2926 queue_pushunique(&dq, dqs.elements[i]);
2933 int decisioncount = solv->decisionq.count;
2937 /* simple case, just one package. no need to choose */
2940 POOL_DEBUG(SAT_DEBUG_POLICY, "installing supplemented %s\n", solvable2str(pool, pool->solvables + p));
2942 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2943 queue_push(&solv->recommendations, p);
2944 level = setpropagatelearn(solv, level, p, 0, 0);
2948 /* filter and create a map of result */
2949 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
2950 map_init(&dqmap, pool->nsolvables);
2951 for (i = 0; i < dq.count; i++)
2952 MAPSET(&dqmap, dq.elements[i]);
2954 /* install all supplemented packages */
2955 for (i = 0; i < dqs.count; i++)
2957 p = dqs.elements[i];
2958 if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
2960 POOL_DEBUG(SAT_DEBUG_POLICY, "installing supplemented %s\n", solvable2str(pool, pool->solvables + p));
2961 queue_push(&solv->recommendations, p);
2963 level = setpropagatelearn(solv, level, p, 0, 0);
2964 if (level <= olevel)
2967 if (i < dqs.count || solv->decisionq.count < decisioncount)
2973 /* install all recommended packages */
2974 /* more work as we want to created branches if multiple
2975 * choices are valid */
2976 for (i = 0; i < decisioncount; i++)
2979 p = solv->decisionq.elements[i];
2982 s = pool->solvables + p;
2983 if (!s->repo || (solv->ignorealreadyrecommended && s->repo == solv->installed))
2987 recp = s->repo->idarraydata + s->recommends;
2988 while ((rec = *recp++) != 0)
2991 FOR_PROVIDES(p, pp, rec)
2993 if (solv->decisionmap[p] > 0)
2998 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
2999 queue_pushunique(&dq, p);
3005 /* multiple candidates, open a branch */
3006 for (i = 1; i < dq.count; i++)
3007 queue_push(&solv->branches, dq.elements[i]);
3008 queue_push(&solv->branches, -level);
3011 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
3012 queue_push(&solv->recommendations, p);
3014 level = setpropagatelearn(solv, level, p, 0, 0);
3015 if (level <= olevel || solv->decisionq.count < decisioncount)
3019 break; /* had a problem above, quit loop */
3028 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
3030 /* prefer recommended patterns (bnc#450226) */
3031 /* real fix is to minimize recommended packages as well */
3032 for (i = 0; i < dq.count; i++)
3033 if (!strncmp(id2str(pool, pool->solvables[dq.elements[i]].name), "pattern:", 8))
3038 POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
3039 queue_push(&solv->recommendations, p);
3040 level = setpropagatelearn(solv, level, p, 0, 0);
3046 if (solv->distupgrade && solv->installed)
3048 /* let's see if we can install some unsupported package */
3049 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unsupported packages\n");
3050 for (i = 0; i < solv->orphaned.count; i++)
3052 p = solv->orphaned.elements[i];
3053 if (!solv->decisionmap[p])
3056 if (i < solv->orphaned.count)
3058 p = solv->orphaned.elements[i];
3059 if (solv->distupgrade_removeunsupported)
3061 POOL_DEBUG(SAT_DEBUG_STATS, "removing unsupported %s\n", solvable2str(pool, pool->solvables + p));
3062 level = setpropagatelearn(solv, level, -p, 0, 0);
3066 POOL_DEBUG(SAT_DEBUG_STATS, "keeping unsupported %s\n", solvable2str(pool, pool->solvables + p));
3067 level = setpropagatelearn(solv, level, p, 0, 0);
3073 if (solv->solution_callback)
3075 solv->solution_callback(solv, solv->solution_callback_data);
3076 if (solv->branches.count)
3078 int i = solv->branches.count - 1;
3079 int l = -solv->branches.elements[i];
3083 if (solv->branches.elements[i - 1] < 0)
3085 p = solv->branches.elements[i];
3086 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
3088 for (j = i + 1; j < solv->branches.count; j++)
3089 queue_push(&dq, solv->branches.elements[j]);
3090 solv->branches.count = i;
3092 revert(solv, level);
3094 for (j = 0; j < dq.count; j++)
3095 queue_push(&solv->branches, dq.elements[j]);
3097 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
3099 level = setpropagatelearn(solv, level, p, disablerules, why);
3108 /* all branches done, we're finally finished */
3112 /* minimization step */
3113 if (solv->branches.count)
3115 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);
3140 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
3143 level = setpropagatelearn(solv, level, p, disablerules, why);
3155 POOL_DEBUG(SAT_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
3157 POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
3163 /*-------------------------------------------------------------------
3167 * at this point, all rules that led to conflicts are disabled.
3168 * we re-enable all rules of a problem set but rule "sug", then
3169 * continue to disable more rules until there as again a solution.
3172 /* FIXME: think about conflicting assertions */
3175 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
3177 Pool *pool = solv->pool;
3183 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
3185 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
3186 for (i = 0; problem[i]; i++)
3188 if (problem[i] == sug)
3189 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
3190 solver_printproblem(solv, problem[i]);
3193 queue_init(&disabled);
3194 queue_empty(refined);
3195 queue_push(refined, sug);
3197 /* re-enable all problem rules with the exception of "sug"(gestion) */
3201 for (i = 0; problem[i]; i++)
3202 if (problem[i] != sug)
3203 enableproblem(solv, problem[i]);
3206 disableupdaterules(solv, job, -(sug + 1));
3207 else if (sug >= solv->updaterules && sug < solv->updaterules_end)
3209 /* enable feature rule */
3210 Rule *r = solv->rules + solv->featurerules + (sug - solv->updaterules);
3212 enablerule(solv, r);
3215 enableweakrules(solv);
3219 int njob, nfeature, nupdate;
3220 queue_empty(&solv->problems);
3221 revert(solv, 1); /* XXX no longer needed? */
3224 if (!solv->problems.count)
3225 run_solver(solv, 0, 0);
3227 if (!solv->problems.count)
3229 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
3230 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3231 solver_printdecisions(solv);
3232 break; /* great, no more problems */
3234 disabledcnt = disabled.count;
3235 /* start with 1 to skip over proof index */
3236 njob = nfeature = nupdate = 0;
3237 for (i = 1; i < solv->problems.count - 1; i++)
3239 /* ignore solutions in refined */
3240 v = solv->problems.elements[i];
3242 break; /* end of problem reached */
3243 for (j = 0; problem[j]; j++)
3244 if (problem[j] != sug && problem[j] == v)
3248 if (v >= solv->featurerules && v < solv->featurerules_end)
3254 if ((job->elements[-v -1] & SOLVER_ESSENTIAL) != 0)
3255 continue; /* not that one! */
3258 queue_push(&disabled, v);
3260 if (disabled.count == disabledcnt)
3262 /* no solution found, this was an invalid suggestion! */
3263 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
3267 if (!njob && nupdate && nfeature)
3269 /* got only update rules, filter out feature rules */
3270 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "throwing away feature rules\n");
3271 for (i = j = disabledcnt; i < disabled.count; i++)
3273 v = disabled.elements[i];
3274 if (v < solv->featurerules || v >= solv->featurerules_end)
3275 disabled.elements[j++] = v;
3280 if (disabled.count == disabledcnt + 1)
3282 /* just one suggestion, add it to refined list */
3283 v = disabled.elements[disabledcnt];
3285 queue_push(refined, v); /* do not record feature rules */
3286 disableproblem(solv, v);
3287 if (v >= solv->updaterules && v < solv->updaterules_end)
3289 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
3291 enablerule(solv, r); /* enable corresponding feature rule */
3294 disableupdaterules(solv, job, -(v + 1));
3298 /* more than one solution, disable all */
3299 /* do not push anything on refine list, as we do not know which solution to choose */
3300 /* thus, the user will get another problem if he selects this solution, where he
3301 * can choose the right one */
3302 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
3304 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
3305 for (i = disabledcnt; i < disabled.count; i++)
3306 solver_printproblem(solv, disabled.elements[i]);
3308 for (i = disabledcnt; i < disabled.count; i++)
3310 v = disabled.elements[i];
3311 disableproblem(solv, v);
3312 if (v >= solv->updaterules && v < solv->updaterules_end)
3314 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
3316 enablerule(solv, r);
3321 /* all done, get us back into the same state as before */
3322 /* enable refined rules again */
3323 for (i = 0; i < disabled.count; i++)
3324 enableproblem(solv, disabled.elements[i]);
3325 /* disable problem rules again */
3328 for (i = 0; problem[i]; i++)
3329 enableproblem(solv, problem[i]);
3330 disableupdaterules(solv, job, -1);
3332 /* disable problem rules again */
3333 for (i = 0; problem[i]; i++)
3334 disableproblem(solv, problem[i]);
3335 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
3339 /*-------------------------------------------------------------------
3340 * sorting helper for problems
3342 * bring update rules before job rules
3343 * make essential job rules last
3346 Queue *problems_sort_data;
3349 problems_sortcmp(const void *ap, const void *bp)
3351 Id a = *(Id *)ap, b = *(Id *)bp;
3358 Queue *job = problems_sort_data;
3359 int af = job->elements[-a - 1] & SOLVER_ESSENTIAL;
3360 int bf = job->elements[-b - 1] & SOLVER_ESSENTIAL;
3369 /*-------------------------------------------------------------------
3374 problems_sort(Solver *solv, Queue *job)
3377 if (!solv->problems.count)
3379 for (i = j = 1; i < solv->problems.count; i++)
3381 if (!solv->problems.elements[i])
3385 problems_sort_data = job;
3386 qsort(solv->problems.elements + j, i - j, sizeof(Id), problems_sortcmp);
3388 if (++i == solv->problems.count)
3396 /*-------------------------------------------------------------------
3397 * convert problems to solutions
3401 problems_to_solutions(Solver *solv, Queue *job)
3403 Pool *pool = solv->pool;
3409 int i, j, nsol, probsolved;
3410 unsigned int now, refnow;
3412 if (!solv->problems.count)
3414 now = sat_timems(0);
3415 problems_sort(solv, job);
3416 queue_clone(&problems, &solv->problems);
3417 queue_init(&solution);
3418 queue_init(&solutions);
3419 /* copy over proof index */
3420 queue_push(&solutions, problems.elements[0]);
3421 problem = problems.elements + 1;
3423 refnow = sat_timems(0);
3424 for (i = 1; i < problems.count; i++)
3426 Id v = problems.elements[i];
3429 /* mark end of this problem */
3430 queue_push(&solutions, 0);
3431 queue_push(&solutions, 0);
3432 POOL_DEBUG(SAT_DEBUG_STATS, "refining took %d ms\n", sat_timems(refnow));
3433 if (i + 1 == problems.count)
3435 /* copy over proof of next problem */
3436 queue_push(&solutions, problems.elements[i + 1]);
3438 problem = problems.elements + i + 1;
3439 refnow = sat_timems(0);
3443 if (v < 0 && (job->elements[-v - 1] & SOLVER_ESSENTIAL))
3445 /* essential job, skip if we already have a non-essential
3449 probsolved = -1; /* show all solutions */
3451 refine_suggestion(solv, job, problem, v, &solution);
3452 if (!solution.count)
3453 continue; /* this solution didn't work out */
3456 for (j = 0; j < solution.count; j++)
3458 why = solution.elements[j];
3459 /* must be either job descriptor or update rule */
3460 assert(why < 0 || (why >= solv->updaterules && why < solv->updaterules_end));
3462 solver_printproblem(solv, why);
3466 /* job descriptor */
3467 queue_push(&solutions, 0);
3468 queue_push(&solutions, -why);
3472 /* update rule, find replacement package */
3475 p = solv->installed->start + (why - solv->updaterules);
3476 rr = solv->rules + solv->featurerules + (why - solv->updaterules);
3478 rr = solv->rules + why;
3479 if (solv->distupgrade && solv->rules[why].p != p && solv->decisionmap[p] > 0)
3481 /* distupgrade case, allow to keep old package */
3482 queue_push(&solutions, p);
3483 queue_push(&solutions, p);
3487 if (solv->decisionmap[p] > 0)
3488 continue; /* false alarm, turned out we can keep the package */
3491 int mvrp = 0; /* multi-version replacement */
3492 FOR_RULELITERALS(rp, dp, rr)
3494 if (rp > 0 && solv->decisionmap[rp] > 0 && pool->solvables[rp].repo != solv->installed)
3497 if (!(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, rp)))
3503 /* found only multi-version replacements */
3504 /* have to split solution into two parts */
3505 queue_push(&solutions, p);
3506 queue_push(&solutions, mvrp);
3510 queue_push(&solutions, p);
3511 queue_push(&solutions, rp);
3515 /* mark end of this solution */
3520 queue_push(&solutions, 0);
3521 queue_push(&solutions, 0);
3525 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "Oops, everything was fine?\n");
3528 queue_free(&solution);
3529 queue_free(&problems);
3530 /* copy queue over to solutions */
3531 queue_free(&solv->problems);
3532 queue_clone(&solv->problems, &solutions);
3534 /* bring solver back into problem state */
3535 revert(solv, 1); /* XXX move to reset_solver? */
3538 assert(solv->problems.count == solutions.count);
3539 queue_free(&solutions);
3540 POOL_DEBUG(SAT_DEBUG_STATS, "problems_to_solutions took %d ms\n", sat_timems(now));
3544 /*-------------------------------------------------------------------
3548 * advance to next problem
3552 solver_next_problem(Solver *solv, Id problem)
3556 return solv->problems.count ? 1 : 0;
3557 pp = solv->problems.elements + problem;
3558 while (pp[0] || pp[1])
3562 while (pp[0] || pp[1])
3567 problem = pp - solv->problems.elements;
3568 if (problem >= solv->problems.count)
3574 /*-------------------------------------------------------------------
3580 solver_next_solution(Solver *solv, Id problem, Id solution)
3586 pp = solv->problems.elements + solution;
3587 return pp[0] || pp[1] ? solution : 0;
3589 pp = solv->problems.elements + solution;
3590 while (pp[0] || pp[1])
3593 solution = pp - solv->problems.elements;
3594 return pp[0] || pp[1] ? solution : 0;
3598 /*-------------------------------------------------------------------
3600 * solution element iterator
3604 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
3607 element = element ? element + 2 : solution;
3608 pp = solv->problems.elements + element;
3609 if (!(pp[0] || pp[1]))
3617 /*-------------------------------------------------------------------
3619 * Retrieve information about a problematic rule
3621 * this is basically the reverse of addrpmrulesforsolvable
3625 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
3627 Pool *pool = solv->pool;
3628 Repo *installed = solv->installed;
3632 Id p, d, w2, pp, req, *reqp, con, *conp, obs, *obsp, *dp;
3635 if (rid >= solv->jobrules && rid < solv->jobrules_end)
3638 r = solv->rules + rid;
3639 p = solv->ruletojob.elements[rid - solv->jobrules];
3640 *depp = job->elements[p + 1];
3642 *targetp = job->elements[p];
3643 d = r->d < 0 ? -r->d - 1 : r->d;
3644 if (d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && (job->elements[p] & SOLVER_SELECTMASK) != SOLVER_SOLVABLE_ONE_OF)
3645 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
3646 return SOLVER_PROBLEM_JOB_RULE;
3648 if (rid >= solv->updaterules && rid < solv->updaterules_end)
3651 *sourcep = solv->installed->start + (rid - solv->updaterules);
3653 return SOLVER_PROBLEM_UPDATE_RULE;
3655 assert(rid < solv->rpmrules_end);
3656 r = solv->rules + rid;
3658 d = r->d < 0 ? -r->d - 1 : r->d;
3659 if (d == 0 && r->w2 == 0)
3661 /* a rpm rule assertion */
3662 s = pool->solvables - r->p;
3663 if (installed && !solv->fixsystem && s->repo == installed)
3665 assert(!dontfix); /* dontfix packages never have a neg assertion */
3668 /* see why the package is not installable */
3669 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
3672 return SOLVER_PROBLEM_NOT_INSTALLABLE;
3674 /* check requires */
3677 reqp = s->repo->idarraydata + s->requires;
3678 while ((req = *reqp++) != 0)
3680 if (req == SOLVABLE_PREREQMARKER)
3682 dp = pool->whatprovidesdata + pool_whatprovides(pool, req);
3689 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
3692 if (!solv->allowselfconflicts && s->conflicts)
3694 conp = s->repo->idarraydata + s->conflicts;
3695 while ((con = *conp++) != 0)
3696 FOR_PROVIDES(p, pp, con)
3700 return SOLVER_PROBLEM_SELF_CONFLICT;
3703 /* should never happen */
3705 return SOLVER_PROBLEM_RPM_RULE;
3707 s = pool->solvables - r->p;
3708 if (installed && !solv->fixsystem && s->repo == installed)
3711 if (d && pool->whatprovidesdata[d] < 0)
3713 /* rule looks like -p|-c|x|x|x..., we only create this for patches with multiversion */
3714 /* reduce it to -p|-c case */
3715 w2 = pool->whatprovidesdata[d];
3717 if (d == 0 && w2 < 0)
3719 /* a package conflict */
3720 Solvable *s2 = pool->solvables - w2;
3723 if (installed && !solv->fixsystem && s2->repo == installed)
3726 /* if both packages have the same name and at least one of them
3727 * is not installed, they conflict */
3728 if (s->name == s2->name && !(installed && s->repo == installed && s2->repo == installed))
3730 /* also check noobsoletes map */
3731 if ((s->evr == s2->evr && s->arch == s2->arch) || !solv->noobsoletes.size
3732 || ((!installed || s->repo != installed) && !MAPTST(&solv->noobsoletes, -r->p))
3733 || ((!installed || s2->repo != installed) && !MAPTST(&solv->noobsoletes, -w2)))
3738 return SOLVER_PROBLEM_SAME_NAME;
3742 /* check conflicts in both directions */
3745 conp = s->repo->idarraydata + s->conflicts;
3746 while ((con = *conp++) != 0)
3748 FOR_PROVIDES(p, pp, con)
3750 if (dontfix && pool->solvables[p].repo == installed)
3757 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3763 conp = s2->repo->idarraydata + s2->conflicts;
3764 while ((con = *conp++) != 0)
3766 FOR_PROVIDES(p, pp, con)
3768 if (dontfix2 && pool->solvables[p].repo == installed)
3775 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3779 /* check obsoletes in both directions */
3780 if ((!installed || s->repo != installed) && s->obsoletes && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->p)))
3782 obsp = s->repo->idarraydata + s->obsoletes;
3783 while ((obs = *obsp++) != 0)
3785 FOR_PROVIDES(p, pp, obs)
3789 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
3794 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3798 if ((!installed || s2->repo != installed) && s2->obsoletes && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -w2)))
3800 obsp = s2->repo->idarraydata + s2->obsoletes;
3801 while ((obs = *obsp++) != 0)
3803 FOR_PROVIDES(p, pp, obs)
3807 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
3812 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3816 if (solv->implicitobsoleteusesprovides && (!installed || s->repo != installed) && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->p)))
3818 FOR_PROVIDES(p, pp, s->name)
3825 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3828 if (solv->implicitobsoleteusesprovides && (!installed || s2->repo != installed) && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -w2)))
3830 FOR_PROVIDES(p, pp, s2->name)
3837 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3840 /* all cases checked, can't happen */
3844 return SOLVER_PROBLEM_RPM_RULE;
3846 /* simple requires */
3849 reqp = s->repo->idarraydata + s->requires;
3850 while ((req = *reqp++) != 0)
3852 if (req == SOLVABLE_PREREQMARKER)
3854 dp = pool->whatprovidesdata + pool_whatprovides(pool, req);
3857 if (*dp == r->w2 && dp[1] == 0)
3860 else if (dp - pool->whatprovidesdata == d)
3868 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
3871 /* all cases checked, can't happen */
3875 return SOLVER_PROBLEM_RPM_RULE;
3879 /*-------------------------------------------------------------------
3885 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3888 Id lreqr, lconr, lsysr, ljobr;
3892 lreqr = lconr = lsysr = ljobr = 0;
3893 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3896 if (rid >= solv->learntrules)
3897 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3898 else if (rid >= solv->jobrules && rid < solv->jobrules_end)
3903 else if (rid >= solv->updaterules && rid < solv->updaterules_end)
3910 assert(rid < solv->rpmrules_end);
3911 r = solv->rules + rid;
3912 d = r->d < 0 ? -r->d - 1 : r->d;
3913 if (!d && r->w2 < 0)
3920 if (!d && r->w2 == 0 && !reqassert)
3922 if (*reqrp > 0 && r->p < -1)
3924 Id op = -solv->rules[*reqrp].p;
3925 if (op > 1 && solv->pool->solvables[op].arch != solv->pool->solvables[-r->p].arch)
3926 continue; /* different arch, skip */
3928 /* prefer assertions */
3934 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed && !reqassert)
3936 /* prefer rules of installed packages */
3942 if (!*reqrp && lreqr)
3944 if (!*conrp && lconr)
3946 if (!*jobrp && ljobr)
3948 if (!*sysrp && lsysr)
3953 /*-------------------------------------------------------------------
3957 * search for a rule that describes the problem to the
3958 * user. A pretty hopeless task, actually. We currently
3959 * prefer simple requires.
3963 solver_findproblemrule(Solver *solv, Id problem)
3965 Id reqr, conr, sysr, jobr;
3966 Id idx = solv->problems.elements[problem - 1];
3967 reqr = conr = sysr = jobr = 0;
3968 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3981 /*-------------------------------------------------------------------
3983 * create reverse obsoletes map for installed solvables
3985 * for each installed solvable find which packages with *different* names
3986 * obsolete the solvable.
3987 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3991 create_obsolete_index(Solver *solv)
3993 Pool *pool = solv->pool;
3995 Repo *installed = solv->installed;
3996 Id p, pp, obs, *obsp, *obsoletes, *obsoletes_data;
3999 if (!installed || !installed->nsolvables)
4001 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
4002 for (i = 1; i < pool->nsolvables; i++)
4004 s = pool->solvables + i;
4007 if (!pool_installable(pool, s))
4009 obsp = s->repo->idarraydata + s->obsoletes;
4010 while ((obs = *obsp++) != 0)
4012 FOR_PROVIDES(p, pp, obs)
4014 if (pool->solvables[p].repo != installed)
4016 if (pool->solvables[p].name == s->name)
4018 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
4020 obsoletes[p - installed->start]++;
4025 for (i = 0; i < installed->nsolvables; i++)
4028 n += obsoletes[i] + 1;
4031 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
4032 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
4033 for (i = pool->nsolvables - 1; i > 0; i--)
4035 s = pool->solvables + i;
4038 if (!pool_installable(pool, s))
4040 obsp = s->repo->idarraydata + s->obsoletes;
4041 while ((obs = *obsp++) != 0)
4043 FOR_PROVIDES(p, pp, obs)
4045 if (pool->solvables[p].repo != installed)
4047 if (pool->solvables[p].name == s->name)
4049 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
4051 p -= installed->start;
4052 if (obsoletes_data[obsoletes[p]] != i)
4053 obsoletes_data[--obsoletes[p]] = i;
4060 /*-------------------------------------------------------------------
4062 * remove disabled conflicts
4066 removedisabledconflicts(Solver *solv, Queue *removed)
4068 Pool *pool = solv->pool;
4073 Id *decisionmap = solv->decisionmap;
4075 POOL_DEBUG(SAT_DEBUG_SCHUBI, "removedisabledconflicts\n");
4076 queue_empty(removed);
4077 for (i = 0; i < solv->decisionq.count; i++)
4079 p = solv->decisionq.elements[i];
4082 /* a conflict. we never do conflicts on free decisions, so there
4083 * must have been an unit rule */
4084 why = solv->decisionq_why.elements[i];
4086 r = solv->rules + why;
4087 if (r->d < 0 && decisionmap[-p])
4089 /* rule is now disabled, remove from decisionmap */
4090 POOL_DEBUG(SAT_DEBUG_SCHUBI, "removing conflict for package %s[%d]\n", solvable2str(pool, pool->solvables - p), -p);
4091 queue_push(removed, -p);
4092 queue_push(removed, decisionmap[-p]);
4093 decisionmap[-p] = 0;
4096 if (!removed->count)
4098 /* we removed some confliced packages. some of them might still
4099 * be in conflict, so search for unit rules and re-conflict */
4101 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
4103 if (i == solv->nrules)
4106 r = solv->rules + i;
4112 if (r->p < 0 && !decisionmap[-r->p])
4118 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
4120 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
4125 if (r->p < 0 && decisionmap[-r->p] == 0)
4127 if (new || DECISIONMAP_FALSE(r->p))
4129 dp = pool->whatprovidesdata + r->d;
4130 while ((p = *dp++) != 0)
4132 if (new && p == new)
4134 if (p < 0 && decisionmap[-p] == 0)
4143 else if (!DECISIONMAP_FALSE(p))
4153 POOL_DEBUG(SAT_DEBUG_SCHUBI, "re-conflicting package %s[%d]\n", solvable2str(pool, pool->solvables - new), -new);
4154 decisionmap[-new] = -1;
4156 n = 0; /* redo all rules */
4162 /*-------------------------------------------------------------------
4164 * weaken solvable dependencies
4168 weaken_solvable_deps(Solver *solv, Id p)
4173 for (i = 1, r = solv->rules + i; i < solv->rpmrules_end; i++, r++)
4177 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
4178 continue; /* conflict */
4179 queue_push(&solv->weakruleq, i);
4183 /********************************************************************/
4193 solver_solve(Solver *solv, Queue *job)
4195 Pool *pool = solv->pool;
4196 Repo *installed = solv->installed;
4199 Map addedmap; /* '1' == have rpm-rules for solvable */
4200 Map installcandidatemap;
4201 Id how, what, select, name, weak, p, pp, d;
4206 int now, solve_start;
4208 solve_start = sat_timems(0);
4209 POOL_DEBUG(SAT_DEBUG_STATS, "solver started\n");
4210 POOL_DEBUG(SAT_DEBUG_STATS, "fixsystem=%d updatesystem=%d dosplitprovides=%d, noupdateprovide=%d\n", solv->fixsystem, solv->updatesystem, solv->dosplitprovides, solv->noupdateprovide);
4211 POOL_DEBUG(SAT_DEBUG_STATS, "distupgrade=%d distupgrade_removeunsupported=%d\n", solv->distupgrade, solv->distupgrade_removeunsupported);
4212 POOL_DEBUG(SAT_DEBUG_STATS, "allowuninstall=%d, allowdowngrade=%d, allowarchchange=%d, allowvendorchange=%d\n", solv->allowuninstall, solv->allowdowngrade, solv->allowarchchange, solv->allowvendorchange);
4213 POOL_DEBUG(SAT_DEBUG_STATS, "promoteepoch=%d, allowvirtualconflicts=%d, allowselfconflicts=%d\n", pool->promoteepoch, solv->allowvirtualconflicts, solv->allowselfconflicts);
4214 POOL_DEBUG(SAT_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d\n", solv->obsoleteusesprovides, solv->implicitobsoleteusesprovides);
4215 POOL_DEBUG(SAT_DEBUG_STATS, "dontinstallrecommended=%d, ignorealreadyrecommended=%d, dontshowinstalledrecommended=%d\n", solv->dontinstallrecommended, solv->ignorealreadyrecommended, solv->dontshowinstalledrecommended);
4216 /* create whatprovides if not already there */
4217 if (!pool->whatprovides)
4218 pool_createwhatprovides(pool);
4220 /* create obsolete index */
4221 create_obsolete_index(solv);
4227 * create basic rule set of all involved packages
4228 * use addedmap bitmap to make sure we don't create rules twice
4232 /* create noobsolete map if needed */
4233 for (i = 0; i < job->count; i += 2)
4235 how = job->elements[i] & ~SOLVER_WEAK;
4236 if ((how & SOLVER_JOBMASK) != SOLVER_NOOBSOLETES)
4238 what = job->elements[i + 1];
4239 select = how & SOLVER_SELECTMASK;
4240 if (!solv->noobsoletes.size)
4241 map_init(&solv->noobsoletes, pool->nsolvables);
4242 FOR_JOB_SELECT(p, pp, select, what)
4243 MAPSET(&solv->noobsoletes, p);
4246 map_init(&addedmap, pool->nsolvables);
4247 map_init(&installcandidatemap, pool->nsolvables);
4251 * always install our system solvable
4253 MAPSET(&addedmap, SYSTEMSOLVABLE);
4254 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
4255 queue_push(&solv->decisionq_why, 0);
4256 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
4258 now = sat_timems(0);
4260 * create rules for all package that could be involved with the solving
4261 * so called: rpm rules
4266 oldnrules = solv->nrules;
4267 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
4268 FOR_REPO_SOLVABLES(installed, p, s)
4269 addrpmrulesforsolvable(solv, s, &addedmap);
4270 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
4271 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
4272 oldnrules = solv->nrules;
4273 FOR_REPO_SOLVABLES(installed, p, s)
4274 addrpmrulesforupdaters(solv, s, &addedmap, 1);
4275 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
4279 * create rules for all packages involved in the job
4280 * (to be installed or removed)
4283 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
4284 oldnrules = solv->nrules;
4285 for (i = 0; i < job->count; i += 2)
4287 how = job->elements[i];
4288 what = job->elements[i + 1];
4289 select = how & SOLVER_SELECTMASK;
4291 switch (how & SOLVER_JOBMASK)
4293 case SOLVER_INSTALL:
4294 FOR_JOB_SELECT(p, pp, select, what)
4296 MAPSET(&installcandidatemap, p);
4297 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
4301 /* FIXME: semantics? */
4302 FOR_JOB_SELECT(p, pp, select, what)
4303 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
4307 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
4309 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
4311 oldnrules = solv->nrules;
4314 * add rules for suggests, enhances
4316 addrpmrulesforweak(solv, &addedmap);
4317 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
4319 IF_POOLDEBUG (SAT_DEBUG_STATS)
4321 int possible = 0, installable = 0;
4322 for (i = 1; i < pool->nsolvables; i++)
4324 if (pool_installable(pool, pool->solvables + i))
4326 if (MAPTST(&addedmap, i))
4329 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
4333 * first pass done, we now have all the rpm rules we need.
4334 * unify existing rules before going over all job rules and
4336 * at this point the system is always solvable,
4337 * as an empty system (remove all packages) is a valid solution
4340 unifyrules(solv); /* remove duplicate rpm rules */
4342 solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
4344 solv->directdecisions = solv->decisionq.count;
4345 POOL_DEBUG(SAT_DEBUG_STATS, "rpm rule memory usage: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
4346 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
4347 POOL_DEBUG(SAT_DEBUG_STATS, "rpm rule creation took %d ms\n", sat_timems(now));
4350 * create feature rules
4352 * foreach installed:
4353 * create assertion (keep installed, if no update available)
4355 * create update rule (A|update1(A)|update2(A)|...)
4357 * those are used later on to keep a version of the installed packages in
4361 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add feature rules ***\n");
4362 solv->featurerules = solv->nrules; /* mark start of feature rules */
4365 /* foreach possibly installed solvable */
4366 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
4368 if (s->repo != installed)
4370 addrule(solv, 0, 0); /* create dummy rule */
4373 addupdaterule(solv, s, 1); /* allow s to be updated */
4376 * assert one rule per installed solvable,
4377 * either an assertion (A)
4378 * or a possible update (A|update1(A)|update2(A)|...)
4380 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
4382 solv->featurerules_end = solv->nrules;
4385 * Add update rules for installed solvables
4387 * almost identical to feature rules
4388 * except that downgrades/archchanges/vendorchanges are not allowed
4391 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add update rules ***\n");
4392 solv->updaterules = solv->nrules;
4395 { /* foreach installed solvables */
4396 /* we create all update rules, but disable some later on depending on the job */
4397 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
4401 if (s->repo != installed)
4403 addrule(solv, 0, 0); /* create dummy rule */
4406 addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
4408 * check for and remove duplicate
4410 r = solv->rules + solv->nrules - 1; /* r: update rule */
4411 sr = r - (installed->end - installed->start); /* sr: feature rule */
4412 /* it's orphaned if there is no feature rule or the feature rule
4413 * consists just of the installed package */
4414 if (!sr->p || (sr->p == i && !sr->d && !sr->w2))
4415 queue_push(&solv->orphaned, i);
4418 assert(solv->distupgrade && !sr->p);
4421 unifyrules_sortcmp_data = pool;
4422 if (!unifyrules_sortcmp(r, sr))
4424 /* identical rule, kill unneeded rule */
4425 if (solv->allowuninstall)
4427 /* keep feature rule, make it weak */
4428 memset(r, 0, sizeof(*r));
4429 queue_push(&solv->weakruleq, sr - solv->rules);
4433 /* keep update rule */
4434 memset(sr, 0, sizeof(*sr));
4437 else if (solv->allowuninstall)
4439 /* make both feature and update rule weak */
4440 queue_push(&solv->weakruleq, r - solv->rules);
4441 queue_push(&solv->weakruleq, sr - solv->rules);
4444 disablerule(solv, sr);
4446 /* consistency check: we added a rule for _every_ installed solvable */
4447 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
4449 solv->updaterules_end = solv->nrules;
4453 * now add all job rules
4456 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
4458 solv->jobrules = solv->nrules;
4459 for (i = 0; i < job->count; i += 2)
4461 oldnrules = solv->nrules;
4463 how = job->elements[i];
4464 what = job->elements[i + 1];
4465 weak = how & SOLVER_WEAK;
4466 select = how & SOLVER_SELECTMASK;
4467 switch (how & SOLVER_JOBMASK)
4469 case SOLVER_INSTALL:
4470 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4471 if (select == SOLVER_SOLVABLE)
4479 FOR_JOB_SELECT(p, pp, select, what)
4483 /* no candidate found, make this an impossible rule */
4484 queue_push(&q, -SYSTEMSOLVABLE);
4486 p = queue_shift(&q); /* get first candidate */
4487 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
4489 addrule(solv, p, d); /* add install rule */
4490 queue_push(&solv->ruletojob, i);
4492 queue_push(&solv->weakruleq, solv->nrules - 1);
4495 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4496 if (select == SOLVER_SOLVABLE && solv->installed && pool->solvables[what].repo == solv->installed)
4498 /* special case for "erase a specific solvable": we also
4499 * erase all other solvables with that name, so that they
4500 * don't get picked up as replacement */
4501 name = pool->solvables[what].name;
4502 FOR_PROVIDES(p, pp, name)
4506 s = pool->solvables + p;
4507 if (s->name != name)
4509 /* keep other versions installed */
4510 if (s->repo == solv->installed)
4512 /* keep installcandidates of other jobs */
4513 if (MAPTST(&installcandidatemap, p))
4515 addrule(solv, -p, 0); /* remove by Id */
4516 queue_push(&solv->ruletojob, i);
4518 queue_push(&solv->weakruleq, solv->nrules - 1);
4521 FOR_JOB_SELECT(p, pp, select, what)
4523 addrule(solv, -p, 0);
4524 queue_push(&solv->ruletojob, i);
4526 queue_push(&solv->weakruleq, solv->nrules - 1);
4531 POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4532 if (select != SOLVER_SOLVABLE)
4534 s = pool->solvables + what;
4535 POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solvable2str(pool, s));
4536 addupdaterule(solv, s, 0);
4537 queue_push(&solv->ruletojob, i);
4539 queue_push(&solv->weakruleq, solv->nrules - 1);
4541 case SOLVER_WEAKENDEPS:
4542 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4543 if (select != SOLVER_SOLVABLE)
4545 s = pool->solvables + what;
4546 weaken_solvable_deps(solv, what);
4548 case SOLVER_NOOBSOLETES:
4549 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sno obsolete %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4552 POOL_DEBUG(SAT_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(solv, select, what));
4553 FOR_JOB_SELECT(p, pp, select, what)
4555 s = pool->solvables + p;
4556 if (installed && s->repo == installed)
4557 addrule(solv, p, 0);
4559 addrule(solv, -p, 0);
4560 queue_push(&solv->ruletojob, i);
4562 queue_push(&solv->weakruleq, solv->nrules - 1);
4566 POOL_DEBUG(SAT_DEBUG_JOB, "job: unknown job\n");
4574 IF_POOLDEBUG (SAT_DEBUG_JOB)
4577 if (solv->nrules == oldnrules)
4578 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created\n");
4579 for (j = oldnrules; j < solv->nrules; j++)
4581 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
4582 solver_printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
4586 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
4587 solv->jobrules_end = solv->nrules;
4589 /* all rules created
4590 * --------------------------------------------------------------
4591 * prepare for solving
4594 /* free unneeded memory */
4595 map_free(&addedmap);
4596 map_free(&installcandidatemap);
4599 /* create weak map */
4600 map_init(&solv->weakrulemap, solv->nrules);
4601 for (i = 0; i < solv->weakruleq.count; i++)
4603 p = solv->weakruleq.elements[i];
4604 MAPSET(&solv->weakrulemap, p);
4607 /* all new rules are learnt after this point */
4608 solv->learntrules = solv->nrules;
4610 /* create assertion index. it is only used to speed up
4611 * makeruledecsions() a bit */
4612 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
4613 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
4614 queue_push(&solv->ruleassertions, i);
4616 /* disable update rules that conflict with our job */
4617 disableupdaterules(solv, job, -1);
4619 /* make decisions based on job/update assertions */
4620 makeruledecisions(solv);
4622 /* create watches chains */
4625 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
4628 * ********************************************
4630 * ********************************************
4633 now = sat_timems(0);
4634 run_solver(solv, 1, solv->dontinstallrecommended ? 0 : 1);
4635 POOL_DEBUG(SAT_DEBUG_STATS, "solver took %d ms\n", sat_timems(now));
4639 /* disable all erase jobs (including weak "keep uninstalled" rules) */
4640 for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++)
4642 if (r->d < 0) /* disabled ? */
4644 if (r->p > 0) /* install job? */
4646 disablerule(solv, r);
4652 enabledisablelearntrules(solv);
4653 removedisabledconflicts(solv, &redoq);
4657 * find recommended packages
4660 /* if redoq.count == 0 we already found all recommended in the
4662 if (redoq.count || solv->dontinstallrecommended || !solv->dontshowinstalledrecommended || solv->ignorealreadyrecommended)
4664 Id rec, *recp, p, pp;
4666 /* create map of all recommened packages */
4667 solv->recommends_index = -1;
4668 MAPZERO(&solv->recommendsmap);
4669 for (i = 0; i < solv->decisionq.count; i++)
4671 p = solv->decisionq.elements[i];
4674 s = pool->solvables + p;
4677 recp = s->repo->idarraydata + s->recommends;
4678 while ((rec = *recp++) != 0)
4680 FOR_PROVIDES(p, pp, rec)
4681 if (solv->decisionmap[p] > 0)
4685 if (!solv->dontshowinstalledrecommended)
4687 FOR_PROVIDES(p, pp, rec)
4688 if (solv->decisionmap[p] > 0)
4689 MAPSET(&solv->recommendsmap, p);
4691 continue; /* p != 0: already fulfilled */
4693 FOR_PROVIDES(p, pp, rec)
4694 MAPSET(&solv->recommendsmap, p);
4698 for (i = 1; i < pool->nsolvables; i++)
4700 if (solv->decisionmap[i] < 0)
4702 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
4704 s = pool->solvables + i;
4705 if (!MAPTST(&solv->recommendsmap, i))
4707 if (!s->supplements)
4709 if (!pool_installable(pool, s))
4711 if (!solver_is_supplementing(solv, s))
4714 if (solv->dontinstallrecommended)
4715 queue_push(&solv->recommendations, i);
4717 queue_pushunique(&solv->recommendations, i);
4719 /* we use MODE_SUGGEST here so that repo prio is ignored */
4720 policy_filter_unwanted(solv, &solv->recommendations, POLICY_MODE_SUGGEST);
4724 * find suggested packages
4729 Id sug, *sugp, p, pp;
4731 /* create map of all suggests that are still open */
4732 solv->recommends_index = -1;
4733 MAPZERO(&solv->suggestsmap);
4734 for (i = 0; i < solv->decisionq.count; i++)
4736 p = solv->decisionq.elements[i];
4739 s = pool->solvables + p;
4742 sugp = s->repo->idarraydata + s->suggests;
4743 while ((sug = *sugp++) != 0)
4745 FOR_PROVIDES(p, pp, sug)
4746 if (solv->decisionmap[p] > 0)
4750 if (!solv->dontshowinstalledrecommended)
4752 FOR_PROVIDES(p, pp, sug)
4753 if (solv->decisionmap[p] > 0)
4754 MAPSET(&solv->suggestsmap, p);
4756 continue; /* already fulfilled */
4758 FOR_PROVIDES(p, pp, sug)
4759 MAPSET(&solv->suggestsmap, p);
4763 for (i = 1; i < pool->nsolvables; i++)
4765 if (solv->decisionmap[i] < 0)
4767 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
4769 s = pool->solvables + i;
4770 if (!MAPTST(&solv->suggestsmap, i))
4774 if (!pool_installable(pool, s))
4776 if (!solver_is_enhancing(solv, s))
4779 queue_push(&solv->suggestions, i);
4781 policy_filter_unwanted(solv, &solv->suggestions, POLICY_MODE_SUGGEST);
4786 /* restore decisionmap */
4787 for (i = 0; i < redoq.count; i += 2)
4788 solv->decisionmap[redoq.elements[i]] = redoq.elements[i + 1];
4792 * if unsolvable, prepare solutions
4795 if (solv->problems.count)
4797 int recocount = solv->recommendations.count;
4798 solv->recommendations.count = 0; /* so that revert() doesn't mess with it */
4799 queue_empty(&redoq);
4800 for (i = 0; i < solv->decisionq.count; i++)
4802 Id p = solv->decisionq.elements[i];
4803 queue_push(&redoq, p);
4804 queue_push(&redoq, solv->decisionq_why.elements[i]);
4805 queue_push(&redoq, solv->decisionmap[p > 0 ? p : -p]);
4807 problems_to_solutions(solv, job);
4808 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
4809 queue_empty(&solv->decisionq);
4810 queue_empty(&solv->decisionq_why);
4811 for (i = 0; i < redoq.count; i += 3)
4813 Id p = redoq.elements[i];
4814 queue_push(&solv->decisionq, p);
4815 queue_push(&solv->decisionq_why, redoq.elements[i + 1]);
4816 solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
4818 solv->recommendations.count = recocount;
4822 POOL_DEBUG(SAT_DEBUG_STATS, "final solver statistics: %d learned rules, %d unsolvable\n", solv->stats_learned, solv->stats_unsolvable);
4823 POOL_DEBUG(SAT_DEBUG_STATS, "solver_solve took %d ms\n", sat_timems(solve_start));
4827 /***********************************************************************/
4828 /* disk usage computations */
4830 /*-------------------------------------------------------------------
4832 * calculate DU changes
4836 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
4840 solver_create_state_maps(solv, &installedmap, 0);
4841 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
4842 map_free(&installedmap);
4846 /*-------------------------------------------------------------------
4848 * calculate changes in install size
4852 solver_calc_installsizechange(Solver *solv)
4857 solver_create_state_maps(solv, &installedmap, 0);
4858 change = pool_calc_installsizechange(solv->pool, &installedmap);
4859 map_free(&installedmap);
4863 #define FIND_INVOLVED_DEBUG 0
4865 solver_find_involved(Solver *solv, Queue *installedq, Solvable *ts, Queue *q)
4867 Pool *pool = solv->pool;
4872 Queue installedq_internal;
4873 Id tp, ip, p, pp, req, *reqp, sup, *supp;
4876 tp = ts - pool->solvables;
4878 queue_init(&installedq_internal);
4879 map_init(&im, pool->nsolvables);
4880 map_init(&installedm, pool->nsolvables);
4884 installedq = &installedq_internal;
4885 if (solv->installed)
4887 for (ip = solv->installed->start; ip < solv->installed->end; ip++)
4889 s = pool->solvables + ip;
4890 if (s->repo != solv->installed)
4892 queue_push(installedq, ip);
4896 for (i = 0; i < installedq->count; i++)
4898 ip = installedq->elements[i];
4899 MAPSET(&installedm, ip);
4903 queue_push(&iq, ts - pool->solvables);
4906 ip = queue_shift(&iq);
4907 if (!MAPTST(&im, ip))
4909 if (!MAPTST(&installedm, ip))
4912 s = pool->solvables + ip;
4913 #if FIND_INVOLVED_DEBUG
4914 printf("hello %s\n", solvable2str(pool, s));
4918 reqp = s->repo->idarraydata + s->requires;
4919 while ((req = *reqp++) != 0)
4921 if (req == SOLVABLE_PREREQMARKER)
4923 /* count number of installed packages that match */
4925 FOR_PROVIDES(p, pp, req)
4926 if (MAPTST(&installedm, p))
4930 FOR_PROVIDES(p, pp, req)
4934 #if FIND_INVOLVED_DEBUG
4935 printf("%s requires %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
4944 reqp = s->repo->idarraydata + s->recommends;
4945 while ((req = *reqp++) != 0)
4948 FOR_PROVIDES(p, pp, req)
4949 if (MAPTST(&installedm, p))
4953 FOR_PROVIDES(p, pp, req)
4957 #if FIND_INVOLVED_DEBUG
4958 printf("%s recommends %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
4967 /* supplements pass */
4968 for (i = 0; i < installedq->count; i++)
4970 ip = installedq->elements[i];
4971 s = pool->solvables + ip;
4972 if (!s->supplements)
4974 if (!MAPTST(&im, ip))
4976 supp = s->repo->idarraydata + s->supplements;
4977 while ((sup = *supp++) != 0)
4978 if (!dep_possible(solv, sup, &im) && dep_possible(solv, sup, &installedm))
4980 /* no longer supplemented, also erase */
4983 #if FIND_INVOLVED_DEBUG
4984 printf("%s supplemented\n", solvable2str(pool, pool->solvables + ip));
4986 queue_push(&iq, ip);
4992 for (i = 0; i < installedq->count; i++)
4994 ip = installedq->elements[i];
4995 if (MAPTST(&im, ip))
4996 queue_push(&iq, ip);
5001 ip = queue_shift(&iq);
5002 if (!MAPTST(&installedm, ip))
5004 s = pool->solvables + ip;
5005 #if FIND_INVOLVED_DEBUG
5006 printf("bye %s\n", solvable2str(pool, s));
5010 reqp = s->repo->idarraydata + s->requires;
5011 while ((req = *reqp++) != 0)
5013 FOR_PROVIDES(p, pp, req)
5015 if (!MAPTST(&im, p))
5019 #if FIND_INVOLVED_DEBUG
5020 printf("%s requires %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
5030 reqp = s->repo->idarraydata + s->recommends;
5031 while ((req = *reqp++) != 0)
5033 FOR_PROVIDES(p, pp, req)
5035 if (!MAPTST(&im, p))
5039 #if FIND_INVOLVED_DEBUG
5040 printf("%s recommends %s\n", solvable2str(pool, pool->solvables + ip), solvable2str(pool, pool->solvables + p));
5050 /* supplements pass */
5051 for (i = 0; i < installedq->count; i++)
5053 ip = installedq->elements[i];
5056 s = pool->solvables + ip;
5057 if (!s->supplements)
5059 if (MAPTST(&im, ip))
5061 supp = s->repo->idarraydata + s->supplements;
5062 while ((sup = *supp++) != 0)
5063 if (dep_possible(solv, sup, &im))
5067 #if FIND_INVOLVED_DEBUG
5068 printf("%s supplemented\n", solvable2str(pool, pool->solvables + ip));
5071 queue_push(&iq, ip);
5079 /* convert map into result */
5080 for (i = 0; i < installedq->count; i++)
5082 ip = installedq->elements[i];
5083 if (MAPTST(&im, ip))
5085 if (ip == ts - pool->solvables)
5090 map_free(&installedm);
5091 queue_free(&installedq_internal);