2 * Copyright (c) 2007, 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"
30 #define RULES_BLOCK 63
32 /********************************************************************
34 * dependency check helpers
38 static inline Id dep2name(Pool *pool, Id dep)
42 Reldep *rd = rd = GETRELDEP(pool, dep);
49 solver_splitprovides(Solver *solv, Id dep)
51 Pool *pool = solv->pool;
56 if (!solv->dosplitprovides || !solv->installed)
60 rd = GETRELDEP(pool, dep);
61 if (rd->flags != REL_WITH)
63 FOR_PROVIDES(p, pp, dep)
65 s = pool->solvables + p;
66 if (s->repo == solv->installed && s->name == rd->name)
73 solver_dep_installed(Solver *solv, Id dep)
76 Pool *pool = solv->pool;
81 Reldep *rd = GETRELDEP(pool, dep);
82 if (rd->flags == REL_AND)
84 if (!solver_dep_installed(solv, rd->name))
86 return solver_dep_installed(solv, rd->evr);
88 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
89 return solver_dep_installed(solv, rd->evr);
91 FOR_PROVIDES(p, pp, dep)
93 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
101 /* this mirrors solver_dep_fulfilled but uses map m instead of the decisionmap */
103 dep_possible(Solver *solv, Id dep, Map *m)
105 Pool *pool = solv->pool;
110 Reldep *rd = GETRELDEP(pool, dep);
111 if (rd->flags == REL_AND)
113 if (!dep_possible(solv, rd->name, m))
115 return dep_possible(solv, rd->evr, m);
117 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
118 return solver_splitprovides(solv, rd->evr);
119 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
120 return solver_dep_installed(solv, rd->evr);
122 FOR_PROVIDES(p, pp, dep)
130 /********************************************************************
136 static Pool *unifyrules_sortcmp_data;
139 * compare rules for unification sort
143 unifyrules_sortcmp(const void *ap, const void *bp)
145 Pool *pool = unifyrules_sortcmp_data;
146 Rule *a = (Rule *)ap;
147 Rule *b = (Rule *)bp;
153 return x; /* p differs */
156 if (a->d == 0 && b->d == 0)
157 return a->w2 - b->w2; /* assertion: return w2 diff */
159 if (a->d == 0) /* a is assertion, b not */
161 x = a->w2 - pool->whatprovidesdata[b->d];
165 if (b->d == 0) /* b is assertion, a not */
167 x = pool->whatprovidesdata[a->d] - b->w2;
171 /* compare whatprovidesdata */
172 ad = pool->whatprovidesdata + a->d;
173 bd = pool->whatprovidesdata + b->d;
175 if ((x = *ad++ - *bd++) != 0)
186 unifyrules(Solver *solv)
188 Pool *pool = solv->pool;
192 if (solv->nrules <= 1) /* nothing to unify */
195 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
197 /* sort rules first */
198 unifyrules_sortcmp_data = solv->pool;
199 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
206 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
208 if (jr && !unifyrules_sortcmp(ir, jr))
209 continue; /* prune! */
210 jr = solv->rules + j++; /* keep! */
215 /* reduced count from nrules to j rules */
216 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
218 /* adapt rule buffer */
220 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
221 IF_POOLDEBUG (SAT_DEBUG_STATS)
228 for (i = 1; i < solv->nrules; i++)
235 dp = solv->pool->whatprovidesdata + r->d;
240 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
241 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
243 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
253 hashrule(Solver *solv, Id p, Id d, int n)
255 unsigned int x = (unsigned int)p;
259 return (x * 37) ^ (unsigned int)d;
260 dp = solv->pool->whatprovidesdata + d;
262 x = (x * 37) ^ (unsigned int)*dp++;
270 * p = direct literal; always < 0 for installed rpm rules
271 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
274 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
276 * p < 0 : pkg id of A
277 * d > 0 : Offset in whatprovidesdata (list of providers of b)
279 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
280 * p < 0 : pkg id of A
281 * d < 0 : Id of solvable (e.g. B1)
283 * d == 0: unary rule, assertion => (A) or (-A)
285 * Install: p > 0, d = 0 (A) user requested install
286 * Remove: p < 0, d = 0 (-A) user requested remove
287 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
288 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
289 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
290 * ? p > 0, d < 0 (A|-B)
291 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
295 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
296 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
297 * every other : w1 = p, w2 = whatprovidesdata[d];
298 * Disabled rule: w1 = 0
300 * always returns a rule for non-rpm rules
304 addrule(Solver *solv, Id p, Id d)
306 Pool *pool = solv->pool;
310 int n = 0; /* number of literals in rule - 1
311 0 = direct assertion (single literal)
315 /* it often happenes that requires lead to adding the same rpm rule
316 * multiple times, so we prune those duplicates right away to make
317 * the work for unifyrules a bit easier */
319 if (solv->nrules && !solv->jobrules)
321 r = solv->rules + solv->nrules - 1; /* get the last added rule */
322 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
328 /* always a binary rule */
330 return 0; /* ignore self conflict */
335 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
337 return 0; /* rule is self-fulfilling */
339 d = dp[-1]; /* take single literal */
343 if (n == 0 && !solv->jobrules)
345 /* this is a rpm rule assertion, we do not have to allocate it */
346 /* it can be identified by a level of 1 and a zero reason */
347 /* we must not drop those rules from the decisionq when rewinding! */
349 assert(solv->decisionmap[-p] == 0 || solv->decisionmap[-p] == -1);
350 if (solv->decisionmap[-p])
351 return 0; /* already got that one */
352 queue_push(&solv->decisionq, p);
353 queue_push(&solv->decisionq_why, 0);
354 solv->decisionmap[-p] = -1;
361 /* smallest literal first so we can find dups */
365 n = 1; /* re-set n, was used as temp var */
368 /* check if the last added rule is exactly the same as what we're looking for. */
369 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
370 return r; /* binary rule */
372 if (r && n > 1 && r->d && r->p == p)
374 /* Rule where d is an offset in whatprovidesdata */
378 dp2 = pool->whatprovidesdata + r->d;
379 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
390 /* extend rule buffer */
391 solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
392 r = solv->rules + solv->nrules++; /* point to rule space */
397 /* direct assertion, no watch needed */
413 r->w2 = pool->whatprovidesdata[d];
418 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
420 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
421 solver_printrule(solv, SAT_DEBUG_RULE_CREATION, r);
428 disablerule(Solver *solv, Rule *r)
435 enablerule(Solver *solv, Rule *r)
442 /**********************************************************************************/
444 /* a problem is an item on the solver's problem list. It can either be >0, in that
445 * case it is a update rule, or it can be <0, which makes it refer to a job
446 * consisting of multiple job rules.
450 disableproblem(Solver *solv, Id v)
458 disablerule(solv, solv->rules + v);
462 jp = solv->ruletojob.elements;
463 for (i = solv->jobrules, r = solv->rules + i; i < solv->updaterules; i++, r++, jp++)
465 disablerule(solv, r);
469 enableproblem(Solver *solv, Id v)
477 if (v >= solv->featurerules && v < solv->learntrules)
479 /* do not enable feature rule if update rule is enabled */
480 r = solv->rules + v - (solv->installed->end - solv->installed->start);
484 enablerule(solv, solv->rules + v);
485 if (v >= solv->updaterules && v < solv->featurerules)
487 r = solv->rules + v + (solv->installed->end - solv->installed->start);
489 disablerule(solv, r);
494 jp = solv->ruletojob.elements;
495 for (i = solv->jobrules, r = solv->rules + i; i < solv->updaterules; i++, r++, jp++)
501 /************************************************************************/
503 /* go through update and job rules and add direct assertions
504 * to the decisionqueue. If we find a conflict, disable rules and
505 * add them to problem queue.
508 makeruledecisions(Solver *solv)
510 Pool *pool = solv->pool;
516 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
518 decisionstart = solv->decisionq.count;
519 for (ii = 0; ii < solv->ruleassertions.count; ii++)
521 ri = solv->ruleassertions.elements[ii];
522 r = solv->rules + ri;
523 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
525 /* do weak rules in phase 2 */
526 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
530 if (!solv->decisionmap[vv])
532 queue_push(&solv->decisionq, v);
533 queue_push(&solv->decisionq_why, r - solv->rules);
534 solv->decisionmap[vv] = v > 0 ? 1 : -1;
535 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
537 Solvable *s = solv->pool->solvables + vv;
539 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
541 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
545 if (v > 0 && solv->decisionmap[vv] > 0)
547 if (v < 0 && solv->decisionmap[vv] < 0)
549 /* found a conflict! */
550 if (ri >= solv->learntrules)
552 /* conflict with a learnt rule */
553 /* can happen when packages cannot be installed for
554 * multiple reasons. */
555 /* we disable the learnt rule in this case */
556 disablerule(solv, r);
559 /* only job and update rules left in the decisionq */
560 /* find the decision which is the "opposite" of the jobrule */
561 for (i = 0; i < solv->decisionq.count; i++)
562 if (solv->decisionq.elements[i] == -v)
564 assert(i < solv->decisionq.count);
565 if (v == -SYSTEMSOLVABLE) {
566 /* conflict with system solvable */
567 queue_push(&solv->problems, solv->learnt_pool.count);
568 queue_push(&solv->learnt_pool, ri);
569 queue_push(&solv->learnt_pool, 0);
570 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
571 if (ri < solv->updaterules)
572 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
575 queue_push(&solv->problems, v);
576 queue_push(&solv->problems, 0);
577 disableproblem(solv, v);
580 assert(solv->decisionq_why.elements[i]);
581 if (solv->decisionq_why.elements[i] < solv->jobrules)
583 /* conflict with rpm rule assertion */
584 queue_push(&solv->problems, solv->learnt_pool.count);
585 queue_push(&solv->learnt_pool, ri);
586 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
587 queue_push(&solv->learnt_pool, 0);
588 assert(v > 0 || v == -SYSTEMSOLVABLE);
589 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
590 if (ri < solv->updaterules)
591 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
594 queue_push(&solv->problems, v);
595 queue_push(&solv->problems, 0);
596 disableproblem(solv, v);
600 /* conflict with another job or update rule */
602 queue_push(&solv->problems, solv->learnt_pool.count);
603 queue_push(&solv->learnt_pool, ri);
604 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
605 queue_push(&solv->learnt_pool, 0);
607 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
609 /* push all of our rules asserting this literal on the problem stack */
610 for (i = solv->jobrules, rr = solv->rules + i; i < solv->nrules; i++, rr++)
612 if (rr->d < 0 || rr->w2)
614 if (rr->p != vv && rr->p != -vv)
616 if (i >= solv->learntrules)
618 if (MAPTST(&solv->weakrulemap, i))
620 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
622 if (i < solv->updaterules)
623 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
624 queue_push(&solv->problems, v);
625 disableproblem(solv, v);
627 queue_push(&solv->problems, 0);
630 while (solv->decisionq.count > decisionstart)
632 v = solv->decisionq.elements[--solv->decisionq.count];
633 --solv->decisionq_why.count;
635 solv->decisionmap[vv] = 0;
640 /* phase 2: now do the weak assertions */
641 for (ii = 0; ii < solv->ruleassertions.count; ii++)
643 ri = solv->ruleassertions.elements[ii];
644 r = solv->rules + ri;
645 if (r->d < 0 || r->w2) /* disabled or no assertion */
647 if (!MAPTST(&solv->weakrulemap, ri))
651 if (!solv->decisionmap[vv])
653 queue_push(&solv->decisionq, v);
654 queue_push(&solv->decisionq_why, r - solv->rules);
655 solv->decisionmap[vv] = v > 0 ? 1 : -1;
656 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
658 Solvable *s = solv->pool->solvables + vv;
660 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", solvable2str(solv->pool, s));
662 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", solvable2str(solv->pool, s));
666 if (v > 0 && solv->decisionmap[vv] > 0)
668 if (v < 0 && solv->decisionmap[vv] < 0)
670 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
671 solver_printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
672 disablerule(solv, r);
675 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
679 * we have enabled or disabled some of our rules. We now reenable all
680 * of our learnt rules but the ones that were learnt from rules that
684 enabledisablelearntrules(Solver *solv)
686 Pool *pool = solv->pool;
691 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
692 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
694 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
695 while ((why = *whyp++) != 0)
697 assert(why > 0 && why < i);
698 if (solv->rules[why].d < 0)
701 /* why != 0: we found a disabled rule, disable the learnt rule */
702 if (why && r->d >= 0)
704 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
706 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling ");
707 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
709 disablerule(solv, r);
711 else if (!why && r->d < 0)
713 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
715 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling ");
716 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
724 enableweakrules(Solver *solv)
729 for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++)
733 if (!MAPTST(&solv->weakrulemap, i))
740 /* FIXME: bad code ahead, replace as soon as possible */
741 /* FIXME: should probably look at SOLVER_INSTALL_SOLVABLE_ONE_OF */
744 disableupdaterules(Solver *solv, Queue *job, int jobidx)
746 Pool *pool = solv->pool;
748 Id name, how, what, p, *pp;
754 installed = solv->installed;
760 how = job->elements[jobidx] & ~SOLVER_WEAK;
763 case SOLVER_INSTALL_SOLVABLE:
764 case SOLVER_ERASE_SOLVABLE:
765 case SOLVER_ERASE_SOLVABLE_NAME:
766 case SOLVER_ERASE_SOLVABLE_PROVIDES:
772 /* go through all enabled job rules */
773 MAPZERO(&solv->noupdate);
774 for (i = solv->jobrules; i < solv->updaterules; i++)
777 if (r->d < 0) /* disabled? */
779 j = solv->ruletojob.elements[i - solv->jobrules];
783 how = job->elements[j] & ~SOLVER_WEAK;
784 what = job->elements[j + 1];
787 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
788 s = pool->solvables + what;
789 FOR_PROVIDES(p, pp, s->name)
791 if (pool->solvables[p].name != s->name)
793 if (pool->solvables[p].repo == installed)
794 MAPSET(&solv->noupdate, p - installed->start);
797 case SOLVER_ERASE_SOLVABLE:
798 s = pool->solvables + what;
799 if (s->repo == installed)
800 MAPSET(&solv->noupdate, what - installed->start);
802 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
803 case SOLVER_ERASE_SOLVABLE_PROVIDES:
804 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
805 while (ISRELDEP(name))
807 Reldep *rd = GETRELDEP(pool, name);
810 FOR_PROVIDES(p, pp, what)
812 if (name && pool->solvables[p].name != name)
814 if (pool->solvables[p].repo == installed)
815 MAPSET(&solv->noupdate, p - installed->start);
823 /* fixup update rule status */
826 /* we just disabled job #jobidx. enable all update rules
827 * that aren't disabled by the remaining job rules */
828 how = job->elements[jobidx] & ~SOLVER_WEAK;
829 what = job->elements[jobidx + 1];
832 case SOLVER_INSTALL_SOLVABLE:
833 s = pool->solvables + what;
834 FOR_PROVIDES(p, pp, s->name)
836 if (pool->solvables[p].name != s->name)
838 if (pool->solvables[p].repo != installed)
840 if (MAPTST(&solv->noupdate, p - installed->start))
842 r = solv->rules + solv->updaterules + (p - installed->start);
846 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
848 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
849 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
853 case SOLVER_ERASE_SOLVABLE:
854 s = pool->solvables + what;
855 if (s->repo != installed)
857 if (MAPTST(&solv->noupdate, what - installed->start))
859 r = solv->rules + solv->updaterules + (what - installed->start);
863 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
865 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
866 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
869 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
870 case SOLVER_ERASE_SOLVABLE_PROVIDES:
871 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
872 while (ISRELDEP(name))
874 Reldep *rd = GETRELDEP(pool, name);
877 FOR_PROVIDES(p, pp, what)
879 if (name && pool->solvables[p].name != name)
881 if (pool->solvables[p].repo != installed)
883 if (MAPTST(&solv->noupdate, p - installed->start))
885 r = solv->rules + solv->updaterules + (p - installed->start);
889 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
891 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
892 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
902 for (i = 0; i < installed->nsolvables; i++)
904 r = solv->rules + solv->updaterules + i;
905 if (r->d >= 0 && MAPTST(&solv->noupdate, i))
906 disablerule(solv, r); /* was enabled, need to disable */
907 r = solv->rules + solv->featurerules + i;
908 if (r->d >= 0 && MAPTST(&solv->noupdate, i))
909 disablerule(solv, r); /* was enabled, need to disable */
915 addpatchatomrequires(Solver *solv, Solvable *s, Id *dp, Queue *q, Map *m)
917 Pool *pool = solv->pool;
918 Id fre, *frep, p, *pp, ndp;
924 queue_init_buffer(&fq, qbuf, sizeof(qbuf)/sizeof(*qbuf));
925 queue_push(&fq, -(s - pool->solvables));
927 queue_push(&fq, *dp);
928 ndp = pool_queuetowhatprovides(pool, &fq);
929 frep = s->repo->idarraydata + s->freshens;
930 while ((fre = *frep++) != 0)
932 FOR_PROVIDES(p, pp, fre)
934 ps = pool->solvables + p;
935 addrule(solv, -p, ndp);
943 for (i = 1; i < fq.count; i++)
956 * add (install) rules for solvable
957 * for unfulfilled requirements, conflicts, obsoletes,....
958 * add a negative assertion for solvables that are not installable
962 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
964 Pool *pool = solv->pool;
965 Repo *installed = solv->installed;
980 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
982 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
983 queue_push(&q, s - pool->solvables); /* push solvable Id */
989 * s: Pointer to solvable
993 if (MAPTST(m, n)) /* continue if already done */
997 s = pool->solvables + n; /* s = Solvable in question */
1000 if (installed /* Installed system available */
1001 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
1002 && s->repo == installed) /* solvable is installed? */
1004 dontfix = 1; /* dont care about broken rpm deps */
1007 if (!dontfix && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
1009 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
1010 addrule(solv, -n, 0); /* uninstallable */
1014 if (s->freshens && !s->supplements)
1016 const char *name = id2str(pool, s->name);
1017 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
1021 /*-----------------------------------------
1022 * check requires of s
1027 reqp = s->repo->idarraydata + s->requires;
1028 while ((req = *reqp++) != 0) /* go throw all requires */
1030 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
1033 dp = pool_whatprovides(pool, req);
1035 if (*dp == SYSTEMSOLVABLE) /* always installed */
1041 addpatchatomrequires(solv, s, dp, &q, m);
1047 /* the strategy here is to not insist on dependencies
1048 * that are already broken. so if we find one provider
1049 * that was already installed, we know that the
1050 * dependency was not broken before so we enforce it */
1051 for (i = 0; (p = dp[i]) != 0; i++) /* for all providers */
1053 if (pool->solvables[p].repo == installed)
1054 break; /* provider was installed */
1056 if (!p) /* previously broken dependency */
1058 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1065 /* nothing provides req! */
1066 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1067 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1071 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1073 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1074 for (i = 0; dp[i]; i++)
1075 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1078 /* add 'requires' dependency */
1079 /* rule: (-requestor|provider1|provider2|...|providerN) */
1080 addrule(solv, -n, dp - pool->whatprovidesdata);
1082 /* descend the dependency tree */
1083 for (; *dp; dp++) /* loop through all providers */
1085 if (!MAPTST(m, *dp))
1086 queue_push(&q, *dp);
1089 } /* while, requirements of n */
1091 } /* if, requirements */
1093 /* that's all we check for src packages */
1094 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1097 /*-----------------------------------------
1098 * check conflicts of s
1103 conp = s->repo->idarraydata + s->conflicts;
1104 while ((con = *conp++) != 0)
1106 FOR_PROVIDES(p, pp, con)
1108 /* dontfix: dont care about conflicts with already installed packs */
1109 if (dontfix && pool->solvables[p].repo == installed)
1111 if (p == n && !solv->allowselfconflicts)
1112 p = 0; /* make it a negative assertion */
1113 /* rule: -n|-p: either solvable _or_ provider of conflict */
1114 addrule(solv, -n, -p);
1119 /*-----------------------------------------
1120 * check obsoletes if not installed
1122 if (!installed || pool->solvables[n].repo != installed)
1123 { /* not installed */
1126 obsp = s->repo->idarraydata + s->obsoletes;
1127 while ((obs = *obsp++) != 0)
1129 Id obsname = dep2name(pool, obs);
1130 FOR_PROVIDES(p, pp, obs)
1132 if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
1134 addrule(solv, -n, -p);
1138 FOR_PROVIDES(p, pp, s->name)
1140 if (!solv->implicitobsoleteusesprovides && s->name != pool->solvables[p].name)
1142 addrule(solv, -n, -p);
1146 /*-----------------------------------------
1147 * add recommends to the rule list
1151 recp = s->repo->idarraydata + s->recommends;
1152 while ((rec = *recp++) != 0)
1154 FOR_PROVIDES(p, pp, rec)
1161 sugp = s->repo->idarraydata + s->suggests;
1162 while ((sug = *sugp++) != 0)
1164 FOR_PROVIDES(p, pp, sug)
1171 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1175 addrpmrulesforweak(Solver *solv, Map *m)
1177 Pool *pool = solv->pool;
1182 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1183 for (i = n = 1; n < pool->nsolvables; i++, n++)
1185 if (i == pool->nsolvables)
1189 s = pool->solvables + i;
1190 if (!pool_installable(pool, s))
1195 supp = s->repo->idarraydata + s->supplements;
1196 while ((sup = *supp++) != ID_NULL)
1197 if (dep_possible(solv, sup, m))
1200 if (!sup && s->freshens)
1202 supp = s->repo->idarraydata + s->freshens;
1203 while ((sup = *supp++) != ID_NULL)
1204 if (dep_possible(solv, sup, m))
1207 if (!sup && s->enhances)
1209 supp = s->repo->idarraydata + s->enhances;
1210 while ((sup = *supp++) != ID_NULL)
1211 if (dep_possible(solv, sup, m))
1216 addrpmrulesforsolvable(solv, s, m);
1219 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1223 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
1225 Pool *pool = solv->pool;
1230 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1232 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1233 policy_findupdatepackages(solv, s, &qs, allowall);
1234 if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
1235 addrpmrulesforsolvable(solv, s, m);
1236 for (i = 0; i < qs.count; i++)
1237 if (!MAPTST(m, qs.elements[i]))
1238 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1241 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1245 * add rule for update
1246 * (A|A1|A2|A3...) An = update candidates for A
1248 * s = (installed) solvable
1252 addupdaterule(Solver *solv, Solvable *s, int allowall)
1254 /* installed packages get a special upgrade allowed rule */
1255 Pool *pool = solv->pool;
1260 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1262 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1263 policy_findupdatepackages(solv, s, &qs, allowall);
1264 if (qs.count == 0) /* no updaters found */
1267 d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
1269 addrule(solv, s - pool->solvables, d); /* allow update of s */
1270 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1274 /*-----------------------------------------------------------------*/
1281 * initial setup for all watches
1285 makewatches(Solver *solv)
1289 int nsolvables = solv->pool->nsolvables;
1291 sat_free(solv->watches);
1292 /* lower half for removals, upper half for installs */
1293 solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
1295 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
1296 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1298 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1301 if (!r->w2) /* assertions do not need watches */
1304 /* see addwatches_rule(solv, r) */
1305 r->n1 = solv->watches[nsolvables + r->w1];
1306 solv->watches[nsolvables + r->w1] = r - solv->rules;
1308 r->n2 = solv->watches[nsolvables + r->w2];
1309 solv->watches[nsolvables + r->w2] = r - solv->rules;
1315 * add watches (for rule)
1319 addwatches_rule(Solver *solv, Rule *r)
1321 int nsolvables = solv->pool->nsolvables;
1323 r->n1 = solv->watches[nsolvables + r->w1];
1324 solv->watches[nsolvables + r->w1] = r - solv->rules;
1326 r->n2 = solv->watches[nsolvables + r->w2];
1327 solv->watches[nsolvables + r->w2] = r - solv->rules;
1331 /*-----------------------------------------------------------------*/
1332 /* rule propagation */
1334 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1335 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
1340 * propagate decision to all rules
1341 * return : 0 = everything is OK
1342 * watched rule = there is a conflict
1346 propagate(Solver *solv, int level)
1348 Pool *pool = solv->pool;
1353 Id *decisionmap = solv->decisionmap;
1354 Id *watches = solv->watches + pool->nsolvables;
1356 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1358 while (solv->propagate_index < solv->decisionq.count)
1360 /* negate because our watches trigger if literal goes FALSE */
1361 pkg = -solv->decisionq.elements[solv->propagate_index++];
1362 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1364 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
1365 solver_printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1368 for (rp = watches + pkg; *rp; rp = nrp)
1370 r = solv->rules + *rp;
1373 /* rule is disabled */
1381 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1383 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1384 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
1389 ow = r->w2; /* regard the second watchpoint to come to a solution */
1394 ow = r->w1; /* regard the first watchpoint to come to a solution */
1397 /* if clause is TRUE, nothing to do */
1398 if (DECISIONMAP_TRUE(ow))
1403 /* not a binary clause, check if we need to move our watch */
1404 /* search for a literal that is not ow and not false */
1405 /* (true is also ok, in that case the rule is fulfilled) */
1406 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1409 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1410 if (p != ow && !DECISIONMAP_TRUE(-p))
1414 /* p is free to watch, move watch to p */
1415 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1418 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1420 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1434 watches[p] = r - solv->rules;
1438 /* unit clause found, set other watch to TRUE */
1439 if (DECISIONMAP_TRUE(-ow))
1440 return r; /* eek, a conflict! */
1441 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1443 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
1444 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
1447 decisionmap[ow] = level;
1449 decisionmap[-ow] = -level;
1450 queue_push(&solv->decisionq, ow);
1451 queue_push(&solv->decisionq_why, r - solv->rules);
1452 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1454 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1456 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
1458 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
1462 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
1464 return 0; /* all is well */
1468 /*-----------------------------------------------------------------*/
1477 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
1479 Pool *pool = solv->pool;
1482 Map seen; /* global? */
1483 Id d, v, vv, *dp, why;
1485 int num = 0, l1num = 0;
1486 int learnt_why = solv->learnt_pool.count;
1487 Id *decisionmap = solv->decisionmap;
1491 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
1492 map_init(&seen, pool->nsolvables);
1493 idx = solv->decisionq.count;
1496 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1497 solver_printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1498 queue_push(&solv->learnt_pool, c - solv->rules);
1499 d = c->d < 0 ? -c->d - 1 : c->d;
1500 dp = d ? pool->whatprovidesdata + d : 0;
1501 /* go through all literals of the rule */
1513 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1515 vv = v > 0 ? v : -v;
1516 if (MAPTST(&seen, vv))
1518 l = solv->decisionmap[vv];
1523 l1num++; /* need to do this one in level1 pass */
1524 else if (l == level)
1525 num++; /* need to do this one as well */
1528 queue_push(&r, v); /* not level1 or conflict level, add to new rule */
1534 if (!num && !--l1num)
1535 break; /* all level 1 literals done */
1539 v = solv->decisionq.elements[--idx];
1540 vv = v > 0 ? v : -v;
1541 if (MAPTST(&seen, vv))
1545 if (num && --num == 0)
1547 *pr = -v; /* so that v doesn't get lost */
1550 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1551 for (i = 0; i < r.count; i++)
1554 MAPCLR(&seen, v > 0 ? v : -v);
1556 /* only level 1 marks left */
1560 why = solv->decisionq_why.elements[idx];
1561 if (!why) /* just in case, maye for SYSTEMSOLVABLE */
1563 c = solv->rules + why;
1569 else if (r.count == 1 && r.elements[0] < 0)
1570 *dr = r.elements[0];
1572 *dr = pool_queuetowhatprovides(pool, &r);
1573 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1575 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1576 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
1577 for (i = 0; i < r.count; i++)
1578 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
1580 /* push end marker on learnt reasons stack */
1581 queue_push(&solv->learnt_pool, 0);
1584 solv->stats_learned++;
1591 * reset the solver decisions to right after the rpm rules.
1592 * called after rules have been enabled/disabled
1596 reset_solver(Solver *solv)
1598 Pool *pool = solv->pool;
1602 /* rewind decisions to direct rpm rule assertions */
1603 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
1605 v = solv->decisionq.elements[i];
1606 solv->decisionmap[v > 0 ? v : -v] = 0;
1609 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
1611 solv->decisionq_why.count = solv->directdecisions;
1612 solv->decisionq.count = solv->directdecisions;
1613 solv->recommends_index = -1;
1614 solv->propagate_index = 0;
1616 /* adapt learnt rule status to new set of enabled/disabled rules */
1617 enabledisablelearntrules(solv);
1619 /* redo all job/update decisions */
1620 makeruledecisions(solv);
1621 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
1626 * analyze_unsolvable_rule
1630 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
1632 Pool *pool = solv->pool;
1634 Id why = r - solv->rules;
1636 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1637 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1638 if (solv->learntrules && why >= solv->learntrules)
1640 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1641 if (solv->learnt_pool.elements[i] > 0)
1642 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp);
1645 if (MAPTST(&solv->weakrulemap, why))
1646 if (!*lastweakp || why > *lastweakp)
1648 /* do not add rpm rules to problem */
1649 if (why < solv->jobrules)
1651 /* turn rule into problem */
1652 if (why >= solv->jobrules && why < solv->updaterules)
1653 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1654 /* return if problem already countains our rule */
1655 if (solv->problems.count)
1657 for (i = solv->problems.count - 1; i >= 0; i--)
1658 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1660 else if (solv->problems.elements[i] == why)
1663 queue_push(&solv->problems, why);
1668 * analyze_unsolvable
1670 * return: 1 - disabled some rules, try again
1675 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1677 Pool *pool = solv->pool;
1679 Map seen; /* global to speed things up? */
1680 Id d, v, vv, *dp, why;
1682 Id *decisionmap = solv->decisionmap;
1683 int oldproblemcount;
1684 int oldlearntpoolcount;
1687 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1688 solv->stats_unsolvable++;
1689 oldproblemcount = solv->problems.count;
1690 oldlearntpoolcount = solv->learnt_pool.count;
1692 /* make room for proof index */
1693 /* must update it later, as analyze_unsolvable_rule would confuse
1694 * it with a rule index if we put the real value in already */
1695 queue_push(&solv->problems, 0);
1698 map_init(&seen, pool->nsolvables);
1699 queue_push(&solv->learnt_pool, r - solv->rules);
1701 analyze_unsolvable_rule(solv, r, &lastweak);
1702 d = r->d < 0 ? -r->d - 1 : r->d;
1703 dp = d ? pool->whatprovidesdata + d : 0;
1714 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1716 vv = v > 0 ? v : -v;
1717 l = solv->decisionmap[vv];
1722 idx = solv->decisionq.count;
1725 v = solv->decisionq.elements[--idx];
1726 vv = v > 0 ? v : -v;
1727 if (!MAPTST(&seen, vv))
1729 why = solv->decisionq_why.elements[idx];
1730 queue_push(&solv->learnt_pool, why);
1731 r = solv->rules + why;
1732 analyze_unsolvable_rule(solv, r, &lastweak);
1733 d = r->d < 0 ? -r->d - 1 : r->d;
1734 dp = d ? pool->whatprovidesdata + d : 0;
1745 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1747 vv = v > 0 ? v : -v;
1748 l = solv->decisionmap[vv];
1755 queue_push(&solv->problems, 0); /* mark end of this problem */
1759 /* disable last weak rule */
1760 solv->problems.count = oldproblemcount;
1761 solv->learnt_pool.count = oldlearntpoolcount;
1762 r = solv->rules + lastweak;
1763 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling ");
1764 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1765 disablerule(solv, r);
1771 queue_push(&solv->learnt_pool, 0);
1772 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1776 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1777 disableproblem(solv, solv->problems.elements[i]);
1778 /* XXX: might want to enable all weak rules again */
1782 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1787 /*-----------------------------------------------------------------*/
1788 /* Decision revert */
1792 * revert decision at level
1796 revert(Solver *solv, int level)
1798 Pool *pool = solv->pool;
1800 while (solv->decisionq.count)
1802 v = solv->decisionq.elements[solv->decisionq.count - 1];
1803 vv = v > 0 ? v : -v;
1804 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1806 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1807 if (v > 0 && solv->recommendations.count && v == solv->recommendations.elements[solv->recommendations.count - 1])
1808 solv->recommendations.count--;
1809 solv->decisionmap[vv] = 0;
1810 solv->decisionq.count--;
1811 solv->decisionq_why.count--;
1812 solv->propagate_index = solv->decisionq.count;
1814 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1816 solv->branches.count--;
1817 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1818 solv->branches.count--;
1820 solv->recommends_index = -1;
1825 * watch2onhighest - put watch2 on literal with highest level
1829 watch2onhighest(Solver *solv, Rule *r)
1834 d = r->d < 0 ? -r->d - 1 : r->d;
1836 return; /* binary rule, both watches are set */
1837 dp = solv->pool->whatprovidesdata + d;
1838 while ((v = *dp++) != 0)
1840 l = solv->decisionmap[v < 0 ? -v : v];
1855 * add free decision to decisionq, increase level and
1856 * propagate decision, return if no conflict.
1857 * in conflict case, analyze conflict rule, add resulting
1858 * rule to learnt rule set, make decision from learnt
1859 * rule (always unit) and re-propagate.
1861 * returns the new solver level or 0 if unsolvable
1866 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1868 Pool *pool = solv->pool;
1877 solv->decisionmap[decision] = level;
1879 solv->decisionmap[-decision] = -level;
1880 queue_push(&solv->decisionq, decision);
1881 queue_push(&solv->decisionq_why, 0);
1885 r = propagate(solv, level);
1889 return analyze_unsolvable(solv, r, disablerules);
1890 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1891 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1892 assert(l > 0 && l < level);
1893 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
1895 revert(solv, level);
1896 r = addrule(solv, p, d); /* p requires d */
1898 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1899 queue_push(&solv->learnt_why, why);
1902 /* at least 2 literals, needs watches */
1903 watch2onhighest(solv, r);
1904 addwatches_rule(solv, r);
1908 /* learnt rule is an assertion */
1909 queue_push(&solv->ruleassertions, r - solv->rules);
1911 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1912 queue_push(&solv->decisionq, p);
1913 queue_push(&solv->decisionq_why, r - solv->rules);
1914 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1916 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
1917 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
1918 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
1919 solver_printrule(solv, SAT_DEBUG_ANALYZE, r);
1927 * install best package from the queue. We add an extra package, inst, if
1928 * provided. See comment in weak install section.
1930 * returns the new solver level or 0 if unsolvable
1934 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
1936 Pool *pool = solv->pool;
1940 if (dq->count > 1 || inst)
1941 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
1946 /* choose the supplemented one */
1947 for (i = 0; i < dq->count; i++)
1948 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1952 for (i = 1; i < dq->count; i++)
1953 queue_push(&solv->branches, dq->elements[i]);
1954 queue_push(&solv->branches, -level);
1958 p = dq->elements[i];
1960 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
1962 return setpropagatelearn(solv, level, p, disablerules);
1966 /*-----------------------------------------------------------------*/
1967 /* Main solver interface */
1972 * create solver structure
1974 * pool: all available solvables
1975 * installed: installed Solvables
1978 * Upon solving, rules are created to flag the Solvables
1979 * of the 'installed' Repo as installed.
1983 solver_create(Pool *pool, Repo *installed)
1986 solv = (Solver *)sat_calloc(1, sizeof(Solver));
1988 solv->installed = installed;
1990 queue_init(&solv->ruletojob);
1991 queue_init(&solv->decisionq);
1992 queue_init(&solv->decisionq_why);
1993 queue_init(&solv->problems);
1994 queue_init(&solv->suggestions);
1995 queue_init(&solv->recommendations);
1996 queue_init(&solv->learnt_why);
1997 queue_init(&solv->learnt_pool);
1998 queue_init(&solv->branches);
1999 queue_init(&solv->covenantq);
2000 queue_init(&solv->weakruleq);
2001 queue_init(&solv->ruleassertions);
2003 map_init(&solv->recommendsmap, pool->nsolvables);
2004 map_init(&solv->suggestsmap, pool->nsolvables);
2005 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
2006 solv->recommends_index = 0;
2008 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2010 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
2011 memset(solv->rules, 0, sizeof(Rule));
2022 solver_free(Solver *solv)
2024 queue_free(&solv->ruletojob);
2025 queue_free(&solv->decisionq);
2026 queue_free(&solv->decisionq_why);
2027 queue_free(&solv->learnt_why);
2028 queue_free(&solv->learnt_pool);
2029 queue_free(&solv->problems);
2030 queue_free(&solv->suggestions);
2031 queue_free(&solv->recommendations);
2032 queue_free(&solv->branches);
2033 queue_free(&solv->covenantq);
2034 queue_free(&solv->weakruleq);
2035 queue_free(&solv->ruleassertions);
2037 map_free(&solv->recommendsmap);
2038 map_free(&solv->suggestsmap);
2039 map_free(&solv->noupdate);
2040 map_free(&solv->weakrulemap);
2042 sat_free(solv->decisionmap);
2043 sat_free(solv->rules);
2044 sat_free(solv->watches);
2045 sat_free(solv->obsoletes);
2046 sat_free(solv->obsoletes_data);
2051 /*-------------------------------------------------------*/
2056 * all rules have been set up, now actually run the solver
2061 run_solver(Solver *solv, int disablerules, int doweak)
2069 Pool *pool = solv->pool;
2072 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2074 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2075 for (i = 1; i < solv->nrules; i++)
2076 solver_printruleclass(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2079 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2081 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2082 solver_printdecisions(solv);
2084 /* start SAT algorithm */
2086 systemlevel = level + 1;
2087 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2092 * here's the main loop:
2093 * 1) propagate new decisions (only needed for level 1)
2094 * 2) try to keep installed packages
2095 * 3) fulfill all unresolved rules
2096 * 4) install recommended packages
2097 * 5) minimalize solution if we had choices
2098 * if we encounter a problem, we rewind to a safe level and restart
2110 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2111 if ((r = propagate(solv, level)) != 0)
2113 if (analyze_unsolvable(solv, r, disablerules))
2121 * installed packages
2124 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2126 if (!solv->updatesystem)
2128 /* try to keep as many packages as possible */
2129 POOL_DEBUG(SAT_DEBUG_STATS, "installing old packages\n");
2130 for (i = solv->installed->start; i < solv->installed->end; i++)
2132 s = pool->solvables + i;
2133 if (s->repo != solv->installed)
2135 if (solv->decisionmap[i] != 0)
2137 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2139 level = setpropagatelearn(solv, level, i, disablerules);
2145 if (level <= olevel)
2148 if (i < solv->installed->end)
2151 POOL_DEBUG(SAT_DEBUG_STATS, "resolving update/feature rules\n");
2152 for (i = solv->installed->start, r = solv->rules + solv->updaterules; i < solv->installed->end; i++, r++)
2156 s = pool->solvables + i;
2157 if (s->repo != solv->installed)
2159 if (solv->decisionmap[i] > 0)
2161 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2162 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2166 if (rr->d < 0) /* disabled ? */
2167 rr += solv->installed->end - solv->installed->start;
2168 if (!rr->p) /* identical to update rule? */
2170 d = rr->d < 0 ? -rr->d - 1 : rr->d;
2173 if (!rr->w2 || solv->decisionmap[rr->w2] > 0)
2175 if (solv->decisionmap[rr->w2] == 0)
2176 queue_push(&dq, rr->w2);
2180 dp = pool->whatprovidesdata + d;
2181 while ((p = *dp++) != 0)
2183 if (solv->decisionmap[p] > 0)
2185 if (solv->decisionmap[p] == 0)
2191 if (!dq.count && solv->decisionmap[i] != 0)
2194 /* FIXME: i is handled a bit different because we do not want
2195 * to have it pruned just because it is not recommened.
2196 * we should not prune installed packages instead */
2197 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2203 if (level <= olevel)
2206 if (i < solv->installed->end)
2208 systemlevel = level;
2215 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unresolved rules\n");
2216 for (i = 1, n = 1; ; i++, n++)
2218 if (n == solv->nrules)
2220 if (i == solv->nrules)
2222 r = solv->rules + i;
2223 if (r->d < 0) /* ignore disabled rules */
2228 /* binary or unary rule */
2229 /* need two positive undecided literals */
2230 if (r->p < 0 || r->w2 <= 0)
2232 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2234 queue_push(&dq, r->p);
2235 queue_push(&dq, r->w2);
2240 * all negative literals are installed
2241 * no positive literal is installed
2242 * i.e. the rule is not fulfilled and we
2243 * just need to decide on the positive literals
2247 if (solv->decisionmap[-r->p] <= 0)
2252 if (solv->decisionmap[r->p] > 0)
2254 if (solv->decisionmap[r->p] == 0)
2255 queue_push(&dq, r->p);
2257 dp = pool->whatprovidesdata + r->d;
2258 while ((p = *dp++) != 0)
2262 if (solv->decisionmap[-p] <= 0)
2267 if (solv->decisionmap[p] > 0)
2269 if (solv->decisionmap[p] == 0)
2276 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2278 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2279 solver_printruleclass(solv, SAT_DEBUG_PROPAGATE, r);
2281 /* dq.count < 2 cannot happen as this means that
2282 * the rule is unit */
2283 assert(dq.count > 1);
2286 level = selectandinstall(solv, level, &dq, 0, disablerules);
2292 if (level < systemlevel)
2295 } /* for(), decide */
2297 if (n != solv->nrules) /* continue if level < systemlevel */
2304 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
2306 for (i = 1; i < pool->nsolvables; i++)
2308 if (solv->decisionmap[i] < 0)
2310 if (solv->decisionmap[i] > 0)
2312 Id *recp, rec, *pp, p;
2313 s = pool->solvables + i;
2314 /* installed, check for recommends */
2315 /* XXX need to special case AND ? */
2318 recp = s->repo->idarraydata + s->recommends;
2319 while ((rec = *recp++) != 0)
2322 FOR_PROVIDES(p, pp, rec)
2324 if (solv->decisionmap[p] > 0)
2329 else if (solv->decisionmap[p] == 0)
2331 queue_pushunique(&dq, p);
2339 s = pool->solvables + i;
2340 if (!s->supplements && !s->freshens)
2342 if (!pool_installable(pool, s))
2344 if (solver_is_supplementing(solv, s))
2345 queue_pushunique(&dq, i);
2351 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2353 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2354 queue_push(&solv->recommendations, p);
2355 level = setpropagatelearn(solv, level, p, 0);
2360 if (solv->solution_callback)
2362 solv->solution_callback(solv, solv->solution_callback_data);
2363 if (solv->branches.count)
2365 int i = solv->branches.count - 1;
2366 int l = -solv->branches.elements[i];
2368 if (solv->branches.elements[i - 1] < 0)
2370 p = solv->branches.elements[i];
2371 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
2373 for (j = i + 1; j < solv->branches.count; j++)
2374 queue_push(&dq, solv->branches.elements[j]);
2375 solv->branches.count = i;
2377 revert(solv, level);
2379 for (j = 0; j < dq.count; j++)
2380 queue_push(&solv->branches, dq.elements[j]);
2382 level = setpropagatelearn(solv, level, p, disablerules);
2390 /* all branches done, we're finally finished */
2394 /* minimization step */
2395 if (solv->branches.count)
2397 int l = 0, lasti = -1, lastl = -1;
2399 for (i = solv->branches.count - 1; i >= 0; i--)
2401 p = solv->branches.elements[i];
2404 else if (p > 0 && solv->decisionmap[p] > l + 1)
2412 /* kill old solvable so that we do not loop */
2413 p = solv->branches.elements[lasti];
2414 solv->branches.elements[lasti] = 0;
2415 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
2418 revert(solv, level);
2420 level = setpropagatelearn(solv, level, p, disablerules);
2431 POOL_DEBUG(SAT_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable\n", solv->stats_learned, solv->stats_unsolvable);
2433 POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
2440 * at this point, all rules that led to conflicts are disabled.
2441 * we re-enable all rules of a problem set but rule "sug", then
2442 * continue to disable more rules until there as again a solution.
2445 /* FIXME: think about conflicting assertions */
2448 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2450 Pool *pool = solv->pool;
2456 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2458 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
2459 for (i = 0; problem[i]; i++)
2461 if (problem[i] == sug)
2462 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
2463 solver_printproblem(solv, problem[i]);
2466 queue_init(&disabled);
2467 queue_empty(refined);
2468 queue_push(refined, sug);
2470 /* re-enable all problem rules with the exception of "sug"(gestion) */
2474 for (i = 0; problem[i]; i++)
2475 if (problem[i] != sug)
2476 enableproblem(solv, problem[i]);
2479 disableupdaterules(solv, job, -(sug + 1));
2483 int njob, nfeature, nupdate;
2484 queue_empty(&solv->problems);
2485 enableweakrules(solv);
2486 revert(solv, 1); /* XXX no longer needed? */
2489 if (!solv->problems.count)
2490 run_solver(solv, 0, 0);
2492 if (!solv->problems.count)
2494 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
2495 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2496 solver_printdecisions(solv);
2497 break; /* great, no more problems */
2499 disabledcnt = disabled.count;
2500 /* start with 1 to skip over proof index */
2501 njob = nfeature = nupdate = 0;
2502 for (i = 1; i < solv->problems.count - 1; i++)
2504 /* ignore solutions in refined */
2505 v = solv->problems.elements[i];
2507 break; /* end of problem reached */
2508 for (j = 0; problem[j]; j++)
2509 if (problem[j] != sug && problem[j] == v)
2513 if (v >= solv->featurerules && v < solv->learntrules)
2519 queue_push(&disabled, v);
2521 if (disabled.count == disabledcnt)
2523 /* no solution found, this was an invalid suggestion! */
2524 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
2528 if (!njob && nupdate && nfeature)
2530 /* got only update rules, filter out feature rules */
2531 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "throwing away feature rules\n");
2532 for (i = j = disabledcnt; i < disabled.count; i++)
2534 v = disabled.elements[i];
2535 if (v < solv->featurerules || v >= solv->learntrules)
2536 disabled.elements[j++] = v;
2541 if (disabled.count == disabledcnt + 1)
2543 /* just one suggestion, add it to refined list */
2544 v = disabled.elements[disabledcnt];
2546 queue_push(refined, v); /* do not record feature rules */
2547 disableproblem(solv, v);
2548 if (v >= solv->updaterules && v < solv->featurerules)
2550 Rule *r = solv->rules + v + (solv->installed->end - solv->installed->start);
2552 enablerule(solv, r); /* enable corresponding feature rule */
2555 disableupdaterules(solv, job, -(v + 1));
2559 /* more than one solution, disable all */
2560 /* do not push anything on refine list, as we do not know which solution to choose */
2561 /* thus, the user will get another problem if he selects this solution, where he
2562 * can choose the right one */
2563 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2565 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
2566 for (i = disabledcnt; i < disabled.count; i++)
2567 solver_printproblem(solv, disabled.elements[i]);
2569 for (i = disabledcnt; i < disabled.count; i++)
2571 v = disabled.elements[i];
2572 disableproblem(solv, v);
2573 if (v >= solv->updaterules && v < solv->featurerules)
2575 Rule *r = solv->rules + v + (solv->installed->end - solv->installed->start);
2577 enablerule(solv, r);
2582 /* all done, get us back into the same state as before */
2583 /* enable refined rules again */
2584 for (i = 0; i < disabled.count; i++)
2585 enableproblem(solv, disabled.elements[i]);
2586 /* disable problem rules again */
2587 for (i = 0; problem[i]; i++)
2588 disableproblem(solv, problem[i]);
2589 disableupdaterules(solv, job, -1);
2590 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
2594 problems_to_solutions(Solver *solv, Queue *job)
2596 Pool *pool = solv->pool;
2604 if (!solv->problems.count)
2606 queue_clone(&problems, &solv->problems);
2607 queue_init(&solution);
2608 queue_init(&solutions);
2609 /* copy over proof index */
2610 queue_push(&solutions, problems.elements[0]);
2611 problem = problems.elements + 1;
2612 for (i = 1; i < problems.count; i++)
2614 Id v = problems.elements[i];
2617 /* mark end of this problem */
2618 queue_push(&solutions, 0);
2619 queue_push(&solutions, 0);
2620 if (i + 1 == problems.count)
2622 /* copy over proof of next problem */
2623 queue_push(&solutions, problems.elements[i + 1]);
2625 problem = problems.elements + i + 1;
2628 refine_suggestion(solv, job, problem, v, &solution);
2629 if (!solution.count)
2630 continue; /* this solution didn't work out */
2632 for (j = 0; j < solution.count; j++)
2634 why = solution.elements[j];
2635 /* must be either job descriptor or update rule */
2636 assert(why < 0 || (why >= solv->updaterules && why < solv->featurerules));
2638 solver_printproblem(solv, why);
2642 /* job descriptor */
2643 queue_push(&solutions, 0);
2644 queue_push(&solutions, -why);
2648 /* update rule, find replacement package */
2649 Id p, d, *dp, rp = 0;
2651 p = solv->installed->start + (why - solv->updaterules);
2652 if (solv->decisionmap[p] > 0)
2653 continue; /* false alarm, turned out we can keep the package */
2654 rr = solv->rules + solv->featurerules + (why - solv->updaterules);
2656 rr = solv->rules + why;
2659 d = rr->d < 0 ? -rr->d - 1 : rr->d;
2662 if (solv->decisionmap[rr->w2] > 0 && pool->solvables[rr->w2].repo != solv->installed)
2667 for (dp = pool->whatprovidesdata + d; *dp; dp++)
2669 if (solv->decisionmap[*dp] > 0 && pool->solvables[*dp].repo != solv->installed)
2677 queue_push(&solutions, p);
2678 queue_push(&solutions, rp);
2681 /* mark end of this solution */
2682 queue_push(&solutions, 0);
2683 queue_push(&solutions, 0);
2685 queue_free(&solution);
2686 queue_free(&problems);
2687 /* copy queue over to solutions */
2688 queue_free(&solv->problems);
2689 queue_clone(&solv->problems, &solutions);
2691 /* bring solver back into problem state */
2692 revert(solv, 1); /* XXX move to reset_solver? */
2695 assert(solv->problems.count == solutions.count);
2696 queue_free(&solutions);
2700 solver_next_problem(Solver *solv, Id problem)
2704 return solv->problems.count ? 1 : 0;
2705 pp = solv->problems.elements + problem;
2706 while (pp[0] || pp[1])
2710 while (pp[0] || pp[1])
2715 problem = pp - solv->problems.elements;
2716 if (problem >= solv->problems.count)
2722 solver_next_solution(Solver *solv, Id problem, Id solution)
2728 pp = solv->problems.elements + solution;
2729 return pp[0] || pp[1] ? solution : 0;
2731 pp = solv->problems.elements + solution;
2732 while (pp[0] || pp[1])
2735 solution = pp - solv->problems.elements;
2736 return pp[0] || pp[1] ? solution : 0;
2740 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
2743 element = element ? element + 2 : solution;
2744 pp = solv->problems.elements + element;
2745 if (!(pp[0] || pp[1]))
2753 /* this is basically the reverse of addrpmrulesforsolvable */
2755 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
2757 Pool *pool = solv->pool;
2758 Repo *installed = solv->installed;
2762 Id p, d, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
2765 if (rid >= solv->updaterules)
2768 *sourcep = solv->installed->start + (rid - solv->updaterules);
2770 return SOLVER_PROBLEM_UPDATE_RULE;
2772 if (rid >= solv->jobrules)
2775 r = solv->rules + rid;
2776 p = solv->ruletojob.elements[rid - solv->jobrules];
2777 *depp = job->elements[p + 1];
2779 *targetp = job->elements[p];
2780 d = r->d < 0 ? -r->d - 1 : r->d;
2781 if (d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && job->elements[p] != SOLVER_INSTALL_SOLVABLE_ONE_OF)
2782 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
2783 return SOLVER_PROBLEM_JOB_RULE;
2785 r = solv->rules + rid;
2787 d = r->d < 0 ? -r->d - 1 : r->d;
2788 if (d == 0 && r->w2 == 0)
2790 /* a rpm rule assertion */
2791 s = pool->solvables - r->p;
2792 if (installed && !solv->fixsystem && s->repo == installed)
2794 assert(!dontfix); /* dontfix packages never have a neg assertion */
2797 /* see why the package is not installable */
2798 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
2801 return SOLVER_PROBLEM_NOT_INSTALLABLE;
2803 /* check requires */
2806 reqp = s->repo->idarraydata + s->requires;
2807 while ((req = *reqp++) != 0)
2809 if (req == SOLVABLE_PREREQMARKER)
2811 dp = pool_whatprovides(pool, req);
2818 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
2821 assert(!solv->allowselfconflicts);
2822 assert(s->conflicts);
2823 conp = s->repo->idarraydata + s->conflicts;
2824 while ((con = *conp++) != 0)
2825 FOR_PROVIDES(p, pp, con)
2829 return SOLVER_PROBLEM_SELF_CONFLICT;
2833 s = pool->solvables - r->p;
2834 if (installed && !solv->fixsystem && s->repo == installed)
2836 if (d == 0 && r->w2 < 0)
2838 /* a package conflict */
2839 Solvable *s2 = pool->solvables - r->w2;
2842 if (installed && !solv->fixsystem && s2->repo == installed)
2845 /* if both packages have the same name and at least one of them
2846 * is not installed, they conflict */
2847 if (s->name == s2->name && (!installed || (s->repo != installed || s2->repo != installed)))
2852 return SOLVER_PROBLEM_SAME_NAME;
2855 /* check conflicts in both directions */
2858 conp = s->repo->idarraydata + s->conflicts;
2859 while ((con = *conp++) != 0)
2861 FOR_PROVIDES(p, pp, con)
2863 if (dontfix && pool->solvables[p].repo == installed)
2870 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
2876 conp = s2->repo->idarraydata + s2->conflicts;
2877 while ((con = *conp++) != 0)
2879 FOR_PROVIDES(p, pp, con)
2881 if (dontfix2 && pool->solvables[p].repo == installed)
2888 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
2892 /* check obsoletes in both directions */
2893 if ((!installed || s->repo != installed) && s->obsoletes)
2895 obsp = s->repo->idarraydata + s->obsoletes;
2896 while ((obs = *obsp++) != 0)
2898 Id obsname = dep2name(pool, obs);
2899 FOR_PROVIDES(p, pp, obs)
2903 if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
2908 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
2912 if ((!installed || s2->repo != installed) && s2->obsoletes)
2914 obsp = s2->repo->idarraydata + s2->obsoletes;
2915 while ((obs = *obsp++) != 0)
2917 Id obsname = dep2name(pool, obs);
2918 FOR_PROVIDES(p, pp, obs)
2922 if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
2927 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
2931 if (solv->implicitobsoleteusesprovides && (!installed || s->repo != installed))
2933 FOR_PROVIDES(p, pp, s->name)
2940 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
2943 if (solv->implicitobsoleteusesprovides && (!installed || s2->repo != installed))
2945 FOR_PROVIDES(p, pp, s2->name)
2952 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
2955 /* all cases checked, can't happen */
2958 /* simple requires */
2959 assert(s->requires);
2960 reqp = s->repo->idarraydata + s->requires;
2961 while ((req = *reqp++) != 0)
2963 if (req == SOLVABLE_PREREQMARKER)
2965 dp = pool_whatprovides(pool, req);
2968 if (*dp == r->w2 && dp[1] == 0)
2971 else if (dp - pool->whatprovidesdata == d)
2978 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
2982 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
2985 Id lreqr, lconr, lsysr, ljobr;
2989 lreqr = lconr = lsysr = ljobr = 0;
2990 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
2993 if (rid >= solv->learntrules)
2994 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
2995 else if (rid >= solv->updaterules)
3000 else if (rid >= solv->jobrules)
3007 r = solv->rules + rid;
3008 d = r->d < 0 ? -r->d - 1 : r->d;
3009 if (!d && r->w2 < 0)
3016 if (!d && r->w2 == 0 && !reqassert)
3018 /* prefer assertions (XXX: bad idea?) */
3024 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed)
3026 /* prefer rules of installed packages */
3027 Id op = *reqrp >= 0 ? solv->rules[*reqrp].p : -*reqrp;
3028 if (op <= 0 || solv->pool->solvables[op].repo != solv->installed)
3034 if (!*reqrp && lreqr)
3036 if (!*conrp && lconr)
3038 if (!*jobrp && ljobr)
3040 if (!*sysrp && lsysr)
3045 * search for a rule that describes the problem to the
3046 * user. A pretty hopeless task, actually. We currently
3047 * prefer simple requires.
3050 solver_findproblemrule(Solver *solv, Id problem)
3052 Id reqr, conr, sysr, jobr;
3053 Id idx = solv->problems.elements[problem - 1];
3054 reqr = conr = sysr = jobr = 0;
3055 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3068 /* create reverse obsoletes map for installed solvables
3070 * for each installed solvable find which packages with *different* names
3071 * obsolete the solvable.
3072 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3076 create_obsolete_index(Solver *solv)
3078 Pool *pool = solv->pool;
3080 Repo *installed = solv->installed;
3081 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3084 if (!installed || !installed->nsolvables)
3086 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
3087 for (i = 1; i < pool->nsolvables; i++)
3089 s = pool->solvables + i;
3092 if (!pool_installable(pool, s))
3094 obsp = s->repo->idarraydata + s->obsoletes;
3095 while ((obs = *obsp++) != 0)
3096 FOR_PROVIDES(p, pp, obs)
3098 if (pool->solvables[p].repo != installed)
3100 if (pool->solvables[p].name == s->name)
3102 obsoletes[p - installed->start]++;
3106 for (i = 0; i < installed->nsolvables; i++)
3109 n += obsoletes[i] + 1;
3112 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
3113 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
3114 for (i = pool->nsolvables - 1; i > 0; i--)
3116 s = pool->solvables + i;
3119 if (!pool_installable(pool, s))
3121 obsp = s->repo->idarraydata + s->obsoletes;
3122 while ((obs = *obsp++) != 0)
3123 FOR_PROVIDES(p, pp, obs)
3125 if (pool->solvables[p].repo != installed)
3127 if (pool->solvables[p].name == s->name)
3129 p -= installed->start;
3130 if (obsoletes_data[obsoletes[p]] != i)
3131 obsoletes_data[--obsoletes[p]] = i;
3137 removedisabledconflicts(Solver *solv, Queue *removed)
3139 Pool *pool = solv->pool;
3144 Id *decisionmap = solv->decisionmap;
3146 POOL_DEBUG(SAT_DEBUG_STATS, "removedisabledconflicts\n");
3147 queue_empty(removed);
3148 for (i = 0; i < solv->decisionq.count; i++)
3150 p = solv->decisionq.elements[i];
3153 /* a conflict. we never do conflicts on free decisions, so there
3154 * must have been an unit rule */
3155 why = solv->decisionq_why.elements[i];
3157 r = solv->rules + why;
3158 if (r->d < 0 && decisionmap[-p])
3160 /* rule is now disabled, remove from decisionmap */
3161 POOL_DEBUG(SAT_DEBUG_STATS, "removing conflict for package %s[%d]\n", solvable2str(pool, pool->solvables - p), -p);
3162 queue_push(removed, -p);
3163 queue_push(removed, decisionmap[-p]);
3164 decisionmap[-p] = 0;
3167 if (!removed->count)
3169 /* we removed some confliced packages. some of them might still
3170 * be in conflict, so search for unit rules and re-conflict */
3172 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
3174 if (i == solv->nrules)
3177 r = solv->rules + i;
3183 if (r->p < 0 && !decisionmap[-r->p])
3189 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
3191 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
3196 if (r->p < 0 && decisionmap[-r->p] == 0)
3198 if (new || DECISIONMAP_FALSE(r->p))
3200 dp = pool->whatprovidesdata + r->d;
3201 while ((p = *dp++) != 0)
3203 if (new && p == new)
3205 if (p < 0 && decisionmap[-p] == 0)
3214 else if (!DECISIONMAP_FALSE(p))
3224 POOL_DEBUG(SAT_DEBUG_STATS, "re-conflicting package %s[%d]\n", solvable2str(pool, pool->solvables - new), -new);
3225 decisionmap[-new] = -1;
3227 n = 0; /* redo all rules */
3233 weaken_solvable_deps(Solver *solv, Id p)
3238 for (i = 1, r = solv->rules + i; i < solv->jobrules; i++, r++)
3242 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3243 continue; /* conflict */
3244 queue_push(&solv->weakruleq, i);
3248 /*-----------------------------------------------------------------*/
3258 solver_solve(Solver *solv, Queue *job)
3260 Pool *pool = solv->pool;
3261 Repo *installed = solv->installed;
3264 Map addedmap; /* '1' == have rpm-rules for solvable */
3265 Id how, what, weak, name, p, *pp, d;
3271 /* create whatprovides if not already there */
3272 if (!pool->whatprovides)
3273 pool_createwhatprovides(pool);
3275 /* create obsolete index if needed */
3276 if (solv->noupdateprovide)
3277 create_obsolete_index(solv);
3280 * create basic rule set of all involved packages
3281 * use addedmap bitmap to make sure we don't create rules twice
3285 map_init(&addedmap, pool->nsolvables);
3289 * always install our system solvable
3291 MAPSET(&addedmap, SYSTEMSOLVABLE);
3292 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3293 queue_push(&solv->decisionq_why, 0);
3294 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3297 * create rules for all package that could be involved with the solving
3298 * so called: rpm rules
3303 oldnrules = solv->nrules;
3304 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
3305 FOR_REPO_SOLVABLES(installed, p, s)
3306 addrpmrulesforsolvable(solv, s, &addedmap);
3307 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3308 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
3309 oldnrules = solv->nrules;
3310 FOR_REPO_SOLVABLES(installed, p, s)
3311 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3312 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3315 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
3316 oldnrules = solv->nrules;
3317 for (i = 0; i < job->count; i += 2)
3319 how = job->elements[i] & ~SOLVER_WEAK;
3320 what = job->elements[i + 1];
3324 case SOLVER_INSTALL_SOLVABLE:
3325 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3327 case SOLVER_INSTALL_SOLVABLE_NAME:
3328 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3329 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3330 while (ISRELDEP(name))
3332 Reldep *rd = GETRELDEP(pool, name);
3335 FOR_PROVIDES(p, pp, what)
3337 /* if by name, ensure that the name matches */
3338 if (name && pool->solvables[p].name != name)
3340 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3343 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3344 /* dont allow downgrade */
3345 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3347 case SOLVER_INSTALL_SOLVABLE_ONE_OF:
3348 pp = pool->whatprovidesdata + what;
3349 while ((p = *pp++) != 0)
3350 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3354 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3356 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
3358 oldnrules = solv->nrules;
3359 addrpmrulesforweak(solv, &addedmap);
3360 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3362 IF_POOLDEBUG (SAT_DEBUG_STATS)
3364 int possible = 0, installable = 0;
3365 for (i = 1; i < pool->nsolvables; i++)
3367 if (pool_installable(pool, pool->solvables + i))
3369 if (MAPTST(&addedmap, i))
3372 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3376 * first pass done, we now have all the rpm rules we need.
3377 * unify existing rules before going over all job rules and
3379 * at this point the system is always solvable,
3380 * as an empty system (remove all packages) is a valid solution
3383 unifyrules(solv); /* remove duplicate rpm rules */
3384 solv->directdecisions = solv->decisionq.count;
3386 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
3387 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3388 solver_printdecisions (solv);
3391 * now add all job rules
3394 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
3396 solv->jobrules = solv->nrules;
3398 for (i = 0; i < job->count; i += 2)
3400 oldnrules = solv->nrules;
3402 how = job->elements[i] & ~SOLVER_WEAK;
3403 weak = job->elements[i] & SOLVER_WEAK;
3404 what = job->elements[i + 1];
3407 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3408 s = pool->solvables + what;
3409 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall solvable %s\n", weak ? "weak " : "", solvable2str(pool, s));
3410 addrule(solv, what, 0); /* install by Id */
3411 queue_push(&solv->ruletojob, i);
3413 queue_push(&solv->weakruleq, solv->nrules - 1);
3415 case SOLVER_ERASE_SOLVABLE:
3416 s = pool->solvables + what;
3417 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase solvable %s\n", weak ? "weak " : "", solvable2str(pool, s));
3418 addrule(solv, -what, 0); /* remove by Id */
3419 queue_push(&solv->ruletojob, i);
3421 queue_push(&solv->weakruleq, solv->nrules - 1);
3423 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3424 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3425 if (how == SOLVER_INSTALL_SOLVABLE_NAME)
3426 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall name %s\n", weak ? "weak " : "", dep2str(pool, what));
3427 if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3428 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall provides %s\n", weak ? "weak " : "", dep2str(pool, what));
3430 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3431 while (ISRELDEP(name))
3433 Reldep *rd = GETRELDEP(pool, name);
3436 FOR_PROVIDES(p, pp, what)
3438 /* if by name, ensure that the name matches */
3439 if (name && pool->solvables[p].name != name)
3445 /* no provider, make this an impossible rule */
3446 queue_push(&q, -SYSTEMSOLVABLE);
3449 p = queue_shift(&q); /* get first provider */
3451 d = 0; /* single provider ? -> make assertion */
3453 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3454 addrule(solv, p, d); /* add 'requires' rule */
3455 queue_push(&solv->ruletojob, i);
3457 queue_push(&solv->weakruleq, solv->nrules - 1);
3459 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3460 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3461 if (how == SOLVER_ERASE_SOLVABLE_NAME)
3462 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase name %s\n", weak ? "weak " : "", dep2str(pool, what));
3463 if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3464 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase provides %s\n", weak ? "weak " : "", dep2str(pool, what));
3465 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
3466 while (ISRELDEP(name))
3468 Reldep *rd = GETRELDEP(pool, name);
3471 FOR_PROVIDES(p, pp, what)
3473 /* if by name, ensure that the name matches */
3474 if (name && pool->solvables[p].name != name)
3476 addrule(solv, -p, 0); /* add 'remove' rule */
3477 queue_push(&solv->ruletojob, i);
3479 queue_push(&solv->weakruleq, solv->nrules - 1);
3482 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3483 s = pool->solvables + what;
3484 POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solvable2str(pool, s));
3485 addupdaterule(solv, s, 0);
3486 queue_push(&solv->ruletojob, i);
3488 queue_push(&solv->weakruleq, solv->nrules - 1);
3490 case SOLVER_INSTALL_SOLVABLE_ONE_OF:
3491 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sone of\n", weak ? "weak " : "");
3492 for (pp = pool->whatprovidesdata + what; *pp; pp++)
3493 POOL_DEBUG(SAT_DEBUG_JOB, " %s\n", solvable2str(pool, pool->solvables + *pp));
3494 addrule(solv, -SYSTEMSOLVABLE, what);
3495 queue_push(&solv->ruletojob, i);
3497 queue_push(&solv->weakruleq, solv->nrules - 1);
3499 case SOLVER_WEAKEN_SOLVABLE_DEPS:
3500 s = pool->solvables + what;
3501 POOL_DEBUG(SAT_DEBUG_JOB, "job: weaken deps %s\n", solvable2str(pool, s));
3502 weaken_solvable_deps(solv, what);
3505 IF_POOLDEBUG (SAT_DEBUG_JOB)
3508 if (solv->nrules == oldnrules)
3509 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created\n");
3510 for (j = oldnrules; j < solv->nrules; j++)
3512 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
3513 solver_printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
3517 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3520 * now add update rules
3524 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add update rules ***\n");
3529 * create rules for updating installed solvables
3533 solv->updaterules = solv->nrules;
3535 { /* loop over all installed solvables */
3536 /* we create all update rules, but disable some later on depending on the job */
3537 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3539 /* no update rules for patch atoms */
3540 if (s->freshens && !s->supplements)
3542 const char *name = id2str(pool, s->name);
3543 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
3545 addrule(solv, 0, 0);
3549 if (s->repo != installed)
3551 addrule(solv, 0, 0); /* create dummy rule */
3554 addupdaterule(solv, s, 0); /* allowall = 0 */
3555 if (solv->allowuninstall)
3556 queue_push(&solv->weakruleq, solv->nrules - 1);
3558 /* consistency check: we added a rule for _every_ installed solvable */
3559 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
3562 /* create feature rules */
3563 /* those are used later on to keep a version of the installed packages in
3565 solv->featurerules = solv->nrules;
3568 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3571 if (s->freshens && !s->supplements)
3573 const char *name = id2str(pool, s->name);
3574 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
3576 addrule(solv, 0, 0);
3580 if (s->repo != installed)
3582 addrule(solv, 0, 0); /* create dummy rule */
3585 addupdaterule(solv, s, 1);
3586 r = solv->rules + solv->nrules - 1;
3587 sr = r - (installed->end - installed->start);
3588 unifyrules_sortcmp_data = pool;
3589 if (!unifyrules_sortcmp(r, sr))
3591 /* identical rule, kill feature rule */
3592 memset(r, 0, sizeof(*r));
3595 disablerule(solv, r);
3596 if (r->p && solv->allowuninstall)
3597 queue_push(&solv->weakruleq, solv->nrules - 1);
3599 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
3602 /* free unneeded memory */
3603 map_free(&addedmap);
3606 /* create weak map */
3607 map_init(&solv->weakrulemap, solv->nrules);
3608 for (i = 0; i < solv->weakruleq.count; i++)
3610 p = solv->weakruleq.elements[i];
3611 MAPSET(&solv->weakrulemap, p);
3614 /* all new rules are learnt after this point */
3615 solv->learntrules = solv->nrules;
3617 /* create assertion index. it is only used to speed up
3618 * makeruledecsions() a bit */
3619 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
3620 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
3621 queue_push(&solv->ruleassertions, i);
3623 /* disable update rules that conflict with our job */
3624 disableupdaterules(solv, job, -1);
3627 /* make decisions based on job/update assertions */
3628 makeruledecisions(solv);
3630 /* create watches chains */
3633 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
3636 run_solver(solv, 1, solv->dontinstallrecommended ? 0 : 1);
3640 /* disable all erase jobs (including weak "keep uninstalled" rules) */
3641 for (i = solv->jobrules, r = solv->rules + i; i < solv->updaterules; i++, r++)
3643 if (r->d < 0) /* disabled ? */
3645 if (r->p > 0) /* install job? */
3647 disablerule(solv, r);
3653 enabledisablelearntrules(solv);
3654 removedisabledconflicts(solv, &redoq);
3657 /* find recommended packages */
3658 /* if redoq.count == 0 we already found all recommended in the
3660 if (redoq.count || solv->dontinstallrecommended || !solv->dontshowinstalledrecommended)
3662 Id rec, *recp, p, *pp;
3664 /* create map of all recommened packages */
3665 solv->recommends_index = -1;
3666 MAPZERO(&solv->recommendsmap);
3667 for (i = 0; i < solv->decisionq.count; i++)
3669 p = solv->decisionq.elements[i];
3672 s = pool->solvables + p;
3675 recp = s->repo->idarraydata + s->recommends;
3676 while ((rec = *recp++) != 0)
3678 FOR_PROVIDES(p, pp, rec)
3679 if (solv->decisionmap[p] > 0)
3683 if (!solv->dontshowinstalledrecommended)
3685 FOR_PROVIDES(p, pp, rec)
3686 if (solv->decisionmap[p] > 0)
3687 MAPSET(&solv->recommendsmap, p);
3689 continue; /* p != 0: already fulfilled */
3691 FOR_PROVIDES(p, pp, rec)
3692 MAPSET(&solv->recommendsmap, p);
3696 for (i = 1; i < pool->nsolvables; i++)
3698 if (solv->decisionmap[i] < 0)
3700 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
3702 s = pool->solvables + i;
3703 if (!MAPTST(&solv->recommendsmap, i))
3705 if (!s->supplements)
3707 if (!pool_installable(pool, s))
3709 if (!solver_is_supplementing(solv, s))
3712 if (solv->dontinstallrecommended)
3713 queue_push(&solv->recommendations, i);
3715 queue_pushunique(&solv->recommendations, i);
3717 /* we use MODE_SUGGEST here so that repo prio is ignored */
3718 policy_filter_unwanted(solv, &solv->recommendations, 0, POLICY_MODE_SUGGEST);
3721 /* find suggested packages */
3724 Id sug, *sugp, p, *pp;
3726 /* create map of all suggests that are still open */
3727 solv->recommends_index = -1;
3728 MAPZERO(&solv->suggestsmap);
3729 for (i = 0; i < solv->decisionq.count; i++)
3731 p = solv->decisionq.elements[i];
3734 s = pool->solvables + p;
3737 sugp = s->repo->idarraydata + s->suggests;
3738 while ((sug = *sugp++) != 0)
3740 FOR_PROVIDES(p, pp, sug)
3741 if (solv->decisionmap[p] > 0)
3745 if (!solv->dontshowinstalledrecommended)
3747 FOR_PROVIDES(p, pp, sug)
3748 if (solv->decisionmap[p] > 0)
3749 MAPSET(&solv->suggestsmap, p);
3751 continue; /* already fulfilled */
3753 FOR_PROVIDES(p, pp, sug)
3754 MAPSET(&solv->suggestsmap, p);
3758 for (i = 1; i < pool->nsolvables; i++)
3760 if (solv->decisionmap[i] < 0)
3762 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
3764 s = pool->solvables + i;
3765 if (!MAPTST(&solv->suggestsmap, i))
3769 if (!pool_installable(pool, s))
3771 if (!solver_is_enhancing(solv, s))
3774 queue_push(&solv->suggestions, i);
3776 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
3781 /* restore decisionmap */
3782 for (i = 0; i < redoq.count; i += 2)
3783 solv->decisionmap[redoq.elements[i]] = redoq.elements[i + 1];
3787 if (solv->problems.count)
3789 int recocount = solv->recommendations.count;
3790 solv->recommendations.count = 0; /* so that revert() doesn't mess with it */
3791 queue_empty(&redoq);
3792 for (i = 0; i < solv->decisionq.count; i++)
3794 Id p = solv->decisionq.elements[i];
3795 queue_push(&redoq, p);
3796 queue_push(&redoq, solv->decisionq_why.elements[i]);
3797 queue_push(&redoq, solv->decisionmap[p > 0 ? p : -p]);
3799 problems_to_solutions(solv, job);
3800 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
3801 queue_empty(&solv->decisionq);
3802 queue_empty(&solv->decisionq_why);
3803 for (i = 0; i < redoq.count; i += 3)
3805 Id p = redoq.elements[i];
3806 queue_push(&solv->decisionq, p);
3807 queue_push(&solv->decisionq_why, redoq.elements[i + 1]);
3808 solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
3810 solv->recommendations.count = recocount;
3813 POOL_DEBUG(SAT_DEBUG_STATS, "final solver statistics: %d learned rules, %d unsolvable\n", solv->stats_learned, solv->stats_unsolvable);
3817 /***********************************************************************/
3820 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
3824 solver_create_state_maps(solv, &installedmap, 0);
3825 pool_calc_duchanges(solv->pool, solv->installed, &installedmap, mps, nmps);
3826 map_free(&installedmap);
3830 solver_calc_installsizechange(Solver *solv)
3835 solver_create_state_maps(solv, &installedmap, 0);
3836 change = pool_calc_installsizechange(solv->pool, solv->installed, &installedmap);
3837 map_free(&installedmap);