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
29 #define RULES_BLOCK 63
30 #define REGARD_RECOMMENDS_OF_INSTALLED_ITEMS 1
34 solver_splitprovides(Solver *solv, Id dep)
36 Pool *pool = solv->pool;
41 if (!solv->dosplitprovides || !solv->installed)
45 rd = GETRELDEP(pool, dep);
46 if (rd->flags != REL_WITH)
48 FOR_PROVIDES(p, pp, dep)
50 s = pool->solvables + p;
51 if (s->repo == solv->installed && s->name == rd->name)
58 solver_dep_installed(Solver *solv, Id dep)
61 Pool *pool = solv->pool;
66 Reldep *rd = GETRELDEP(pool, dep);
67 if (rd->flags == REL_AND)
69 if (!solver_dep_installed(solv, rd->name))
71 return solver_dep_installed(solv, rd->evr);
73 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
74 return solver_dep_installed(solv, rd->evr);
76 FOR_PROVIDES(p, pp, dep)
78 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
86 /* this mirrors solver_dep_fulfilled but uses map m instead of the decisionmap */
88 dep_possible(Solver *solv, Id dep, Map *m)
90 Pool *pool = solv->pool;
95 Reldep *rd = GETRELDEP(pool, dep);
96 if (rd->flags == REL_AND)
98 if (!dep_possible(solv, rd->name, m))
100 return dep_possible(solv, rd->evr, m);
102 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
103 return solver_splitprovides(solv, rd->evr);
104 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
105 return solver_dep_installed(solv, rd->evr);
107 FOR_PROVIDES(p, pp, dep)
115 /*-----------------------------------------------------------------*/
122 printruleelement(Solver *solv, int type, Rule *r, Id v)
124 Pool *pool = solv->pool;
128 s = pool->solvables + -v;
129 POOL_DEBUG(type, " !%s [%d]", solvable2str(pool, s), -v);
133 s = pool->solvables + v;
134 POOL_DEBUG(type, " %s [%d]", solvable2str(pool, s), v);
139 POOL_DEBUG(type, " (w1)");
141 POOL_DEBUG(type, " (w2)");
143 if (solv->decisionmap[s - pool->solvables] > 0)
144 POOL_DEBUG(type, " Install.level%d", solv->decisionmap[s - pool->solvables]);
145 if (solv->decisionmap[s - pool->solvables] < 0)
146 POOL_DEBUG(type, " Conflict.level%d", -solv->decisionmap[s - pool->solvables]);
147 POOL_DEBUG(type, "\n");
156 printrule(Solver *solv, int type, Rule *r)
158 Pool *pool = solv->pool;
162 if (r >= solv->rules && r < solv->rules + solv->nrules) /* r is a solver rule */
163 POOL_DEBUG(type, "Rule #%d:", (int)(r - solv->rules));
165 POOL_DEBUG(type, "Rule:"); /* r is any rule */
167 POOL_DEBUG(type, " (disabled)");
168 POOL_DEBUG(type, "\n");
172 /* print direct literal */
174 else if (r->d == ID_NULL)
178 /* binary rule --> print w2 as second literal */
182 /* every other which is in d */
183 v = solv->pool->whatprovidesdata[r->d + i - 1];
186 printruleelement(solv, type, r, v);
188 POOL_DEBUG(type, " next rules: %d %d\n", r->n1, r->n2);
192 printruleclass(Solver *solv, int type, Rule *r)
194 Pool *pool = solv->pool;
195 Id p = r - solv->rules;
197 if (p < solv->learntrules)
198 if (MAPTST(&solv->weakrulemap, p))
199 POOL_DEBUG(type, "WEAK ");
200 if (p >= solv->learntrules)
201 POOL_DEBUG(type, "LEARNT ");
202 else if (p >= solv->systemrules)
203 POOL_DEBUG(type, "SYSTEM ");
204 else if (p >= solv->jobrules)
205 POOL_DEBUG(type, "JOB ");
206 printrule(solv, type, r);
210 /*-----------------------------------------------------------------*/
216 static Pool *unifyrules_sortcmp_data;
219 * compare rules for unification sort
223 unifyrules_sortcmp(const void *ap, const void *bp)
225 Pool *pool = unifyrules_sortcmp_data;
226 Rule *a = (Rule *)ap;
227 Rule *b = (Rule *)bp;
233 return x; /* p differs */
236 if (a->d == 0 && b->d == 0)
237 return a->w2 - b->w2; /* assertion: return w2 diff */
239 if (a->d == 0) /* a is assertion, b not */
241 x = a->w2 - pool->whatprovidesdata[b->d];
245 if (b->d == 0) /* b is assertion, a not */
247 x = pool->whatprovidesdata[a->d] - b->w2;
251 /* compare whatprovidesdata */
252 ad = pool->whatprovidesdata + a->d;
253 bd = pool->whatprovidesdata + b->d;
255 if ((x = *ad++ - *bd++) != 0)
266 unifyrules(Solver *solv)
268 Pool *pool = solv->pool;
272 if (solv->nrules <= 1) /* nothing to unify */
275 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
277 /* sort rules first */
278 unifyrules_sortcmp_data = solv->pool;
279 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
286 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
288 if (jr && !unifyrules_sortcmp(ir, jr))
289 continue; /* prune! */
290 jr = solv->rules + j++; /* keep! */
295 /* reduced count from nrules to j rules */
296 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
298 /* adapt rule buffer */
300 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
301 IF_POOLDEBUG (SAT_DEBUG_STATS)
308 for (i = 1; i < solv->nrules; i++)
315 dp = solv->pool->whatprovidesdata + r->d;
320 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
321 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
323 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
333 hashrule(Solver *solv, Id p, Id d, int n)
335 unsigned int x = (unsigned int)p;
339 return (x * 37) ^ (unsigned int)d;
340 dp = solv->pool->whatprovidesdata + d;
342 x = (x * 37) ^ (unsigned int)*dp++;
350 * p = direct literal; always < 0 for installed rpm rules
351 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
354 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
356 * p < 0 : pkg id of A
357 * d > 0 : Offset in whatprovidesdata (list of providers of b)
359 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
360 * p < 0 : pkg id of A
361 * d < 0 : Id of solvable (e.g. B1)
363 * d == 0: unary rule, assertion => (A) or (-A)
365 * Install: p > 0, d = 0 (A) user requested install
366 * Remove: p < 0, d = 0 (-A) user requested remove
367 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
368 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
369 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
370 * ? p > 0, d < 0 (A|-B)
371 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
375 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
376 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
377 * every other : w1 = p, w2 = whatprovidesdata[d];
378 * Disabled rule: w1 = 0
380 * always returns a rule for non-rpm rules
384 addrule(Solver *solv, Id p, Id d)
386 Pool *pool = solv->pool;
390 int n = 0; /* number of literals in rule - 1
391 0 = direct assertion (single literal)
395 /* it often happenes that requires lead to adding the same rpm rule
396 * multiple times, so we prune those duplicates right away to make
397 * the work for unifyrules a bit easier */
399 if (solv->nrules && !solv->jobrules)
401 r = solv->rules + solv->nrules - 1; /* get the last added rule */
402 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
408 /* always a binary rule */
410 return 0; /* ignore self conflict */
415 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
417 return 0; /* rule is self-fulfilling */
419 d = dp[-1]; /* take single literal */
423 if (n == 0 && !solv->jobrules)
425 /* this is a rpm rule assertion, we do not have to allocate it */
426 /* it can be identified by a level of 1 and a zero reason */
427 /* we must not drop those rules from the decisionq when rewinding! */
429 assert(solv->decisionmap[-p] == 0 || solv->decisionmap[-p] == -1);
430 if (solv->decisionmap[-p])
431 return 0; /* already got that one */
432 queue_push(&solv->decisionq, p);
433 queue_push(&solv->decisionq_why, 0);
434 solv->decisionmap[-p] = -1;
441 /* smallest literal first so we can find dups */
445 n = 1; /* re-set n, was used as temp var */
448 /* check if the last added rule is exactly the same as what we're looking for. */
449 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
450 return r; /* binary rule */
452 if (r && n > 1 && r->d && r->p == p)
454 /* Rule where d is an offset in whatprovidesdata */
458 dp2 = pool->whatprovidesdata + r->d;
459 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
470 /* extend rule buffer */
471 solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
472 r = solv->rules + solv->nrules++; /* point to rule space */
477 /* direct assertion, no watch needed */
493 r->w2 = pool->whatprovidesdata[d];
498 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
500 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
501 printrule(solv, SAT_DEBUG_RULE_CREATION, r);
508 disablerule(Solver *solv, Rule *r)
514 enablerule(Solver *solv, Rule *r)
516 if (r->d == 0 || r->w2 != r->p)
519 r->w1 = solv->pool->whatprovidesdata[r->d];
523 /**********************************************************************************/
525 /* a problem is an item on the solver's problem list. It can either be >0, in that
526 * case it is a system (upgrade) rule, or it can be <0, which makes it refer to a job
527 * consisting of multiple job rules.
531 disableproblem(Solver *solv, Id v)
539 disablerule(solv, solv->rules + v);
543 jp = solv->ruletojob.elements;
544 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
546 disablerule(solv, r);
550 enableproblem(Solver *solv, Id v)
558 enablerule(solv, solv->rules + v);
562 jp = solv->ruletojob.elements;
563 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
569 printproblem(Solver *solv, Id v)
571 Pool *pool = solv->pool;
577 printrule(solv, SAT_DEBUG_SOLUTIONS, solv->rules + v);
581 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "JOB %d\n", v);
582 jp = solv->ruletojob.elements;
583 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
586 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "- ");
587 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
589 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "ENDJOB\n");
595 /************************************************************************/
597 /* go through system and job rules and add direct assertions
598 * to the decisionqueue. If we find a conflict, disable rules and
599 * add them to problem queue.
602 makeruledecisions(Solver *solv)
604 Pool *pool = solv->pool;
610 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
612 decisionstart = solv->decisionq.count;
613 /* rpm rules don't have assertions, so we can start with the job
614 * rules (rpm assertions are not resulting in a rule, but cause a
615 * immediate decision) */
616 /* nowadays they can be weak, so start with rule 1 */
617 for (ri = 1, r = solv->rules + ri; ri < solv->nrules; ri++, r++)
619 if (!r->w1 || r->w2) /* disabled or no assertion */
621 /* do weak rules in phase 2 */
622 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
626 if (!solv->decisionmap[vv])
628 queue_push(&solv->decisionq, v);
629 queue_push(&solv->decisionq_why, r - solv->rules);
630 solv->decisionmap[vv] = v > 0 ? 1 : -1;
631 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
633 Solvable *s = solv->pool->solvables + vv;
635 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
637 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
641 if (v > 0 && solv->decisionmap[vv] > 0)
643 if (v < 0 && solv->decisionmap[vv] < 0)
645 /* found a conflict! */
646 if (ri >= solv->learntrules)
648 /* conflict with a learnt rule */
649 /* can happen when packages cannot be installed for
650 * multiple reasons. */
651 /* we disable the learnt rule in this case */
652 disablerule(solv, r);
655 /* only job and system rules left in the decisionq */
656 /* find the decision which is the "opposite" of the jobrule */
657 for (i = 0; i < solv->decisionq.count; i++)
658 if (solv->decisionq.elements[i] == -v)
660 assert(i < solv->decisionq.count);
661 if (v == -SYSTEMSOLVABLE) {
662 /* conflict with system solvable */
663 queue_push(&solv->problems, solv->learnt_pool.count);
664 queue_push(&solv->learnt_pool, ri);
665 queue_push(&solv->learnt_pool, 0);
666 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
667 if (ri < solv->systemrules)
668 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
671 queue_push(&solv->problems, v);
672 queue_push(&solv->problems, 0);
673 disableproblem(solv, v);
676 assert(solv->decisionq_why.elements[i]);
677 if (solv->decisionq_why.elements[i] < solv->jobrules)
679 /* conflict with rpm rule assertion */
680 queue_push(&solv->problems, solv->learnt_pool.count);
681 queue_push(&solv->learnt_pool, ri);
682 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
683 queue_push(&solv->learnt_pool, 0);
684 assert(v > 0 || v == -SYSTEMSOLVABLE);
685 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
686 if (ri < solv->systemrules)
687 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
690 queue_push(&solv->problems, v);
691 queue_push(&solv->problems, 0);
692 disableproblem(solv, v);
696 /* conflict with another job or system rule */
698 queue_push(&solv->problems, solv->learnt_pool.count);
699 queue_push(&solv->learnt_pool, ri);
700 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
701 queue_push(&solv->learnt_pool, 0);
703 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting system/job assertions over literal %d\n", vv);
705 /* push all of our rules asserting this literal on the problem stack */
706 for (i = solv->jobrules, rr = solv->rules + i; i < solv->nrules; i++, rr++)
708 if (!rr->w1 || rr->w2)
710 if (rr->p != vv && rr->p != -vv)
712 if (i >= solv->learntrules)
714 if (MAPTST(&solv->weakrulemap, i))
716 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
718 if (i < solv->systemrules)
719 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
720 queue_push(&solv->problems, v);
721 disableproblem(solv, v);
723 queue_push(&solv->problems, 0);
726 while (solv->decisionq.count > decisionstart)
728 v = solv->decisionq.elements[--solv->decisionq.count];
729 --solv->decisionq_why.count;
731 solv->decisionmap[vv] = 0;
733 ri = solv->jobrules - 1;
734 r = solv->rules + ri;
737 /* phase 2: now do the weak assertions */
738 for (ri = 1, r = solv->rules + ri; ri < solv->learntrules; ri++, r++)
740 if (!r->w1 || r->w2) /* disabled or no assertion */
742 if (!MAPTST(&solv->weakrulemap, ri))
746 if (!solv->decisionmap[vv])
748 queue_push(&solv->decisionq, v);
749 queue_push(&solv->decisionq_why, r - solv->rules);
750 solv->decisionmap[vv] = v > 0 ? 1 : -1;
751 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
753 Solvable *s = solv->pool->solvables + vv;
755 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", solvable2str(solv->pool, s));
757 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", solvable2str(solv->pool, s));
761 if (v > 0 && solv->decisionmap[vv] > 0)
763 if (v < 0 && solv->decisionmap[vv] < 0)
765 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
766 printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
767 disablerule(solv, r);
770 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
774 * we have enabled or disabled some of our rules. We now reenable all
775 * of our learnt rules but the ones that were learnt from rules that
779 enabledisablelearntrules(Solver *solv)
781 Pool *pool = solv->pool;
786 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
787 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
789 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
790 while ((why = *whyp++) != 0)
794 continue; /* rpm assertion */
797 if (!solv->rules[why].w1)
800 /* why != 0: we found a disabled rule, disable the learnt rule */
803 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
805 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling ");
806 printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
808 disablerule(solv, r);
810 else if (!why && !r->w1)
812 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
814 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling ");
815 printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
823 /* FIXME: bad code ahead, replace as soon as possible */
824 /* FIXME: should probably look at SOLVER_INSTALL_SOLVABLE_ONE_OF */
827 disableupdaterules(Solver *solv, Queue *job, int jobidx)
829 Pool *pool = solv->pool;
831 Id name, how, what, p, *pp;
837 installed = solv->installed;
843 how = job->elements[jobidx] & ~SOLVER_WEAK;
846 case SOLVER_INSTALL_SOLVABLE:
847 case SOLVER_ERASE_SOLVABLE:
848 case SOLVER_ERASE_SOLVABLE_NAME:
849 case SOLVER_ERASE_SOLVABLE_PROVIDES:
855 /* go through all enabled job rules */
856 MAPZERO(&solv->noupdate);
857 for (i = solv->jobrules; i < solv->systemrules; i++)
860 if (!r->w1) /* disabled? */
862 j = solv->ruletojob.elements[i - solv->jobrules];
866 how = job->elements[j] & ~SOLVER_WEAK;
867 what = job->elements[j + 1];
870 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
871 s = pool->solvables + what;
872 FOR_PROVIDES(p, pp, s->name)
874 if (pool->solvables[p].name != s->name)
876 if (pool->solvables[p].repo == installed)
877 MAPSET(&solv->noupdate, p - installed->start);
880 case SOLVER_ERASE_SOLVABLE:
881 s = pool->solvables + what;
882 if (s->repo == installed)
883 MAPSET(&solv->noupdate, what - installed->start);
885 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
886 case SOLVER_ERASE_SOLVABLE_PROVIDES:
887 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
888 while (ISRELDEP(name))
890 Reldep *rd = GETRELDEP(pool, name);
893 FOR_PROVIDES(p, pp, what)
895 if (name && pool->solvables[p].name != name)
897 if (pool->solvables[p].repo == installed)
898 MAPSET(&solv->noupdate, p - installed->start);
906 /* fixup update rule status */
907 if (solv->allowuninstall)
908 return; /* no update rules at all */
912 /* we just disabled job #jobidx. enable all update rules
913 * that aren't disabled by the remaining job rules */
914 how = job->elements[jobidx] & ~SOLVER_WEAK;
915 what = job->elements[jobidx + 1];
918 case SOLVER_INSTALL_SOLVABLE:
919 s = pool->solvables + what;
920 FOR_PROVIDES(p, pp, s->name)
922 if (pool->solvables[p].name != s->name)
924 if (pool->solvables[p].repo != installed)
926 if (MAPTST(&solv->noupdate, p - installed->start))
928 r = solv->rules + solv->systemrules + (p - installed->start);
932 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
934 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
935 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
939 case SOLVER_ERASE_SOLVABLE:
940 s = pool->solvables + what;
941 if (s->repo != installed)
943 if (MAPTST(&solv->noupdate, what - installed->start))
945 r = solv->rules + solv->systemrules + (what - installed->start);
949 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
951 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
952 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
955 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
956 case SOLVER_ERASE_SOLVABLE_PROVIDES:
957 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
958 while (ISRELDEP(name))
960 Reldep *rd = GETRELDEP(pool, name);
963 FOR_PROVIDES(p, pp, what)
965 if (name && pool->solvables[p].name != name)
967 if (pool->solvables[p].repo != installed)
969 if (MAPTST(&solv->noupdate, p - installed->start))
971 r = solv->rules + solv->systemrules + (p - installed->start);
975 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
977 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
978 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
988 for (i = 0; i < installed->nsolvables; i++)
990 r = solv->rules + solv->systemrules + i;
991 if (r->w1 && MAPTST(&solv->noupdate, i))
992 disablerule(solv, r); /* was enabled, need to disable */
998 addpatchatomrequires(Solver *solv, Solvable *s, Id *dp, Queue *q, Map *m)
1000 Pool *pool = solv->pool;
1001 Id fre, *frep, p, *pp, ndp;
1007 queue_init_buffer(&fq, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1008 queue_push(&fq, -(s - pool->solvables));
1010 queue_push(&fq, *dp);
1011 ndp = pool_queuetowhatprovides(pool, &fq);
1012 frep = s->repo->idarraydata + s->freshens;
1013 while ((fre = *frep++) != 0)
1015 FOR_PROVIDES(p, pp, fre)
1017 ps = pool->solvables + p;
1018 addrule(solv, -p, ndp);
1026 for (i = 1; i < fq.count; i++)
1039 * add (install) rules for solvable
1040 * for unfulfilled requirements, conflicts, obsoletes,....
1041 * add a negative assertion for solvables that are not installable
1045 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
1047 Pool *pool = solv->pool;
1048 Repo *installed = solv->installed;
1063 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
1065 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1066 queue_push(&q, s - pool->solvables); /* push solvable Id */
1072 * s: Pointer to solvable
1075 n = queue_shift(&q);
1076 if (MAPTST(m, n)) /* continue if already done */
1080 s = pool->solvables + n; /* s = Solvable in question */
1083 if (installed /* Installed system available */
1084 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
1085 && s->repo == installed) /* solvable is installed? */
1087 dontfix = 1; /* dont care about broken rpm deps */
1090 if (!dontfix && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
1092 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
1093 addrule(solv, -n, 0); /* uninstallable */
1097 if (s->freshens && !s->supplements)
1099 const char *name = id2str(pool, s->name);
1100 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
1104 /*-----------------------------------------
1105 * check requires of s
1110 reqp = s->repo->idarraydata + s->requires;
1111 while ((req = *reqp++) != 0) /* go throw all requires */
1113 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
1116 dp = pool_whatprovides(pool, req);
1118 if (*dp == SYSTEMSOLVABLE) /* always installed */
1124 addpatchatomrequires(solv, s, dp, &q, m);
1130 /* the strategy here is to not insist on dependencies
1131 * that are already broken. so if we find one provider
1132 * that was already installed, we know that the
1133 * dependency was not broken before so we enforce it */
1134 for (i = 0; (p = dp[i]) != 0; i++) /* for all providers */
1136 if (pool->solvables[p].repo == installed)
1137 break; /* provider was installed */
1139 if (!p) /* previously broken dependency */
1141 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1148 /* nothing provides req! */
1149 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1150 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1154 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1156 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1157 for (i = 0; dp[i]; i++)
1158 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1161 /* add 'requires' dependency */
1162 /* rule: (-requestor|provider1|provider2|...|providerN) */
1163 addrule(solv, -n, dp - pool->whatprovidesdata);
1165 /* descend the dependency tree */
1166 for (; *dp; dp++) /* loop through all providers */
1168 if (!MAPTST(m, *dp))
1169 queue_push(&q, *dp);
1172 } /* while, requirements of n */
1174 } /* if, requirements */
1176 /* that's all we check for src packages */
1177 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1180 /*-----------------------------------------
1181 * check conflicts of s
1186 conp = s->repo->idarraydata + s->conflicts;
1187 while ((con = *conp++) != 0)
1189 FOR_PROVIDES(p, pp, con)
1191 /* dontfix: dont care about conflicts with already installed packs */
1192 if (dontfix && pool->solvables[p].repo == installed)
1194 /* rule: -n|-p: either solvable _or_ provider of conflict */
1195 addrule(solv, -n, -p);
1200 /*-----------------------------------------
1201 * check obsoletes if not installed
1203 if (!installed || pool->solvables[n].repo != installed)
1204 { /* not installed */
1207 obsp = s->repo->idarraydata + s->obsoletes;
1208 while ((obs = *obsp++) != 0)
1210 FOR_PROVIDES(p, pp, obs)
1211 addrule(solv, -n, -p);
1214 FOR_PROVIDES(p, pp, s->name)
1216 if (s->name == pool->solvables[p].name)
1217 addrule(solv, -n, -p);
1221 /*-----------------------------------------
1222 * add recommends to the rule list
1226 recp = s->repo->idarraydata + s->recommends;
1227 while ((rec = *recp++) != 0)
1229 FOR_PROVIDES(p, pp, rec)
1236 sugp = s->repo->idarraydata + s->suggests;
1237 while ((sug = *sugp++) != 0)
1239 FOR_PROVIDES(p, pp, sug)
1246 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1250 addrpmrulesforweak(Solver *solv, Map *m)
1252 Pool *pool = solv->pool;
1257 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1258 for (i = n = 1; n < pool->nsolvables; i++, n++)
1260 if (i == pool->nsolvables)
1264 s = pool->solvables + i;
1265 if (!pool_installable(pool, s))
1270 supp = s->repo->idarraydata + s->supplements;
1271 while ((sup = *supp++) != ID_NULL)
1272 if (dep_possible(solv, sup, m))
1275 if (!sup && s->freshens)
1277 supp = s->repo->idarraydata + s->freshens;
1278 while ((sup = *supp++) != ID_NULL)
1279 if (dep_possible(solv, sup, m))
1282 if (!sup && s->enhances)
1284 supp = s->repo->idarraydata + s->enhances;
1285 while ((sup = *supp++) != ID_NULL)
1286 if (dep_possible(solv, sup, m))
1291 addrpmrulesforsolvable(solv, s, m);
1294 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1298 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
1300 Pool *pool = solv->pool;
1305 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1307 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1308 policy_findupdatepackages(solv, s, &qs, allowall);
1309 if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
1310 addrpmrulesforsolvable(solv, s, m);
1311 for (i = 0; i < qs.count; i++)
1312 if (!MAPTST(m, qs.elements[i]))
1313 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1316 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1320 * add rule for update
1321 * (A|A1|A2|A3...) An = update candidates for A
1323 * s = (installed) solvable
1327 addupdaterule(Solver *solv, Solvable *s, int allowall)
1329 /* installed packages get a special upgrade allowed rule */
1330 Pool *pool = solv->pool;
1335 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1337 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1338 policy_findupdatepackages(solv, s, &qs, allowall);
1339 if (qs.count == 0) /* no updaters found */
1342 d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
1344 addrule(solv, s - pool->solvables, d); /* allow update of s */
1345 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1349 /*-----------------------------------------------------------------*/
1358 printWatches(Solver *solv, int type)
1360 Pool *pool = solv->pool;
1363 POOL_DEBUG(type, "Watches: \n");
1364 for (counter = -(pool->nsolvables - 1); counter < pool->nsolvables; counter++)
1365 POOL_DEBUG(type, " solvable [%d] -- rule [%d]\n", counter, solv->watches[counter + pool->nsolvables]);
1371 * initial setup for all watches
1375 makewatches(Solver *solv)
1379 int nsolvables = solv->pool->nsolvables;
1381 sat_free(solv->watches);
1382 /* lower half for removals, upper half for installs */
1383 solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
1385 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
1386 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1388 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1391 if (!r->w1 /* rule is disabled */
1392 || !r->w2) /* rule is assertion */
1395 /* see addwatches(solv, r) */
1396 r->n1 = solv->watches[nsolvables + r->w1];
1397 solv->watches[nsolvables + r->w1] = r - solv->rules;
1399 r->n2 = solv->watches[nsolvables + r->w2];
1400 solv->watches[nsolvables + r->w2] = r - solv->rules;
1406 * add watches (for rule)
1410 addwatches(Solver *solv, Rule *r)
1412 int nsolvables = solv->pool->nsolvables;
1414 r->n1 = solv->watches[nsolvables + r->w1];
1415 solv->watches[nsolvables + r->w1] = r - solv->rules;
1417 r->n2 = solv->watches[nsolvables + r->w2];
1418 solv->watches[nsolvables + r->w2] = r - solv->rules;
1422 /*-----------------------------------------------------------------*/
1423 /* rule propagation */
1425 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1426 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
1431 * propagate decision to all rules
1432 * return : 0 = everything is OK
1433 * watched rule = there is a conflict
1437 propagate(Solver *solv, int level)
1439 Pool *pool = solv->pool;
1444 Id *decisionmap = solv->decisionmap;
1445 Id *watches = solv->watches + pool->nsolvables;
1447 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1449 while (solv->propagate_index < solv->decisionq.count)
1451 /* negate because our watches trigger if literal goes FALSE */
1452 pkg = -solv->decisionq.elements[solv->propagate_index++];
1453 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1455 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
1456 printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1458 printWatches(solv, SAT_DEBUG_SCHUBI);
1461 for (rp = watches + pkg; *rp; rp = nrp)
1463 r = solv->rules + *rp;
1465 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1467 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1468 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1473 ow = r->w2; /* regard the second watchpoint to come to a solution */
1478 ow = r->w1; /* regard the first watchpoint to come to a solution */
1481 /* if clause is TRUE, nothing to do */
1482 if (DECISIONMAP_TRUE(ow))
1487 /* not a binary clause, check if we need to move our watch */
1488 /* search for a literal that is not ow and not false */
1489 /* (true is also ok, in that case the rule is fulfilled) */
1490 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1493 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1494 if (p != ow && !DECISIONMAP_TRUE(-p))
1498 /* p is free to watch, move watch to p */
1499 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1502 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1504 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1518 watches[p] = r - solv->rules;
1522 /* unit clause found, set other watch to TRUE */
1523 if (DECISIONMAP_TRUE(-ow))
1524 return r; /* eek, a conflict! */
1525 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1527 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
1528 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1531 decisionmap[ow] = level;
1533 decisionmap[-ow] = -level;
1534 queue_push(&solv->decisionq, ow);
1535 queue_push(&solv->decisionq_why, r - solv->rules);
1536 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1538 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1540 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
1542 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
1546 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
1548 return 0; /* all is well */
1552 /*-----------------------------------------------------------------*/
1561 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
1563 Pool *pool = solv->pool;
1566 Map seen; /* global? */
1569 int num = 0, l1num = 0;
1570 int learnt_why = solv->learnt_pool.count;
1571 Id *decisionmap = solv->decisionmap;
1575 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
1576 map_init(&seen, pool->nsolvables);
1577 idx = solv->decisionq.count;
1580 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1581 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1582 queue_push(&solv->learnt_pool, c - solv->rules);
1583 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1584 /* go through all literals of the rule */
1596 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1598 vv = v > 0 ? v : -v;
1599 if (MAPTST(&seen, vv))
1601 l = solv->decisionmap[vv];
1606 /* a level 1 literal, mark it for later */
1607 MAPSET(&seen, vv); /* mark for scanning in level 1 phase */
1613 num++; /* need to do this one as well */
1624 v = solv->decisionq.elements[--idx];
1625 vv = v > 0 ? v : -v;
1626 if (MAPTST(&seen, vv))
1629 c = solv->rules + solv->decisionq_why.elements[idx];
1634 *pr = -v; /* so that v doesn't get lost */
1636 /* add involved level 1 rules */
1639 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1643 v = solv->decisionq.elements[--idx];
1644 vv = v > 0 ? v : -v;
1645 if (!MAPTST(&seen, vv))
1647 why = solv->decisionq_why.elements[idx];
1650 queue_push(&solv->learnt_pool, -vv);
1651 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1653 POOL_DEBUG(SAT_DEBUG_ANALYZE, "RPM ASSERT Rule:\n");
1654 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, v);
1658 queue_push(&solv->learnt_pool, why);
1659 c = solv->rules + why;
1660 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1661 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1662 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1673 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1675 vv = v > 0 ? v : -v;
1676 l = solv->decisionmap[vv];
1677 if (l != 1 && l != -1)
1687 else if (r.count == 1 && r.elements[0] < 0)
1688 *dr = r.elements[0];
1690 *dr = pool_queuetowhatprovides(pool, &r);
1691 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1693 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1694 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
1695 for (i = 0; i < r.count; i++)
1696 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
1698 /* push end marker on learnt reasons stack */
1699 queue_push(&solv->learnt_pool, 0);
1708 * reset the solver decisions to right after the rpm rules.
1709 * called after rules have been enabled/disabled
1713 reset_solver(Solver *solv)
1715 Pool *pool = solv->pool;
1719 /* rewind decisions to direct rpm rule assertions */
1720 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
1722 v = solv->decisionq.elements[i];
1723 solv->decisionmap[v > 0 ? v : -v] = 0;
1726 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
1728 solv->decisionq_why.count = solv->directdecisions;
1729 solv->decisionq.count = solv->directdecisions;
1730 solv->recommends_index = -1;
1731 solv->propagate_index = 0;
1733 /* adapt learnt rule status to new set of enabled/disabled rules */
1734 enabledisablelearntrules(solv);
1736 /* redo all job/system decisions */
1737 makeruledecisions(solv);
1738 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
1740 /* recreate watch chains */
1746 * analyze_unsolvable_rule
1750 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
1752 Pool *pool = solv->pool;
1754 Id why = r - solv->rules;
1756 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1757 printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1758 if (solv->learntrules && why >= solv->learntrules)
1760 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1761 if (solv->learnt_pool.elements[i] > 0)
1762 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp);
1765 if (MAPTST(&solv->weakrulemap, why))
1766 if (!*lastweakp || why > *lastweakp)
1768 /* do not add rpm rules to problem */
1769 if (why < solv->jobrules)
1771 /* turn rule into problem */
1772 if (why >= solv->jobrules && why < solv->systemrules)
1773 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1774 /* return if problem already countains our rule */
1775 if (solv->problems.count)
1777 for (i = solv->problems.count - 1; i >= 0; i--)
1778 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1780 else if (solv->problems.elements[i] == why)
1783 queue_push(&solv->problems, why);
1788 * analyze_unsolvable
1790 * return: 1 - disabled some rules, try again
1795 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1797 Pool *pool = solv->pool;
1799 Map seen; /* global to speed things up? */
1802 Id *decisionmap = solv->decisionmap;
1803 int oldproblemcount;
1804 int oldlearntpoolcount;
1807 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1808 oldproblemcount = solv->problems.count;
1809 oldlearntpoolcount = solv->learnt_pool.count;
1811 /* make room for proof index */
1812 /* must update it later, as analyze_unsolvable_rule would confuse
1813 * it with a rule index if we put the real value in already */
1814 queue_push(&solv->problems, 0);
1817 map_init(&seen, pool->nsolvables);
1818 queue_push(&solv->learnt_pool, r - solv->rules);
1820 analyze_unsolvable_rule(solv, r, &lastweak);
1821 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1832 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1834 vv = v > 0 ? v : -v;
1835 l = solv->decisionmap[vv];
1840 idx = solv->decisionq.count;
1843 v = solv->decisionq.elements[--idx];
1844 vv = v > 0 ? v : -v;
1845 if (!MAPTST(&seen, vv))
1847 why = solv->decisionq_why.elements[idx];
1848 queue_push(&solv->learnt_pool, why);
1849 r = solv->rules + why;
1850 analyze_unsolvable_rule(solv, r, &lastweak);
1851 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1862 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1864 vv = v > 0 ? v : -v;
1865 l = solv->decisionmap[vv];
1872 queue_push(&solv->problems, 0); /* mark end of this problem */
1876 /* disable last weak rule */
1877 solv->problems.count = oldproblemcount;
1878 solv->learnt_pool.count = oldlearntpoolcount;
1879 r = solv->rules + lastweak;
1880 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling ");
1881 printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1882 disablerule(solv, r);
1888 queue_push(&solv->learnt_pool, 0);
1889 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1893 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1894 disableproblem(solv, solv->problems.elements[i]);
1898 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1903 /*-----------------------------------------------------------------*/
1904 /* Decision revert */
1908 * revert decision at level
1912 revert(Solver *solv, int level)
1914 Pool *pool = solv->pool;
1916 while (solv->decisionq.count)
1918 v = solv->decisionq.elements[solv->decisionq.count - 1];
1919 vv = v > 0 ? v : -v;
1920 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1922 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1923 if (v > 0 && solv->recommendations.count && v == solv->recommendations.elements[solv->recommendations.count - 1])
1924 solv->recommendations.count--;
1925 solv->decisionmap[vv] = 0;
1926 solv->decisionq.count--;
1927 solv->decisionq_why.count--;
1928 solv->propagate_index = solv->decisionq.count;
1930 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1932 solv->branches.count--;
1933 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1934 solv->branches.count--;
1936 solv->recommends_index = -1;
1941 * watch2onhighest - put watch2 on literal with highest level
1945 watch2onhighest(Solver *solv, Rule *r)
1951 return; /* binary rule, both watches are set */
1952 dp = solv->pool->whatprovidesdata + r->d;
1953 while ((v = *dp++) != 0)
1955 l = solv->decisionmap[v < 0 ? -v : v];
1970 * add free decision to decisionq, increase level and
1971 * propagate decision, return if no conflict.
1972 * in conflict case, analyze conflict rule, add resulting
1973 * rule to learnt rule set, make decision from learnt
1974 * rule (always unit) and re-propagate.
1976 * returns the new solver level or 0 if unsolvable
1981 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1983 Pool *pool = solv->pool;
1992 solv->decisionmap[decision] = level;
1994 solv->decisionmap[-decision] = -level;
1995 queue_push(&solv->decisionq, decision);
1996 queue_push(&solv->decisionq_why, 0);
2000 r = propagate(solv, level);
2004 return analyze_unsolvable(solv, r, disablerules);
2005 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
2006 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
2007 assert(l > 0 && l < level);
2008 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
2010 revert(solv, level);
2011 r = addrule(solv, p, d); /* p requires d */
2013 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
2014 queue_push(&solv->learnt_why, why);
2017 /* at least 2 literals, needs watches */
2018 watch2onhighest(solv, r);
2019 addwatches(solv, r);
2021 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
2022 queue_push(&solv->decisionq, p);
2023 queue_push(&solv->decisionq_why, r - solv->rules);
2024 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
2026 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
2027 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
2028 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
2029 printrule(solv, SAT_DEBUG_ANALYZE, r);
2037 * install best package from the queue. We add an extra package, inst, if
2038 * provided. See comment in weak install section.
2040 * returns the new solver level or 0 if unsolvable
2044 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
2046 Pool *pool = solv->pool;
2050 if (dq->count > 1 || inst)
2051 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
2056 /* choose the supplemented one */
2057 for (i = 0; i < dq->count; i++)
2058 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
2062 for (i = 1; i < dq->count; i++)
2063 queue_push(&solv->branches, dq->elements[i]);
2064 queue_push(&solv->branches, -level);
2068 p = dq->elements[i];
2070 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
2072 return setpropagatelearn(solv, level, p, disablerules);
2076 /*-----------------------------------------------------------------*/
2077 /* Main solver interface */
2082 * create solver structure
2084 * pool: all available solvables
2085 * installed: installed Solvables
2088 * Upon solving, rules are created to flag the Solvables
2089 * of the 'installed' Repo as installed.
2093 solver_create(Pool *pool, Repo *installed)
2096 solv = (Solver *)sat_calloc(1, sizeof(Solver));
2098 solv->installed = installed;
2100 queue_init(&solv->ruletojob);
2101 queue_init(&solv->decisionq);
2102 queue_init(&solv->decisionq_why);
2103 queue_init(&solv->problems);
2104 queue_init(&solv->suggestions);
2105 queue_init(&solv->recommendations);
2106 queue_init(&solv->learnt_why);
2107 queue_init(&solv->learnt_pool);
2108 queue_init(&solv->branches);
2109 queue_init(&solv->covenantq);
2110 queue_init(&solv->weakruleq);
2112 map_init(&solv->recommendsmap, pool->nsolvables);
2113 map_init(&solv->suggestsmap, pool->nsolvables);
2114 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
2115 solv->recommends_index = 0;
2117 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2119 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
2120 memset(solv->rules, 0, sizeof(Rule));
2131 solver_free(Solver *solv)
2133 queue_free(&solv->ruletojob);
2134 queue_free(&solv->decisionq);
2135 queue_free(&solv->decisionq_why);
2136 queue_free(&solv->learnt_why);
2137 queue_free(&solv->learnt_pool);
2138 queue_free(&solv->problems);
2139 queue_free(&solv->suggestions);
2140 queue_free(&solv->recommendations);
2141 queue_free(&solv->branches);
2142 queue_free(&solv->covenantq);
2143 queue_free(&solv->weakruleq);
2145 map_free(&solv->recommendsmap);
2146 map_free(&solv->suggestsmap);
2147 map_free(&solv->noupdate);
2148 map_free(&solv->weakrulemap);
2150 sat_free(solv->decisionmap);
2151 sat_free(solv->rules);
2152 sat_free(solv->watches);
2153 sat_free(solv->weaksystemrules);
2154 sat_free(solv->obsoletes);
2155 sat_free(solv->obsoletes_data);
2160 /*-------------------------------------------------------*/
2165 * all rules have been set up, now actually run the solver
2170 run_solver(Solver *solv, int disablerules, int doweak)
2178 Pool *pool = solv->pool;
2181 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2183 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2184 for (i = 1; i < solv->nrules; i++)
2185 printruleclass(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2188 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2190 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2191 printdecisions(solv);
2193 /* start SAT algorithm */
2195 systemlevel = level + 1;
2196 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2201 * here's the main loop:
2202 * 1) propagate new decisions (only needed for level 1)
2203 * 2) try to keep installed packages
2204 * 3) fulfill all unresolved rules
2205 * 4) install recommended packages
2206 * 5) minimalize solution if we had choices
2207 * if we encounter a problem, we rewind to a safe level and restart
2219 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2220 if ((r = propagate(solv, level)) != 0)
2222 if (analyze_unsolvable(solv, r, disablerules))
2230 * installed packages
2233 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2235 if (!solv->updatesystem)
2237 /* try to keep as many packages as possible */
2238 POOL_DEBUG(SAT_DEBUG_STATS, "installing system packages\n");
2239 for (i = solv->installed->start; i < solv->installed->end; i++)
2241 s = pool->solvables + i;
2242 if (s->repo != solv->installed)
2244 if (solv->decisionmap[i] != 0)
2246 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2248 level = setpropagatelearn(solv, level, i, disablerules);
2254 if (level <= olevel)
2257 if (i < solv->installed->end)
2260 if (solv->weaksystemrules)
2262 POOL_DEBUG(SAT_DEBUG_STATS, "installing weak system packages\n");
2263 for (i = solv->installed->start; i < solv->installed->end; i++)
2265 s = pool->solvables + i;
2266 if (s->repo != solv->installed)
2268 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
2270 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2271 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2274 if (solv->weaksystemrules[i - solv->installed->start])
2276 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
2277 while ((p = *dp++) != 0)
2279 if (solv->decisionmap[p] > 0)
2281 if (solv->decisionmap[p] == 0)
2285 continue; /* update package already installed */
2287 if (!dq.count && solv->decisionmap[i] != 0)
2290 /* FIXME: i is handled a bit different because we do not want
2291 * to have it pruned just because it is not recommened.
2292 * we should not prune installed packages instead */
2293 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2299 if (level <= olevel)
2302 if (i < solv->installed->end)
2305 systemlevel = level;
2312 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unresolved rules\n");
2313 for (i = 1, n = 1; ; i++, n++)
2315 if (n == solv->nrules)
2317 if (i == solv->nrules)
2319 r = solv->rules + i;
2320 if (!r->w1) /* ignore disabled rules */
2325 /* binary or unary rule */
2326 /* need two positive undecided literals */
2327 if (r->p < 0 || r->w2 <= 0)
2329 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2331 queue_push(&dq, r->p);
2332 queue_push(&dq, r->w2);
2337 * all negative literals are installed
2338 * no positive literal is installed
2339 * i.e. the rule is not fulfilled and we
2340 * just need to decide on the positive literals
2344 if (solv->decisionmap[-r->p] <= 0)
2349 if (solv->decisionmap[r->p] > 0)
2351 if (solv->decisionmap[r->p] == 0)
2352 queue_push(&dq, r->p);
2354 dp = pool->whatprovidesdata + r->d;
2355 while ((p = *dp++) != 0)
2359 if (solv->decisionmap[-p] <= 0)
2364 if (solv->decisionmap[p] > 0)
2366 if (solv->decisionmap[p] == 0)
2373 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2375 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2376 printruleclass(solv, SAT_DEBUG_PROPAGATE, r);
2378 /* dq.count < 2 cannot happen as this means that
2379 * the rule is unit */
2380 assert(dq.count > 1);
2383 level = selectandinstall(solv, level, &dq, 0, disablerules);
2389 if (level < systemlevel)
2392 } /* for(), decide */
2394 if (n != solv->nrules) /* continue if level < systemlevel */
2397 if (doweak && !solv->problems.count)
2401 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
2403 if (!solv->dosplitprovides && !REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2405 for (i = 1; i < solv->decisionq.count; i++)
2407 p = solv->decisionq.elements[i];
2408 if (p > 0 && pool->solvables[p].repo == solv->installed)
2409 solv->decisionmap[p] = -solv->decisionmap[p];
2414 for (i = 1; i < pool->nsolvables; i++)
2416 if (solv->decisionmap[i] < 0)
2418 if (solv->decisionmap[i] > 0)
2420 Id *recp, rec, *pp, p;
2421 s = pool->solvables + i;
2422 /* installed, check for recommends */
2423 /* XXX need to special case AND ? */
2426 recp = s->repo->idarraydata + s->recommends;
2427 while ((rec = *recp++) != 0)
2430 FOR_PROVIDES(p, pp, rec)
2432 if (solv->decisionmap[p] > 0)
2437 else if (solv->decisionmap[p] == 0)
2439 queue_pushunique(&dq, p);
2447 s = pool->solvables + i;
2448 if (!s->supplements && !s->freshens)
2450 if (!pool_installable(pool, s))
2452 if (solver_is_supplementing(solv, s))
2453 queue_pushunique(&dq, i);
2457 if (!solv->dosplitprovides && !REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2459 for (i = 1; i < solv->decisionq.count; i++)
2461 p = solv->decisionq.elements[i];
2462 if (p > 0 && pool->solvables[p].repo == solv->installed)
2463 solv->decisionmap[p] = -solv->decisionmap[p];
2470 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2472 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2473 queue_push(&solv->recommendations, p);
2474 level = setpropagatelearn(solv, level, p, 0);
2479 if (solv->solution_callback)
2481 solv->solution_callback(solv, solv->solution_callback_data);
2482 if (solv->branches.count)
2484 int i = solv->branches.count - 1;
2485 int l = -solv->branches.elements[i];
2487 if (solv->branches.elements[i - 1] < 0)
2489 p = solv->branches.elements[i];
2490 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
2492 for (j = i + 1; j < solv->branches.count; j++)
2493 queue_push(&dq, solv->branches.elements[j]);
2494 solv->branches.count = i;
2496 revert(solv, level);
2498 for (j = 0; j < dq.count; j++)
2499 queue_push(&solv->branches, dq.elements[j]);
2501 level = setpropagatelearn(solv, level, p, disablerules);
2509 /* all branches done, we're finally finished */
2513 /* minimization step */
2514 if (solv->branches.count)
2516 int l = 0, lasti = -1, lastl = -1;
2518 for (i = solv->branches.count - 1; i >= 0; i--)
2520 p = solv->branches.elements[i];
2523 else if (p > 0 && solv->decisionmap[p] > l + 1)
2531 /* kill old solvable so that we do not loop */
2532 p = solv->branches.elements[lasti];
2533 solv->branches.elements[lasti] = 0;
2534 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
2537 revert(solv, level);
2539 level = setpropagatelearn(solv, level, p, disablerules);
2550 POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
2557 * at this point, all rules that led to conflicts are disabled.
2558 * we re-enable all rules of a problem set but rule "sug", then
2559 * continue to disable more rules until there as again a solution.
2562 /* FIXME: think about conflicting assertions */
2565 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2567 Pool *pool = solv->pool;
2574 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2576 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
2577 for (i = 0; problem[i]; i++)
2579 if (problem[i] == sug)
2580 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
2581 printproblem(solv, problem[i]);
2584 queue_init(&disabled);
2585 queue_empty(refined);
2586 queue_push(refined, sug);
2588 /* re-enable all problem rules with the exception of "sug"(gests) */
2592 for (i = 0; problem[i]; i++)
2593 if (problem[i] != sug)
2594 enableproblem(solv, problem[i]);
2597 disableupdaterules(solv, job, -(sug + 1));
2601 /* re-enable as many weak rules as possible */
2602 for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++)
2606 if (!MAPTST(&solv->weakrulemap, i))
2608 enablerule(solv, r);
2611 queue_empty(&solv->problems);
2612 revert(solv, 1); /* XXX move to reset_solver? */
2615 if (!solv->problems.count)
2616 run_solver(solv, 0, 0);
2618 if (!solv->problems.count)
2620 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
2621 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2622 printdecisions(solv);
2623 break; /* great, no more problems */
2625 disabledcnt = disabled.count;
2626 /* start with 1 to skip over proof index */
2627 for (i = 1; i < solv->problems.count - 1; i++)
2629 /* ignore solutions in refined */
2630 v = solv->problems.elements[i];
2632 break; /* end of problem reached */
2633 for (j = 0; problem[j]; j++)
2634 if (problem[j] != sug && problem[j] == v)
2638 queue_push(&disabled, v);
2640 if (disabled.count == disabledcnt)
2642 /* no solution found, this was an invalid suggestion! */
2643 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
2647 if (disabled.count == disabledcnt + 1)
2649 /* just one suggestion, add it to refined list */
2650 v = disabled.elements[disabledcnt];
2651 queue_push(refined, v);
2652 disableproblem(solv, v);
2654 disableupdaterules(solv, job, -(v + 1));
2658 /* more than one solution, disable all */
2659 /* do not push anything on refine list */
2660 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2662 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
2663 for (i = disabledcnt; i < disabled.count; i++)
2664 printproblem(solv, disabled.elements[i]);
2666 for (i = disabledcnt; i < disabled.count; i++)
2667 disableproblem(solv, disabled.elements[i]);
2670 /* all done, get us back into the same state as before */
2671 /* enable refined rules again */
2672 for (i = 0; i < disabled.count; i++)
2673 enableproblem(solv, disabled.elements[i]);
2674 /* disable problem rules again */
2675 for (i = 0; problem[i]; i++)
2676 disableproblem(solv, problem[i]);
2677 disableupdaterules(solv, job, -1);
2678 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
2682 problems_to_solutions(Solver *solv, Queue *job)
2684 Pool *pool = solv->pool;
2692 if (!solv->problems.count)
2694 queue_clone(&problems, &solv->problems);
2695 queue_init(&solution);
2696 queue_init(&solutions);
2697 /* copy over proof index */
2698 queue_push(&solutions, problems.elements[0]);
2699 problem = problems.elements + 1;
2700 for (i = 1; i < problems.count; i++)
2702 Id v = problems.elements[i];
2705 /* mark end of this problem */
2706 queue_push(&solutions, 0);
2707 queue_push(&solutions, 0);
2708 if (i + 1 == problems.count)
2710 /* copy over proof of next problem */
2711 queue_push(&solutions, problems.elements[i + 1]);
2713 problem = problems.elements + i + 1;
2716 refine_suggestion(solv, job, problem, v, &solution);
2717 if (!solution.count)
2718 continue; /* this solution didn't work out */
2720 for (j = 0; j < solution.count; j++)
2722 why = solution.elements[j];
2723 /* must be either job descriptor or system rule */
2724 assert(why < 0 || (why >= solv->systemrules && why < solv->learntrules));
2726 printproblem(solv, why);
2730 /* job descriptor */
2731 queue_push(&solutions, 0);
2732 queue_push(&solutions, -why);
2736 /* system rule, find replacement package */
2738 p = solv->installed->start + (why - solv->systemrules);
2739 if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
2741 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
2744 if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
2746 if (solv->decisionmap[*dp] > 0)
2753 queue_push(&solutions, p);
2754 queue_push(&solutions, rp);
2757 /* mark end of this solution */
2758 queue_push(&solutions, 0);
2759 queue_push(&solutions, 0);
2761 queue_free(&solution);
2762 queue_free(&problems);
2763 /* copy queue over to solutions */
2764 queue_free(&solv->problems);
2765 queue_clone(&solv->problems, &solutions);
2767 /* bring solver back into problem state */
2768 revert(solv, 1); /* XXX move to reset_solver? */
2771 assert(solv->problems.count == solutions.count);
2772 queue_free(&solutions);
2776 solver_next_problem(Solver *solv, Id problem)
2780 return solv->problems.count ? 1 : 0;
2781 pp = solv->problems.elements + problem;
2782 while (pp[0] || pp[1])
2786 while (pp[0] || pp[1])
2791 problem = pp - solv->problems.elements;
2792 if (problem >= solv->problems.count)
2798 solver_next_solution(Solver *solv, Id problem, Id solution)
2804 pp = solv->problems.elements + solution;
2805 return pp[0] || pp[1] ? solution : 0;
2807 pp = solv->problems.elements + solution;
2808 while (pp[0] || pp[1])
2811 solution = pp - solv->problems.elements;
2812 return pp[0] || pp[1] ? solution : 0;
2816 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
2819 element = element ? element + 2 : solution;
2820 pp = solv->problems.elements + element;
2821 if (!(pp[0] || pp[1]))
2830 * create obsoletesmap from solver decisions
2831 * required for decision handling
2835 create_decisions_obsoletesmap(Solver *solv)
2837 Pool *pool = solv->pool;
2838 Repo *installed = solv->installed;
2839 Id p, *obsoletesmap = NULL;
2843 obsoletesmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2846 for (i = 0; i < solv->decisionq.count; i++)
2850 n = solv->decisionq.elements[i];
2853 if (n == SYSTEMSOLVABLE)
2855 s = pool->solvables + n;
2856 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2858 FOR_PROVIDES(p, pp, s->name)
2859 if (s->name == pool->solvables[p].name)
2861 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2863 obsoletesmap[p] = n;
2868 for (i = 0; i < solv->decisionq.count; i++)
2873 n = solv->decisionq.elements[i];
2876 if (n == SYSTEMSOLVABLE)
2878 s = pool->solvables + n;
2879 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2883 obsp = s->repo->idarraydata + s->obsoletes;
2884 while ((obs = *obsp++) != 0)
2885 FOR_PROVIDES(p, pp, obs)
2887 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2889 obsoletesmap[p] = n;
2895 return obsoletesmap;
2903 printdecisions(Solver *solv)
2905 Pool *pool = solv->pool;
2906 Repo *installed = solv->installed;
2907 Id p, *obsoletesmap = create_decisions_obsoletesmap( solv );
2911 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
2913 /* print solvables to be erased */
2917 FOR_REPO_SOLVABLES(installed, p, s)
2919 if (solv->decisionmap[p] >= 0)
2921 if (obsoletesmap[p])
2923 POOL_DEBUG(SAT_DEBUG_RESULT, "erase %s\n", solvable2str(pool, s));
2927 /* print solvables to be installed */
2929 for (i = 0; i < solv->decisionq.count; i++)
2932 p = solv->decisionq.elements[i];
2935 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2938 s = pool->solvables + p;
2939 POOL_DEBUG(SAT_DEBUG_SCHUBI, "level of %s is %d\n", solvable2str(pool, s), p);
2943 if (p == SYSTEMSOLVABLE)
2945 POOL_DEBUG(SAT_DEBUG_SCHUBI, "SYSTEMSOLVABLE\n");
2948 s = pool->solvables + p;
2949 if (installed && s->repo == installed)
2952 if (!obsoletesmap[p])
2954 POOL_DEBUG(SAT_DEBUG_RESULT, "install %s", solvable2str(pool, s));
2958 POOL_DEBUG(SAT_DEBUG_RESULT, "update %s", solvable2str(pool, s));
2959 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
2960 for (j = installed->start; j < installed->end; j++)
2961 if (obsoletesmap[j] == p)
2962 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
2963 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
2965 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
2968 sat_free(obsoletesmap);
2970 if (solv->recommendations.count)
2972 POOL_DEBUG(SAT_DEBUG_RESULT, "\nrecommended packages:\n");
2973 for (i = 0; i < solv->recommendations.count; i++)
2975 s = pool->solvables + solv->recommendations.elements[i];
2976 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
2980 if (solv->suggestions.count)
2982 POOL_DEBUG(SAT_DEBUG_RESULT, "\nsuggested packages:\n");
2983 for (i = 0; i < solv->suggestions.count; i++)
2985 s = pool->solvables + solv->suggestions.elements[i];
2986 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
2989 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
2993 /* this is basically the reverse of addrpmrulesforsolvable */
2995 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
2997 Pool *pool = solv->pool;
2998 Repo *installed = solv->installed;
3002 Id p, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
3005 if (rid >= solv->systemrules)
3008 *sourcep = solv->installed->start + (rid - solv->systemrules);
3010 return SOLVER_PROBLEM_UPDATE_RULE;
3012 if (rid >= solv->jobrules)
3015 r = solv->rules + rid;
3016 p = solv->ruletojob.elements[rid - solv->jobrules];
3017 *depp = job->elements[p + 1];
3019 *targetp = job->elements[p];
3020 if (r->d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && job->elements[p] != SOLVER_INSTALL_SOLVABLE_ONE_OF)
3021 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
3022 return SOLVER_PROBLEM_JOB_RULE;
3024 r = solv->rules + rid;
3026 if (r->d == 0 && r->w2 == 0)
3028 /* a rpm rule assertion */
3029 s = pool->solvables - r->p;
3030 if (installed && !solv->fixsystem && s->repo == installed)
3032 assert(!dontfix); /* dontfix packages never have a neg assertion */
3035 /* see why the package is not installable */
3036 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
3039 return SOLVER_PROBLEM_NOT_INSTALLABLE;
3041 /* check requires */
3042 assert(s->requires);
3043 reqp = s->repo->idarraydata + s->requires;
3044 while ((req = *reqp++) != 0)
3046 if (req == SOLVABLE_PREREQMARKER)
3048 dp = pool_whatprovides(pool, req);
3054 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
3056 s = pool->solvables - r->p;
3057 if (installed && !solv->fixsystem && s->repo == installed)
3059 if (r->d == 0 && r->w2 < 0)
3061 /* a package conflict */
3062 Solvable *s2 = pool->solvables - r->w2;
3065 if (installed && !solv->fixsystem && s2->repo == installed)
3068 /* if both packages have the same name and at least one of them
3069 * is not installed, they conflict */
3070 if (s->name == s2->name && (!installed || (s->repo != installed || s2->repo != installed)))
3075 return SOLVER_PROBLEM_SAME_NAME;
3078 /* check conflicts in both directions */
3081 conp = s->repo->idarraydata + s->conflicts;
3082 while ((con = *conp++) != 0)
3084 FOR_PROVIDES(p, pp, con)
3086 if (dontfix && pool->solvables[p].repo == installed)
3093 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3099 conp = s2->repo->idarraydata + s2->conflicts;
3100 while ((con = *conp++) != 0)
3102 FOR_PROVIDES(p, pp, con)
3104 if (dontfix2 && pool->solvables[p].repo == installed)
3111 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3115 /* check obsoletes in both directions */
3116 if ((!installed || s->repo != installed) && s->obsoletes)
3118 obsp = s->repo->idarraydata + s->obsoletes;
3119 while ((obs = *obsp++) != 0)
3121 FOR_PROVIDES(p, pp, obs)
3128 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3132 if ((!installed || s2->repo != installed) && s2->obsoletes)
3134 obsp = s2->repo->idarraydata + s2->obsoletes;
3135 while ((obs = *obsp++) != 0)
3137 FOR_PROVIDES(p, pp, obs)
3144 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3148 /* all cases checked, can't happen */
3151 /* simple requires */
3152 assert(s->requires);
3153 reqp = s->repo->idarraydata + s->requires;
3154 while ((req = *reqp++) != 0)
3156 if (req == SOLVABLE_PREREQMARKER)
3158 dp = pool_whatprovides(pool, req);
3161 if (*dp == r->w2 && dp[1] == 0)
3164 else if (dp - pool->whatprovidesdata == r->d)
3171 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
3175 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3178 Id lreqr, lconr, lsysr, ljobr;
3182 lreqr = lconr = lsysr = ljobr = 0;
3183 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3186 if (rid >= solv->learntrules)
3187 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3188 else if (rid >= solv->systemrules)
3193 else if (rid >= solv->jobrules)
3200 r = solv->rules + rid;
3201 if (!r->d && r->w2 < 0)
3208 if (r->d == 0 && r->w2 == 0 && !reqassert)
3210 /* prefer assertions (XXX: bad idea?) */
3216 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed)
3218 /* prefer rules of installed packages */
3219 Id op = *reqrp >= 0 ? solv->rules[*reqrp].p : -*reqrp;
3220 if (op <= 0 || solv->pool->solvables[op].repo != solv->installed)
3226 if (!*reqrp && lreqr)
3228 if (!*conrp && lconr)
3230 if (!*jobrp && ljobr)
3232 if (!*sysrp && lsysr)
3237 * search for a rule that describes the problem to the
3238 * user. A pretty hopeless task, actually. We currently
3239 * prefer simple requires.
3242 solver_findproblemrule(Solver *solv, Id problem)
3244 Id reqr, conr, sysr, jobr;
3245 Id idx = solv->problems.elements[problem - 1];
3246 reqr = conr = sysr = jobr = 0;
3247 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3260 printprobleminfo(Solver *solv, Queue *job, Id problem)
3262 Pool *pool = solv->pool;
3264 Id dep, source, target;
3267 probr = solver_findproblemrule(solv, problem);
3268 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
3270 case SOLVER_PROBLEM_UPDATE_RULE:
3271 s = pool_id2solvable(pool, source);
3272 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
3274 case SOLVER_PROBLEM_JOB_RULE:
3275 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
3277 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
3278 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
3280 case SOLVER_PROBLEM_NOT_INSTALLABLE:
3281 s = pool_id2solvable(pool, source);
3282 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
3284 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
3285 s = pool_id2solvable(pool, source);
3286 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
3288 case SOLVER_PROBLEM_SAME_NAME:
3289 s = pool_id2solvable(pool, source);
3290 s2 = pool_id2solvable(pool, target);
3291 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
3293 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
3294 s = pool_id2solvable(pool, source);
3295 s2 = pool_id2solvable(pool, target);
3296 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3298 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
3299 s = pool_id2solvable(pool, source);
3300 s2 = pool_id2solvable(pool, target);
3301 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3303 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
3304 s = pool_id2solvable(pool, source);
3305 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
3311 printsolutions(Solver *solv, Queue *job)
3313 Pool *pool = solv->pool;
3315 Id p, rp, how, what;
3316 Id problem, solution, element;
3319 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
3322 while ((problem = solver_next_problem(solv, problem)) != 0)
3324 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
3325 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
3326 printprobleminfo(solv, job, problem);
3327 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3329 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
3332 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
3336 /* job, rp is index into job queue */
3337 how = job->elements[rp - 1] & ~SOLVER_WEAK;
3338 what = job->elements[rp];
3341 case SOLVER_INSTALL_SOLVABLE:
3342 s = pool->solvables + what;
3343 if (solv->installed && s->repo == solv->installed)
3344 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, s));
3346 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solvable2str(pool, s));
3348 case SOLVER_ERASE_SOLVABLE:
3349 s = pool->solvables + what;
3350 if (solv->installed && s->repo == solv->installed)
3351 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solvable2str(pool, s));
3353 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, s));
3355 case SOLVER_INSTALL_SOLVABLE_NAME:
3356 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", dep2str(pool, what));
3358 case SOLVER_ERASE_SOLVABLE_NAME:
3359 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", dep2str(pool, what));
3361 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3362 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable providing %s\n", dep2str(pool, what));
3364 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3365 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables providing %s\n", dep2str(pool, what));
3367 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3368 s = pool->solvables + what;
3369 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solvable2str(pool, s));
3372 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
3378 /* policy, replace p with rp */
3379 s = pool->solvables + p;
3380 sd = rp ? pool->solvables + rp : 0;
3384 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
3386 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3389 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
3391 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3394 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
3397 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change from '%s' (%s) to '%s' (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), id2str(pool, sd->vendor), solvable2str(pool, sd));
3399 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change from '%s' (%s) to no vendor (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), solvable2str(pool, sd));
3403 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3407 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
3412 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3418 /* create reverse obsoletes map for installed solvables
3420 * for each installed solvable find which packages with *different* names
3421 * obsolete the solvable.
3422 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3426 create_obsolete_index(Solver *solv)
3428 Pool *pool = solv->pool;
3430 Repo *installed = solv->installed;
3431 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3434 if (!installed || !installed->nsolvables)
3436 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
3437 for (i = 1; i < pool->nsolvables; i++)
3439 s = pool->solvables + i;
3440 if (s->repo == installed)
3444 if (!pool_installable(pool, s))
3446 obsp = s->repo->idarraydata + s->obsoletes;
3447 while ((obs = *obsp++) != 0)
3448 FOR_PROVIDES(p, pp, obs)
3450 if (pool->solvables[p].repo != installed)
3452 if (pool->solvables[p].name == s->name)
3454 obsoletes[p - installed->start]++;
3458 for (i = 0; i < installed->nsolvables; i++)
3461 n += obsoletes[i] + 1;
3464 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
3465 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
3466 for (i = pool->nsolvables - 1; i > 0; i--)
3468 s = pool->solvables + i;
3469 if (s->repo == installed)
3473 if (!pool_installable(pool, s))
3475 obsp = s->repo->idarraydata + s->obsoletes;
3476 while ((obs = *obsp++) != 0)
3477 FOR_PROVIDES(p, pp, obs)
3479 if (pool->solvables[p].repo != installed)
3481 if (pool->solvables[p].name == s->name)
3483 p -= installed->start;
3484 if (obsoletes_data[obsoletes[p]] != i)
3485 obsoletes_data[--obsoletes[p]] = i;
3491 removedisabledconflicts(Solver *solv, Queue *removed)
3493 Pool *pool = solv->pool;
3498 Id *decisionmap = solv->decisionmap;
3500 POOL_DEBUG(SAT_DEBUG_STATS, "removedisabledconflicts\n");
3501 queue_empty(removed);
3502 for (i = 0; i < solv->decisionq.count; i++)
3504 p = solv->decisionq.elements[i];
3507 /* a conflict. we never do conflicts on free decisions, so there
3508 * must have been an unit rule */
3509 why = solv->decisionq_why.elements[i];
3511 r = solv->rules + why;
3512 if (!r->w1 && decisionmap[-p])
3514 /* rule is now disabled, remove from decisionmap */
3515 POOL_DEBUG(SAT_DEBUG_STATS, "removing conflict for package %s[%d]\n", solvable2str(pool, pool->solvables - p), -p);
3516 queue_push(removed, -p);
3517 queue_push(removed, decisionmap[-p]);
3518 decisionmap[-p] = 0;
3521 if (!removed->count)
3523 /* we removed some confliced packages. some of them might still
3524 * be in conflict, so search for unit rules and re-conflict */
3526 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
3528 if (i == solv->nrules)
3531 r = solv->rules + i;
3537 if (r->p < 0 && !decisionmap[-r->p])
3543 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
3545 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
3550 if (r->p < 0 && decisionmap[-r->p] == 0)
3552 if (new || DECISIONMAP_FALSE(r->p))
3554 dp = pool->whatprovidesdata + r->d;
3555 while ((p = *dp++) != 0)
3557 if (new && p == new)
3559 if (p < 0 && decisionmap[-p] == 0)
3568 else if (!DECISIONMAP_FALSE(p))
3578 POOL_DEBUG(SAT_DEBUG_STATS, "re-conflicting package %s[%d]\n", solvable2str(pool, pool->solvables - new), -new);
3579 decisionmap[-new] = -1;
3580 n = 0; /* redo all rules */
3586 weaken_solvable_deps(Solver *solv, Id p)
3591 for (i = 1, r = solv->rules + i; i < solv->jobrules; i++, r++)
3595 if (r->d == 0 && r->w2 < 0)
3596 continue; /* conflict */
3597 queue_push(&solv->weakruleq, i);
3601 /*-----------------------------------------------------------------*/
3611 solver_solve(Solver *solv, Queue *job)
3613 Pool *pool = solv->pool;
3614 Repo *installed = solv->installed;
3617 Map addedmap; /* '1' == have rpm-rules for solvable */
3618 Id how, what, weak, name, p, *pp, d;
3622 /* create whatprovides if not already there */
3623 if (!pool->whatprovides)
3624 pool_createwhatprovides(pool);
3626 /* create obsolete index if needed */
3627 if (solv->noupdateprovide)
3628 create_obsolete_index(solv);
3631 * create basic rule set of all involved packages
3632 * use addedmap bitmap to make sure we don't create rules twice
3636 map_init(&addedmap, pool->nsolvables);
3640 * always install our system solvable
3642 MAPSET(&addedmap, SYSTEMSOLVABLE);
3643 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3644 queue_push(&solv->decisionq_why, 0);
3645 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3648 * create rules for all package that could be involved with the solving
3649 * so called: rpm rules
3654 oldnrules = solv->nrules;
3655 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
3656 FOR_REPO_SOLVABLES(installed, p, s)
3657 addrpmrulesforsolvable(solv, s, &addedmap);
3658 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3659 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
3660 oldnrules = solv->nrules;
3661 FOR_REPO_SOLVABLES(installed, p, s)
3662 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3663 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3666 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
3667 oldnrules = solv->nrules;
3668 for (i = 0; i < job->count; i += 2)
3670 how = job->elements[i] & ~SOLVER_WEAK;
3671 what = job->elements[i + 1];
3675 case SOLVER_INSTALL_SOLVABLE:
3676 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3678 case SOLVER_INSTALL_SOLVABLE_NAME:
3679 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3680 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3681 while (ISRELDEP(name))
3683 Reldep *rd = GETRELDEP(pool, name);
3686 FOR_PROVIDES(p, pp, what)
3688 /* if by name, ensure that the name matches */
3689 if (name && pool->solvables[p].name != name)
3691 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3694 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3695 /* dont allow downgrade */
3696 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3698 case SOLVER_INSTALL_SOLVABLE_ONE_OF:
3699 pp = pool->whatprovidesdata + what;
3700 while ((p = *pp++) != 0)
3701 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3705 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3707 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
3709 oldnrules = solv->nrules;
3710 addrpmrulesforweak(solv, &addedmap);
3711 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3713 IF_POOLDEBUG (SAT_DEBUG_STATS)
3715 int possible = 0, installable = 0;
3716 for (i = 1; i < pool->nsolvables; i++)
3718 if (pool_installable(pool, pool->solvables + i))
3720 if (MAPTST(&addedmap, i))
3723 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3727 * first pass done, we now have all the rpm rules we need.
3728 * unify existing rules before going over all job rules and
3730 * at this point the system is always solvable,
3731 * as an empty system (remove all packages) is a valid solution
3734 unifyrules(solv); /* remove duplicate rpm rules */
3735 solv->directdecisions = solv->decisionq.count;
3737 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
3738 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3739 printdecisions (solv);
3742 * now add all job rules
3745 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
3747 solv->jobrules = solv->nrules;
3749 for (i = 0; i < job->count; i += 2)
3751 oldnrules = solv->nrules;
3753 how = job->elements[i] & ~SOLVER_WEAK;
3754 weak = job->elements[i] & SOLVER_WEAK;
3755 what = job->elements[i + 1];
3758 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3759 s = pool->solvables + what;
3760 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall solvable %s\n", weak ? "weak " : "", solvable2str(pool, s));
3761 addrule(solv, what, 0); /* install by Id */
3762 queue_push(&solv->ruletojob, i);
3764 queue_push(&solv->weakruleq, solv->nrules - 1);
3766 case SOLVER_ERASE_SOLVABLE:
3767 s = pool->solvables + what;
3768 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase solvable %s\n", weak ? "weak " : "", solvable2str(pool, s));
3769 addrule(solv, -what, 0); /* remove by Id */
3770 queue_push(&solv->ruletojob, i);
3772 queue_push(&solv->weakruleq, solv->nrules - 1);
3774 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3775 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3776 if (how == SOLVER_INSTALL_SOLVABLE_NAME)
3777 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall name %s\n", weak ? "weak " : "", dep2str(pool, what));
3778 if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3779 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall provides %s\n", weak ? "weak " : "", dep2str(pool, what));
3781 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3782 while (ISRELDEP(name))
3784 Reldep *rd = GETRELDEP(pool, name);
3787 FOR_PROVIDES(p, pp, what)
3789 /* if by name, ensure that the name matches */
3790 if (name && pool->solvables[p].name != name)
3796 /* no provider, make this an impossible rule */
3797 queue_push(&q, -SYSTEMSOLVABLE);
3800 p = queue_shift(&q); /* get first provider */
3802 d = 0; /* single provider ? -> make assertion */
3804 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3805 addrule(solv, p, d); /* add 'requires' rule */
3806 queue_push(&solv->ruletojob, i);
3808 queue_push(&solv->weakruleq, solv->nrules - 1);
3810 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3811 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3812 if (how == SOLVER_ERASE_SOLVABLE_NAME)
3813 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase name %s\n", weak ? "weak " : "", dep2str(pool, what));
3814 if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3815 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase provides %s\n", weak ? "weak " : "", dep2str(pool, what));
3816 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
3817 while (ISRELDEP(name))
3819 Reldep *rd = GETRELDEP(pool, name);
3822 FOR_PROVIDES(p, pp, what)
3824 /* if by name, ensure that the name matches */
3825 if (name && pool->solvables[p].name != name)
3827 addrule(solv, -p, 0); /* add 'remove' rule */
3828 queue_push(&solv->ruletojob, i);
3830 queue_push(&solv->weakruleq, solv->nrules - 1);
3833 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3834 s = pool->solvables + what;
3835 POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solvable2str(pool, s));
3836 addupdaterule(solv, s, 0);
3837 queue_push(&solv->ruletojob, i);
3839 queue_push(&solv->weakruleq, solv->nrules - 1);
3841 case SOLVER_INSTALL_SOLVABLE_ONE_OF:
3842 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sone of\n", weak ? "weak " : "");
3843 for (pp = pool->whatprovidesdata + what; *pp; pp++)
3844 POOL_DEBUG(SAT_DEBUG_JOB, " %s\n", solvable2str(pool, pool->solvables + *pp));
3845 addrule(solv, -SYSTEMSOLVABLE, what);
3846 queue_push(&solv->ruletojob, i);
3848 queue_push(&solv->weakruleq, solv->nrules - 1);
3850 case SOLVER_WEAKEN_SOLVABLE_DEPS:
3851 s = pool->solvables + what;
3852 POOL_DEBUG(SAT_DEBUG_JOB, "job: weaken deps %s\n", solvable2str(pool, s));
3853 weaken_solvable_deps(solv, what);
3856 IF_POOLDEBUG (SAT_DEBUG_JOB)
3859 if (solv->nrules == oldnrules)
3860 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created\n");
3861 for (j = oldnrules; j < solv->nrules; j++)
3863 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
3864 printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
3868 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3871 * now add system rules
3875 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add system rules ***\n");
3878 solv->systemrules = solv->nrules;
3881 * create rules for updating installed solvables
3885 if (installed && !solv->allowuninstall)
3886 { /* loop over all installed solvables */
3887 /* we create all update rules, but disable some later on depending on the job */
3888 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3890 /* no system rules for patch atoms */
3891 if (s->freshens && !s->supplements)
3893 const char *name = id2str(pool, s->name);
3894 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
3896 addrule(solv, 0, 0);
3900 if (s->repo == installed)
3901 addupdaterule(solv, s, 0); /* allowall = 0 */
3903 addrule(solv, 0, 0); /* create dummy rule */
3905 /* consistency check: we added a rule for _every_ system solvable */
3906 assert(solv->nrules - solv->systemrules == installed->end - installed->start);
3909 /* create special weak system rules */
3910 /* those are used later on to keep a version of the installed packages in
3912 if (installed && installed->nsolvables)
3914 solv->weaksystemrules = sat_calloc(installed->end - installed->start, sizeof(Id));
3915 FOR_REPO_SOLVABLES(installed, p, s)
3917 policy_findupdatepackages(solv, s, &q, 1);
3919 solv->weaksystemrules[p - installed->start] = pool_queuetowhatprovides(pool, &q);
3923 /* free unneeded memory */
3924 map_free(&addedmap);
3927 /* create weak map */
3928 map_init(&solv->weakrulemap, solv->nrules);
3929 for (i = 0; i < solv->weakruleq.count; i++)
3931 p = solv->weakruleq.elements[i];
3932 MAPSET(&solv->weakrulemap, p);
3935 /* all new rules are learnt after this point */
3936 solv->learntrules = solv->nrules;
3938 /* disable system rules that conflict with our job */
3939 disableupdaterules(solv, job, -1);
3941 /* make decisions based on job/system assertions */
3942 makeruledecisions(solv);
3944 /* create watches chains */
3947 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
3950 run_solver(solv, 1, solv->dontinstallrecommended ? 0 : 1);
3953 if (!solv->problems.count)
3958 /* disable all weak erase rules for recommened/suggestes search */
3959 for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
3961 if (!MAPTST(&solv->weakrulemap, i))
3965 disablerule(solv, r);
3970 enabledisablelearntrules(solv);
3971 removedisabledconflicts(solv, &redoq);
3975 /* find recommended packages */
3976 /* if q.count == 0 we already found all recommended in the
3978 if (!solv->problems.count && (redoq.count || solv->dontinstallrecommended))
3980 Id rec, *recp, p, *pp;
3982 /* create map of all suggests that are still open */
3983 solv->recommends_index = -1;
3984 MAPZERO(&solv->recommendsmap);
3985 for (i = 0; i < solv->decisionq.count; i++)
3987 p = solv->decisionq.elements[i];
3990 s = pool->solvables + p;
3993 recp = s->repo->idarraydata + s->recommends;
3994 while ((rec = *recp++) != 0)
3996 FOR_PROVIDES(p, pp, rec)
3997 if (solv->decisionmap[p] > 0)
4000 continue; /* p != 0: already fulfilled */
4001 FOR_PROVIDES(p, pp, rec)
4002 MAPSET(&solv->recommendsmap, p);
4006 for (i = 1; i < pool->nsolvables; i++)
4008 if (solv->decisionmap[i] != 0)
4010 s = pool->solvables + i;
4011 if (!MAPTST(&solv->recommendsmap, i))
4013 if (!s->supplements)
4015 if (!pool_installable(pool, s))
4017 if (!solver_is_supplementing(solv, s))
4020 if (solv->dontinstallrecommended)
4021 queue_push(&solv->recommendations, i);
4023 queue_pushunique(&solv->recommendations, i);
4025 /* we use MODE_SUGGEST here so that repo prio is ignored */
4026 policy_filter_unwanted(solv, &solv->recommendations, 0, POLICY_MODE_SUGGEST);
4029 /* find suggested packages */
4030 if (!solv->problems.count)
4032 Id sug, *sugp, p, *pp;
4034 /* create map of all suggests that are still open */
4035 solv->recommends_index = -1;
4036 MAPZERO(&solv->suggestsmap);
4037 for (i = 0; i < solv->decisionq.count; i++)
4039 p = solv->decisionq.elements[i];
4042 s = pool->solvables + p;
4045 sugp = s->repo->idarraydata + s->suggests;
4046 while ((sug = *sugp++) != 0)
4048 FOR_PROVIDES(p, pp, sug)
4049 if (solv->decisionmap[p] > 0)
4052 continue; /* already fulfilled */
4053 FOR_PROVIDES(p, pp, sug)
4054 MAPSET(&solv->suggestsmap, p);
4058 for (i = 1; i < pool->nsolvables; i++)
4060 if (solv->decisionmap[i] != 0)
4062 s = pool->solvables + i;
4063 if (!MAPTST(&solv->suggestsmap, i))
4067 if (!pool_installable(pool, s))
4069 if (!solver_is_enhancing(solv, s))
4072 queue_push(&solv->suggestions, i);
4074 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
4079 /* restore decisionmap */
4080 for (i = 0; i < redoq.count; i += 2)
4081 solv->decisionmap[redoq.elements[i]] = redoq.elements[i + 1];
4085 if (solv->problems.count)
4086 problems_to_solutions(solv, job);
4089 /***********************************************************************/
4092 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
4096 solver_create_state_maps(solv, &installedmap, 0);
4097 pool_calc_duchanges(solv->pool, solv->installed, &installedmap, mps, nmps);
4098 map_free(&installedmap);
4102 solver_calc_installsizechange(Solver *solv)
4107 solver_create_state_maps(solv, &installedmap, 0);
4108 change = pool_calc_installsizechange(solv->pool, solv->installed, &installedmap);
4109 map_free(&installedmap);