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, "propagate 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; i < solv->installed->end; i++)
2194 s = pool->solvables + i;
2195 if (s->repo != solv->installed)
2197 if (solv->decisionmap[i] != 0)
2199 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2201 level = setpropagatelearn(solv, level, i, disablerules);
2207 if (level <= olevel)
2210 if (i < solv->installed->end)
2213 if (solv->weaksystemrules)
2215 POOL_DEBUG(SAT_DEBUG_STATS, "installing weak system packages\n");
2216 for (i = solv->installed->start; i < solv->installed->end; i++)
2218 s = pool->solvables + i;
2219 if (s->repo != solv->installed)
2221 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
2223 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2224 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2227 if (solv->weaksystemrules[i - solv->installed->start])
2229 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
2230 while ((p = *dp++) != 0)
2232 if (solv->decisionmap[p] > 0)
2234 if (solv->decisionmap[p] == 0)
2238 continue; /* update package already installed */
2240 if (!dq.count && solv->decisionmap[i] != 0)
2243 /* FIXME: i is handled a bit different because we do not want
2244 * to have it pruned just because it is not recommened.
2245 * we should not prune installed packages instead */
2246 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2252 if (level <= olevel)
2255 if (i < solv->installed->end)
2258 systemlevel = level;
2265 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unresolved rules\n");
2266 for (i = 1, n = 1; ; i++, n++)
2268 if (n == solv->nrules)
2270 if (i == solv->nrules)
2272 r = solv->rules + i;
2273 if (!r->w1) /* ignore disabled rules */
2278 /* binary or unary rule */
2279 /* need two positive undecided literals */
2280 if (r->p < 0 || r->w2 <= 0)
2282 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2284 queue_push(&dq, r->p);
2285 queue_push(&dq, r->w2);
2290 * all negative literals are installed
2291 * no positive literal is installed
2292 * i.e. the rule is not fulfilled and we
2293 * just need to decide on the positive literals
2297 if (solv->decisionmap[-r->p] <= 0)
2302 if (solv->decisionmap[r->p] > 0)
2304 if (solv->decisionmap[r->p] == 0)
2305 queue_push(&dq, r->p);
2307 dp = pool->whatprovidesdata + r->d;
2308 while ((p = *dp++) != 0)
2312 if (solv->decisionmap[-p] <= 0)
2317 if (solv->decisionmap[p] > 0)
2319 if (solv->decisionmap[p] == 0)
2326 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2328 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2329 printrule(solv, SAT_DEBUG_PROPAGATE, r);
2331 /* dq.count < 2 cannot happen as this means that
2332 * the rule is unit */
2333 assert(dq.count > 1);
2336 level = selectandinstall(solv, level, &dq, 0, disablerules);
2342 if (level < systemlevel)
2345 } /* for(), decide */
2347 if (n != solv->nrules) /* continue if level < systemlevel */
2350 if (doweak && !solv->problems.count)
2354 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
2355 if (!solv->dosplitprovides && !REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2357 for (i = 1; i < solv->decisionq.count; i++)
2359 p = solv->decisionq.elements[i];
2360 if (p > 0 && pool->solvables[p].repo == solv->installed)
2361 solv->decisionmap[p] = -solv->decisionmap[p];
2365 for (i = 1; i < pool->nsolvables; i++)
2367 if (solv->decisionmap[i] < 0)
2369 if (solv->decisionmap[i] > 0)
2371 Id *recp, rec, *pp, p;
2372 s = pool->solvables + i;
2373 /* installed, check for recommends */
2374 /* XXX need to special case AND ? */
2377 recp = s->repo->idarraydata + s->recommends;
2378 while ((rec = *recp++) != 0)
2381 FOR_PROVIDES(p, pp, rec)
2383 if (solv->decisionmap[p] > 0)
2388 else if (solv->decisionmap[p] == 0)
2390 queue_pushunique(&dq, p);
2398 s = pool->solvables + i;
2399 if (!s->supplements && !s->freshens)
2401 if (!pool_installable(pool, s))
2403 if (solver_is_supplementing(solv, s))
2404 queue_pushunique(&dq, i);
2407 if (!solv->dosplitprovides && !REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2409 for (i = 1; i < solv->decisionq.count; i++)
2411 p = solv->decisionq.elements[i];
2412 if (p > 0 && pool->solvables[p].repo == solv->installed)
2413 solv->decisionmap[p] = -solv->decisionmap[p];
2419 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2421 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2422 queue_push(&solv->recommendations, p);
2423 level = setpropagatelearn(solv, level, p, 0);
2428 if (solv->solution_callback)
2430 solv->solution_callback(solv, solv->solution_callback_data);
2431 if (solv->branches.count)
2433 int i = solv->branches.count - 1;
2434 int l = -solv->branches.elements[i];
2436 if (solv->branches.elements[i - 1] < 0)
2438 p = solv->branches.elements[i];
2439 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
2441 for (j = i + 1; j < solv->branches.count; j++)
2442 queue_push(&dq, solv->branches.elements[j]);
2443 solv->branches.count = i;
2445 revert(solv, level);
2447 for (j = 0; j < dq.count; j++)
2448 queue_push(&solv->branches, dq.elements[j]);
2450 level = setpropagatelearn(solv, level, p, disablerules);
2458 /* all branches done, we're finally finished */
2462 /* minimization step */
2463 if (solv->branches.count)
2465 int l = 0, lasti = -1, lastl = -1;
2467 for (i = solv->branches.count - 1; i >= 0; i--)
2469 p = solv->branches.elements[i];
2472 else if (p > 0 && solv->decisionmap[p] > l + 1)
2480 /* kill old solvable so that we do not loop */
2481 p = solv->branches.elements[lasti];
2482 solv->branches.elements[lasti] = 0;
2483 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
2486 revert(solv, level);
2488 level = setpropagatelearn(solv, level, p, disablerules);
2499 POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
2506 * at this point, all rules that led to conflicts are disabled.
2507 * we re-enable all rules of a problem set but rule "sug", then
2508 * continue to disable more rules until there as again a solution.
2511 /* FIXME: think about conflicting assertions */
2514 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2516 Pool *pool = solv->pool;
2523 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2525 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
2526 for (i = 0; problem[i]; i++)
2528 if (problem[i] == sug)
2529 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
2530 printproblem(solv, problem[i]);
2533 queue_init(&disabled);
2534 queue_empty(refined);
2535 queue_push(refined, sug);
2537 /* re-enable all problem rules with the exception of "sug"(gests) */
2541 for (i = 0; problem[i]; i++)
2542 if (problem[i] != sug)
2543 enableproblem(solv, problem[i]);
2546 disableupdaterules(solv, job, -(sug + 1));
2550 /* re-enable as many weak rules as possible */
2551 for (i = solv->weakrules; i < solv->learntrules; i++)
2553 r = solv->rules + i;
2555 enablerule(solv, r);
2558 queue_empty(&solv->problems);
2559 revert(solv, 1); /* XXX move to reset_solver? */
2562 if (!solv->problems.count)
2563 run_solver(solv, 0, 0);
2565 if (!solv->problems.count)
2567 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
2568 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2569 printdecisions(solv);
2570 break; /* great, no more problems */
2572 disabledcnt = disabled.count;
2573 /* start with 1 to skip over proof index */
2574 for (i = 1; i < solv->problems.count - 1; i++)
2576 /* ignore solutions in refined */
2577 v = solv->problems.elements[i];
2579 break; /* end of problem reached */
2580 for (j = 0; problem[j]; j++)
2581 if (problem[j] != sug && problem[j] == v)
2585 queue_push(&disabled, v);
2587 if (disabled.count == disabledcnt)
2589 /* no solution found, this was an invalid suggestion! */
2590 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
2594 if (disabled.count == disabledcnt + 1)
2596 /* just one suggestion, add it to refined list */
2597 v = disabled.elements[disabledcnt];
2598 queue_push(refined, v);
2599 disableproblem(solv, v);
2601 disableupdaterules(solv, job, -(v + 1));
2605 /* more than one solution, disable all */
2606 /* do not push anything on refine list */
2607 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2609 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
2610 for (i = disabledcnt; i < disabled.count; i++)
2611 printproblem(solv, disabled.elements[i]);
2613 for (i = disabledcnt; i < disabled.count; i++)
2614 disableproblem(solv, disabled.elements[i]);
2617 /* all done, get us back into the same state as before */
2618 /* enable refined rules again */
2619 for (i = 0; i < disabled.count; i++)
2620 enableproblem(solv, disabled.elements[i]);
2621 /* disable problem rules again */
2622 for (i = 0; problem[i]; i++)
2623 disableproblem(solv, problem[i]);
2624 disableupdaterules(solv, job, -1);
2625 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
2629 problems_to_solutions(Solver *solv, Queue *job)
2631 Pool *pool = solv->pool;
2639 if (!solv->problems.count)
2641 queue_clone(&problems, &solv->problems);
2642 queue_init(&solution);
2643 queue_init(&solutions);
2644 /* copy over proof index */
2645 queue_push(&solutions, problems.elements[0]);
2646 problem = problems.elements + 1;
2647 for (i = 1; i < problems.count; i++)
2649 Id v = problems.elements[i];
2652 /* mark end of this problem */
2653 queue_push(&solutions, 0);
2654 queue_push(&solutions, 0);
2655 if (i + 1 == problems.count)
2657 /* copy over proof of next problem */
2658 queue_push(&solutions, problems.elements[i + 1]);
2660 problem = problems.elements + i + 1;
2663 refine_suggestion(solv, job, problem, v, &solution);
2664 if (!solution.count)
2665 continue; /* this solution didn't work out */
2667 for (j = 0; j < solution.count; j++)
2669 why = solution.elements[j];
2670 /* must be either job descriptor or system rule */
2671 assert(why < 0 || (why >= solv->systemrules && why < solv->weakrules));
2673 printproblem(solv, why);
2677 /* job descriptor */
2678 queue_push(&solutions, 0);
2679 queue_push(&solutions, -why);
2683 /* system rule, find replacement package */
2685 p = solv->installed->start + (why - solv->systemrules);
2686 if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
2688 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
2691 if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
2693 if (solv->decisionmap[*dp] > 0)
2700 queue_push(&solutions, p);
2701 queue_push(&solutions, rp);
2704 /* mark end of this solution */
2705 queue_push(&solutions, 0);
2706 queue_push(&solutions, 0);
2708 queue_free(&solution);
2709 queue_free(&problems);
2710 /* copy queue over to solutions */
2711 queue_free(&solv->problems);
2712 queue_clone(&solv->problems, &solutions);
2714 /* bring solver back into problem state */
2715 revert(solv, 1); /* XXX move to reset_solver? */
2718 assert(solv->problems.count == solutions.count);
2719 queue_free(&solutions);
2723 solver_next_problem(Solver *solv, Id problem)
2727 return solv->problems.count ? 1 : 0;
2728 pp = solv->problems.elements + problem;
2729 while (pp[0] || pp[1])
2733 while (pp[0] || pp[1])
2738 problem = pp - solv->problems.elements;
2739 if (problem >= solv->problems.count)
2745 solver_next_solution(Solver *solv, Id problem, Id solution)
2751 pp = solv->problems.elements + solution;
2752 return pp[0] || pp[1] ? solution : 0;
2754 pp = solv->problems.elements + solution;
2755 while (pp[0] || pp[1])
2758 solution = pp - solv->problems.elements;
2759 return pp[0] || pp[1] ? solution : 0;
2763 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
2766 element = element ? element + 2 : solution;
2767 pp = solv->problems.elements + element;
2768 if (!(pp[0] || pp[1]))
2777 * create obsoletesmap from solver decisions
2778 * required for decision handling
2782 create_decisions_obsoletesmap(Solver *solv)
2784 Pool *pool = solv->pool;
2785 Repo *installed = solv->installed;
2786 Id p, *obsoletesmap = NULL;
2790 obsoletesmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2793 for (i = 0; i < solv->decisionq.count; i++)
2797 n = solv->decisionq.elements[i];
2800 if (n == SYSTEMSOLVABLE)
2802 s = pool->solvables + n;
2803 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2805 FOR_PROVIDES(p, pp, s->name)
2806 if (s->name == pool->solvables[p].name)
2808 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2810 obsoletesmap[p] = n;
2815 for (i = 0; i < solv->decisionq.count; i++)
2820 n = solv->decisionq.elements[i];
2823 if (n == SYSTEMSOLVABLE)
2825 s = pool->solvables + n;
2826 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2830 obsp = s->repo->idarraydata + s->obsoletes;
2831 while ((obs = *obsp++) != 0)
2832 FOR_PROVIDES(p, pp, obs)
2834 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2836 obsoletesmap[p] = n;
2842 return obsoletesmap;
2851 printdecisions(Solver *solv)
2853 Pool *pool = solv->pool;
2854 Repo *installed = solv->installed;
2855 Id p, *obsoletesmap = create_decisions_obsoletesmap( solv );
2859 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
2861 /* print solvables to be erased */
2865 FOR_REPO_SOLVABLES(installed, p, s)
2867 if (solv->decisionmap[p] >= 0)
2869 if (obsoletesmap[p])
2871 POOL_DEBUG(SAT_DEBUG_RESULT, "erase %s\n", solvable2str(pool, s));
2875 /* print solvables to be installed */
2877 for (i = 0; i < solv->decisionq.count; i++)
2880 p = solv->decisionq.elements[i];
2883 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2886 s = pool->solvables + p;
2887 POOL_DEBUG(SAT_DEBUG_SCHUBI, "level of %s is %d\n", solvable2str(pool, s), p);
2891 if (p == SYSTEMSOLVABLE)
2893 POOL_DEBUG(SAT_DEBUG_SCHUBI, "SYSTEMSOLVABLE\n");
2896 s = pool->solvables + p;
2897 if (installed && s->repo == installed)
2900 if (!obsoletesmap[p])
2902 POOL_DEBUG(SAT_DEBUG_RESULT, "install %s", solvable2str(pool, s));
2906 POOL_DEBUG(SAT_DEBUG_RESULT, "update %s", solvable2str(pool, s));
2907 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
2908 for (j = installed->start; j < installed->end; j++)
2909 if (obsoletesmap[j] == p)
2910 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
2911 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
2913 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
2916 sat_free(obsoletesmap);
2918 if (solv->recommendations.count)
2920 POOL_DEBUG(SAT_DEBUG_RESULT, "\nrecommended packages:\n");
2921 for (i = 0; i < solv->recommendations.count; i++)
2923 s = pool->solvables + solv->recommendations.elements[i];
2924 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
2928 if (solv->suggestions.count)
2930 POOL_DEBUG(SAT_DEBUG_RESULT, "\nsuggested packages:\n");
2931 for (i = 0; i < solv->suggestions.count; i++)
2933 s = pool->solvables + solv->suggestions.elements[i];
2934 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
2937 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
2940 /* this is basically the reverse of addrpmrulesforsolvable */
2942 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
2944 Pool *pool = solv->pool;
2945 Repo *installed = solv->installed;
2949 Id p, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
2951 assert(rid < solv->weakrules);
2952 if (rid >= solv->systemrules)
2955 *sourcep = solv->installed->start + (rid - solv->systemrules);
2957 return SOLVER_PROBLEM_UPDATE_RULE;
2959 if (rid >= solv->jobrules)
2962 r = solv->rules + rid;
2963 p = solv->ruletojob.elements[rid - solv->jobrules];
2964 *depp = job->elements[p + 1];
2966 *targetp = job->elements[p];
2967 if (r->d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE)
2968 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
2969 return SOLVER_PROBLEM_JOB_RULE;
2973 /* a rpm rule assertion */
2974 assert(rid != -SYSTEMSOLVABLE);
2975 s = pool->solvables - rid;
2976 if (installed && !solv->fixsystem && s->repo == installed)
2978 assert(!dontfix); /* dontfix packages never have a neg assertion */
2979 /* see why the package is not installable */
2980 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
2985 return SOLVER_PROBLEM_NOT_INSTALLABLE;
2987 /* check requires */
2988 assert(s->requires);
2989 reqp = s->repo->idarraydata + s->requires;
2990 while ((req = *reqp++) != 0)
2992 if (req == SOLVABLE_PREREQMARKER)
2994 dp = pool_whatprovides(pool, req);
3002 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
3004 r = solv->rules + rid;
3006 if (r->d == 0 && r->w2 == 0)
3008 /* an assertion. we don't store them as rpm rules, so
3012 s = pool->solvables - r->p;
3013 if (installed && !solv->fixsystem && s->repo == installed)
3015 if (r->d == 0 && r->w2 < 0)
3017 /* a package conflict */
3018 Solvable *s2 = pool->solvables - r->w2;
3021 if (installed && !solv->fixsystem && s2->repo == installed)
3024 /* if both packages have the same name and at least one of them
3025 * is not installed, they conflict */
3026 if (s->name == s2->name && (!installed || (s->repo != installed || s2->repo != installed)))
3031 return SOLVER_PROBLEM_SAME_NAME;
3034 /* check conflicts in both directions */
3037 conp = s->repo->idarraydata + s->conflicts;
3038 while ((con = *conp++) != 0)
3040 FOR_PROVIDES(p, pp, con)
3042 if (dontfix && pool->solvables[p].repo == installed)
3049 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3055 conp = s2->repo->idarraydata + s2->conflicts;
3056 while ((con = *conp++) != 0)
3058 FOR_PROVIDES(p, pp, con)
3060 if (dontfix2 && pool->solvables[p].repo == installed)
3067 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3071 /* check obsoletes in both directions */
3072 if ((!installed || s->repo != installed) && s->obsoletes)
3074 obsp = s->repo->idarraydata + s->obsoletes;
3075 while ((obs = *obsp++) != 0)
3077 FOR_PROVIDES(p, pp, obs)
3084 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3088 if ((!installed || s2->repo != installed) && s2->obsoletes)
3090 obsp = s2->repo->idarraydata + s2->obsoletes;
3091 while ((obs = *obsp++) != 0)
3093 FOR_PROVIDES(p, pp, obs)
3100 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3104 /* all cases checked, can't happen */
3107 /* simple requires */
3108 assert(s->requires);
3109 reqp = s->repo->idarraydata + s->requires;
3110 while ((req = *reqp++) != 0)
3112 if (req == SOLVABLE_PREREQMARKER)
3114 dp = pool_whatprovides(pool, req);
3117 if (*dp == r->w2 && dp[1] == 0)
3120 else if (dp - pool->whatprovidesdata == r->d)
3127 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
3131 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3134 Id lreqr, lconr, lsysr, ljobr;
3138 lreqr = lconr = lsysr = ljobr = 0;
3139 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3141 if (rid >= solv->learntrules)
3142 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3143 else if (rid >= solv->systemrules)
3148 else if (rid >= solv->jobrules)
3155 r = solv->rules + rid;
3156 if (!r->d && r->w2 < 0)
3165 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed)
3167 /* prefer rules of installed packages */
3168 Id op = *reqrp >= 0 ? solv->rules[*reqrp].p : -*reqrp;
3169 if (op <= 0 || solv->pool->solvables[op].repo != solv->installed)
3176 /* assertion, counts as require rule */
3177 /* ignore system solvable as we need useful info */
3178 if (rid == -SYSTEMSOLVABLE)
3180 if (!*reqrp || !reqassert)
3185 else if (solv->installed && solv->pool->solvables[-rid].repo == solv->installed)
3187 /* prefer rules of installed packages */
3188 Id op = *reqrp >= 0 ? solv->rules[*reqrp].p : -*reqrp;
3189 if (op <= 0 || solv->pool->solvables[op].repo != solv->installed)
3194 if (!*reqrp && lreqr)
3196 if (!*conrp && lconr)
3198 if (!*jobrp && ljobr)
3200 if (!*sysrp && lsysr)
3205 solver_findproblemrule(Solver *solv, Id problem)
3207 Id reqr, conr, sysr, jobr;
3208 Id idx = solv->problems.elements[problem - 1];
3209 reqr = conr = sysr = jobr = 0;
3210 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3223 printprobleminfo(Solver *solv, Queue *job, Id problem)
3225 Pool *pool = solv->pool;
3227 Id dep, source, target;
3230 probr = solver_findproblemrule(solv, problem);
3231 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
3233 case SOLVER_PROBLEM_UPDATE_RULE:
3234 s = pool_id2solvable(pool, source);
3235 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
3237 case SOLVER_PROBLEM_JOB_RULE:
3238 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
3240 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
3241 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
3243 case SOLVER_PROBLEM_NOT_INSTALLABLE:
3244 s = pool_id2solvable(pool, source);
3245 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
3247 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
3248 s = pool_id2solvable(pool, source);
3249 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
3251 case SOLVER_PROBLEM_SAME_NAME:
3252 s = pool_id2solvable(pool, source);
3253 s2 = pool_id2solvable(pool, target);
3254 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
3256 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
3257 s = pool_id2solvable(pool, source);
3258 s2 = pool_id2solvable(pool, target);
3259 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3261 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
3262 s = pool_id2solvable(pool, source);
3263 s2 = pool_id2solvable(pool, target);
3264 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3266 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
3267 s = pool_id2solvable(pool, source);
3268 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
3274 printsolutions(Solver *solv, Queue *job)
3276 Pool *pool = solv->pool;
3279 Id problem, solution, element;
3282 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
3285 while ((problem = solver_next_problem(solv, problem)) != 0)
3287 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
3288 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
3289 printprobleminfo(solv, job, problem);
3290 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3292 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
3295 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
3299 /* job, rp is index into job queue */
3300 what = job->elements[rp];
3301 switch (job->elements[rp - 1])
3303 case SOLVER_INSTALL_SOLVABLE:
3304 s = pool->solvables + what;
3305 if (solv->installed && s->repo == solv->installed)
3306 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, s));
3308 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solvable2str(pool, s));
3310 case SOLVER_ERASE_SOLVABLE:
3311 s = pool->solvables + what;
3312 if (solv->installed && s->repo == solv->installed)
3313 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solvable2str(pool, s));
3315 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, s));
3317 case SOLVER_INSTALL_SOLVABLE_NAME:
3318 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", dep2str(pool, what));
3320 case SOLVER_ERASE_SOLVABLE_NAME:
3321 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", dep2str(pool, what));
3323 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3324 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable providing %s\n", dep2str(pool, what));
3326 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3327 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables providing %s\n", dep2str(pool, what));
3329 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3330 s = pool->solvables + what;
3331 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solvable2str(pool, s));
3334 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
3340 /* policy, replace p with rp */
3341 s = pool->solvables + p;
3342 sd = rp ? pool->solvables + rp : 0;
3346 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
3348 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3351 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
3353 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3356 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
3359 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));
3361 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));
3365 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3369 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
3374 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3380 /* create reverse obsoletes map for installed solvables
3382 * for each installed solvable find which packages with *different* names
3383 * obsolete the solvable.
3384 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3388 create_obsolete_index(Solver *solv)
3390 Pool *pool = solv->pool;
3392 Repo *installed = solv->installed;
3393 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3396 if (!installed || !installed->nsolvables)
3398 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
3399 for (i = 1; i < pool->nsolvables; i++)
3401 s = pool->solvables + i;
3402 if (s->repo == installed)
3406 if (!pool_installable(pool, s))
3408 obsp = s->repo->idarraydata + s->obsoletes;
3409 while ((obs = *obsp++) != 0)
3410 FOR_PROVIDES(p, pp, obs)
3412 if (pool->solvables[p].repo != installed)
3414 if (pool->solvables[p].name == s->name)
3416 obsoletes[p - installed->start]++;
3420 for (i = 0; i < installed->nsolvables; i++)
3423 n += obsoletes[i] + 1;
3426 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
3427 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
3428 for (i = pool->nsolvables - 1; i > 0; i--)
3430 s = pool->solvables + i;
3431 if (s->repo == installed)
3435 if (!pool_installable(pool, s))
3437 obsp = s->repo->idarraydata + s->obsoletes;
3438 while ((obs = *obsp++) != 0)
3439 FOR_PROVIDES(p, pp, obs)
3441 if (pool->solvables[p].repo != installed)
3443 if (pool->solvables[p].name == s->name)
3445 p -= installed->start;
3446 if (obsoletes_data[obsoletes[p]] != i)
3447 obsoletes_data[--obsoletes[p]] = i;
3453 /*-----------------------------------------------------------------*/
3463 solver_solve(Solver *solv, Queue *job)
3465 Pool *pool = solv->pool;
3466 Repo *installed = solv->installed;
3469 Map addedmap; /* '1' == have rpm-rules for solvable */
3470 Id how, what, name, p, *pp, d;
3474 /* create whatprovides if not already there */
3475 if (!pool->whatprovides)
3476 pool_createwhatprovides(pool);
3478 /* create obsolete index if needed */
3479 if (solv->noupdateprovide)
3480 create_obsolete_index(solv);
3483 * create basic rule set of all involved packages
3484 * use addedmap bitmap to make sure we don't create rules twice
3488 map_init(&addedmap, pool->nsolvables);
3492 * always install our system solvable
3494 MAPSET(&addedmap, SYSTEMSOLVABLE);
3495 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3496 queue_push(&solv->decisionq_why, 0);
3497 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3500 * create rules for all package that could be involved with the solving
3501 * so called: rpm rules
3506 oldnrules = solv->nrules;
3507 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
3508 FOR_REPO_SOLVABLES(installed, p, s)
3509 addrpmrulesforsolvable(solv, s, &addedmap);
3510 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3511 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
3512 oldnrules = solv->nrules;
3513 FOR_REPO_SOLVABLES(installed, p, s)
3514 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3515 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3518 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
3519 oldnrules = solv->nrules;
3520 for (i = 0; i < job->count; i += 2)
3522 how = job->elements[i];
3523 what = job->elements[i + 1];
3527 case SOLVER_INSTALL_SOLVABLE:
3528 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3530 case SOLVER_INSTALL_SOLVABLE_NAME:
3531 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3532 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3533 while (ISRELDEP(name))
3535 Reldep *rd = GETRELDEP(pool, name);
3538 FOR_PROVIDES(p, pp, what)
3540 /* if by name, ensure that the name matches */
3541 if (name && pool->solvables[p].name != name)
3543 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3546 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3547 /* dont allow downgrade */
3548 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3552 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3554 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
3556 oldnrules = solv->nrules;
3557 addrpmrulesforweak(solv, &addedmap);
3558 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3560 IF_POOLDEBUG (SAT_DEBUG_STATS)
3562 int possible = 0, installable = 0;
3563 for (i = 1; i < pool->nsolvables; i++)
3565 if (pool_installable(pool, pool->solvables + i))
3567 if (MAPTST(&addedmap, i))
3570 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3574 * first pass done, we now have all the rpm rules we need.
3575 * unify existing rules before going over all job rules and
3577 * at this point the system is always solvable,
3578 * as an empty system (remove all packages) is a valid solution
3581 unifyrules(solv); /* remove duplicate rpm rules */
3582 solv->directdecisions = solv->decisionq.count;
3584 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
3585 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3586 printdecisions (solv);
3589 * now add all job rules
3592 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
3594 solv->jobrules = solv->nrules;
3596 for (i = 0; i < job->count; i += 2)
3598 oldnrules = solv->nrules;
3600 how = job->elements[i];
3601 what = job->elements[i + 1];
3604 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3605 s = pool->solvables + what;
3606 POOL_DEBUG(SAT_DEBUG_JOB, "job: install solvable %s\n", solvable2str(pool, s));
3607 addrule(solv, what, 0); /* install by Id */
3608 queue_push(&solv->ruletojob, i);
3610 case SOLVER_ERASE_SOLVABLE:
3611 s = pool->solvables + what;
3612 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase solvable %s\n", solvable2str(pool, s));
3613 addrule(solv, -what, 0); /* remove by Id */
3614 queue_push(&solv->ruletojob, i);
3616 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3617 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3618 if (how == SOLVER_INSTALL_SOLVABLE_NAME)
3619 POOL_DEBUG(SAT_DEBUG_JOB, "job: install name %s\n", dep2str(pool, what));
3620 if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3621 POOL_DEBUG(SAT_DEBUG_JOB, "job: install provides %s\n", dep2str(pool, what));
3623 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3624 while (ISRELDEP(name))
3626 Reldep *rd = GETRELDEP(pool, name);
3629 FOR_PROVIDES(p, pp, what)
3631 /* if by name, ensure that the name matches */
3632 if (name && pool->solvables[p].name != name)
3638 /* no provider, make this an impossible rule */
3639 queue_push(&q, -SYSTEMSOLVABLE);
3642 p = queue_shift(&q); /* get first provider */
3644 d = 0; /* single provider ? -> make assertion */
3646 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3647 addrule(solv, p, d); /* add 'requires' rule */
3648 queue_push(&solv->ruletojob, i);
3650 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3651 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3652 if (how == SOLVER_ERASE_SOLVABLE_NAME)
3653 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase name %s\n", dep2str(pool, what));
3654 if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3655 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase provides %s\n", dep2str(pool, what));
3656 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
3657 while (ISRELDEP(name))
3659 Reldep *rd = GETRELDEP(pool, name);
3662 FOR_PROVIDES(p, pp, what)
3664 /* if by name, ensure that the name matches */
3665 if (name && pool->solvables[p].name != name)
3667 addrule(solv, -p, 0); /* add 'remove' rule */
3668 queue_push(&solv->ruletojob, i);
3671 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3672 s = pool->solvables + what;
3673 POOL_DEBUG(SAT_DEBUG_JOB, "job: update %s\n", solvable2str(pool, s));
3674 addupdaterule(solv, s, 0);
3675 queue_push(&solv->ruletojob, i);
3678 IF_POOLDEBUG (SAT_DEBUG_JOB)
3681 if (solv->nrules == oldnrules)
3682 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created\n");
3683 for (j = oldnrules; j < solv->nrules; j++)
3685 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
3686 printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
3690 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3693 * now add system rules
3697 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add system rules ***\n");
3700 solv->systemrules = solv->nrules;
3703 * create rules for updating installed solvables
3707 if (installed && !solv->allowuninstall)
3708 { /* loop over all installed solvables */
3709 /* we create all update rules, but disable some later on depending on the job */
3710 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3712 /* no system rules for patch atoms */
3713 if (s->freshens && !s->supplements)
3715 const char *name = id2str(pool, s->name);
3716 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
3718 addrule(solv, 0, 0);
3722 if (s->repo == installed)
3723 addupdaterule(solv, s, 0); /* allowall = 0 */
3725 addrule(solv, 0, 0); /* create dummy rule */
3727 /* consistency check: we added a rule for _every_ system solvable */
3728 assert(solv->nrules - solv->systemrules == installed->end - installed->start);
3731 /* create special weak system rules */
3732 /* those are used later on to keep a version of the installed packages in
3734 if (installed && installed->nsolvables)
3736 solv->weaksystemrules = sat_calloc(installed->end - installed->start, sizeof(Id));
3737 FOR_REPO_SOLVABLES(installed, p, s)
3739 policy_findupdatepackages(solv, s, &q, 1);
3741 solv->weaksystemrules[p - installed->start] = pool_queuetowhatprovides(pool, &q);
3745 /* free unneeded memory */
3746 map_free(&addedmap);
3749 solv->weakrules = solv->nrules;
3751 /* try real hard to keep packages installed */
3754 FOR_REPO_SOLVABLES(installed, p, s)
3756 /* FIXME: can't work with refine_suggestion! */
3757 /* need to always add the rule but disable it */
3758 if (MAPTST(&solv->noupdate, p - installed->start))
3760 d = solv->weaksystemrules[p - installed->start];
3761 addrule(solv, p, d);
3765 /* all new rules are learnt after this point */
3766 solv->learntrules = solv->nrules;
3768 /* disable system rules that conflict with our job */
3769 disableupdaterules(solv, job, -1);
3771 /* make decisions based on job/system assertions */
3772 makeruledecisions(solv);
3774 /* create watches chains */
3777 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
3780 run_solver(solv, solv->dontinstallrecommended ? 0 : 1, 1);
3782 /* find recommended packages */
3783 if (!solv->problems.count && solv->dontinstallrecommended)
3785 Id rec, *recp, p, *pp;
3787 /* create map of all suggests that are still open */
3788 solv->recommends_index = -1;
3789 MAPZERO(&solv->recommendsmap);
3790 for (i = 0; i < solv->decisionq.count; i++)
3792 p = solv->decisionq.elements[i];
3795 s = pool->solvables + p;
3798 recp = s->repo->idarraydata + s->recommends;
3799 while ((rec = *recp++) != 0)
3801 FOR_PROVIDES(p, pp, rec)
3802 if (solv->decisionmap[p] > 0)
3805 continue; /* already fulfilled */
3806 FOR_PROVIDES(p, pp, rec)
3807 MAPSET(&solv->recommendsmap, p);
3811 for (i = 1; i < pool->nsolvables; i++)
3813 if (solv->decisionmap[i] != 0)
3815 s = pool->solvables + i;
3816 if (!MAPTST(&solv->recommendsmap, i))
3818 if (!s->supplements)
3820 if (!pool_installable(pool, s))
3822 if (!solver_is_supplementing(solv, s))
3825 queue_push(&solv->recommendations, i);
3827 /* we use MODE_SUGGEST here so that repo prio is ignored */
3828 policy_filter_unwanted(solv, &solv->recommendations, 0, POLICY_MODE_SUGGEST);
3831 /* find suggested packages */
3832 if (!solv->problems.count)
3834 Id sug, *sugp, p, *pp;
3836 /* create map of all suggests that are still open */
3837 solv->recommends_index = -1;
3838 MAPZERO(&solv->suggestsmap);
3839 for (i = 0; i < solv->decisionq.count; i++)
3841 p = solv->decisionq.elements[i];
3844 s = pool->solvables + p;
3847 sugp = s->repo->idarraydata + s->suggests;
3848 while ((sug = *sugp++) != 0)
3850 FOR_PROVIDES(p, pp, sug)
3851 if (solv->decisionmap[p] > 0)
3854 continue; /* already fulfilled */
3855 FOR_PROVIDES(p, pp, sug)
3856 MAPSET(&solv->suggestsmap, p);
3860 for (i = 1; i < pool->nsolvables; i++)
3862 if (solv->decisionmap[i] != 0)
3864 s = pool->solvables + i;
3865 if (!MAPTST(&solv->suggestsmap, i))
3869 if (!pool_installable(pool, s))
3871 if (!solver_is_enhancing(solv, s))
3874 queue_push(&solv->suggestions, i);
3876 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
3879 if (solv->problems.count)
3880 problems_to_solutions(solv, job);
3883 /***********************************************************************/
3886 solver_calc_changed_pkgs(Solver *solv, Queue *pkgs)
3888 Pool *pool = solv->pool;
3894 /* create list of solvables that have to be installed */
3895 /* (this is actually just a simple sort) */
3896 map_init(&installmap, pool->nsolvables);
3897 for (i = 1; i < solv->decisionq.count; i++)
3899 Id p = solv->decisionq.elements[i];
3902 s = pool->solvables + p;
3905 if (solv->installed && s->repo == solv->installed)
3907 MAPSET(&installmap, p);
3909 for (p = 1; p < pool->nsolvables; p++)
3910 if (MAPTST(&installmap, p))
3911 queue_push(pkgs, p);
3912 map_free(&installmap);
3913 /* run through erase solvable dudata */
3914 if (solv->installed)
3916 FOR_REPO_SOLVABLES(solv->installed, p, s)
3918 if (solv->decisionmap[p] < 0)
3919 queue_push(pkgs, -p);
3925 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
3929 solver_calc_changed_pkgs(solv, &pkgs);
3930 pool_calc_duchanges(solv->pool, &pkgs, mps, nmps);
3935 solver_calc_installsizechange(Solver *solv)
3940 solver_calc_changed_pkgs(solv, &pkgs);
3941 change = pool_calc_installsizechange(solv->pool, &pkgs);