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 0
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 if (r - solv->rules >= solv->learntrules)
196 POOL_DEBUG(type, "LEARNT ");
197 else if (r - solv->rules >= solv->weakrules)
198 POOL_DEBUG(type, "WEAK ");
199 else if (r - solv->rules >= solv->systemrules)
200 POOL_DEBUG(type, "SYSTEM ");
201 else if (r - solv->rules >= solv->jobrules)
202 POOL_DEBUG(type, "JOB ");
203 printrule(solv, type, r);
207 /*-----------------------------------------------------------------*/
213 static Pool *unifyrules_sortcmp_data;
216 * compare rules for unification sort
220 unifyrules_sortcmp(const void *ap, const void *bp)
222 Pool *pool = unifyrules_sortcmp_data;
223 Rule *a = (Rule *)ap;
224 Rule *b = (Rule *)bp;
230 return x; /* p differs */
233 if (a->d == 0 && b->d == 0)
234 return a->w2 - b->w2; /* assertion: return w2 diff */
236 if (a->d == 0) /* a is assertion, b not */
238 x = a->w2 - pool->whatprovidesdata[b->d];
242 if (b->d == 0) /* b is assertion, a not */
244 x = pool->whatprovidesdata[a->d] - b->w2;
248 /* compare whatprovidesdata */
249 ad = pool->whatprovidesdata + a->d;
250 bd = pool->whatprovidesdata + b->d;
252 if ((x = *ad++ - *bd++) != 0)
263 unifyrules(Solver *solv)
265 Pool *pool = solv->pool;
269 if (solv->nrules <= 1) /* nothing to unify */
272 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
274 /* sort rules first */
275 unifyrules_sortcmp_data = solv->pool;
276 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
283 for (i = j = 1, ir = solv->rules + 1; i < solv->nrules; i++, ir++)
285 if (jr && !unifyrules_sortcmp(ir, jr))
286 continue; /* prune! */
287 jr = solv->rules + j++; /* keep! */
292 /* reduced count from nrules to j rules */
293 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
295 /* adapt rule buffer */
297 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
298 IF_POOLDEBUG (SAT_DEBUG_STATS)
305 for (i = 1; i < solv->nrules; i++)
312 dp = solv->pool->whatprovidesdata + r->d;
317 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
318 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
320 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
330 hashrule(Solver *solv, Id p, Id d, int n)
332 unsigned int x = (unsigned int)p;
336 return (x * 37) ^ (unsigned int)d;
337 dp = solv->pool->whatprovidesdata + d;
339 x = (x * 37) ^ (unsigned int)*dp++;
347 * p = direct literal; always < 0 for installed rpm rules
348 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
351 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
353 * p < 0 : pkg id of A
354 * d > 0 : Offset in whatprovidesdata (list of providers of b)
356 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
357 * p < 0 : pkg id of A
358 * d < 0 : Id of solvable (e.g. B1)
360 * d == 0: unary rule, assertion => (A) or (-A)
362 * Install: p > 0, d = 0 (A) user requested install
363 * Remove: p < 0, d = 0 (-A) user requested remove
364 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
365 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
366 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
367 * ? p > 0, d < 0 (A|-B)
368 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
372 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
373 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
374 * every other : w1 = p, w2 = whatprovidesdata[d];
375 * Disabled rule: w1 = 0
377 * always returns a rule for non-rpm rules
381 addrule(Solver *solv, Id p, Id d)
383 Pool *pool = solv->pool;
387 int n = 0; /* number of literals in rule - 1
388 0 = direct assertion (single literal)
392 /* it often happenes that requires lead to adding the same rpm rule
393 * multiple times, so we prune those duplicates right away to make
394 * the work for unifyrules a bit easier */
396 if (solv->nrules && !solv->jobrules)
398 r = solv->rules + solv->nrules - 1; /* get the last added rule */
399 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
405 /* always a binary rule */
407 return 0; /* ignore self conflict */
412 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
414 return 0; /* rule is self-fulfilling */
416 d = dp[-1]; /* take single literal */
419 if (n == 0 && !solv->jobrules)
421 /* this is a rpm rule assertion, we do not have to allocate it */
422 /* it can be identified by a level of 1 and a zero reason */
423 /* we must not drop those rules from the decisionq when rewinding! */
425 assert(solv->decisionmap[-p] == 0 || solv->decisionmap[-p] == -1);
426 if (solv->decisionmap[-p])
427 return 0; /* already got that one */
428 queue_push(&solv->decisionq, p);
429 queue_push(&solv->decisionq_why, 0);
430 solv->decisionmap[-p] = -1;
435 /* smallest literal first so we can find dups */
439 n = 1; /* re-set n, was used as temp var */
442 /* check if the last added rule is exactly the same as what we're looking for. */
443 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
444 return r; /* binary rule */
446 if (r && n > 1 && r->d && r->p == p)
448 /* Rule where d is an offset in whatprovidesdata */
452 dp2 = pool->whatprovidesdata + r->d;
453 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
464 /* extend rule buffer */
465 solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
466 r = solv->rules + solv->nrules++; /* point to rule space */
471 /* direct assertion, no watch needed */
487 r->w2 = pool->whatprovidesdata[d];
492 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
494 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
495 printrule(solv, SAT_DEBUG_RULE_CREATION, r);
502 disablerule(Solver *solv, Rule *r)
508 enablerule(Solver *solv, Rule *r)
510 if (r->d == 0 || r->w2 != r->p)
513 r->w1 = solv->pool->whatprovidesdata[r->d];
517 /**********************************************************************************/
519 /* a problem is an item on the solver's problem list. It can either be >0, in that
520 * case it is a system (upgrade) rule, or it can be <0, which makes it refer to a job
521 * consisting of multiple job rules.
525 disableproblem(Solver *solv, Id v)
533 disablerule(solv, solv->rules + v);
537 jp = solv->ruletojob.elements;
538 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
540 disablerule(solv, r);
544 enableproblem(Solver *solv, Id v)
552 enablerule(solv, solv->rules + v);
556 jp = solv->ruletojob.elements;
557 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
563 printproblem(Solver *solv, Id v)
565 Pool *pool = solv->pool;
571 printrule(solv, SAT_DEBUG_SOLUTIONS, solv->rules + v);
575 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "JOB %d\n", v);
576 jp = solv->ruletojob.elements;
577 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
580 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "- ");
581 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
583 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "ENDJOB\n");
589 /************************************************************************/
591 /* go through system and job rules and add direct assertions
592 * to the decisionqueue. If we find a conflict, disable rules and
593 * add them to problem queue.
596 makeruledecisions(Solver *solv)
598 Pool *pool = solv->pool;
604 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
606 decisionstart = solv->decisionq.count;
607 /* rpm rules don't have assertions, so we can start with the job
609 for (ri = solv->jobrules, r = solv->rules + ri; ri < solv->nrules; ri++, r++)
611 if (!r->w1 || r->w2) /* disabled or no assertion */
615 if (solv->decisionmap[vv] == 0)
617 queue_push(&solv->decisionq, v);
618 queue_push(&solv->decisionq_why, r - solv->rules);
619 solv->decisionmap[vv] = v > 0 ? 1 : -1;
620 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
622 Solvable *s = solv->pool->solvables + vv;
624 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
626 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
630 if (v > 0 && solv->decisionmap[vv] > 0)
632 if (v < 0 && solv->decisionmap[vv] < 0)
634 /* found a conflict! */
635 if (ri >= solv->learntrules)
637 /* conflict with a learnt rule */
638 /* can happen when packages cannot be installed for
639 * multiple reasons. */
640 /* we disable the learnt rule in this case */
641 disablerule(solv, r);
644 /* if we are weak, just disable ourself */
645 if (ri >= solv->weakrules)
647 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
648 printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
649 disablerule(solv, r);
653 /* only job and system rules left in the decisionq*/
654 /* find the decision which is the "opposite" of the jobrule */
655 for (i = 0; i < solv->decisionq.count; i++)
656 if (solv->decisionq.elements[i] == -v)
658 assert(i < solv->decisionq.count);
659 if (solv->decisionq_why.elements[i] == 0)
661 /* conflict with rpm rule, need only disable our rule */
662 assert(v > 0 || v == -SYSTEMSOLVABLE);
664 queue_push(&solv->problems, solv->learnt_pool.count);
665 queue_push(&solv->learnt_pool, ri);
666 queue_push(&solv->learnt_pool, v != -SYSTEMSOLVABLE ? -v : v);
667 queue_push(&solv->learnt_pool, 0);
668 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
669 if (ri < solv->systemrules)
670 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
673 queue_push(&solv->problems, v);
674 queue_push(&solv->problems, 0);
675 disableproblem(solv, v);
679 /* conflict with another job or system rule */
681 queue_push(&solv->problems, solv->learnt_pool.count);
682 queue_push(&solv->learnt_pool, ri);
683 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
684 queue_push(&solv->learnt_pool, 0);
686 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting system/job assertions over literal %d\n", vv);
687 /* push all of our rules asserting this literal on the problem stack */
688 for (i = solv->jobrules, rr = solv->rules + i; i < solv->nrules; i++, rr++)
690 if (!rr->w1 || rr->w2)
692 if (rr->p != vv && rr->p != -vv)
694 /* See the large comment in front of the very first loop in this
695 function at FIXME. */
696 if (i >= solv->learntrules)
698 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
700 if (i < solv->systemrules)
701 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
702 queue_push(&solv->problems, v);
703 disableproblem(solv, v);
705 queue_push(&solv->problems, 0);
708 while (solv->decisionq.count > decisionstart)
710 v = solv->decisionq.elements[--solv->decisionq.count];
711 --solv->decisionq_why.count;
713 solv->decisionmap[vv] = 0;
715 ri = solv->jobrules - 1;
716 r = solv->rules + ri;
719 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
723 * we have enabled or disabled some of our rules. We now reenable all
724 * of our learnt rules but the ones that were learnt from rules that
728 enabledisablelearntrules(Solver *solv)
730 Pool *pool = solv->pool;
735 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
736 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
738 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
739 while ((why = *whyp++) != 0)
742 continue; /* rpm assertion */
744 if (!solv->rules[why].w1)
747 /* why != 0: we found a disabled rule, disable the learnt rule */
750 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
752 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling learnt ");
753 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
755 disablerule(solv, r);
757 else if (!why && !r->w1)
759 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
761 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling learnt ");
762 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
770 /* FIXME: bad code ahead, replace as soon as possible */
772 disableupdaterules(Solver *solv, Queue *job, int jobidx)
774 Pool *pool = solv->pool;
776 Id name, how, what, p, *pp;
782 installed = solv->installed;
788 how = job->elements[jobidx];
791 case SOLVER_INSTALL_SOLVABLE:
792 case SOLVER_ERASE_SOLVABLE:
793 case SOLVER_ERASE_SOLVABLE_NAME:
794 case SOLVER_ERASE_SOLVABLE_PROVIDES:
800 /* go through all enabled job rules */
801 MAPZERO(&solv->noupdate);
802 for (i = solv->jobrules; i < solv->systemrules; i++)
805 if (!r->w1) /* disabled? */
807 j = solv->ruletojob.elements[i - solv->jobrules];
811 how = job->elements[j];
812 what = job->elements[j + 1];
815 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
816 s = pool->solvables + what;
817 FOR_PROVIDES(p, pp, s->name)
819 if (pool->solvables[p].name != s->name)
821 if (pool->solvables[p].repo == installed)
822 MAPSET(&solv->noupdate, p - installed->start);
825 case SOLVER_ERASE_SOLVABLE:
826 s = pool->solvables + what;
827 if (s->repo == installed)
828 MAPSET(&solv->noupdate, what - installed->start);
830 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
831 case SOLVER_ERASE_SOLVABLE_PROVIDES:
832 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
833 while (ISRELDEP(name))
835 Reldep *rd = GETRELDEP(pool, name);
838 FOR_PROVIDES(p, pp, what)
840 if (name && pool->solvables[p].name != name)
842 if (pool->solvables[p].repo == installed)
843 MAPSET(&solv->noupdate, p - installed->start);
851 /* fixup update rule status */
852 if (solv->allowuninstall)
853 return; /* no update rules at all */
857 /* we just disabled job #jobidx. enable all update rules
858 * that aren't disabled by the remaining job rules */
859 how = job->elements[jobidx];
860 what = job->elements[jobidx + 1];
863 case SOLVER_INSTALL_SOLVABLE:
864 s = pool->solvables + what;
865 FOR_PROVIDES(p, pp, s->name)
867 if (pool->solvables[p].name != s->name)
869 if (pool->solvables[p].repo != installed)
871 if (MAPTST(&solv->noupdate, p - installed->start))
873 r = solv->rules + solv->systemrules + (p - installed->start);
877 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
879 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
880 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
884 case SOLVER_ERASE_SOLVABLE:
885 s = pool->solvables + what;
886 if (s->repo != installed)
888 if (MAPTST(&solv->noupdate, what - installed->start))
890 r = solv->rules + solv->systemrules + (what - installed->start);
894 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
896 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
897 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
900 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
901 case SOLVER_ERASE_SOLVABLE_PROVIDES:
902 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
903 while (ISRELDEP(name))
905 Reldep *rd = GETRELDEP(pool, name);
908 FOR_PROVIDES(p, pp, what)
910 if (name && pool->solvables[p].name != name)
912 if (pool->solvables[p].repo != installed)
914 if (MAPTST(&solv->noupdate, p - installed->start))
916 r = solv->rules + solv->systemrules + (p - installed->start);
920 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
922 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
923 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
933 for (i = 0; i < installed->nsolvables; i++)
935 r = solv->rules + solv->systemrules + i;
936 if (r->w1 && MAPTST(&solv->noupdate, i))
937 disablerule(solv, r); /* was enabled, need to disable */
943 addpatchatomrequires(Solver *solv, Solvable *s, Id *dp, Queue *q, Map *m)
945 Pool *pool = solv->pool;
946 Id fre, *frep, p, *pp, ndp;
952 queue_init_buffer(&fq, qbuf, sizeof(qbuf)/sizeof(*qbuf));
953 queue_push(&fq, -(s - pool->solvables));
955 queue_push(&fq, *dp);
956 ndp = pool_queuetowhatprovides(pool, &fq);
957 frep = s->repo->idarraydata + s->freshens;
958 while ((fre = *frep++) != 0)
960 FOR_PROVIDES(p, pp, fre)
962 ps = pool->solvables + p;
963 addrule(solv, -p, ndp);
971 for (i = 1; i < fq.count; i++)
983 * add (install) rules for solvable
984 * for unfulfilled requirements, conflicts, obsoletes,....
985 * add a negative assertion for solvables that are not installable
989 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
991 Pool *pool = solv->pool;
992 Repo *installed = solv->installed;
1007 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
1009 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1010 queue_push(&q, s - pool->solvables); /* push solvable Id */
1016 * s: Pointer to solvable
1019 n = queue_shift(&q);
1020 if (MAPTST(m, n)) /* continue if already done */
1024 s = pool->solvables + n; /* s = Solvable in question */
1027 if (installed /* Installed system available */
1028 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
1029 && s->repo == installed) /* solvable is installed? */
1031 dontfix = 1; /* dont care about broken rpm deps */
1034 if (!dontfix && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
1036 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
1037 addrule(solv, -n, 0); /* uninstallable */
1041 if (s->freshens && !s->supplements)
1043 const char *name = id2str(pool, s->name);
1044 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
1048 /*-----------------------------------------
1049 * check requires of s
1054 reqp = s->repo->idarraydata + s->requires;
1055 while ((req = *reqp++) != 0) /* go throw all requires */
1057 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
1060 dp = pool_whatprovides(pool, req);
1062 if (*dp == SYSTEMSOLVABLE) /* always installed */
1068 addpatchatomrequires(solv, s, dp, &q, m);
1074 /* the strategy here is to not insist on dependencies
1075 * that are already broken. so if we find one provider
1076 * that was already installed, we know that the
1077 * dependency was not broken before so we enforce it */
1078 for (i = 0; (p = dp[i]) != 0; i++) /* for all providers */
1080 if (pool->solvables[p].repo == installed)
1081 break; /* provider was installed */
1083 if (!p) /* previously broken dependency */
1085 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1092 /* nothing provides req! */
1093 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1094 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1098 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1100 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1101 for (i = 0; dp[i]; i++)
1102 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1105 /* add 'requires' dependency */
1106 /* rule: (-requestor|provider1|provider2|...|providerN) */
1107 addrule(solv, -n, dp - pool->whatprovidesdata);
1109 /* descend the dependency tree */
1110 for (; *dp; dp++) /* loop through all providers */
1112 if (!MAPTST(m, *dp))
1113 queue_push(&q, *dp);
1116 } /* while, requirements of n */
1118 } /* if, requirements */
1120 /* that's all we check for src packages */
1121 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1124 /*-----------------------------------------
1125 * check conflicts of s
1130 conp = s->repo->idarraydata + s->conflicts;
1131 while ((con = *conp++) != 0)
1133 FOR_PROVIDES(p, pp, con)
1135 /* dontfix: dont care about conflicts with already installed packs */
1136 if (dontfix && pool->solvables[p].repo == installed)
1138 /* rule: -n|-p: either solvable _or_ provider of conflict */
1139 addrule(solv, -n, -p);
1144 /*-----------------------------------------
1145 * check obsoletes if not installed
1147 if (!installed || pool->solvables[n].repo != installed)
1148 { /* not installed */
1151 obsp = s->repo->idarraydata + s->obsoletes;
1152 while ((obs = *obsp++) != 0)
1154 FOR_PROVIDES(p, pp, obs)
1155 addrule(solv, -n, -p);
1158 FOR_PROVIDES(p, pp, s->name)
1160 if (s->name == pool->solvables[p].name)
1161 addrule(solv, -n, -p);
1165 /*-----------------------------------------
1166 * add recommends to the rule list
1170 recp = s->repo->idarraydata + s->recommends;
1171 while ((rec = *recp++) != 0)
1173 FOR_PROVIDES(p, pp, rec)
1180 sugp = s->repo->idarraydata + s->suggests;
1181 while ((sug = *sugp++) != 0)
1183 FOR_PROVIDES(p, pp, sug)
1190 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1194 addrpmrulesforweak(Solver *solv, Map *m)
1196 Pool *pool = solv->pool;
1201 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1202 for (i = n = 1; n < pool->nsolvables; i++, n++)
1204 if (i == pool->nsolvables)
1208 s = pool->solvables + i;
1209 if (!pool_installable(pool, s))
1214 supp = s->repo->idarraydata + s->supplements;
1215 while ((sup = *supp++) != ID_NULL)
1216 if (dep_possible(solv, sup, m))
1219 if (!sup && s->freshens)
1221 supp = s->repo->idarraydata + s->freshens;
1222 while ((sup = *supp++) != ID_NULL)
1223 if (dep_possible(solv, sup, m))
1226 if (!sup && s->enhances)
1228 supp = s->repo->idarraydata + s->enhances;
1229 while ((sup = *supp++) != ID_NULL)
1230 if (dep_possible(solv, sup, m))
1235 addrpmrulesforsolvable(solv, s, m);
1238 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1242 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
1244 Pool *pool = solv->pool;
1249 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1251 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1252 policy_findupdatepackages(solv, s, &qs, allowall);
1253 if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
1254 addrpmrulesforsolvable(solv, s, m);
1255 for (i = 0; i < qs.count; i++)
1256 if (!MAPTST(m, qs.elements[i]))
1257 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1260 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1264 * add rule for update
1265 * (A|A1|A2|A3...) An = update candidates for A
1267 * s = (installed) solvable
1271 addupdaterule(Solver *solv, Solvable *s, int allowall)
1273 /* installed packages get a special upgrade allowed rule */
1274 Pool *pool = solv->pool;
1279 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1281 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1282 policy_findupdatepackages(solv, s, &qs, allowall);
1283 if (qs.count == 0) /* no updaters found */
1286 d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
1288 addrule(solv, s - pool->solvables, d); /* allow update of s */
1289 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1293 /*-----------------------------------------------------------------*/
1302 printWatches(Solver *solv, int type)
1304 Pool *pool = solv->pool;
1307 POOL_DEBUG(type, "Watches: \n");
1309 for (counter = -(pool->nsolvables); counter <= pool->nsolvables; counter ++)
1311 POOL_DEBUG(type, " solvable [%d] -- rule [%d]\n", counter, solv->watches[counter+pool->nsolvables]);
1318 * initial setup for all watches
1322 makewatches(Solver *solv)
1326 int nsolvables = solv->pool->nsolvables;
1328 sat_free(solv->watches);
1329 /* lower half for removals, upper half for installs */
1330 solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
1332 /* do it reverse so rpm rules get triggered first */
1333 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1335 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1338 if (!r->w1 /* rule is disabled */
1339 || !r->w2) /* rule is assertion */
1342 /* see addwatches(solv, r) */
1343 r->n1 = solv->watches[nsolvables + r->w1];
1344 solv->watches[nsolvables + r->w1] = r - solv->rules;
1346 r->n2 = solv->watches[nsolvables + r->w2];
1347 solv->watches[nsolvables + r->w2] = r - solv->rules;
1353 * add watches (for rule)
1357 addwatches(Solver *solv, Rule *r)
1359 int nsolvables = solv->pool->nsolvables;
1361 r->n1 = solv->watches[nsolvables + r->w1];
1362 solv->watches[nsolvables + r->w1] = r - solv->rules;
1364 r->n2 = solv->watches[nsolvables + r->w2];
1365 solv->watches[nsolvables + r->w2] = r - solv->rules;
1369 /*-----------------------------------------------------------------*/
1370 /* rule propagation */
1372 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1377 * propagate decision to all rules
1378 * return : 0 = everything is OK
1379 * watched rule = there is a conflict
1383 propagate(Solver *solv, int level)
1385 Pool *pool = solv->pool;
1390 Id *decisionmap = solv->decisionmap;
1391 Id *watches = solv->watches + pool->nsolvables;
1393 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1395 while (solv->propagate_index < solv->decisionq.count)
1397 /* negate because our watches trigger if literal goes FALSE */
1398 pkg = -solv->decisionq.elements[solv->propagate_index++];
1399 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1401 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "popagate for decision %d level %d\n", -pkg, level);
1402 printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1404 printWatches(solv, SAT_DEBUG_SCHUBI);
1407 for (rp = watches + pkg; *rp; rp = nrp)
1409 r = solv->rules + *rp;
1411 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1413 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1414 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1419 ow = r->w2; /* regard the second watchpoint to come to a solution */
1424 ow = r->w1; /* regard the first watchpoint to come to a solution */
1427 /* if clause is TRUE, nothing to do */
1428 if (DECISIONMAP_TRUE(ow))
1433 /* not a binary clause, check if we need to move our watch */
1434 /* search for a literal that is not ow and not false */
1435 /* (true is also ok, in that case the rule is fulfilled) */
1436 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1439 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1440 if (p != ow && !DECISIONMAP_TRUE(-p))
1444 /* p is free to watch, move watch to p */
1445 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1448 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1450 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1464 watches[p] = r - solv->rules;
1468 /* unit clause found, set other watch to TRUE */
1469 if (DECISIONMAP_TRUE(-ow))
1470 return r; /* eek, a conflict! */
1471 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1473 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
1474 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1477 decisionmap[ow] = level;
1479 decisionmap[-ow] = -level;
1480 queue_push(&solv->decisionq, ow);
1481 queue_push(&solv->decisionq_why, r - solv->rules);
1482 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1484 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1486 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
1488 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
1492 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
1494 return 0; /* all is well */
1498 /*-----------------------------------------------------------------*/
1507 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
1509 Pool *pool = solv->pool;
1512 Map seen; /* global? */
1515 int num = 0, l1num = 0;
1516 int learnt_why = solv->learnt_pool.count;
1517 Id *decisionmap = solv->decisionmap;
1521 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
1522 map_init(&seen, pool->nsolvables);
1523 idx = solv->decisionq.count;
1526 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1527 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1528 queue_push(&solv->learnt_pool, c - solv->rules);
1529 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1530 /* go through all literals of the rule */
1542 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1544 vv = v > 0 ? v : -v;
1545 if (MAPTST(&seen, vv))
1547 l = solv->decisionmap[vv];
1552 /* a level 1 literal, mark it for later */
1553 MAPSET(&seen, vv); /* mark for scanning in level 1 phase */
1559 num++; /* need to do this one as well */
1570 v = solv->decisionq.elements[--idx];
1571 vv = v > 0 ? v : -v;
1572 if (MAPTST(&seen, vv))
1575 c = solv->rules + solv->decisionq_why.elements[idx];
1580 *pr = -v; /* so that v doesn't get lost */
1582 /* add involved level 1 rules */
1585 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1589 v = solv->decisionq.elements[--idx];
1590 vv = v > 0 ? v : -v;
1591 if (!MAPTST(&seen, vv))
1593 why = solv->decisionq_why.elements[idx];
1596 queue_push(&solv->learnt_pool, -vv);
1597 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1599 POOL_DEBUG(SAT_DEBUG_ANALYZE, "RPM ASSERT Rule:\n");
1600 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, v);
1604 queue_push(&solv->learnt_pool, why);
1605 c = solv->rules + why;
1606 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1607 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1608 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1619 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1621 vv = v > 0 ? v : -v;
1622 l = solv->decisionmap[vv];
1623 if (l != 1 && l != -1)
1633 else if (r.count == 1 && r.elements[0] < 0)
1634 *dr = r.elements[0];
1636 *dr = pool_queuetowhatprovides(pool, &r);
1637 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1639 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1640 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
1641 for (i = 0; i < r.count; i++)
1642 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
1644 /* push end marker on learnt reasons stack */
1645 queue_push(&solv->learnt_pool, 0);
1654 * reset the solver decisions to right after the rpm rules.
1655 * called after rules have been enabled/disabled
1659 reset_solver(Solver *solv)
1661 Pool *pool = solv->pool;
1665 /* rewind decisions to direct rpm rule assertions */
1666 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
1668 v = solv->decisionq.elements[i];
1669 solv->decisionmap[v > 0 ? v : -v] = 0;
1672 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
1674 solv->decisionq_why.count = solv->directdecisions;
1675 solv->decisionq.count = solv->directdecisions;
1676 solv->recommends_index = -1;
1677 solv->propagate_index = 0;
1679 /* adapt learnt rule status to new set of enabled/disabled rules */
1680 enabledisablelearntrules(solv);
1682 /* redo all job/system decisions */
1683 makeruledecisions(solv);
1684 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
1686 /* recreate watch chains */
1692 * analyze_unsolvable_rule
1696 analyze_unsolvable_rule(Solver *solv, Rule *r)
1698 Pool *pool = solv->pool;
1700 Id why = r - solv->rules;
1701 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1702 printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1703 if (solv->learntrules && why >= solv->learntrules)
1705 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1706 if (solv->learnt_pool.elements[i] > 0)
1707 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i]);
1710 /* do not add rpm rules to problem */
1711 if (why < solv->jobrules)
1713 /* turn rule into problem */
1714 if (why >= solv->jobrules && why < solv->systemrules)
1715 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1716 /* return if problem already countains our rule */
1717 if (solv->problems.count)
1719 for (i = solv->problems.count - 1; i >= 0; i--)
1720 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1722 else if (solv->problems.elements[i] == why)
1725 queue_push(&solv->problems, why);
1730 * analyze_unsolvable
1732 * return: 1 - disabled some rules, try again
1737 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1739 Pool *pool = solv->pool;
1741 Map seen; /* global to speed things up? */
1744 Id *decisionmap = solv->decisionmap;
1745 int oldproblemcount;
1746 int oldlearntpoolcount;
1749 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1750 oldproblemcount = solv->problems.count;
1751 oldlearntpoolcount = solv->learnt_pool.count;
1753 /* make room for proof index */
1754 /* must update it later, as analyze_unsolvable_rule would confuse
1755 * it with a rule index if we put the real value in already */
1756 queue_push(&solv->problems, 0);
1759 map_init(&seen, pool->nsolvables);
1760 queue_push(&solv->learnt_pool, r - solv->rules);
1761 analyze_unsolvable_rule(solv, r);
1762 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1773 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1775 vv = v > 0 ? v : -v;
1776 l = solv->decisionmap[vv];
1781 idx = solv->decisionq.count;
1784 v = solv->decisionq.elements[--idx];
1785 vv = v > 0 ? v : -v;
1786 if (!MAPTST(&seen, vv))
1788 why = solv->decisionq_why.elements[idx];
1791 /* level 1 and no why, must be an rpm assertion */
1792 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1794 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "RPM ");
1795 printruleelement(solv, SAT_DEBUG_UNSOLVABLE, 0, v);
1797 /* this is the only positive rpm assertion */
1798 if (v == SYSTEMSOLVABLE)
1801 queue_push(&solv->learnt_pool, v);
1804 queue_push(&solv->learnt_pool, why);
1805 r = solv->rules + why;
1806 analyze_unsolvable_rule(solv, r);
1807 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1818 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1820 vv = v > 0 ? v : -v;
1821 l = solv->decisionmap[vv];
1828 queue_push(&solv->problems, 0); /* mark end of this problem */
1831 if (solv->weakrules != solv->learntrules)
1833 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1835 why = solv->problems.elements[i];
1836 if (why < solv->weakrules || why >= solv->learntrules)
1838 if (!lastweak || lastweak < why)
1844 /* disable last weak rule */
1845 solv->problems.count = oldproblemcount;
1846 solv->learnt_pool.count = oldlearntpoolcount;
1847 r = solv->rules + lastweak;
1848 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling weak ");
1849 printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
1850 disablerule(solv, r);
1856 queue_push(&solv->learnt_pool, 0);
1857 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1861 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1862 disableproblem(solv, solv->problems.elements[i]);
1866 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1871 /*-----------------------------------------------------------------*/
1872 /* Decision revert */
1876 * revert decision at level
1880 revert(Solver *solv, int level)
1882 Pool *pool = solv->pool;
1884 while (solv->decisionq.count)
1886 v = solv->decisionq.elements[solv->decisionq.count - 1];
1887 vv = v > 0 ? v : -v;
1888 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1890 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1891 if (v > 0 && solv->recommendations.count && v == solv->recommendations.elements[solv->recommendations.count - 1])
1892 solv->recommendations.count--;
1893 solv->decisionmap[vv] = 0;
1894 solv->decisionq.count--;
1895 solv->decisionq_why.count--;
1896 solv->propagate_index = solv->decisionq.count;
1898 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1900 solv->branches.count--;
1901 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1902 solv->branches.count--;
1904 solv->recommends_index = -1;
1909 * watch2onhighest - put watch2 on literal with highest level
1913 watch2onhighest(Solver *solv, Rule *r)
1919 return; /* binary rule, both watches are set */
1920 dp = solv->pool->whatprovidesdata + r->d;
1921 while ((v = *dp++) != 0)
1923 l = solv->decisionmap[v < 0 ? -v : v];
1938 * add free decision to decisionq, increase level and
1939 * propagate decision, return if no conflict.
1940 * in conflict case, analyze conflict rule, add resulting
1941 * rule to learnt rule set, make decision from learnt
1942 * rule (always unit) and re-propagate.
1944 * returns the new solver level or 0 if unsolvable
1949 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1951 Pool *pool = solv->pool;
1960 solv->decisionmap[decision] = level;
1962 solv->decisionmap[-decision] = -level;
1963 queue_push(&solv->decisionq, decision);
1964 queue_push(&solv->decisionq_why, 0);
1968 r = propagate(solv, level);
1972 return analyze_unsolvable(solv, r, disablerules);
1973 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1974 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1975 assert(l > 0 && l < level);
1976 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
1978 revert(solv, level);
1979 r = addrule(solv, p, d); /* p requires d */
1981 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1982 queue_push(&solv->learnt_why, why);
1985 /* at least 2 literals, needs watches */
1986 watch2onhighest(solv, r);
1987 addwatches(solv, r);
1989 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1990 queue_push(&solv->decisionq, p);
1991 queue_push(&solv->decisionq_why, r - solv->rules);
1992 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1994 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
1995 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
1996 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
1997 printrule(solv, SAT_DEBUG_ANALYZE, r);
2005 * install best package from the queue. We add an extra package, inst, if
2006 * provided. See comment in weak install section.
2008 * returns the new solver level or 0 if unsolvable
2012 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
2014 Pool *pool = solv->pool;
2018 if (dq->count > 1 || inst)
2019 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
2024 /* choose the supplemented one */
2025 for (i = 0; i < dq->count; i++)
2026 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
2030 for (i = 1; i < dq->count; i++)
2031 queue_push(&solv->branches, dq->elements[i]);
2032 queue_push(&solv->branches, -level);
2036 p = dq->elements[i];
2038 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
2040 return setpropagatelearn(solv, level, p, disablerules);
2044 /*-----------------------------------------------------------------*/
2045 /* Main solver interface */
2050 * create solver structure
2052 * pool: all available solvables
2053 * installed: installed Solvables
2056 * Upon solving, rules are created to flag the Solvables
2057 * of the 'installed' Repo as installed.
2061 solver_create(Pool *pool, Repo *installed)
2064 solv = (Solver *)sat_calloc(1, sizeof(Solver));
2066 solv->installed = installed;
2068 queue_init(&solv->ruletojob);
2069 queue_init(&solv->decisionq);
2070 queue_init(&solv->decisionq_why);
2071 queue_init(&solv->problems);
2072 queue_init(&solv->suggestions);
2073 queue_init(&solv->recommendations);
2074 queue_init(&solv->learnt_why);
2075 queue_init(&solv->learnt_pool);
2076 queue_init(&solv->branches);
2077 queue_init(&solv->covenantq);
2079 map_init(&solv->recommendsmap, pool->nsolvables);
2080 map_init(&solv->suggestsmap, pool->nsolvables);
2081 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
2082 solv->recommends_index = 0;
2084 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2086 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
2087 memset(solv->rules, 0, sizeof(Rule));
2098 solver_free(Solver *solv)
2100 queue_free(&solv->ruletojob);
2101 queue_free(&solv->decisionq);
2102 queue_free(&solv->decisionq_why);
2103 queue_free(&solv->learnt_why);
2104 queue_free(&solv->learnt_pool);
2105 queue_free(&solv->problems);
2106 queue_free(&solv->suggestions);
2107 queue_free(&solv->recommendations);
2108 queue_free(&solv->branches);
2109 queue_free(&solv->covenantq);
2111 map_free(&solv->recommendsmap);
2112 map_free(&solv->suggestsmap);
2113 map_free(&solv->noupdate);
2115 sat_free(solv->decisionmap);
2116 sat_free(solv->rules);
2117 sat_free(solv->watches);
2118 sat_free(solv->weaksystemrules);
2119 sat_free(solv->obsoletes);
2120 sat_free(solv->obsoletes_data);
2125 /*-------------------------------------------------------*/
2130 * all rules have been set up, now actually run the solver
2135 run_solver(Solver *solv, int disablerules, int doweak)
2143 Pool *pool = solv->pool;
2146 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2148 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2149 for (i = 0; i < solv->nrules; i++)
2150 printrule(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2153 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2155 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2156 printdecisions(solv);
2158 /* start SAT algorithm */
2160 systemlevel = level + 1;
2161 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2172 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2173 if ((r = propagate(solv, level)) != 0)
2175 if (analyze_unsolvable(solv, r, disablerules))
2183 * installed packages
2186 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2188 if (!solv->updatesystem)
2190 /* try to keep as many packages as possible */
2191 POOL_DEBUG(SAT_DEBUG_STATS, "installing system packages\n");
2192 for (i = solv->installed->start, n = 0; ; i++)
2194 if (n == solv->installed->nsolvables)
2196 if (i == solv->installed->end)
2197 i = solv->installed->start;
2198 s = pool->solvables + i;
2199 if (s->repo != solv->installed)
2202 if (solv->decisionmap[i] != 0)
2204 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2206 level = setpropagatelearn(solv, level, i, disablerules);
2212 if (level <= olevel)
2216 if (solv->weaksystemrules)
2218 POOL_DEBUG(SAT_DEBUG_STATS, "installing weak system packages\n");
2219 for (i = solv->installed->start; i < solv->installed->end; i++)
2221 if (pool->solvables[i].repo != solv->installed)
2223 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
2225 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2226 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2229 if (solv->weaksystemrules[i - solv->installed->start])
2231 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
2232 while ((p = *dp++) != 0)
2234 if (solv->decisionmap[p] > 0)
2236 if (solv->decisionmap[p] == 0)
2240 continue; /* update package already installed */
2242 if (!dq.count && solv->decisionmap[i] != 0)
2245 /* FIXME: i is handled a bit different because we do not want
2246 * to have it pruned just because it is not recommened.
2247 * we should not prune installed packages instead */
2248 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2254 if (level <= olevel)
2257 if (i < solv->installed->end)
2260 systemlevel = level;
2267 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unresolved rules\n");
2268 for (i = 1, n = 1; ; i++, n++)
2270 if (n == solv->nrules)
2272 if (i == solv->nrules)
2274 r = solv->rules + i;
2275 if (!r->w1) /* ignore disabled rules */
2280 /* binary or unary rule */
2281 /* need two positive undecided literals */
2282 if (r->p < 0 || r->w2 <= 0)
2284 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2286 queue_push(&dq, r->p);
2287 queue_push(&dq, r->w2);
2292 * all negative literals are installed
2293 * no positive literal is installed
2294 * i.e. the rule is not fulfilled and we
2295 * just need to decide on the positive literals
2299 if (solv->decisionmap[-r->p] <= 0)
2304 if (solv->decisionmap[r->p] > 0)
2306 if (solv->decisionmap[r->p] == 0)
2307 queue_push(&dq, r->p);
2309 dp = pool->whatprovidesdata + r->d;
2310 while ((p = *dp++) != 0)
2314 if (solv->decisionmap[-p] <= 0)
2319 if (solv->decisionmap[p] > 0)
2321 if (solv->decisionmap[p] == 0)
2328 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2330 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2331 printrule(solv, SAT_DEBUG_PROPAGATE, r);
2333 /* dq.count < 2 cannot happen as this means that
2334 * the rule is unit */
2335 assert(dq.count > 1);
2338 level = selectandinstall(solv, level, &dq, 0, disablerules);
2344 if (level < systemlevel)
2347 } /* for(), decide */
2349 if (n != solv->nrules) /* continue if level < systemlevel */
2352 if (doweak && !solv->problems.count)
2356 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
2357 if (!solv->dosplitprovides && !REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2359 for (i = 1; i < solv->decisionq.count; i++)
2361 p = solv->decisionq.elements[i];
2362 if (p > 0 && pool->solvables[p].repo == solv->installed)
2363 solv->decisionmap[p] = -solv->decisionmap[p];
2367 for (i = 1; i < pool->nsolvables; i++)
2369 if (solv->decisionmap[i] < 0)
2371 if (solv->decisionmap[i] > 0)
2373 Id *recp, rec, *pp, p;
2374 s = pool->solvables + i;
2375 /* installed, check for recommends */
2376 /* XXX need to special case AND ? */
2379 recp = s->repo->idarraydata + s->recommends;
2380 while ((rec = *recp++) != 0)
2383 FOR_PROVIDES(p, pp, rec)
2385 if (solv->decisionmap[p] > 0)
2390 else if (solv->decisionmap[p] == 0)
2392 queue_pushunique(&dq, p);
2400 s = pool->solvables + i;
2401 if (!s->supplements && !s->freshens)
2403 if (!pool_installable(pool, s))
2405 if (solver_is_supplementing(solv, s))
2406 queue_pushunique(&dq, i);
2409 if (!solv->dosplitprovides && !REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2411 for (i = 1; i < solv->decisionq.count; i++)
2413 p = solv->decisionq.elements[i];
2414 if (p > 0 && pool->solvables[p].repo == solv->installed)
2415 solv->decisionmap[p] = -solv->decisionmap[p];
2421 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2423 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2424 queue_push(&solv->recommendations, p);
2425 level = setpropagatelearn(solv, level, p, 0);
2430 if (solv->solution_callback)
2432 solv->solution_callback(solv, solv->solution_callback_data);
2433 if (solv->branches.count)
2435 int i = solv->branches.count - 1;
2436 int l = -solv->branches.elements[i];
2438 if (solv->branches.elements[i - 1] < 0)
2440 p = solv->branches.elements[i];
2441 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
2443 for (j = i + 1; j < solv->branches.count; j++)
2444 queue_push(&dq, solv->branches.elements[j]);
2445 solv->branches.count = i;
2447 revert(solv, level);
2449 for (j = 0; j < dq.count; j++)
2450 queue_push(&solv->branches, dq.elements[j]);
2452 level = setpropagatelearn(solv, level, p, disablerules);
2460 /* all branches done, we're finally finished */
2464 /* minimization step */
2465 if (solv->branches.count)
2467 int l = 0, lasti = -1, lastl = -1;
2469 for (i = solv->branches.count - 1; i >= 0; i--)
2471 p = solv->branches.elements[i];
2474 else if (p > 0 && solv->decisionmap[p] > l + 1)
2482 /* kill old solvable so that we do not loop */
2483 p = solv->branches.elements[lasti];
2484 solv->branches.elements[lasti] = 0;
2485 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
2488 revert(solv, level);
2490 level = setpropagatelearn(solv, level, p, disablerules);
2501 POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
2508 * at this point, all rules that led to conflicts are disabled.
2509 * we re-enable all rules of a problem set but rule "sug", then
2510 * continue to disable more rules until there as again a solution.
2513 /* FIXME: think about conflicting assertions */
2516 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2518 Pool *pool = solv->pool;
2525 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2527 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
2528 for (i = 0; problem[i]; i++)
2530 if (problem[i] == sug)
2531 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
2532 printproblem(solv, problem[i]);
2535 queue_init(&disabled);
2536 queue_empty(refined);
2537 queue_push(refined, sug);
2539 /* re-enable all problem rules with the exception of "sug"(gests) */
2543 for (i = 0; problem[i]; i++)
2544 if (problem[i] != sug)
2545 enableproblem(solv, problem[i]);
2548 disableupdaterules(solv, job, -(sug + 1));
2552 /* re-enable as many weak rules as possible */
2553 for (i = solv->weakrules; i < solv->learntrules; i++)
2555 r = solv->rules + i;
2557 enablerule(solv, r);
2560 queue_empty(&solv->problems);
2561 revert(solv, 1); /* XXX move to reset_solver? */
2564 if (!solv->problems.count)
2565 run_solver(solv, 0, 0);
2567 if (!solv->problems.count)
2569 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
2570 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2571 printdecisions(solv);
2572 break; /* great, no more problems */
2574 disabledcnt = disabled.count;
2575 /* start with 1 to skip over proof index */
2576 for (i = 1; i < solv->problems.count - 1; i++)
2578 /* ignore solutions in refined */
2579 v = solv->problems.elements[i];
2581 break; /* end of problem reached */
2582 for (j = 0; problem[j]; j++)
2583 if (problem[j] != sug && problem[j] == v)
2587 queue_push(&disabled, v);
2589 if (disabled.count == disabledcnt)
2591 /* no solution found, this was an invalid suggestion! */
2592 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
2596 if (disabled.count == disabledcnt + 1)
2598 /* just one suggestion, add it to refined list */
2599 v = disabled.elements[disabledcnt];
2600 queue_push(refined, v);
2601 disableproblem(solv, v);
2603 disableupdaterules(solv, job, -(v + 1));
2607 /* more than one solution, disable all */
2608 /* do not push anything on refine list */
2609 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2611 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
2612 for (i = disabledcnt; i < disabled.count; i++)
2613 printproblem(solv, disabled.elements[i]);
2615 for (i = disabledcnt; i < disabled.count; i++)
2616 disableproblem(solv, disabled.elements[i]);
2619 /* all done, get us back into the same state as before */
2620 /* enable refined rules again */
2621 for (i = 0; i < disabled.count; i++)
2622 enableproblem(solv, disabled.elements[i]);
2623 /* disable problem rules again */
2624 for (i = 0; problem[i]; i++)
2625 disableproblem(solv, problem[i]);
2626 disableupdaterules(solv, job, -1);
2627 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
2631 problems_to_solutions(Solver *solv, Queue *job)
2633 Pool *pool = solv->pool;
2641 if (!solv->problems.count)
2643 queue_clone(&problems, &solv->problems);
2644 queue_init(&solution);
2645 queue_init(&solutions);
2646 /* copy over proof index */
2647 queue_push(&solutions, problems.elements[0]);
2648 problem = problems.elements + 1;
2649 for (i = 1; i < problems.count; i++)
2651 Id v = problems.elements[i];
2654 /* mark end of this problem */
2655 queue_push(&solutions, 0);
2656 queue_push(&solutions, 0);
2657 if (i + 1 == problems.count)
2659 /* copy over proof of next problem */
2660 queue_push(&solutions, problems.elements[i + 1]);
2662 problem = problems.elements + i + 1;
2665 refine_suggestion(solv, job, problem, v, &solution);
2666 if (!solution.count)
2667 continue; /* this solution didn't work out */
2669 for (j = 0; j < solution.count; j++)
2671 why = solution.elements[j];
2672 /* must be either job descriptor or system rule */
2673 assert(why < 0 || (why >= solv->systemrules && why < solv->weakrules));
2675 printproblem(solv, why);
2679 /* job descriptor */
2680 queue_push(&solutions, 0);
2681 queue_push(&solutions, -why);
2685 /* system rule, find replacement package */
2687 p = solv->installed->start + (why - solv->systemrules);
2688 if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
2690 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
2693 if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
2695 if (solv->decisionmap[*dp] > 0)
2702 queue_push(&solutions, p);
2703 queue_push(&solutions, rp);
2706 /* mark end of this solution */
2707 queue_push(&solutions, 0);
2708 queue_push(&solutions, 0);
2710 queue_free(&solution);
2711 queue_free(&problems);
2712 /* copy queue over to solutions */
2713 queue_free(&solv->problems);
2714 queue_clone(&solv->problems, &solutions);
2716 /* bring solver back into problem state */
2717 revert(solv, 1); /* XXX move to reset_solver? */
2720 assert(solv->problems.count == solutions.count);
2721 queue_free(&solutions);
2725 solver_next_problem(Solver *solv, Id problem)
2729 return solv->problems.count ? 1 : 0;
2730 pp = solv->problems.elements + problem;
2731 while (pp[0] || pp[1])
2735 while (pp[0] || pp[1])
2740 problem = pp - solv->problems.elements;
2741 if (problem >= solv->problems.count)
2747 solver_next_solution(Solver *solv, Id problem, Id solution)
2753 pp = solv->problems.elements + solution;
2754 return pp[0] || pp[1] ? solution : 0;
2756 pp = solv->problems.elements + solution;
2757 while (pp[0] || pp[1])
2760 solution = pp - solv->problems.elements;
2761 return pp[0] || pp[1] ? solution : 0;
2765 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
2768 element = element ? element + 2 : solution;
2769 pp = solv->problems.elements + element;
2770 if (!(pp[0] || pp[1]))
2779 * create obsoletesmap from solver decisions
2780 * required for decision handling
2784 create_decisions_obsoletesmap(Solver *solv)
2786 Pool *pool = solv->pool;
2787 Repo *installed = solv->installed;
2788 Id p, *obsoletesmap = NULL;
2792 obsoletesmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2795 for (i = 0; i < solv->decisionq.count; i++)
2799 n = solv->decisionq.elements[i];
2802 if (n == SYSTEMSOLVABLE)
2804 s = pool->solvables + n;
2805 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2807 FOR_PROVIDES(p, pp, s->name)
2808 if (s->name == pool->solvables[p].name)
2810 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2812 obsoletesmap[p] = n;
2817 for (i = 0; i < solv->decisionq.count; i++)
2822 n = solv->decisionq.elements[i];
2825 if (n == SYSTEMSOLVABLE)
2827 s = pool->solvables + n;
2828 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2832 obsp = s->repo->idarraydata + s->obsoletes;
2833 while ((obs = *obsp++) != 0)
2834 FOR_PROVIDES(p, pp, obs)
2836 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2838 obsoletesmap[p] = n;
2844 return obsoletesmap;
2853 printdecisions(Solver *solv)
2855 Pool *pool = solv->pool;
2856 Repo *installed = solv->installed;
2857 Id p, *obsoletesmap = create_decisions_obsoletesmap( solv );
2861 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
2863 /* print solvables to be erased */
2867 FOR_REPO_SOLVABLES(installed, p, s)
2869 if (solv->decisionmap[p] >= 0)
2871 if (obsoletesmap[p])
2873 POOL_DEBUG(SAT_DEBUG_RESULT, "erase %s\n", solvable2str(pool, s));
2877 /* print solvables to be installed */
2879 for (i = 0; i < solv->decisionq.count; i++)
2882 p = solv->decisionq.elements[i];
2885 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2888 s = pool->solvables + p;
2889 POOL_DEBUG(SAT_DEBUG_SCHUBI, "level of %s is %d\n", solvable2str(pool, s), p);
2893 if (p == SYSTEMSOLVABLE)
2895 POOL_DEBUG(SAT_DEBUG_SCHUBI, "SYSTEMSOLVABLE\n");
2898 s = pool->solvables + p;
2899 if (installed && s->repo == installed)
2902 if (!obsoletesmap[p])
2904 POOL_DEBUG(SAT_DEBUG_RESULT, "install %s", solvable2str(pool, s));
2908 POOL_DEBUG(SAT_DEBUG_RESULT, "update %s", solvable2str(pool, s));
2909 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
2910 for (j = installed->start; j < installed->end; j++)
2911 if (obsoletesmap[j] == p)
2912 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
2913 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
2915 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
2918 sat_free(obsoletesmap);
2920 if (solv->recommendations.count)
2922 POOL_DEBUG(SAT_DEBUG_RESULT, "\nrecommended packages:\n");
2923 for (i = 0; i < solv->recommendations.count; i++)
2925 s = pool->solvables + solv->recommendations.elements[i];
2926 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
2930 if (solv->suggestions.count)
2932 POOL_DEBUG(SAT_DEBUG_RESULT, "\nsuggested packages:\n");
2933 for (i = 0; i < solv->suggestions.count; i++)
2935 s = pool->solvables + solv->suggestions.elements[i];
2936 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
2939 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
2942 /* this is basically the reverse of addrpmrulesforsolvable */
2944 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
2946 Pool *pool = solv->pool;
2947 Repo *installed = solv->installed;
2951 Id p, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
2953 assert(rid < solv->weakrules);
2954 if (rid >= solv->systemrules)
2957 *sourcep = solv->installed->start + (rid - solv->systemrules);
2959 return SOLVER_PROBLEM_UPDATE_RULE;
2961 if (rid >= solv->jobrules)
2964 r = solv->rules + rid;
2965 p = solv->ruletojob.elements[rid - solv->jobrules];
2966 *depp = job->elements[p + 1];
2968 *targetp = job->elements[p];
2969 if (r->d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE)
2970 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
2971 return SOLVER_PROBLEM_JOB_RULE;
2975 /* a rpm rule assertion */
2976 assert(rid != -SYSTEMSOLVABLE);
2977 s = pool->solvables - rid;
2978 if (installed && !solv->fixsystem && s->repo == installed)
2980 assert(!dontfix); /* dontfix packages never have a neg assertion */
2981 /* see why the package is not installable */
2982 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
2987 return SOLVER_PROBLEM_NOT_INSTALLABLE;
2989 /* check requires */
2990 assert(s->requires);
2991 reqp = s->repo->idarraydata + s->requires;
2992 while ((req = *reqp++) != 0)
2994 if (req == SOLVABLE_PREREQMARKER)
2996 dp = pool_whatprovides(pool, req);
3004 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
3006 r = solv->rules + rid;
3008 if (r->d == 0 && r->w2 == 0)
3010 /* an assertion. we don't store them as rpm rules, so
3014 s = pool->solvables - r->p;
3015 if (installed && !solv->fixsystem && s->repo == installed)
3017 if (r->d == 0 && r->w2 < 0)
3019 /* a package conflict */
3020 Solvable *s2 = pool->solvables - r->w2;
3023 if (installed && !solv->fixsystem && s2->repo == installed)
3026 /* if both packages have the same name and at least one of them
3027 * is not installed, they conflict */
3028 if (s->name == s2->name && (!installed || (s->repo != installed || s2->repo != installed)))
3033 return SOLVER_PROBLEM_SAME_NAME;
3036 /* check conflicts in both directions */
3039 conp = s->repo->idarraydata + s->conflicts;
3040 while ((con = *conp++) != 0)
3042 FOR_PROVIDES(p, pp, con)
3044 if (dontfix && pool->solvables[p].repo == installed)
3051 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3057 conp = s2->repo->idarraydata + s2->conflicts;
3058 while ((con = *conp++) != 0)
3060 FOR_PROVIDES(p, pp, con)
3062 if (dontfix2 && pool->solvables[p].repo == installed)
3069 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3073 /* check obsoletes in both directions */
3074 if ((!installed || s->repo != installed) && s->obsoletes)
3076 obsp = s->repo->idarraydata + s->obsoletes;
3077 while ((obs = *obsp++) != 0)
3079 FOR_PROVIDES(p, pp, obs)
3086 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3090 if ((!installed || s2->repo != installed) && s2->obsoletes)
3092 obsp = s2->repo->idarraydata + s2->obsoletes;
3093 while ((obs = *obsp++) != 0)
3095 FOR_PROVIDES(p, pp, obs)
3102 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3106 /* all cases checked, can't happen */
3109 /* simple requires */
3110 assert(s->requires);
3111 reqp = s->repo->idarraydata + s->requires;
3112 while ((req = *reqp++) != 0)
3114 if (req == SOLVABLE_PREREQMARKER)
3116 dp = pool_whatprovides(pool, req);
3119 if (*dp == r->w2 && dp[1] == 0)
3122 else if (dp - pool->whatprovidesdata == r->d)
3129 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
3133 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3136 Id lreqr, lconr, lsysr, ljobr;
3140 lreqr = lconr = lsysr = ljobr = 0;
3141 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3143 if (rid >= solv->learntrules)
3144 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3145 else if (rid >= solv->systemrules)
3150 else if (rid >= solv->jobrules)
3157 r = solv->rules + rid;
3158 if (!r->d && r->w2 < 0)
3167 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed)
3169 /* prefer rules of installed packages */
3170 Id op = *reqrp >= 0 ? solv->rules[*reqrp].p : -*reqrp;
3171 if (op <= 0 || solv->pool->solvables[op].repo != solv->installed)
3178 /* assertion, counts as require rule */
3179 /* ignore system solvable as we need useful info */
3180 if (rid == -SYSTEMSOLVABLE)
3182 if (!*reqrp || !reqassert)
3187 else if (solv->installed && solv->pool->solvables[-rid].repo == solv->installed)
3189 /* prefer rules of installed packages */
3190 Id op = *reqrp >= 0 ? solv->rules[*reqrp].p : -*reqrp;
3191 if (op <= 0 || solv->pool->solvables[op].repo != solv->installed)
3196 if (!*reqrp && lreqr)
3198 if (!*conrp && lconr)
3200 if (!*jobrp && ljobr)
3202 if (!*sysrp && lsysr)
3207 solver_findproblemrule(Solver *solv, Id problem)
3209 Id reqr, conr, sysr, jobr;
3210 Id idx = solv->problems.elements[problem - 1];
3211 reqr = conr = sysr = jobr = 0;
3212 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3225 printprobleminfo(Solver *solv, Queue *job, Id problem)
3227 Pool *pool = solv->pool;
3229 Id dep, source, target;
3232 probr = solver_findproblemrule(solv, problem);
3233 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
3235 case SOLVER_PROBLEM_UPDATE_RULE:
3236 s = pool_id2solvable(pool, source);
3237 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
3239 case SOLVER_PROBLEM_JOB_RULE:
3240 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
3242 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
3243 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
3245 case SOLVER_PROBLEM_NOT_INSTALLABLE:
3246 s = pool_id2solvable(pool, source);
3247 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
3249 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
3250 s = pool_id2solvable(pool, source);
3251 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
3253 case SOLVER_PROBLEM_SAME_NAME:
3254 s = pool_id2solvable(pool, source);
3255 s2 = pool_id2solvable(pool, target);
3256 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
3258 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
3259 s = pool_id2solvable(pool, source);
3260 s2 = pool_id2solvable(pool, target);
3261 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3263 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
3264 s = pool_id2solvable(pool, source);
3265 s2 = pool_id2solvable(pool, target);
3266 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3268 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
3269 s = pool_id2solvable(pool, source);
3270 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
3276 printsolutions(Solver *solv, Queue *job)
3278 Pool *pool = solv->pool;
3281 Id problem, solution, element;
3284 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
3287 while ((problem = solver_next_problem(solv, problem)) != 0)
3289 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
3290 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
3291 printprobleminfo(solv, job, problem);
3292 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3294 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
3297 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
3301 /* job, rp is index into job queue */
3302 what = job->elements[rp];
3303 switch (job->elements[rp - 1])
3305 case SOLVER_INSTALL_SOLVABLE:
3306 s = pool->solvables + what;
3307 if (solv->installed && s->repo == solv->installed)
3308 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, s));
3310 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solvable2str(pool, s));
3312 case SOLVER_ERASE_SOLVABLE:
3313 s = pool->solvables + what;
3314 if (solv->installed && s->repo == solv->installed)
3315 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solvable2str(pool, s));
3317 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, s));
3319 case SOLVER_INSTALL_SOLVABLE_NAME:
3320 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", dep2str(pool, what));
3322 case SOLVER_ERASE_SOLVABLE_NAME:
3323 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", dep2str(pool, what));
3325 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3326 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable providing %s\n", dep2str(pool, what));
3328 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3329 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables providing %s\n", dep2str(pool, what));
3331 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3332 s = pool->solvables + what;
3333 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solvable2str(pool, s));
3336 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
3342 /* policy, replace p with rp */
3343 s = pool->solvables + p;
3344 sd = rp ? pool->solvables + rp : 0;
3348 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
3350 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3353 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
3355 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3358 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
3361 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));
3363 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));
3367 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3371 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
3376 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3382 /* create reverse obsoletes map for installed solvables
3384 * for each installed solvable find which packages with *different* names
3385 * obsolete the solvable.
3386 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3390 create_obsolete_index(Solver *solv)
3392 Pool *pool = solv->pool;
3394 Repo *installed = solv->installed;
3395 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3398 if (!installed || !installed->nsolvables)
3400 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
3401 for (i = 1; i < pool->nsolvables; i++)
3403 s = pool->solvables + i;
3404 if (s->repo == installed)
3408 if (!pool_installable(pool, s))
3410 obsp = s->repo->idarraydata + s->obsoletes;
3411 while ((obs = *obsp++) != 0)
3412 FOR_PROVIDES(p, pp, obs)
3414 if (pool->solvables[p].repo != installed)
3416 if (pool->solvables[p].name == s->name)
3418 obsoletes[p - installed->start]++;
3422 for (i = 0; i < installed->nsolvables; i++)
3425 n += obsoletes[i] + 1;
3428 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
3429 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
3430 for (i = pool->nsolvables - 1; i > 0; i--)
3432 s = pool->solvables + i;
3433 if (s->repo == installed)
3437 if (!pool_installable(pool, s))
3439 obsp = s->repo->idarraydata + s->obsoletes;
3440 while ((obs = *obsp++) != 0)
3441 FOR_PROVIDES(p, pp, obs)
3443 if (pool->solvables[p].repo != installed)
3445 if (pool->solvables[p].name == s->name)
3447 p -= installed->start;
3448 if (obsoletes_data[obsoletes[p]] != i)
3449 obsoletes_data[--obsoletes[p]] = i;
3455 /*-----------------------------------------------------------------*/
3465 solver_solve(Solver *solv, Queue *job)
3467 Pool *pool = solv->pool;
3468 Repo *installed = solv->installed;
3471 Map addedmap; /* '1' == have rpm-rules for solvable */
3472 Id how, what, name, p, *pp, d;
3476 /* create whatprovides if not already there */
3477 if (!pool->whatprovides)
3478 pool_createwhatprovides(pool);
3480 /* create obsolete index if needed */
3481 if (solv->noupdateprovide)
3482 create_obsolete_index(solv);
3485 * create basic rule set of all involved packages
3486 * use addedmap bitmap to make sure we don't create rules twice
3490 map_init(&addedmap, pool->nsolvables);
3494 * always install our system solvable
3496 MAPSET(&addedmap, SYSTEMSOLVABLE);
3497 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3498 queue_push(&solv->decisionq_why, 0);
3499 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3502 * create rules for all package that could be involved with the solving
3503 * so called: rpm rules
3508 oldnrules = solv->nrules;
3509 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
3510 FOR_REPO_SOLVABLES(installed, p, s)
3511 addrpmrulesforsolvable(solv, s, &addedmap);
3512 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3513 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
3514 oldnrules = solv->nrules;
3515 FOR_REPO_SOLVABLES(installed, p, s)
3516 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3517 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3520 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
3521 oldnrules = solv->nrules;
3522 for (i = 0; i < job->count; i += 2)
3524 how = job->elements[i];
3525 what = job->elements[i + 1];
3529 case SOLVER_INSTALL_SOLVABLE:
3530 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3532 case SOLVER_INSTALL_SOLVABLE_NAME:
3533 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3534 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3535 while (ISRELDEP(name))
3537 Reldep *rd = GETRELDEP(pool, name);
3540 FOR_PROVIDES(p, pp, what)
3542 /* if by name, ensure that the name matches */
3543 if (name && pool->solvables[p].name != name)
3545 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3548 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3549 /* dont allow downgrade */
3550 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3554 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3556 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
3558 oldnrules = solv->nrules;
3559 addrpmrulesforweak(solv, &addedmap);
3560 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3562 IF_POOLDEBUG (SAT_DEBUG_STATS)
3564 int possible = 0, installable = 0;
3565 for (i = 1; i < pool->nsolvables; i++)
3567 if (pool_installable(pool, pool->solvables + i))
3569 if (MAPTST(&addedmap, i))
3572 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving (rules has been generated for)\n", possible, installable);
3576 * first pass done, we now have all the rpm rules we need.
3577 * unify existing rules before going over all job rules and
3579 * at this point the system is always solvable,
3580 * as an empty system (remove all packages) is a valid solution
3583 unifyrules(solv); /* remove duplicate rpm rules */
3584 solv->directdecisions = solv->decisionq.count;
3586 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
3587 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3588 printdecisions (solv);
3591 * now add all job rules
3594 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
3596 solv->jobrules = solv->nrules;
3598 for (i = 0; i < job->count; i += 2)
3600 oldnrules = solv->nrules;
3602 how = job->elements[i];
3603 what = job->elements[i + 1];
3606 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3607 s = pool->solvables + what;
3608 POOL_DEBUG(SAT_DEBUG_JOB, "job: install solvable %s\n", solvable2str(pool, s));
3609 addrule(solv, what, 0); /* install by Id */
3610 queue_push(&solv->ruletojob, i);
3612 case SOLVER_ERASE_SOLVABLE:
3613 s = pool->solvables + what;
3614 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase solvable %s\n", solvable2str(pool, s));
3615 addrule(solv, -what, 0); /* remove by Id */
3616 queue_push(&solv->ruletojob, i);
3618 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3619 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3620 if (how == SOLVER_INSTALL_SOLVABLE_NAME)
3621 POOL_DEBUG(SAT_DEBUG_JOB, "job: install name %s\n", dep2str(pool, what));
3622 if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3623 POOL_DEBUG(SAT_DEBUG_JOB, "job: install provides %s\n", dep2str(pool, what));
3625 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3626 while (ISRELDEP(name))
3628 Reldep *rd = GETRELDEP(pool, name);
3631 FOR_PROVIDES(p, pp, what)
3633 /* if by name, ensure that the name matches */
3634 if (name && pool->solvables[p].name != name)
3640 /* no provider, make this an impossible rule */
3641 queue_push(&q, -SYSTEMSOLVABLE);
3644 p = queue_shift(&q); /* get first provider */
3646 d = 0; /* single provider ? -> make assertion */
3648 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3649 addrule(solv, p, d); /* add 'requires' rule */
3650 queue_push(&solv->ruletojob, i);
3652 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3653 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3654 if (how == SOLVER_ERASE_SOLVABLE_NAME)
3655 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase name %s\n", dep2str(pool, what));
3656 if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3657 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase provides %s\n", dep2str(pool, what));
3658 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
3659 while (ISRELDEP(name))
3661 Reldep *rd = GETRELDEP(pool, name);
3664 FOR_PROVIDES(p, pp, what)
3666 /* if by name, ensure that the name matches */
3667 if (name && pool->solvables[p].name != name)
3669 addrule(solv, -p, 0); /* add 'remove' rule */
3670 queue_push(&solv->ruletojob, i);
3673 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3674 s = pool->solvables + what;
3675 POOL_DEBUG(SAT_DEBUG_JOB, "job: update %s\n", solvable2str(pool, s));
3676 addupdaterule(solv, s, 0);
3677 queue_push(&solv->ruletojob, i);
3680 IF_POOLDEBUG (SAT_DEBUG_JOB)
3683 if (solv->nrules == oldnrules)
3684 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created\n");
3685 for (j = oldnrules; j < solv->nrules; j++)
3687 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
3688 printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
3692 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3695 * now add system rules
3699 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add system rules ***\n");
3702 solv->systemrules = solv->nrules;
3705 * create rules for updating installed solvables
3709 if (installed && !solv->allowuninstall)
3710 { /* loop over all installed solvables */
3711 /* we create all update rules, but disable some later on depending on the job */
3712 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3714 /* no system rules for patch atoms */
3715 if (s->freshens && !s->supplements)
3717 const char *name = id2str(pool, s->name);
3718 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
3720 addrule(solv, 0, 0);
3724 if (s->repo == installed)
3725 addupdaterule(solv, s, 0); /* allowall = 0 */
3727 addrule(solv, 0, 0); /* create dummy rule */
3729 /* consistency check: we added a rule for _every_ system solvable */
3730 assert(solv->nrules - solv->systemrules == installed->end - installed->start);
3733 /* create special weak system rules */
3734 /* those are used later on to keep a version of the installed packages in
3736 if (installed && installed->nsolvables)
3738 solv->weaksystemrules = sat_calloc(installed->end - installed->start, sizeof(Id));
3739 FOR_REPO_SOLVABLES(installed, p, s)
3741 policy_findupdatepackages(solv, s, &q, 1);
3743 solv->weaksystemrules[p - installed->start] = pool_queuetowhatprovides(pool, &q);
3747 /* free unneeded memory */
3748 map_free(&addedmap);
3751 solv->weakrules = solv->nrules;
3753 /* try real hard to keep packages installed */
3756 FOR_REPO_SOLVABLES(installed, p, s)
3758 /* FIXME: can't work with refine_suggestion! */
3759 /* need to always add the rule but disable it */
3760 if (MAPTST(&solv->noupdate, p - installed->start))
3762 d = solv->weaksystemrules[p - installed->start];
3763 addrule(solv, p, d);
3767 /* all new rules are learnt after this point */
3768 solv->learntrules = solv->nrules;
3770 /* disable system rules that conflict with our job */
3771 disableupdaterules(solv, job, -1);
3773 /* make decisions based on job/system assertions */
3774 makeruledecisions(solv);
3776 /* create watches chains */
3779 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
3782 run_solver(solv, solv->dontinstallrecommended ? 0 : 1, 1);
3784 /* find recommended packages */
3785 if (!solv->problems.count && solv->dontinstallrecommended)
3787 Id rec, *recp, p, *pp;
3789 /* create map of all suggests that are still open */
3790 solv->recommends_index = -1;
3791 MAPZERO(&solv->recommendsmap);
3792 for (i = 0; i < solv->decisionq.count; i++)
3794 p = solv->decisionq.elements[i];
3797 s = pool->solvables + p;
3800 recp = s->repo->idarraydata + s->recommends;
3801 while ((rec = *recp++) != 0)
3803 FOR_PROVIDES(p, pp, rec)
3804 if (solv->decisionmap[p] > 0)
3807 continue; /* already fulfilled */
3808 FOR_PROVIDES(p, pp, rec)
3809 MAPSET(&solv->recommendsmap, p);
3813 for (i = 1; i < pool->nsolvables; i++)
3815 if (solv->decisionmap[i] != 0)
3817 s = pool->solvables + i;
3818 if (!MAPTST(&solv->recommendsmap, i))
3820 if (!s->supplements)
3822 if (!pool_installable(pool, s))
3824 if (!solver_is_supplementing(solv, s))
3827 queue_push(&solv->recommendations, i);
3829 /* we use MODE_SUGGEST here so that repo prio is ignored */
3830 policy_filter_unwanted(solv, &solv->recommendations, 0, POLICY_MODE_SUGGEST);
3833 /* find suggested packages */
3834 if (!solv->problems.count)
3836 Id sug, *sugp, p, *pp;
3838 /* create map of all suggests that are still open */
3839 solv->recommends_index = -1;
3840 MAPZERO(&solv->suggestsmap);
3841 for (i = 0; i < solv->decisionq.count; i++)
3843 p = solv->decisionq.elements[i];
3846 s = pool->solvables + p;
3849 sugp = s->repo->idarraydata + s->suggests;
3850 while ((sug = *sugp++) != 0)
3852 FOR_PROVIDES(p, pp, sug)
3853 if (solv->decisionmap[p] > 0)
3856 continue; /* already fulfilled */
3857 FOR_PROVIDES(p, pp, sug)
3858 MAPSET(&solv->suggestsmap, p);
3862 for (i = 1; i < pool->nsolvables; i++)
3864 if (solv->decisionmap[i] != 0)
3866 s = pool->solvables + i;
3867 if (!MAPTST(&solv->suggestsmap, i))
3871 if (!pool_installable(pool, s))
3873 if (!solver_is_enhancing(solv, s))
3876 queue_push(&solv->suggestions, i);
3878 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
3881 if (solv->problems.count)
3882 problems_to_solutions(solv, job);
3885 /***********************************************************************/
3888 solver_calc_changed_pkgs(Solver *solv, Queue *pkgs)
3890 Pool *pool = solv->pool;
3896 /* create list of solvables that have to be installed */
3897 /* (this is actually just a simple sort) */
3898 map_init(&installmap, pool->nsolvables);
3899 for (i = 1; i < solv->decisionq.count; i++)
3901 Id p = solv->decisionq.elements[i];
3904 s = pool->solvables + p;
3907 if (solv->installed && s->repo == solv->installed)
3909 MAPSET(&installmap, p);
3911 for (p = 1; p < pool->nsolvables; p++)
3912 if (MAPTST(&installmap, p))
3913 queue_push(pkgs, p);
3914 /* run through erase solvable dudata */
3915 if (solv->installed)
3917 FOR_REPO_SOLVABLES(solv->installed, p, s)
3919 if (solv->decisionmap[p] < 0)
3920 queue_push(pkgs, -p);
3926 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
3930 solver_calc_changed_pkgs(solv, &pkgs);
3931 pool_calc_duchanges(solv->pool, &pkgs, mps, nmps);
3936 solver_calc_installsizechange(Solver *solv)
3941 solver_calc_changed_pkgs(solv, &pkgs);
3942 change = pool_calc_installsizechange(solv->pool, &pkgs);