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->rpmrules_end)
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->rpmrules_end)
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->jobrules_end; i++, r++, jp++)
465 disablerule(solv, r);
469 enableproblem(Solver *solv, Id v)
477 if (v >= solv->featurerules && v < solv->featurerules_end)
479 /* do not enable feature rule if update rule is enabled */
480 r = solv->rules + (v - solv->featurerules + solv->updaterules);
484 enablerule(solv, solv->rules + v);
485 if (v >= solv->updaterules && v < solv->updaterules_end)
487 /* disable feature rule when enabling update rule */
488 r = solv->rules + (v - solv->updaterules + solv->featurerules);
490 disablerule(solv, r);
495 jp = solv->ruletojob.elements;
496 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
502 /************************************************************************/
504 /* go through update and job rules and add direct assertions
505 * to the decisionqueue. If we find a conflict, disable rules and
506 * add them to problem queue.
509 makeruledecisions(Solver *solv)
511 Pool *pool = solv->pool;
517 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
519 decisionstart = solv->decisionq.count;
520 for (ii = 0; ii < solv->ruleassertions.count; ii++)
522 ri = solv->ruleassertions.elements[ii];
523 r = solv->rules + ri;
524 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
526 /* do weak rules in phase 2 */
527 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
531 if (!solv->decisionmap[vv])
533 queue_push(&solv->decisionq, v);
534 queue_push(&solv->decisionq_why, r - solv->rules);
535 solv->decisionmap[vv] = v > 0 ? 1 : -1;
536 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
538 Solvable *s = solv->pool->solvables + vv;
540 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
542 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
546 if (v > 0 && solv->decisionmap[vv] > 0)
548 if (v < 0 && solv->decisionmap[vv] < 0)
550 /* found a conflict! */
551 if (ri >= solv->learntrules)
553 /* conflict with a learnt rule */
554 /* can happen when packages cannot be installed for
555 * multiple reasons. */
556 /* we disable the learnt rule in this case */
557 disablerule(solv, r);
560 /* find the decision which is the "opposite" of the rule */
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->jobrules && ri < solv->jobrules_end)
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->rpmrules_end)
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->jobrules && ri < solv->jobrules_end)
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/feature 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->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
612 if (rr->d < 0 || rr->w2)
614 if (rr->p != vv && rr->p != -vv)
616 if (MAPTST(&solv->weakrulemap, i))
618 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
619 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, solv->rules + i);
621 if (i >= solv->jobrules && i < solv->jobrules_end)
622 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
623 queue_push(&solv->problems, v);
624 disableproblem(solv, v);
626 queue_push(&solv->problems, 0);
629 while (solv->decisionq.count > decisionstart)
631 v = solv->decisionq.elements[--solv->decisionq.count];
632 --solv->decisionq_why.count;
634 solv->decisionmap[vv] = 0;
639 /* phase 2: now do the weak assertions */
640 for (ii = 0; ii < solv->ruleassertions.count; ii++)
642 ri = solv->ruleassertions.elements[ii];
643 r = solv->rules + ri;
644 if (r->d < 0 || r->w2) /* disabled or no assertion */
646 if (!MAPTST(&solv->weakrulemap, ri))
650 if (!solv->decisionmap[vv])
652 queue_push(&solv->decisionq, v);
653 queue_push(&solv->decisionq_why, r - solv->rules);
654 solv->decisionmap[vv] = v > 0 ? 1 : -1;
655 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
657 Solvable *s = solv->pool->solvables + vv;
659 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", solvable2str(solv->pool, s));
661 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", solvable2str(solv->pool, s));
665 if (v > 0 && solv->decisionmap[vv] > 0)
667 if (v < 0 && solv->decisionmap[vv] < 0)
669 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
670 solver_printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
671 disablerule(solv, r);
674 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
678 * we have enabled or disabled some of our rules. We now reenable all
679 * of our learnt rules but the ones that were learnt from rules that
683 enabledisablelearntrules(Solver *solv)
685 Pool *pool = solv->pool;
690 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
691 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
693 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
694 while ((why = *whyp++) != 0)
696 assert(why > 0 && why < i);
697 if (solv->rules[why].d < 0)
700 /* why != 0: we found a disabled rule, disable the learnt rule */
701 if (why && r->d >= 0)
703 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
705 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling ");
706 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
708 disablerule(solv, r);
710 else if (!why && r->d < 0)
712 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
714 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling ");
715 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
723 enableweakrules(Solver *solv)
728 for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
732 if (!MAPTST(&solv->weakrulemap, i))
739 /* FIXME: bad code ahead, replace as soon as possible */
740 /* FIXME: should probably look at SOLVER_INSTALL_SOLVABLE_ONE_OF */
743 disableupdaterules(Solver *solv, Queue *job, int jobidx)
745 Pool *pool = solv->pool;
747 Id name, how, what, p, *pp;
753 installed = solv->installed;
759 how = job->elements[jobidx] & ~SOLVER_WEAK;
762 case SOLVER_INSTALL_SOLVABLE:
763 case SOLVER_ERASE_SOLVABLE:
764 case SOLVER_ERASE_SOLVABLE_NAME:
765 case SOLVER_ERASE_SOLVABLE_PROVIDES:
771 /* go through all enabled job rules */
772 MAPZERO(&solv->noupdate);
773 for (i = solv->jobrules; i < solv->jobrules_end; i++)
776 if (r->d < 0) /* disabled? */
778 j = solv->ruletojob.elements[i - solv->jobrules];
782 how = job->elements[j] & ~SOLVER_WEAK;
783 what = job->elements[j + 1];
786 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
787 s = pool->solvables + what;
788 FOR_PROVIDES(p, pp, s->name)
790 if (pool->solvables[p].name != s->name)
792 if (pool->solvables[p].repo == installed)
793 MAPSET(&solv->noupdate, p - installed->start);
796 case SOLVER_ERASE_SOLVABLE:
797 s = pool->solvables + what;
798 if (s->repo == installed)
799 MAPSET(&solv->noupdate, what - installed->start);
801 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
802 case SOLVER_ERASE_SOLVABLE_PROVIDES:
803 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
804 while (ISRELDEP(name))
806 Reldep *rd = GETRELDEP(pool, name);
809 FOR_PROVIDES(p, pp, what)
811 if (name && pool->solvables[p].name != name)
813 if (pool->solvables[p].repo == installed)
814 MAPSET(&solv->noupdate, p - installed->start);
822 /* fixup update rule status */
825 /* we just disabled job #jobidx. enable all update rules
826 * that aren't disabled by the remaining job rules */
827 how = job->elements[jobidx] & ~SOLVER_WEAK;
828 what = job->elements[jobidx + 1];
831 case SOLVER_INSTALL_SOLVABLE:
832 s = pool->solvables + what;
833 FOR_PROVIDES(p, pp, s->name)
835 if (pool->solvables[p].name != s->name)
837 if (pool->solvables[p].repo != installed)
839 if (MAPTST(&solv->noupdate, p - installed->start))
841 r = solv->rules + solv->updaterules + (p - installed->start);
845 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
847 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
848 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
852 case SOLVER_ERASE_SOLVABLE:
853 s = pool->solvables + what;
854 if (s->repo != installed)
856 if (MAPTST(&solv->noupdate, what - installed->start))
858 r = solv->rules + solv->updaterules + (what - installed->start);
862 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
864 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
865 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
868 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
869 case SOLVER_ERASE_SOLVABLE_PROVIDES:
870 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
871 while (ISRELDEP(name))
873 Reldep *rd = GETRELDEP(pool, name);
876 FOR_PROVIDES(p, pp, what)
878 if (name && pool->solvables[p].name != name)
880 if (pool->solvables[p].repo != installed)
882 if (MAPTST(&solv->noupdate, p - installed->start))
884 r = solv->rules + solv->updaterules + (p - installed->start);
888 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
890 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
891 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
901 for (i = 0; i < installed->nsolvables; i++)
903 r = solv->rules + solv->updaterules + i;
904 if (r->d >= 0 && MAPTST(&solv->noupdate, i))
905 disablerule(solv, r); /* was enabled, need to disable */
906 r = solv->rules + solv->featurerules + i;
907 if (r->d >= 0 && MAPTST(&solv->noupdate, i))
908 disablerule(solv, r); /* was enabled, need to disable */
914 addpatchatomrequires(Solver *solv, Solvable *s, Id *dp, Queue *q, Map *m)
916 Pool *pool = solv->pool;
917 Id fre, *frep, p, *pp, ndp;
923 queue_init_buffer(&fq, qbuf, sizeof(qbuf)/sizeof(*qbuf));
924 queue_push(&fq, -(s - pool->solvables));
926 queue_push(&fq, *dp);
927 ndp = pool_queuetowhatprovides(pool, &fq);
928 frep = s->repo->idarraydata + s->freshens;
929 while ((fre = *frep++) != 0)
931 FOR_PROVIDES(p, pp, fre)
933 ps = pool->solvables + p;
934 addrule(solv, -p, ndp);
942 for (i = 1; i < fq.count; i++)
955 * add (install) rules for solvable
956 * for unfulfilled requirements, conflicts, obsoletes,....
957 * add a negative assertion for solvables that are not installable
961 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
963 Pool *pool = solv->pool;
964 Repo *installed = solv->installed;
979 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
981 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
982 queue_push(&q, s - pool->solvables); /* push solvable Id */
988 * s: Pointer to solvable
992 if (MAPTST(m, n)) /* continue if already done */
996 s = pool->solvables + n; /* s = Solvable in question */
999 if (installed /* Installed system available */
1000 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
1001 && s->repo == installed) /* solvable is installed? */
1003 dontfix = 1; /* dont care about broken rpm deps */
1006 if (!dontfix && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
1008 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
1009 addrule(solv, -n, 0); /* uninstallable */
1013 if (s->freshens && !s->supplements)
1015 const char *name = id2str(pool, s->name);
1016 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
1020 /*-----------------------------------------
1021 * check requires of s
1026 reqp = s->repo->idarraydata + s->requires;
1027 while ((req = *reqp++) != 0) /* go throw all requires */
1029 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
1032 dp = pool_whatprovides(pool, req);
1034 if (*dp == SYSTEMSOLVABLE) /* always installed */
1040 addpatchatomrequires(solv, s, dp, &q, m);
1046 /* the strategy here is to not insist on dependencies
1047 * that are already broken. so if we find one provider
1048 * that was already installed, we know that the
1049 * dependency was not broken before so we enforce it */
1050 for (i = 0; (p = dp[i]) != 0; i++) /* for all providers */
1052 if (pool->solvables[p].repo == installed)
1053 break; /* provider was installed */
1055 if (!p) /* previously broken dependency */
1057 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1064 /* nothing provides req! */
1065 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1066 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1070 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1072 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1073 for (i = 0; dp[i]; i++)
1074 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1077 /* add 'requires' dependency */
1078 /* rule: (-requestor|provider1|provider2|...|providerN) */
1079 addrule(solv, -n, dp - pool->whatprovidesdata);
1081 /* descend the dependency tree */
1082 for (; *dp; dp++) /* loop through all providers */
1084 if (!MAPTST(m, *dp))
1085 queue_push(&q, *dp);
1088 } /* while, requirements of n */
1090 } /* if, requirements */
1092 /* that's all we check for src packages */
1093 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1096 /*-----------------------------------------
1097 * check conflicts of s
1102 conp = s->repo->idarraydata + s->conflicts;
1103 while ((con = *conp++) != 0)
1105 FOR_PROVIDES(p, pp, con)
1107 /* dontfix: dont care about conflicts with already installed packs */
1108 if (dontfix && pool->solvables[p].repo == installed)
1110 if (p == n && !solv->allowselfconflicts)
1111 p = 0; /* make it a negative assertion */
1112 /* rule: -n|-p: either solvable _or_ provider of conflict */
1113 addrule(solv, -n, -p);
1118 /*-----------------------------------------
1119 * check obsoletes if not installed
1121 if (!installed || pool->solvables[n].repo != installed)
1122 { /* not installed */
1125 obsp = s->repo->idarraydata + s->obsoletes;
1126 while ((obs = *obsp++) != 0)
1128 Id obsname = dep2name(pool, obs);
1129 FOR_PROVIDES(p, pp, obs)
1131 if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
1133 addrule(solv, -n, -p);
1137 FOR_PROVIDES(p, pp, s->name)
1139 if (!solv->implicitobsoleteusesprovides && s->name != pool->solvables[p].name)
1141 addrule(solv, -n, -p);
1145 /*-----------------------------------------
1146 * add recommends to the rule list
1150 recp = s->repo->idarraydata + s->recommends;
1151 while ((rec = *recp++) != 0)
1153 FOR_PROVIDES(p, pp, rec)
1160 sugp = s->repo->idarraydata + s->suggests;
1161 while ((sug = *sugp++) != 0)
1163 FOR_PROVIDES(p, pp, sug)
1170 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1174 addrpmrulesforweak(Solver *solv, Map *m)
1176 Pool *pool = solv->pool;
1181 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1182 for (i = n = 1; n < pool->nsolvables; i++, n++)
1184 if (i == pool->nsolvables)
1188 s = pool->solvables + i;
1189 if (!pool_installable(pool, s))
1194 supp = s->repo->idarraydata + s->supplements;
1195 while ((sup = *supp++) != ID_NULL)
1196 if (dep_possible(solv, sup, m))
1199 if (!sup && s->freshens)
1201 supp = s->repo->idarraydata + s->freshens;
1202 while ((sup = *supp++) != ID_NULL)
1203 if (dep_possible(solv, sup, m))
1206 if (!sup && s->enhances)
1208 supp = s->repo->idarraydata + s->enhances;
1209 while ((sup = *supp++) != ID_NULL)
1210 if (dep_possible(solv, sup, m))
1215 addrpmrulesforsolvable(solv, s, m);
1218 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1222 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
1224 Pool *pool = solv->pool;
1229 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1231 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1232 policy_findupdatepackages(solv, s, &qs, allowall);
1233 if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
1234 addrpmrulesforsolvable(solv, s, m);
1235 for (i = 0; i < qs.count; i++)
1236 if (!MAPTST(m, qs.elements[i]))
1237 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1240 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1244 * add rule for update
1245 * (A|A1|A2|A3...) An = update candidates for A
1247 * s = (installed) solvable
1251 addupdaterule(Solver *solv, Solvable *s, int allowall)
1253 /* installed packages get a special upgrade allowed rule */
1254 Pool *pool = solv->pool;
1259 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1261 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1262 policy_findupdatepackages(solv, s, &qs, allowall);
1263 if (qs.count == 0) /* no updaters found */
1266 d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
1268 addrule(solv, s - pool->solvables, d); /* allow update of s */
1269 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1273 /*-----------------------------------------------------------------*/
1280 * initial setup for all watches
1284 makewatches(Solver *solv)
1288 int nsolvables = solv->pool->nsolvables;
1290 sat_free(solv->watches);
1291 /* lower half for removals, upper half for installs */
1292 solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
1294 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
1295 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1297 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1300 if (!r->w2) /* assertions do not need watches */
1303 /* see addwatches_rule(solv, r) */
1304 r->n1 = solv->watches[nsolvables + r->w1];
1305 solv->watches[nsolvables + r->w1] = r - solv->rules;
1307 r->n2 = solv->watches[nsolvables + r->w2];
1308 solv->watches[nsolvables + r->w2] = r - solv->rules;
1314 * add watches (for rule)
1318 addwatches_rule(Solver *solv, Rule *r)
1320 int nsolvables = solv->pool->nsolvables;
1322 r->n1 = solv->watches[nsolvables + r->w1];
1323 solv->watches[nsolvables + r->w1] = r - solv->rules;
1325 r->n2 = solv->watches[nsolvables + r->w2];
1326 solv->watches[nsolvables + r->w2] = r - solv->rules;
1330 /*-----------------------------------------------------------------*/
1331 /* rule propagation */
1333 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1334 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
1339 * propagate decision to all rules
1340 * return : 0 = everything is OK
1341 * watched rule = there is a conflict
1345 propagate(Solver *solv, int level)
1347 Pool *pool = solv->pool;
1352 Id *decisionmap = solv->decisionmap;
1353 Id *watches = solv->watches + pool->nsolvables;
1355 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1357 while (solv->propagate_index < solv->decisionq.count)
1359 /* negate because our watches trigger if literal goes FALSE */
1360 pkg = -solv->decisionq.elements[solv->propagate_index++];
1361 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1363 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
1364 solver_printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1367 for (rp = watches + pkg; *rp; rp = nrp)
1369 r = solv->rules + *rp;
1372 /* rule is disabled */
1380 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1382 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1383 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
1388 ow = r->w2; /* regard the second watchpoint to come to a solution */
1393 ow = r->w1; /* regard the first watchpoint to come to a solution */
1396 /* if clause is TRUE, nothing to do */
1397 if (DECISIONMAP_TRUE(ow))
1402 /* not a binary clause, check if we need to move our watch */
1403 /* search for a literal that is not ow and not false */
1404 /* (true is also ok, in that case the rule is fulfilled) */
1405 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1408 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1409 if (p != ow && !DECISIONMAP_TRUE(-p))
1413 /* p is free to watch, move watch to p */
1414 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1417 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1419 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1433 watches[p] = r - solv->rules;
1437 /* unit clause found, set other watch to TRUE */
1438 if (DECISIONMAP_TRUE(-ow))
1439 return r; /* eek, a conflict! */
1440 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1442 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
1443 solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
1446 decisionmap[ow] = level;
1448 decisionmap[-ow] = -level;
1449 queue_push(&solv->decisionq, ow);
1450 queue_push(&solv->decisionq_why, r - solv->rules);
1451 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1453 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1455 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
1457 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
1461 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
1463 return 0; /* all is well */
1467 /*-----------------------------------------------------------------*/
1476 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
1478 Pool *pool = solv->pool;
1481 Map seen; /* global? */
1482 Id d, v, vv, *dp, why;
1484 int num = 0, l1num = 0;
1485 int learnt_why = solv->learnt_pool.count;
1486 Id *decisionmap = solv->decisionmap;
1490 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
1491 map_init(&seen, pool->nsolvables);
1492 idx = solv->decisionq.count;
1495 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1496 solver_printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1497 queue_push(&solv->learnt_pool, c - solv->rules);
1498 d = c->d < 0 ? -c->d - 1 : c->d;
1499 dp = d ? pool->whatprovidesdata + d : 0;
1500 /* go through all literals of the rule */
1512 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1514 vv = v > 0 ? v : -v;
1515 if (MAPTST(&seen, vv))
1517 l = solv->decisionmap[vv];
1522 l1num++; /* need to do this one in level1 pass */
1523 else if (l == level)
1524 num++; /* need to do this one as well */
1527 queue_push(&r, v); /* not level1 or conflict level, add to new rule */
1533 if (!num && !--l1num)
1534 break; /* all level 1 literals done */
1538 v = solv->decisionq.elements[--idx];
1539 vv = v > 0 ? v : -v;
1540 if (MAPTST(&seen, vv))
1544 if (num && --num == 0)
1546 *pr = -v; /* so that v doesn't get lost */
1549 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1550 for (i = 0; i < r.count; i++)
1553 MAPCLR(&seen, v > 0 ? v : -v);
1555 /* only level 1 marks left */
1559 why = solv->decisionq_why.elements[idx];
1560 if (!why) /* just in case, maye for SYSTEMSOLVABLE */
1562 c = solv->rules + why;
1568 else if (r.count == 1 && r.elements[0] < 0)
1569 *dr = r.elements[0];
1571 *dr = pool_queuetowhatprovides(pool, &r);
1572 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1574 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1575 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
1576 for (i = 0; i < r.count; i++)
1577 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
1579 /* push end marker on learnt reasons stack */
1580 queue_push(&solv->learnt_pool, 0);
1583 solv->stats_learned++;
1590 * reset the solver decisions to right after the rpm rules.
1591 * called after rules have been enabled/disabled
1595 reset_solver(Solver *solv)
1597 Pool *pool = solv->pool;
1601 /* rewind decisions to direct rpm rule assertions */
1602 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
1604 v = solv->decisionq.elements[i];
1605 solv->decisionmap[v > 0 ? v : -v] = 0;
1608 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
1610 solv->decisionq_why.count = solv->directdecisions;
1611 solv->decisionq.count = solv->directdecisions;
1612 solv->recommends_index = -1;
1613 solv->propagate_index = 0;
1615 /* adapt learnt rule status to new set of enabled/disabled rules */
1616 enabledisablelearntrules(solv);
1618 /* redo all job/update decisions */
1619 makeruledecisions(solv);
1620 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
1625 * analyze_unsolvable_rule
1629 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
1631 Pool *pool = solv->pool;
1633 Id why = r - solv->rules;
1635 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1636 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1637 if (solv->learntrules && why >= solv->learntrules)
1639 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1640 if (solv->learnt_pool.elements[i] > 0)
1641 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp);
1644 if (MAPTST(&solv->weakrulemap, why))
1645 if (!*lastweakp || why > *lastweakp)
1647 /* do not add rpm rules to problem */
1648 if (why < solv->rpmrules_end)
1650 /* turn rule into problem */
1651 if (why >= solv->jobrules && why < solv->jobrules_end)
1652 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1653 /* return if problem already countains our rule */
1654 if (solv->problems.count)
1656 for (i = solv->problems.count - 1; i >= 0; i--)
1657 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1659 else if (solv->problems.elements[i] == why)
1662 queue_push(&solv->problems, why);
1667 * analyze_unsolvable
1669 * return: 1 - disabled some rules, try again
1674 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1676 Pool *pool = solv->pool;
1678 Map seen; /* global to speed things up? */
1679 Id d, v, vv, *dp, why;
1681 Id *decisionmap = solv->decisionmap;
1682 int oldproblemcount;
1683 int oldlearntpoolcount;
1686 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1687 solv->stats_unsolvable++;
1688 oldproblemcount = solv->problems.count;
1689 oldlearntpoolcount = solv->learnt_pool.count;
1691 /* make room for proof index */
1692 /* must update it later, as analyze_unsolvable_rule would confuse
1693 * it with a rule index if we put the real value in already */
1694 queue_push(&solv->problems, 0);
1697 map_init(&seen, pool->nsolvables);
1698 queue_push(&solv->learnt_pool, r - solv->rules);
1700 analyze_unsolvable_rule(solv, r, &lastweak);
1701 d = r->d < 0 ? -r->d - 1 : r->d;
1702 dp = d ? pool->whatprovidesdata + d : 0;
1713 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1715 vv = v > 0 ? v : -v;
1716 l = solv->decisionmap[vv];
1721 idx = solv->decisionq.count;
1724 v = solv->decisionq.elements[--idx];
1725 vv = v > 0 ? v : -v;
1726 if (!MAPTST(&seen, vv))
1728 why = solv->decisionq_why.elements[idx];
1729 queue_push(&solv->learnt_pool, why);
1730 r = solv->rules + why;
1731 analyze_unsolvable_rule(solv, r, &lastweak);
1732 d = r->d < 0 ? -r->d - 1 : r->d;
1733 dp = d ? pool->whatprovidesdata + d : 0;
1744 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1746 vv = v > 0 ? v : -v;
1747 l = solv->decisionmap[vv];
1754 queue_push(&solv->problems, 0); /* mark end of this problem */
1758 /* disable last weak rule */
1759 solv->problems.count = oldproblemcount;
1760 solv->learnt_pool.count = oldlearntpoolcount;
1761 r = solv->rules + lastweak;
1762 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling ");
1763 solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1764 disablerule(solv, r);
1770 queue_push(&solv->learnt_pool, 0);
1771 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1775 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1776 disableproblem(solv, solv->problems.elements[i]);
1777 /* XXX: might want to enable all weak rules again */
1781 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1786 /*-----------------------------------------------------------------*/
1787 /* Decision revert */
1791 * revert decision at level
1795 revert(Solver *solv, int level)
1797 Pool *pool = solv->pool;
1799 while (solv->decisionq.count)
1801 v = solv->decisionq.elements[solv->decisionq.count - 1];
1802 vv = v > 0 ? v : -v;
1803 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1805 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1806 if (v > 0 && solv->recommendations.count && v == solv->recommendations.elements[solv->recommendations.count - 1])
1807 solv->recommendations.count--;
1808 solv->decisionmap[vv] = 0;
1809 solv->decisionq.count--;
1810 solv->decisionq_why.count--;
1811 solv->propagate_index = solv->decisionq.count;
1813 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1815 solv->branches.count--;
1816 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1817 solv->branches.count--;
1819 solv->recommends_index = -1;
1824 * watch2onhighest - put watch2 on literal with highest level
1828 watch2onhighest(Solver *solv, Rule *r)
1833 d = r->d < 0 ? -r->d - 1 : r->d;
1835 return; /* binary rule, both watches are set */
1836 dp = solv->pool->whatprovidesdata + d;
1837 while ((v = *dp++) != 0)
1839 l = solv->decisionmap[v < 0 ? -v : v];
1854 * add free decision to decisionq, increase level and
1855 * propagate decision, return if no conflict.
1856 * in conflict case, analyze conflict rule, add resulting
1857 * rule to learnt rule set, make decision from learnt
1858 * rule (always unit) and re-propagate.
1860 * returns the new solver level or 0 if unsolvable
1865 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1867 Pool *pool = solv->pool;
1876 solv->decisionmap[decision] = level;
1878 solv->decisionmap[-decision] = -level;
1879 queue_push(&solv->decisionq, decision);
1880 queue_push(&solv->decisionq_why, 0);
1884 r = propagate(solv, level);
1888 return analyze_unsolvable(solv, r, disablerules);
1889 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1890 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1891 assert(l > 0 && l < level);
1892 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
1894 revert(solv, level);
1895 r = addrule(solv, p, d); /* p requires d */
1897 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1898 queue_push(&solv->learnt_why, why);
1901 /* at least 2 literals, needs watches */
1902 watch2onhighest(solv, r);
1903 addwatches_rule(solv, r);
1907 /* learnt rule is an assertion */
1908 queue_push(&solv->ruleassertions, r - solv->rules);
1910 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1911 queue_push(&solv->decisionq, p);
1912 queue_push(&solv->decisionq_why, r - solv->rules);
1913 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1915 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
1916 solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
1917 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
1918 solver_printrule(solv, SAT_DEBUG_ANALYZE, r);
1926 * install best package from the queue. We add an extra package, inst, if
1927 * provided. See comment in weak install section.
1929 * returns the new solver level or 0 if unsolvable
1933 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
1935 Pool *pool = solv->pool;
1939 if (dq->count > 1 || inst)
1940 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
1945 /* choose the supplemented one */
1946 for (i = 0; i < dq->count; i++)
1947 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1951 for (i = 1; i < dq->count; i++)
1952 queue_push(&solv->branches, dq->elements[i]);
1953 queue_push(&solv->branches, -level);
1957 p = dq->elements[i];
1959 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
1961 return setpropagatelearn(solv, level, p, disablerules);
1965 /*-----------------------------------------------------------------*/
1966 /* Main solver interface */
1971 * create solver structure
1973 * pool: all available solvables
1974 * installed: installed Solvables
1977 * Upon solving, rules are created to flag the Solvables
1978 * of the 'installed' Repo as installed.
1982 solver_create(Pool *pool, Repo *installed)
1985 solv = (Solver *)sat_calloc(1, sizeof(Solver));
1987 solv->installed = installed;
1989 queue_init(&solv->ruletojob);
1990 queue_init(&solv->decisionq);
1991 queue_init(&solv->decisionq_why);
1992 queue_init(&solv->problems);
1993 queue_init(&solv->suggestions);
1994 queue_init(&solv->recommendations);
1995 queue_init(&solv->learnt_why);
1996 queue_init(&solv->learnt_pool);
1997 queue_init(&solv->branches);
1998 queue_init(&solv->covenantq);
1999 queue_init(&solv->weakruleq);
2000 queue_init(&solv->ruleassertions);
2002 map_init(&solv->recommendsmap, pool->nsolvables);
2003 map_init(&solv->suggestsmap, pool->nsolvables);
2004 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
2005 solv->recommends_index = 0;
2007 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2009 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
2010 memset(solv->rules, 0, sizeof(Rule));
2021 solver_free(Solver *solv)
2023 queue_free(&solv->ruletojob);
2024 queue_free(&solv->decisionq);
2025 queue_free(&solv->decisionq_why);
2026 queue_free(&solv->learnt_why);
2027 queue_free(&solv->learnt_pool);
2028 queue_free(&solv->problems);
2029 queue_free(&solv->suggestions);
2030 queue_free(&solv->recommendations);
2031 queue_free(&solv->branches);
2032 queue_free(&solv->covenantq);
2033 queue_free(&solv->weakruleq);
2034 queue_free(&solv->ruleassertions);
2036 map_free(&solv->recommendsmap);
2037 map_free(&solv->suggestsmap);
2038 map_free(&solv->noupdate);
2039 map_free(&solv->weakrulemap);
2041 sat_free(solv->decisionmap);
2042 sat_free(solv->rules);
2043 sat_free(solv->watches);
2044 sat_free(solv->obsoletes);
2045 sat_free(solv->obsoletes_data);
2050 /*-------------------------------------------------------*/
2055 * all rules have been set up, now actually run the solver
2060 run_solver(Solver *solv, int disablerules, int doweak)
2068 Pool *pool = solv->pool;
2071 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2073 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2074 for (i = 1; i < solv->nrules; i++)
2075 solver_printruleclass(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2078 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2080 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2081 solver_printdecisions(solv);
2083 /* start SAT algorithm */
2085 systemlevel = level + 1;
2086 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2091 * here's the main loop:
2092 * 1) propagate new decisions (only needed for level 1)
2093 * 2) try to keep installed packages
2094 * 3) fulfill all unresolved rules
2095 * 4) install recommended packages
2096 * 5) minimalize solution if we had choices
2097 * if we encounter a problem, we rewind to a safe level and restart
2109 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2110 if ((r = propagate(solv, level)) != 0)
2112 if (analyze_unsolvable(solv, r, disablerules))
2120 * installed packages
2123 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2125 if (!solv->updatesystem)
2127 /* try to keep as many packages as possible */
2128 POOL_DEBUG(SAT_DEBUG_STATS, "installing old packages\n");
2129 for (i = solv->installed->start; i < solv->installed->end; i++)
2131 s = pool->solvables + i;
2132 if (s->repo != solv->installed)
2134 if (solv->decisionmap[i] != 0)
2136 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2138 level = setpropagatelearn(solv, level, i, disablerules);
2144 if (level <= olevel)
2147 if (i < solv->installed->end)
2150 POOL_DEBUG(SAT_DEBUG_STATS, "resolving update/feature rules\n");
2151 for (i = solv->installed->start, r = solv->rules + solv->updaterules; i < solv->installed->end; i++, r++)
2155 s = pool->solvables + i;
2156 if (s->repo != solv->installed)
2158 if (solv->decisionmap[i] > 0)
2160 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2161 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2165 if (rr->d < 0) /* disabled -> look at feature rule ? */
2166 rr -= solv->installed->end - solv->installed->start;
2167 if (!rr->p) /* identical to update rule? */
2169 d = rr->d < 0 ? -rr->d - 1 : rr->d;
2172 if (!rr->w2 || solv->decisionmap[rr->w2] > 0)
2174 if (solv->decisionmap[rr->w2] == 0)
2175 queue_push(&dq, rr->w2);
2179 dp = pool->whatprovidesdata + d;
2180 while ((p = *dp++) != 0)
2182 if (solv->decisionmap[p] > 0)
2184 if (solv->decisionmap[p] == 0)
2190 if (!dq.count && solv->decisionmap[i] != 0)
2193 /* FIXME: i is handled a bit different because we do not want
2194 * to have it pruned just because it is not recommened.
2195 * we should not prune installed packages instead */
2196 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2202 if (level <= olevel)
2205 if (i < solv->installed->end)
2207 systemlevel = level;
2214 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unresolved rules\n");
2215 for (i = 1, n = 1; ; i++, n++)
2217 if (n == solv->nrules)
2219 if (i == solv->nrules)
2221 r = solv->rules + i;
2222 if (r->d < 0) /* ignore disabled rules */
2227 /* binary or unary rule */
2228 /* need two positive undecided literals */
2229 if (r->p < 0 || r->w2 <= 0)
2231 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2233 queue_push(&dq, r->p);
2234 queue_push(&dq, r->w2);
2239 * all negative literals are installed
2240 * no positive literal is installed
2241 * i.e. the rule is not fulfilled and we
2242 * just need to decide on the positive literals
2246 if (solv->decisionmap[-r->p] <= 0)
2251 if (solv->decisionmap[r->p] > 0)
2253 if (solv->decisionmap[r->p] == 0)
2254 queue_push(&dq, r->p);
2256 dp = pool->whatprovidesdata + r->d;
2257 while ((p = *dp++) != 0)
2261 if (solv->decisionmap[-p] <= 0)
2266 if (solv->decisionmap[p] > 0)
2268 if (solv->decisionmap[p] == 0)
2275 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2277 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2278 solver_printruleclass(solv, SAT_DEBUG_PROPAGATE, r);
2280 /* dq.count < 2 cannot happen as this means that
2281 * the rule is unit */
2282 assert(dq.count > 1);
2285 level = selectandinstall(solv, level, &dq, 0, disablerules);
2291 if (level < systemlevel)
2294 } /* for(), decide */
2296 if (n != solv->nrules) /* continue if level < systemlevel */
2303 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
2305 for (i = 1; i < pool->nsolvables; i++)
2307 if (solv->decisionmap[i] < 0)
2309 if (solv->decisionmap[i] > 0)
2311 Id *recp, rec, *pp, p;
2312 s = pool->solvables + i;
2313 /* installed, check for recommends */
2314 /* XXX need to special case AND ? */
2317 recp = s->repo->idarraydata + s->recommends;
2318 while ((rec = *recp++) != 0)
2321 FOR_PROVIDES(p, pp, rec)
2323 if (solv->decisionmap[p] > 0)
2328 else if (solv->decisionmap[p] == 0)
2330 queue_pushunique(&dq, p);
2338 s = pool->solvables + i;
2339 if (!s->supplements && !s->freshens)
2341 if (!pool_installable(pool, s))
2343 if (solver_is_supplementing(solv, s))
2344 queue_pushunique(&dq, i);
2350 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2352 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2353 queue_push(&solv->recommendations, p);
2354 level = setpropagatelearn(solv, level, p, 0);
2359 if (solv->solution_callback)
2361 solv->solution_callback(solv, solv->solution_callback_data);
2362 if (solv->branches.count)
2364 int i = solv->branches.count - 1;
2365 int l = -solv->branches.elements[i];
2367 if (solv->branches.elements[i - 1] < 0)
2369 p = solv->branches.elements[i];
2370 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
2372 for (j = i + 1; j < solv->branches.count; j++)
2373 queue_push(&dq, solv->branches.elements[j]);
2374 solv->branches.count = i;
2376 revert(solv, level);
2378 for (j = 0; j < dq.count; j++)
2379 queue_push(&solv->branches, dq.elements[j]);
2381 level = setpropagatelearn(solv, level, p, disablerules);
2389 /* all branches done, we're finally finished */
2393 /* minimization step */
2394 if (solv->branches.count)
2396 int l = 0, lasti = -1, lastl = -1;
2398 for (i = solv->branches.count - 1; i >= 0; i--)
2400 p = solv->branches.elements[i];
2403 else if (p > 0 && solv->decisionmap[p] > l + 1)
2411 /* kill old solvable so that we do not loop */
2412 p = solv->branches.elements[lasti];
2413 solv->branches.elements[lasti] = 0;
2414 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
2417 revert(solv, level);
2419 level = setpropagatelearn(solv, level, p, disablerules);
2430 POOL_DEBUG(SAT_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable\n", solv->stats_learned, solv->stats_unsolvable);
2432 POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
2439 * at this point, all rules that led to conflicts are disabled.
2440 * we re-enable all rules of a problem set but rule "sug", then
2441 * continue to disable more rules until there as again a solution.
2444 /* FIXME: think about conflicting assertions */
2447 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2449 Pool *pool = solv->pool;
2455 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2457 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
2458 for (i = 0; problem[i]; i++)
2460 if (problem[i] == sug)
2461 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
2462 solver_printproblem(solv, problem[i]);
2465 queue_init(&disabled);
2466 queue_empty(refined);
2467 queue_push(refined, sug);
2469 /* re-enable all problem rules with the exception of "sug"(gestion) */
2473 for (i = 0; problem[i]; i++)
2474 if (problem[i] != sug)
2475 enableproblem(solv, problem[i]);
2478 disableupdaterules(solv, job, -(sug + 1));
2479 else if (sug >= solv->updaterules && sug < solv->updaterules_end)
2481 /* enable feature rule */
2482 Rule *r = solv->rules + solv->featurerules + (sug - solv->updaterules);
2484 enablerule(solv, r);
2487 enableweakrules(solv);
2491 int njob, nfeature, nupdate;
2492 queue_empty(&solv->problems);
2493 revert(solv, 1); /* XXX no longer needed? */
2496 if (!solv->problems.count)
2497 run_solver(solv, 0, 0);
2499 if (!solv->problems.count)
2501 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
2502 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2503 solver_printdecisions(solv);
2504 break; /* great, no more problems */
2506 disabledcnt = disabled.count;
2507 /* start with 1 to skip over proof index */
2508 njob = nfeature = nupdate = 0;
2509 for (i = 1; i < solv->problems.count - 1; i++)
2511 /* ignore solutions in refined */
2512 v = solv->problems.elements[i];
2514 break; /* end of problem reached */
2515 for (j = 0; problem[j]; j++)
2516 if (problem[j] != sug && problem[j] == v)
2520 if (v >= solv->featurerules && v < solv->featurerules_end)
2526 queue_push(&disabled, v);
2528 if (disabled.count == disabledcnt)
2530 /* no solution found, this was an invalid suggestion! */
2531 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
2535 if (!njob && nupdate && nfeature)
2537 /* got only update rules, filter out feature rules */
2538 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "throwing away feature rules\n");
2539 for (i = j = disabledcnt; i < disabled.count; i++)
2541 v = disabled.elements[i];
2542 if (v < solv->featurerules || v >= solv->featurerules_end)
2543 disabled.elements[j++] = v;
2548 if (disabled.count == disabledcnt + 1)
2550 /* just one suggestion, add it to refined list */
2551 v = disabled.elements[disabledcnt];
2553 queue_push(refined, v); /* do not record feature rules */
2554 disableproblem(solv, v);
2555 if (v >= solv->updaterules && v < solv->updaterules_end)
2557 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
2559 enablerule(solv, r); /* enable corresponding feature rule */
2562 disableupdaterules(solv, job, -(v + 1));
2566 /* more than one solution, disable all */
2567 /* do not push anything on refine list, as we do not know which solution to choose */
2568 /* thus, the user will get another problem if he selects this solution, where he
2569 * can choose the right one */
2570 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2572 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
2573 for (i = disabledcnt; i < disabled.count; i++)
2574 solver_printproblem(solv, disabled.elements[i]);
2576 for (i = disabledcnt; i < disabled.count; i++)
2578 v = disabled.elements[i];
2579 disableproblem(solv, v);
2580 if (v >= solv->updaterules && v < solv->updaterules_end)
2582 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
2584 enablerule(solv, r);
2589 /* all done, get us back into the same state as before */
2590 /* enable refined rules again */
2591 for (i = 0; i < disabled.count; i++)
2592 enableproblem(solv, disabled.elements[i]);
2593 /* disable problem rules again */
2596 for (i = 0; problem[i]; i++)
2597 enableproblem(solv, problem[i]);
2598 disableupdaterules(solv, job, -1);
2600 /* disable problem rules again */
2601 for (i = 0; problem[i]; i++)
2602 disableproblem(solv, problem[i]);
2603 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
2607 problems_sortcmp(const void *ap, const void *bp)
2609 Id a = *(Id *)ap, b = *(Id *)bp;
2618 problems_sort(Solver *solv)
2621 if (!solv->problems.count)
2623 for (i = j = 1; i < solv->problems.count; i++)
2625 if (!solv->problems.elements[i])
2628 qsort(solv->problems.elements + j, i - j, sizeof(Id), problems_sortcmp);
2629 if (++i == solv->problems.count)
2637 problems_to_solutions(Solver *solv, Queue *job)
2639 Pool *pool = solv->pool;
2647 if (!solv->problems.count)
2649 problems_sort(solv);
2650 queue_clone(&problems, &solv->problems);
2651 queue_init(&solution);
2652 queue_init(&solutions);
2653 /* copy over proof index */
2654 queue_push(&solutions, problems.elements[0]);
2655 problem = problems.elements + 1;
2656 for (i = 1; i < problems.count; i++)
2658 Id v = problems.elements[i];
2661 /* mark end of this problem */
2662 queue_push(&solutions, 0);
2663 queue_push(&solutions, 0);
2664 if (i + 1 == problems.count)
2666 /* copy over proof of next problem */
2667 queue_push(&solutions, problems.elements[i + 1]);
2669 problem = problems.elements + i + 1;
2672 refine_suggestion(solv, job, problem, v, &solution);
2673 if (!solution.count)
2674 continue; /* this solution didn't work out */
2677 for (j = 0; j < solution.count; j++)
2679 why = solution.elements[j];
2680 /* must be either job descriptor or update rule */
2681 assert(why < 0 || (why >= solv->updaterules && why < solv->updaterules_end));
2683 solver_printproblem(solv, why);
2687 /* job descriptor */
2688 queue_push(&solutions, 0);
2689 queue_push(&solutions, -why);
2693 /* update rule, find replacement package */
2694 Id p, d, *dp, rp = 0;
2696 p = solv->installed->start + (why - solv->updaterules);
2697 if (solv->decisionmap[p] > 0)
2698 continue; /* false alarm, turned out we can keep the package */
2699 rr = solv->rules + solv->featurerules + (why - solv->updaterules);
2701 rr = solv->rules + why;
2704 d = rr->d < 0 ? -rr->d - 1 : rr->d;
2707 if (solv->decisionmap[rr->w2] > 0 && pool->solvables[rr->w2].repo != solv->installed)
2712 for (dp = pool->whatprovidesdata + d; *dp; dp++)
2714 if (solv->decisionmap[*dp] > 0 && pool->solvables[*dp].repo != solv->installed)
2722 queue_push(&solutions, p);
2723 queue_push(&solutions, rp);
2727 /* mark end of this solution */
2730 queue_push(&solutions, 0);
2731 queue_push(&solutions, 0);
2735 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "Oops, everything was fine?\n");
2738 queue_free(&solution);
2739 queue_free(&problems);
2740 /* copy queue over to solutions */
2741 queue_free(&solv->problems);
2742 queue_clone(&solv->problems, &solutions);
2744 /* bring solver back into problem state */
2745 revert(solv, 1); /* XXX move to reset_solver? */
2748 assert(solv->problems.count == solutions.count);
2749 queue_free(&solutions);
2753 solver_next_problem(Solver *solv, Id problem)
2757 return solv->problems.count ? 1 : 0;
2758 pp = solv->problems.elements + problem;
2759 while (pp[0] || pp[1])
2763 while (pp[0] || pp[1])
2768 problem = pp - solv->problems.elements;
2769 if (problem >= solv->problems.count)
2775 solver_next_solution(Solver *solv, Id problem, Id solution)
2781 pp = solv->problems.elements + solution;
2782 return pp[0] || pp[1] ? solution : 0;
2784 pp = solv->problems.elements + solution;
2785 while (pp[0] || pp[1])
2788 solution = pp - solv->problems.elements;
2789 return pp[0] || pp[1] ? solution : 0;
2793 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
2796 element = element ? element + 2 : solution;
2797 pp = solv->problems.elements + element;
2798 if (!(pp[0] || pp[1]))
2806 /* this is basically the reverse of addrpmrulesforsolvable */
2808 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
2810 Pool *pool = solv->pool;
2811 Repo *installed = solv->installed;
2815 Id p, d, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
2818 if (rid >= solv->jobrules && rid < solv->jobrules_end)
2821 r = solv->rules + rid;
2822 p = solv->ruletojob.elements[rid - solv->jobrules];
2823 *depp = job->elements[p + 1];
2825 *targetp = job->elements[p];
2826 d = r->d < 0 ? -r->d - 1 : r->d;
2827 if (d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && job->elements[p] != SOLVER_INSTALL_SOLVABLE_ONE_OF)
2828 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
2829 return SOLVER_PROBLEM_JOB_RULE;
2831 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2834 *sourcep = solv->installed->start + (rid - solv->updaterules);
2836 return SOLVER_PROBLEM_UPDATE_RULE;
2838 assert(rid < solv->rpmrules_end);
2839 r = solv->rules + rid;
2841 d = r->d < 0 ? -r->d - 1 : r->d;
2842 if (d == 0 && r->w2 == 0)
2844 /* a rpm rule assertion */
2845 s = pool->solvables - r->p;
2846 if (installed && !solv->fixsystem && s->repo == installed)
2848 assert(!dontfix); /* dontfix packages never have a neg assertion */
2851 /* see why the package is not installable */
2852 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
2855 return SOLVER_PROBLEM_NOT_INSTALLABLE;
2857 /* check requires */
2860 reqp = s->repo->idarraydata + s->requires;
2861 while ((req = *reqp++) != 0)
2863 if (req == SOLVABLE_PREREQMARKER)
2865 dp = pool_whatprovides(pool, req);
2872 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
2875 assert(!solv->allowselfconflicts);
2876 assert(s->conflicts);
2877 conp = s->repo->idarraydata + s->conflicts;
2878 while ((con = *conp++) != 0)
2879 FOR_PROVIDES(p, pp, con)
2883 return SOLVER_PROBLEM_SELF_CONFLICT;
2887 s = pool->solvables - r->p;
2888 if (installed && !solv->fixsystem && s->repo == installed)
2890 if (d == 0 && r->w2 < 0)
2892 /* a package conflict */
2893 Solvable *s2 = pool->solvables - r->w2;
2896 if (installed && !solv->fixsystem && s2->repo == installed)
2899 /* if both packages have the same name and at least one of them
2900 * is not installed, they conflict */
2901 if (s->name == s2->name && (!installed || (s->repo != installed || s2->repo != installed)))
2906 return SOLVER_PROBLEM_SAME_NAME;
2909 /* check conflicts in both directions */
2912 conp = s->repo->idarraydata + s->conflicts;
2913 while ((con = *conp++) != 0)
2915 FOR_PROVIDES(p, pp, con)
2917 if (dontfix && pool->solvables[p].repo == installed)
2924 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
2930 conp = s2->repo->idarraydata + s2->conflicts;
2931 while ((con = *conp++) != 0)
2933 FOR_PROVIDES(p, pp, con)
2935 if (dontfix2 && pool->solvables[p].repo == installed)
2942 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
2946 /* check obsoletes in both directions */
2947 if ((!installed || s->repo != installed) && s->obsoletes)
2949 obsp = s->repo->idarraydata + s->obsoletes;
2950 while ((obs = *obsp++) != 0)
2952 Id obsname = dep2name(pool, obs);
2953 FOR_PROVIDES(p, pp, obs)
2957 if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
2962 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
2966 if ((!installed || s2->repo != installed) && s2->obsoletes)
2968 obsp = s2->repo->idarraydata + s2->obsoletes;
2969 while ((obs = *obsp++) != 0)
2971 Id obsname = dep2name(pool, obs);
2972 FOR_PROVIDES(p, pp, obs)
2976 if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
2981 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
2985 if (solv->implicitobsoleteusesprovides && (!installed || s->repo != installed))
2987 FOR_PROVIDES(p, pp, s->name)
2994 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
2997 if (solv->implicitobsoleteusesprovides && (!installed || s2->repo != installed))
2999 FOR_PROVIDES(p, pp, s2->name)
3006 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3009 /* all cases checked, can't happen */
3012 /* simple requires */
3013 assert(s->requires);
3014 reqp = s->repo->idarraydata + s->requires;
3015 while ((req = *reqp++) != 0)
3017 if (req == SOLVABLE_PREREQMARKER)
3019 dp = pool_whatprovides(pool, req);
3022 if (*dp == r->w2 && dp[1] == 0)
3025 else if (dp - pool->whatprovidesdata == d)
3032 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
3036 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3039 Id lreqr, lconr, lsysr, ljobr;
3043 lreqr = lconr = lsysr = ljobr = 0;
3044 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3047 if (rid >= solv->learntrules)
3048 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3049 else if (rid >= solv->jobrules && rid < solv->jobrules_end)
3054 else if (rid >= solv->updaterules && rid < solv->updaterules_end)
3061 assert(rid < solv->rpmrules_end);
3062 r = solv->rules + rid;
3063 d = r->d < 0 ? -r->d - 1 : r->d;
3064 if (!d && r->w2 < 0)
3071 if (!d && r->w2 == 0 && !reqassert)
3073 /* prefer assertions (XXX: bad idea?) */
3079 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed)
3081 /* prefer rules of installed packages */
3082 Id op = *reqrp >= 0 ? solv->rules[*reqrp].p : -*reqrp;
3083 if (op <= 0 || solv->pool->solvables[op].repo != solv->installed)
3089 if (!*reqrp && lreqr)
3091 if (!*conrp && lconr)
3093 if (!*jobrp && ljobr)
3095 if (!*sysrp && lsysr)
3100 * search for a rule that describes the problem to the
3101 * user. A pretty hopeless task, actually. We currently
3102 * prefer simple requires.
3105 solver_findproblemrule(Solver *solv, Id problem)
3107 Id reqr, conr, sysr, jobr;
3108 Id idx = solv->problems.elements[problem - 1];
3109 reqr = conr = sysr = jobr = 0;
3110 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3123 /* create reverse obsoletes map for installed solvables
3125 * for each installed solvable find which packages with *different* names
3126 * obsolete the solvable.
3127 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3131 create_obsolete_index(Solver *solv)
3133 Pool *pool = solv->pool;
3135 Repo *installed = solv->installed;
3136 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3139 if (!installed || !installed->nsolvables)
3141 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
3142 for (i = 1; i < pool->nsolvables; i++)
3144 s = pool->solvables + i;
3147 if (!pool_installable(pool, s))
3149 obsp = s->repo->idarraydata + s->obsoletes;
3150 while ((obs = *obsp++) != 0)
3152 Id obsname = dep2name(pool, obs);
3153 FOR_PROVIDES(p, pp, obs)
3155 if (pool->solvables[p].repo != installed)
3157 if (pool->solvables[p].name == s->name)
3159 if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
3161 obsoletes[p - installed->start]++;
3166 for (i = 0; i < installed->nsolvables; i++)
3169 n += obsoletes[i] + 1;
3172 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
3173 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
3174 for (i = pool->nsolvables - 1; i > 0; i--)
3176 s = pool->solvables + i;
3179 if (!pool_installable(pool, s))
3181 obsp = s->repo->idarraydata + s->obsoletes;
3182 while ((obs = *obsp++) != 0)
3184 Id obsname = dep2name(pool, obs);
3185 FOR_PROVIDES(p, pp, obs)
3187 if (pool->solvables[p].repo != installed)
3189 if (pool->solvables[p].name == s->name)
3191 if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
3193 p -= installed->start;
3194 if (obsoletes_data[obsoletes[p]] != i)
3195 obsoletes_data[--obsoletes[p]] = i;
3202 removedisabledconflicts(Solver *solv, Queue *removed)
3204 Pool *pool = solv->pool;
3209 Id *decisionmap = solv->decisionmap;
3211 POOL_DEBUG(SAT_DEBUG_STATS, "removedisabledconflicts\n");
3212 queue_empty(removed);
3213 for (i = 0; i < solv->decisionq.count; i++)
3215 p = solv->decisionq.elements[i];
3218 /* a conflict. we never do conflicts on free decisions, so there
3219 * must have been an unit rule */
3220 why = solv->decisionq_why.elements[i];
3222 r = solv->rules + why;
3223 if (r->d < 0 && decisionmap[-p])
3225 /* rule is now disabled, remove from decisionmap */
3226 POOL_DEBUG(SAT_DEBUG_STATS, "removing conflict for package %s[%d]\n", solvable2str(pool, pool->solvables - p), -p);
3227 queue_push(removed, -p);
3228 queue_push(removed, decisionmap[-p]);
3229 decisionmap[-p] = 0;
3232 if (!removed->count)
3234 /* we removed some confliced packages. some of them might still
3235 * be in conflict, so search for unit rules and re-conflict */
3237 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
3239 if (i == solv->nrules)
3242 r = solv->rules + i;
3248 if (r->p < 0 && !decisionmap[-r->p])
3254 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
3256 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
3261 if (r->p < 0 && decisionmap[-r->p] == 0)
3263 if (new || DECISIONMAP_FALSE(r->p))
3265 dp = pool->whatprovidesdata + r->d;
3266 while ((p = *dp++) != 0)
3268 if (new && p == new)
3270 if (p < 0 && decisionmap[-p] == 0)
3279 else if (!DECISIONMAP_FALSE(p))
3289 POOL_DEBUG(SAT_DEBUG_STATS, "re-conflicting package %s[%d]\n", solvable2str(pool, pool->solvables - new), -new);
3290 decisionmap[-new] = -1;
3292 n = 0; /* redo all rules */
3298 weaken_solvable_deps(Solver *solv, Id p)
3303 for (i = 1, r = solv->rules + i; i < solv->featurerules; i++, r++)
3307 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3308 continue; /* conflict */
3309 queue_push(&solv->weakruleq, i);
3313 /*-----------------------------------------------------------------*/
3323 solver_solve(Solver *solv, Queue *job)
3325 Pool *pool = solv->pool;
3326 Repo *installed = solv->installed;
3329 Map addedmap; /* '1' == have rpm-rules for solvable */
3330 Id how, what, weak, name, p, *pp, d;
3336 /* create whatprovides if not already there */
3337 if (!pool->whatprovides)
3338 pool_createwhatprovides(pool);
3340 /* create obsolete index if needed */
3341 if (solv->noupdateprovide)
3342 create_obsolete_index(solv);
3345 * create basic rule set of all involved packages
3346 * use addedmap bitmap to make sure we don't create rules twice
3350 map_init(&addedmap, pool->nsolvables);
3354 * always install our system solvable
3356 MAPSET(&addedmap, SYSTEMSOLVABLE);
3357 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3358 queue_push(&solv->decisionq_why, 0);
3359 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3362 * create rules for all package that could be involved with the solving
3363 * so called: rpm rules
3368 oldnrules = solv->nrules;
3369 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
3370 FOR_REPO_SOLVABLES(installed, p, s)
3371 addrpmrulesforsolvable(solv, s, &addedmap);
3372 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3373 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
3374 oldnrules = solv->nrules;
3375 FOR_REPO_SOLVABLES(installed, p, s)
3376 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3377 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3380 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
3381 oldnrules = solv->nrules;
3382 for (i = 0; i < job->count; i += 2)
3384 how = job->elements[i] & ~SOLVER_WEAK;
3385 what = job->elements[i + 1];
3389 case SOLVER_INSTALL_SOLVABLE:
3390 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3392 case SOLVER_INSTALL_SOLVABLE_NAME:
3393 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3394 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3395 while (ISRELDEP(name))
3397 Reldep *rd = GETRELDEP(pool, name);
3400 FOR_PROVIDES(p, pp, what)
3402 /* if by name, ensure that the name matches */
3403 if (name && pool->solvables[p].name != name)
3405 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3408 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3409 /* dont allow downgrade */
3410 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3412 case SOLVER_INSTALL_SOLVABLE_ONE_OF:
3413 pp = pool->whatprovidesdata + what;
3414 while ((p = *pp++) != 0)
3415 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3419 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3421 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
3423 oldnrules = solv->nrules;
3424 addrpmrulesforweak(solv, &addedmap);
3425 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3427 IF_POOLDEBUG (SAT_DEBUG_STATS)
3429 int possible = 0, installable = 0;
3430 for (i = 1; i < pool->nsolvables; i++)
3432 if (pool_installable(pool, pool->solvables + i))
3434 if (MAPTST(&addedmap, i))
3437 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3441 * first pass done, we now have all the rpm rules we need.
3442 * unify existing rules before going over all job rules and
3444 * at this point the system is always solvable,
3445 * as an empty system (remove all packages) is a valid solution
3448 unifyrules(solv); /* remove duplicate rpm rules */
3449 solv->rpmrules_end = solv->nrules;
3451 solv->directdecisions = solv->decisionq.count;
3452 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
3455 /* create feature rules */
3456 /* those are used later on to keep a version of the installed packages in
3458 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add feature rules ***\n");
3459 solv->featurerules = solv->nrules;
3462 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3464 if (s->freshens && !s->supplements)
3466 const char *name = id2str(pool, s->name);
3467 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
3469 addrule(solv, 0, 0);
3473 if (s->repo != installed)
3475 addrule(solv, 0, 0); /* create dummy rule */
3478 addupdaterule(solv, s, 1);
3480 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
3482 solv->featurerules_end = solv->nrules;
3484 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add update rules ***\n");
3485 solv->updaterules = solv->nrules;
3487 { /* loop over all installed solvables */
3488 /* we create all update rules, but disable some later on depending on the job */
3489 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3492 /* no update rules for patch atoms */
3493 if (s->freshens && !s->supplements)
3495 const char *name = id2str(pool, s->name);
3496 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
3498 addrule(solv, 0, 0);
3502 if (s->repo != installed)
3504 addrule(solv, 0, 0); /* create dummy rule */
3507 addupdaterule(solv, s, 0); /* allowall = 0 */
3508 r = solv->rules + solv->nrules - 1;
3509 sr = r - (installed->end - installed->start);
3510 unifyrules_sortcmp_data = pool;
3511 if (!unifyrules_sortcmp(r, sr))
3513 /* identical rule, kill unneeded rule */
3514 if (solv->allowuninstall)
3516 /* keep feature rule */
3517 memset(r, 0, sizeof(*r));
3518 queue_push(&solv->weakruleq, sr - solv->rules);
3522 /* keep update rule */
3523 memset(sr, 0, sizeof(*sr));
3526 else if (solv->allowuninstall)
3528 /* make both feature and update rule weak */
3529 queue_push(&solv->weakruleq, r - solv->rules);
3530 queue_push(&solv->weakruleq, sr - solv->rules);
3533 disablerule(solv, sr);
3535 /* consistency check: we added a rule for _every_ installed solvable */
3536 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
3538 solv->updaterules_end = solv->nrules;
3543 * now add all job rules
3546 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
3548 solv->jobrules = solv->nrules;
3549 for (i = 0; i < job->count; i += 2)
3551 oldnrules = solv->nrules;
3553 how = job->elements[i] & ~SOLVER_WEAK;
3554 weak = job->elements[i] & SOLVER_WEAK;
3555 what = job->elements[i + 1];
3558 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3559 s = pool->solvables + what;
3560 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall solvable %s\n", weak ? "weak " : "", solvable2str(pool, s));
3561 addrule(solv, what, 0); /* install by Id */
3562 queue_push(&solv->ruletojob, i);
3564 queue_push(&solv->weakruleq, solv->nrules - 1);
3566 case SOLVER_ERASE_SOLVABLE:
3567 s = pool->solvables + what;
3568 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase solvable %s\n", weak ? "weak " : "", solvable2str(pool, s));
3569 addrule(solv, -what, 0); /* remove by Id */
3570 queue_push(&solv->ruletojob, i);
3572 queue_push(&solv->weakruleq, solv->nrules - 1);
3574 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3575 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3576 if (how == SOLVER_INSTALL_SOLVABLE_NAME)
3577 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall name %s\n", weak ? "weak " : "", dep2str(pool, what));
3578 if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3579 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall provides %s\n", weak ? "weak " : "", dep2str(pool, what));
3581 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3582 while (ISRELDEP(name))
3584 Reldep *rd = GETRELDEP(pool, name);
3587 FOR_PROVIDES(p, pp, what)
3589 /* if by name, ensure that the name matches */
3590 if (name && pool->solvables[p].name != name)
3596 /* no provider, make this an impossible rule */
3597 queue_push(&q, -SYSTEMSOLVABLE);
3600 p = queue_shift(&q); /* get first provider */
3602 d = 0; /* single provider ? -> make assertion */
3604 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3605 addrule(solv, p, d); /* add 'requires' rule */
3606 queue_push(&solv->ruletojob, i);
3608 queue_push(&solv->weakruleq, solv->nrules - 1);
3610 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3611 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3612 if (how == SOLVER_ERASE_SOLVABLE_NAME)
3613 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase name %s\n", weak ? "weak " : "", dep2str(pool, what));
3614 if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3615 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase provides %s\n", weak ? "weak " : "", dep2str(pool, what));
3616 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
3617 while (ISRELDEP(name))
3619 Reldep *rd = GETRELDEP(pool, name);
3622 FOR_PROVIDES(p, pp, what)
3624 /* if by name, ensure that the name matches */
3625 if (name && pool->solvables[p].name != name)
3627 addrule(solv, -p, 0); /* add 'remove' rule */
3628 queue_push(&solv->ruletojob, i);
3630 queue_push(&solv->weakruleq, solv->nrules - 1);
3633 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3634 s = pool->solvables + what;
3635 POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solvable2str(pool, s));
3636 addupdaterule(solv, s, 0);
3637 queue_push(&solv->ruletojob, i);
3639 queue_push(&solv->weakruleq, solv->nrules - 1);
3641 case SOLVER_INSTALL_SOLVABLE_ONE_OF:
3642 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sone of\n", weak ? "weak " : "");
3643 for (pp = pool->whatprovidesdata + what; *pp; pp++)
3644 POOL_DEBUG(SAT_DEBUG_JOB, " %s\n", solvable2str(pool, pool->solvables + *pp));
3645 addrule(solv, -SYSTEMSOLVABLE, what);
3646 queue_push(&solv->ruletojob, i);
3648 queue_push(&solv->weakruleq, solv->nrules - 1);
3650 case SOLVER_WEAKEN_SOLVABLE_DEPS:
3651 s = pool->solvables + what;
3652 POOL_DEBUG(SAT_DEBUG_JOB, "job: weaken deps %s\n", solvable2str(pool, s));
3653 weaken_solvable_deps(solv, what);
3656 IF_POOLDEBUG (SAT_DEBUG_JOB)
3659 if (solv->nrules == oldnrules)
3660 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created\n");
3661 for (j = oldnrules; j < solv->nrules; j++)
3663 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
3664 solver_printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
3668 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3669 solv->jobrules_end = solv->nrules;
3671 /* free unneeded memory */
3672 map_free(&addedmap);
3675 /* create weak map */
3676 map_init(&solv->weakrulemap, solv->nrules);
3677 for (i = 0; i < solv->weakruleq.count; i++)
3679 p = solv->weakruleq.elements[i];
3680 MAPSET(&solv->weakrulemap, p);
3683 /* all new rules are learnt after this point */
3684 solv->learntrules = solv->nrules;
3686 /* create assertion index. it is only used to speed up
3687 * makeruledecsions() a bit */
3688 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
3689 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
3690 queue_push(&solv->ruleassertions, i);
3692 /* disable update rules that conflict with our job */
3693 disableupdaterules(solv, job, -1);
3696 /* make decisions based on job/update assertions */
3697 makeruledecisions(solv);
3699 /* create watches chains */
3702 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
3705 run_solver(solv, 1, solv->dontinstallrecommended ? 0 : 1);
3709 /* disable all erase jobs (including weak "keep uninstalled" rules) */
3710 for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++)
3712 if (r->d < 0) /* disabled ? */
3714 if (r->p > 0) /* install job? */
3716 disablerule(solv, r);
3722 enabledisablelearntrules(solv);
3723 removedisabledconflicts(solv, &redoq);
3726 /* find recommended packages */
3727 /* if redoq.count == 0 we already found all recommended in the
3729 if (redoq.count || solv->dontinstallrecommended || !solv->dontshowinstalledrecommended)
3731 Id rec, *recp, p, *pp;
3733 /* create map of all recommened packages */
3734 solv->recommends_index = -1;
3735 MAPZERO(&solv->recommendsmap);
3736 for (i = 0; i < solv->decisionq.count; i++)
3738 p = solv->decisionq.elements[i];
3741 s = pool->solvables + p;
3744 recp = s->repo->idarraydata + s->recommends;
3745 while ((rec = *recp++) != 0)
3747 FOR_PROVIDES(p, pp, rec)
3748 if (solv->decisionmap[p] > 0)
3752 if (!solv->dontshowinstalledrecommended)
3754 FOR_PROVIDES(p, pp, rec)
3755 if (solv->decisionmap[p] > 0)
3756 MAPSET(&solv->recommendsmap, p);
3758 continue; /* p != 0: already fulfilled */
3760 FOR_PROVIDES(p, pp, rec)
3761 MAPSET(&solv->recommendsmap, p);
3765 for (i = 1; i < pool->nsolvables; i++)
3767 if (solv->decisionmap[i] < 0)
3769 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
3771 s = pool->solvables + i;
3772 if (!MAPTST(&solv->recommendsmap, i))
3774 if (!s->supplements)
3776 if (!pool_installable(pool, s))
3778 if (!solver_is_supplementing(solv, s))
3781 if (solv->dontinstallrecommended)
3782 queue_push(&solv->recommendations, i);
3784 queue_pushunique(&solv->recommendations, i);
3786 /* we use MODE_SUGGEST here so that repo prio is ignored */
3787 policy_filter_unwanted(solv, &solv->recommendations, 0, POLICY_MODE_SUGGEST);
3790 /* find suggested packages */
3793 Id sug, *sugp, p, *pp;
3795 /* create map of all suggests that are still open */
3796 solv->recommends_index = -1;
3797 MAPZERO(&solv->suggestsmap);
3798 for (i = 0; i < solv->decisionq.count; i++)
3800 p = solv->decisionq.elements[i];
3803 s = pool->solvables + p;
3806 sugp = s->repo->idarraydata + s->suggests;
3807 while ((sug = *sugp++) != 0)
3809 FOR_PROVIDES(p, pp, sug)
3810 if (solv->decisionmap[p] > 0)
3814 if (!solv->dontshowinstalledrecommended)
3816 FOR_PROVIDES(p, pp, sug)
3817 if (solv->decisionmap[p] > 0)
3818 MAPSET(&solv->suggestsmap, p);
3820 continue; /* already fulfilled */
3822 FOR_PROVIDES(p, pp, sug)
3823 MAPSET(&solv->suggestsmap, p);
3827 for (i = 1; i < pool->nsolvables; i++)
3829 if (solv->decisionmap[i] < 0)
3831 if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
3833 s = pool->solvables + i;
3834 if (!MAPTST(&solv->suggestsmap, i))
3838 if (!pool_installable(pool, s))
3840 if (!solver_is_enhancing(solv, s))
3843 queue_push(&solv->suggestions, i);
3845 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
3850 /* restore decisionmap */
3851 for (i = 0; i < redoq.count; i += 2)
3852 solv->decisionmap[redoq.elements[i]] = redoq.elements[i + 1];
3856 if (solv->problems.count)
3858 int recocount = solv->recommendations.count;
3859 solv->recommendations.count = 0; /* so that revert() doesn't mess with it */
3860 queue_empty(&redoq);
3861 for (i = 0; i < solv->decisionq.count; i++)
3863 Id p = solv->decisionq.elements[i];
3864 queue_push(&redoq, p);
3865 queue_push(&redoq, solv->decisionq_why.elements[i]);
3866 queue_push(&redoq, solv->decisionmap[p > 0 ? p : -p]);
3868 problems_to_solutions(solv, job);
3869 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
3870 queue_empty(&solv->decisionq);
3871 queue_empty(&solv->decisionq_why);
3872 for (i = 0; i < redoq.count; i += 3)
3874 Id p = redoq.elements[i];
3875 queue_push(&solv->decisionq, p);
3876 queue_push(&solv->decisionq_why, redoq.elements[i + 1]);
3877 solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
3879 solv->recommendations.count = recocount;
3882 POOL_DEBUG(SAT_DEBUG_STATS, "final solver statistics: %d learned rules, %d unsolvable\n", solv->stats_learned, solv->stats_unsolvable);
3886 /***********************************************************************/
3889 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
3893 solver_create_state_maps(solv, &installedmap, 0);
3894 pool_calc_duchanges(solv->pool, solv->installed, &installedmap, mps, nmps);
3895 map_free(&installedmap);
3899 solver_calc_installsizechange(Solver *solv)
3904 solver_create_state_maps(solv, &installedmap, 0);
3905 change = pool_calc_installsizechange(solv->pool, solv->installed, &installedmap);
3906 map_free(&installedmap);