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 /* ri >= learntrules cannot happen, as this would mean that the
636 * problem was not solvable, so we wouldn't have created the
637 * learnt rule at all */
638 assert(ri < solv->learntrules);
639 /* if we are weak, just disable ourself */
640 if (ri >= solv->weakrules)
642 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
643 printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
644 disablerule(solv, r);
648 /* only job and system rules left in the decisionq*/
649 /* find the decision which is the "opposite" of the jobrule */
650 for (i = 0; i < solv->decisionq.count; i++)
651 if (solv->decisionq.elements[i] == -v)
653 assert(i < solv->decisionq.count);
654 if (solv->decisionq_why.elements[i] == 0)
656 /* conflict with rpm rule, need only disable our rule */
657 assert(v > 0 || v == -SYSTEMSOLVABLE);
659 queue_push(&solv->problems, solv->learnt_pool.count);
660 queue_push(&solv->learnt_pool, ri);
661 queue_push(&solv->learnt_pool, v != -SYSTEMSOLVABLE ? -v : v);
662 queue_push(&solv->learnt_pool, 0);
663 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
664 if (ri < solv->systemrules)
665 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
668 queue_push(&solv->problems, v);
669 queue_push(&solv->problems, 0);
670 disableproblem(solv, v);
674 /* conflict with another job or system rule */
676 queue_push(&solv->problems, solv->learnt_pool.count);
677 queue_push(&solv->learnt_pool, ri);
678 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
679 queue_push(&solv->learnt_pool, 0);
681 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting system/job assertions over literal %d\n", vv);
682 /* push all of our rules asserting this literal on the problem stack */
683 for (i = solv->jobrules, rr = solv->rules + i; i < solv->nrules; i++, rr++)
685 if (!rr->w1 || rr->w2)
687 if (rr->p != vv && rr->p != -vv)
689 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
691 if (i < solv->systemrules)
692 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
693 queue_push(&solv->problems, v);
694 disableproblem(solv, v);
696 queue_push(&solv->problems, 0);
699 while (solv->decisionq.count > decisionstart)
701 v = solv->decisionq.elements[--solv->decisionq.count];
702 --solv->decisionq_why.count;
704 solv->decisionmap[vv] = 0;
706 ri = solv->jobrules - 1;
707 r = solv->rules + ri;
710 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
714 * we have enabled or disabled some of our rules. We now reenable all
715 * of our learnt rules but the ones that were learnt from rules that
719 enabledisablelearntrules(Solver *solv)
721 Pool *pool = solv->pool;
726 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
727 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
729 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
730 while ((why = *whyp++) != 0)
733 continue; /* rpm assertion */
735 if (!solv->rules[why].w1)
738 /* why != 0: we found a disabled rule, disable the learnt rule */
741 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
743 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling learnt ");
744 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
746 disablerule(solv, r);
748 else if (!why && !r->w1)
750 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
752 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling learnt ");
753 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
761 /* FIXME: bad code ahead, replace as soon as possible */
763 disableupdaterules(Solver *solv, Queue *job, int jobidx)
765 Pool *pool = solv->pool;
767 Id how, what, p, *pp;
773 installed = solv->installed;
779 how = job->elements[jobidx];
782 case SOLVER_INSTALL_SOLVABLE:
783 case SOLVER_ERASE_SOLVABLE:
784 case SOLVER_ERASE_SOLVABLE_NAME:
785 case SOLVER_ERASE_SOLVABLE_PROVIDES:
791 /* go through all enabled job rules */
792 MAPZERO(&solv->noupdate);
793 for (i = solv->jobrules; i < solv->systemrules; i++)
796 if (!r->w1) /* disabled? */
798 j = solv->ruletojob.elements[i - solv->jobrules];
802 how = job->elements[j];
803 what = job->elements[j + 1];
806 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
807 s = pool->solvables + what;
808 FOR_PROVIDES(p, pp, s->name)
810 if (pool->solvables[p].name != s->name)
812 if (pool->solvables[p].repo == installed)
813 MAPSET(&solv->noupdate, p - installed->start);
816 case SOLVER_ERASE_SOLVABLE:
817 s = pool->solvables + what;
818 if (s->repo == installed)
819 MAPSET(&solv->noupdate, what - installed->start);
821 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
822 case SOLVER_ERASE_SOLVABLE_PROVIDES:
823 FOR_PROVIDES(p, pp, what)
825 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
827 if (pool->solvables[p].repo == installed)
828 MAPSET(&solv->noupdate, p - installed->start);
836 /* fixup update rule status */
837 if (solv->allowuninstall)
838 return; /* no update rules at all */
842 /* we just disabled job #jobidx. enable all update rules
843 * that aren't disabled by the remaining job rules */
844 how = job->elements[jobidx];
845 what = job->elements[jobidx + 1];
848 case SOLVER_INSTALL_SOLVABLE:
849 s = pool->solvables + what;
850 FOR_PROVIDES(p, pp, s->name)
852 if (pool->solvables[p].name != s->name)
854 if (pool->solvables[p].repo != installed)
856 if (MAPTST(&solv->noupdate, p - installed->start))
858 r = solv->rules + solv->systemrules + (p - installed->start);
862 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
864 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
865 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
869 case SOLVER_ERASE_SOLVABLE:
870 s = pool->solvables + what;
871 if (s->repo != installed)
873 if (MAPTST(&solv->noupdate, what - installed->start))
875 r = solv->rules + solv->systemrules + (what - installed->start);
879 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
881 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
882 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
885 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
886 case SOLVER_ERASE_SOLVABLE_PROVIDES:
887 FOR_PROVIDES(p, pp, what)
889 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
891 if (pool->solvables[p].repo != installed)
893 if (MAPTST(&solv->noupdate, p - installed->start))
895 r = solv->rules + solv->systemrules + (p - installed->start);
899 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
901 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
902 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
912 for (i = 0; i < installed->nsolvables; i++)
914 r = solv->rules + solv->systemrules + i;
915 if (r->w1 && MAPTST(&solv->noupdate, i))
916 disablerule(solv, r); /* was enabled, need to disable */
922 addpatchatomrequires(Solver *solv, Solvable *s, Id *dp, Queue *q, Map *m)
924 Pool *pool = solv->pool;
925 Id fre, *frep, p, *pp, ndp;
931 queue_init_buffer(&fq, qbuf, sizeof(qbuf)/sizeof(*qbuf));
932 queue_push(&fq, -(s - pool->solvables));
934 queue_push(&fq, *dp);
935 ndp = pool_queuetowhatprovides(pool, &fq);
936 frep = s->repo->idarraydata + s->freshens;
937 while ((fre = *frep++) != 0)
939 FOR_PROVIDES(p, pp, fre)
941 ps = pool->solvables + p;
942 addrule(solv, -p, ndp);
950 for (i = 1; i < fq.count; i++)
962 * add (install) rules for solvable
963 * for unfulfilled requirements, conflicts, obsoletes,....
964 * add a negative assertion for solvables that are not installable
968 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
970 Pool *pool = solv->pool;
971 Repo *installed = solv->installed;
986 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
988 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
989 queue_push(&q, s - pool->solvables); /* push solvable Id */
995 * s: Pointer to solvable
999 if (MAPTST(m, n)) /* continue if already done */
1003 s = pool->solvables + n; /* s = Solvable in question */
1006 if (installed /* Installed system available */
1007 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
1008 && s->repo == installed) /* solvable is installed? */
1010 dontfix = 1; /* dont care about broken rpm deps */
1013 if (!dontfix && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
1015 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
1016 addrule(solv, -n, 0); /* uninstallable */
1020 if (s->freshens && !s->supplements)
1022 const char *name = id2str(pool, s->name);
1023 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
1027 /*-----------------------------------------
1028 * check requires of s
1033 reqp = s->repo->idarraydata + s->requires;
1034 while ((req = *reqp++) != 0) /* go throw all requires */
1036 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
1039 dp = pool_whatprovides(pool, req);
1041 if (*dp == SYSTEMSOLVABLE) /* always installed */
1047 addpatchatomrequires(solv, s, dp, &q, m);
1053 /* the strategy here is to not insist on dependencies
1054 * that are already broken. so if we find one provider
1055 * that was already installed, we know that the
1056 * dependency was not broken before so we enforce it */
1057 for (i = 0; (p = dp[i]) != 0; i++) /* for all providers */
1059 if (pool->solvables[p].repo == installed)
1060 break; /* provider was installed */
1062 if (!p) /* previously broken dependency */
1064 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1071 /* nothing provides req! */
1072 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1073 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1077 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1079 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1080 for (i = 0; dp[i]; i++)
1081 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1084 /* add 'requires' dependency */
1085 /* rule: (-requestor|provider1|provider2|...|providerN) */
1086 addrule(solv, -n, dp - pool->whatprovidesdata);
1088 /* descend the dependency tree */
1089 for (; *dp; dp++) /* loop through all providers */
1091 if (!MAPTST(m, *dp))
1092 queue_push(&q, *dp);
1095 } /* while, requirements of n */
1097 } /* if, requirements */
1099 /* that's all we check for src packages */
1100 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1103 /*-----------------------------------------
1104 * check conflicts of s
1109 conp = s->repo->idarraydata + s->conflicts;
1110 while ((con = *conp++) != 0)
1112 FOR_PROVIDES(p, pp, con)
1114 /* dontfix: dont care about conflicts with already installed packs */
1115 if (dontfix && pool->solvables[p].repo == installed)
1117 /* rule: -n|-p: either solvable _or_ provider of conflict */
1118 addrule(solv, -n, -p);
1123 /*-----------------------------------------
1124 * check obsoletes if not installed
1126 if (!installed || pool->solvables[n].repo != installed)
1127 { /* not installed */
1130 obsp = s->repo->idarraydata + s->obsoletes;
1131 while ((obs = *obsp++) != 0)
1133 FOR_PROVIDES(p, pp, obs)
1134 addrule(solv, -n, -p);
1137 FOR_PROVIDES(p, pp, s->name)
1139 if (s->name == pool->solvables[p].name)
1140 addrule(solv, -n, -p);
1144 /*-----------------------------------------
1145 * add recommends to the rule list
1149 recp = s->repo->idarraydata + s->recommends;
1150 while ((rec = *recp++) != 0)
1152 FOR_PROVIDES(p, pp, rec)
1159 sugp = s->repo->idarraydata + s->suggests;
1160 while ((sug = *sugp++) != 0)
1162 FOR_PROVIDES(p, pp, sug)
1169 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1173 addrpmrulesforweak(Solver *solv, Map *m)
1175 Pool *pool = solv->pool;
1180 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1181 for (i = n = 1; n < pool->nsolvables; i++, n++)
1183 if (i == pool->nsolvables)
1187 s = pool->solvables + i;
1188 if (!pool_installable(pool, s))
1193 supp = s->repo->idarraydata + s->supplements;
1194 while ((sup = *supp++) != ID_NULL)
1195 if (dep_possible(solv, sup, m))
1198 if (!sup && s->freshens)
1200 supp = s->repo->idarraydata + s->freshens;
1201 while ((sup = *supp++) != ID_NULL)
1202 if (dep_possible(solv, sup, m))
1205 if (!sup && s->enhances)
1207 supp = s->repo->idarraydata + s->enhances;
1208 while ((sup = *supp++) != ID_NULL)
1209 if (dep_possible(solv, sup, m))
1214 addrpmrulesforsolvable(solv, s, m);
1217 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1221 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
1223 Pool *pool = solv->pool;
1228 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1230 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1231 policy_findupdatepackages(solv, s, &qs, allowall);
1232 if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
1233 addrpmrulesforsolvable(solv, s, m);
1234 for (i = 0; i < qs.count; i++)
1235 if (!MAPTST(m, qs.elements[i]))
1236 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1239 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1243 * add rule for update
1244 * (A|A1|A2|A3...) An = update candidates for A
1246 * s = (installed) solvable
1250 addupdaterule(Solver *solv, Solvable *s, int allowall)
1252 /* installed packages get a special upgrade allowed rule */
1253 Pool *pool = solv->pool;
1258 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1260 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1261 policy_findupdatepackages(solv, s, &qs, allowall);
1262 if (qs.count == 0) /* no updaters found */
1265 d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
1267 addrule(solv, s - pool->solvables, d); /* allow update of s */
1268 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1272 /*-----------------------------------------------------------------*/
1281 printWatches(Solver *solv, int type)
1283 Pool *pool = solv->pool;
1286 POOL_DEBUG(type, "Watches: \n");
1288 for (counter = -(pool->nsolvables); counter <= pool->nsolvables; counter ++)
1290 POOL_DEBUG(type, " solvable [%d] -- rule [%d]\n", counter, solv->watches[counter+pool->nsolvables]);
1297 * initial setup for all watches
1301 makewatches(Solver *solv)
1305 int nsolvables = solv->pool->nsolvables;
1307 sat_free(solv->watches);
1308 /* lower half for removals, upper half for installs */
1309 solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
1311 /* do it reverse so rpm rules get triggered first */
1312 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1314 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1317 if (!r->w1 /* rule is disabled */
1318 || !r->w2) /* rule is assertion */
1321 /* see addwatches(solv, r) */
1322 r->n1 = solv->watches[nsolvables + r->w1];
1323 solv->watches[nsolvables + r->w1] = r - solv->rules;
1325 r->n2 = solv->watches[nsolvables + r->w2];
1326 solv->watches[nsolvables + r->w2] = r - solv->rules;
1332 * add watches (for rule)
1336 addwatches(Solver *solv, Rule *r)
1338 int nsolvables = solv->pool->nsolvables;
1340 r->n1 = solv->watches[nsolvables + r->w1];
1341 solv->watches[nsolvables + r->w1] = r - solv->rules;
1343 r->n2 = solv->watches[nsolvables + r->w2];
1344 solv->watches[nsolvables + r->w2] = r - solv->rules;
1348 /*-----------------------------------------------------------------*/
1349 /* rule propagation */
1351 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1356 * propagate decision to all rules
1357 * return : 0 = everything is OK
1358 * watched rule = there is a conflict
1362 propagate(Solver *solv, int level)
1364 Pool *pool = solv->pool;
1369 Id *decisionmap = solv->decisionmap;
1370 Id *watches = solv->watches + pool->nsolvables;
1372 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1374 while (solv->propagate_index < solv->decisionq.count)
1376 /* negate because our watches trigger if literal goes FALSE */
1377 pkg = -solv->decisionq.elements[solv->propagate_index++];
1378 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1380 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "popagate for decision %d level %d\n", -pkg, level);
1381 printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1383 printWatches(solv, SAT_DEBUG_SCHUBI);
1386 for (rp = watches + pkg; *rp; rp = nrp)
1388 r = solv->rules + *rp;
1390 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1392 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1393 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1398 ow = r->w2; /* regard the second watchpoint to come to a solution */
1403 ow = r->w1; /* regard the first watchpoint to come to a solution */
1406 /* if clause is TRUE, nothing to do */
1407 if (DECISIONMAP_TRUE(ow))
1412 /* not a binary clause, check if we need to move our watch */
1413 /* search for a literal that is not ow and not false */
1414 /* (true is also ok, in that case the rule is fulfilled) */
1415 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1418 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1419 if (p != ow && !DECISIONMAP_TRUE(-p))
1423 /* p is free to watch, move watch to p */
1424 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1427 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1429 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1443 watches[p] = r - solv->rules;
1447 /* unit clause found, set other watch to TRUE */
1448 if (DECISIONMAP_TRUE(-ow))
1449 return r; /* eek, a conflict! */
1450 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1452 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
1453 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1456 decisionmap[ow] = level;
1458 decisionmap[-ow] = -level;
1459 queue_push(&solv->decisionq, ow);
1460 queue_push(&solv->decisionq_why, r - solv->rules);
1461 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1463 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1465 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
1467 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
1471 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
1473 return 0; /* all is well */
1477 /*-----------------------------------------------------------------*/
1486 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
1488 Pool *pool = solv->pool;
1491 Map seen; /* global? */
1494 int num = 0, l1num = 0;
1495 int learnt_why = solv->learnt_pool.count;
1496 Id *decisionmap = solv->decisionmap;
1500 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
1501 map_init(&seen, pool->nsolvables);
1502 idx = solv->decisionq.count;
1505 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1506 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1507 queue_push(&solv->learnt_pool, c - solv->rules);
1508 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1509 /* go through all literals of the rule */
1521 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1523 vv = v > 0 ? v : -v;
1524 if (MAPTST(&seen, vv))
1526 l = solv->decisionmap[vv];
1531 /* a level 1 literal, mark it for later */
1532 MAPSET(&seen, vv); /* mark for scanning in level 1 phase */
1538 num++; /* need to do this one as well */
1549 v = solv->decisionq.elements[--idx];
1550 vv = v > 0 ? v : -v;
1551 if (MAPTST(&seen, vv))
1554 c = solv->rules + solv->decisionq_why.elements[idx];
1559 *pr = -v; /* so that v doesn't get lost */
1561 /* add involved level 1 rules */
1564 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1568 v = solv->decisionq.elements[--idx];
1569 vv = v > 0 ? v : -v;
1570 if (!MAPTST(&seen, vv))
1572 why = solv->decisionq_why.elements[idx];
1575 queue_push(&solv->learnt_pool, -vv);
1576 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1578 POOL_DEBUG(SAT_DEBUG_ANALYZE, "RPM ASSERT Rule:\n");
1579 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, v);
1583 queue_push(&solv->learnt_pool, why);
1584 c = solv->rules + why;
1585 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1586 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1587 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1598 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1600 vv = v > 0 ? v : -v;
1601 l = solv->decisionmap[vv];
1602 if (l != 1 && l != -1)
1612 else if (r.count == 1 && r.elements[0] < 0)
1613 *dr = r.elements[0];
1615 *dr = pool_queuetowhatprovides(pool, &r);
1616 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1618 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1619 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
1620 for (i = 0; i < r.count; i++)
1621 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
1623 /* push end marker on learnt reasons stack */
1624 queue_push(&solv->learnt_pool, 0);
1633 * reset the solver decisions to right after the rpm rules.
1634 * called after rules have been enabled/disabled
1638 reset_solver(Solver *solv)
1640 Pool *pool = solv->pool;
1644 /* rewind decisions to direct rpm rule assertions */
1645 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
1647 v = solv->decisionq.elements[i];
1648 solv->decisionmap[v > 0 ? v : -v] = 0;
1651 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
1653 solv->decisionq_why.count = solv->directdecisions;
1654 solv->decisionq.count = solv->directdecisions;
1655 solv->recommends_index = -1;
1656 solv->propagate_index = 0;
1658 /* adapt learnt rule status to new set of enabled/disabled rules */
1659 enabledisablelearntrules(solv);
1661 /* redo all job/system decisions */
1662 makeruledecisions(solv);
1663 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
1665 /* recreate watch chains */
1671 * analyze_unsolvable_rule
1675 analyze_unsolvable_rule(Solver *solv, Rule *r)
1677 Pool *pool = solv->pool;
1679 Id why = r - solv->rules;
1680 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1681 printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1682 if (solv->learntrules && why >= solv->learntrules)
1684 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1685 if (solv->learnt_pool.elements[i] > 0)
1686 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i]);
1689 /* do not add rpm rules to problem */
1690 if (why < solv->jobrules)
1692 /* turn rule into problem */
1693 if (why >= solv->jobrules && why < solv->systemrules)
1694 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1695 /* return if problem already countains our rule */
1696 if (solv->problems.count)
1698 for (i = solv->problems.count - 1; i >= 0; i--)
1699 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1701 else if (solv->problems.elements[i] == why)
1704 queue_push(&solv->problems, why);
1709 * analyze_unsolvable
1711 * return: 1 - disabled some rules, try again
1716 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1718 Pool *pool = solv->pool;
1720 Map seen; /* global to speed things up? */
1723 Id *decisionmap = solv->decisionmap;
1724 int oldproblemcount;
1725 int oldlearntpoolcount;
1728 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1729 oldproblemcount = solv->problems.count;
1730 oldlearntpoolcount = solv->learnt_pool.count;
1732 /* make room for proof index */
1733 /* must update it later, as analyze_unsolvable_rule would confuse
1734 * it with a rule index if we put the real value in already */
1735 queue_push(&solv->problems, 0);
1738 map_init(&seen, pool->nsolvables);
1739 queue_push(&solv->learnt_pool, r - solv->rules);
1740 analyze_unsolvable_rule(solv, r);
1741 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1752 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1754 vv = v > 0 ? v : -v;
1755 l = solv->decisionmap[vv];
1760 idx = solv->decisionq.count;
1763 v = solv->decisionq.elements[--idx];
1764 vv = v > 0 ? v : -v;
1765 if (!MAPTST(&seen, vv))
1767 why = solv->decisionq_why.elements[idx];
1770 /* level 1 and no why, must be an rpm assertion */
1771 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1773 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "RPM ");
1774 printruleelement(solv, SAT_DEBUG_UNSOLVABLE, 0, v);
1776 /* this is the only positive rpm assertion */
1777 if (v == SYSTEMSOLVABLE)
1780 queue_push(&solv->learnt_pool, v);
1783 queue_push(&solv->learnt_pool, why);
1784 r = solv->rules + why;
1785 analyze_unsolvable_rule(solv, r);
1786 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1797 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1799 vv = v > 0 ? v : -v;
1800 l = solv->decisionmap[vv];
1807 queue_push(&solv->problems, 0); /* mark end of this problem */
1810 if (solv->weakrules != solv->learntrules)
1812 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1814 why = solv->problems.elements[i];
1815 if (why < solv->weakrules || why >= solv->learntrules)
1817 if (!lastweak || lastweak < why)
1823 /* disable last weak rule */
1824 solv->problems.count = oldproblemcount;
1825 solv->learnt_pool.count = oldlearntpoolcount;
1826 r = solv->rules + lastweak;
1827 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling weak ");
1828 printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
1829 disablerule(solv, r);
1835 queue_push(&solv->learnt_pool, 0);
1836 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1840 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1841 disableproblem(solv, solv->problems.elements[i]);
1845 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1850 /*-----------------------------------------------------------------*/
1851 /* Decision revert */
1855 * revert decision at level
1859 revert(Solver *solv, int level)
1861 Pool *pool = solv->pool;
1863 while (solv->decisionq.count)
1865 v = solv->decisionq.elements[solv->decisionq.count - 1];
1866 vv = v > 0 ? v : -v;
1867 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1869 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1870 solv->decisionmap[vv] = 0;
1871 solv->decisionq.count--;
1872 solv->decisionq_why.count--;
1873 solv->propagate_index = solv->decisionq.count;
1875 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1877 solv->branches.count--;
1878 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1879 solv->branches.count--;
1881 solv->recommends_index = -1;
1886 * watch2onhighest - put watch2 on literal with highest level
1890 watch2onhighest(Solver *solv, Rule *r)
1896 return; /* binary rule, both watches are set */
1897 dp = solv->pool->whatprovidesdata + r->d;
1898 while ((v = *dp++) != 0)
1900 l = solv->decisionmap[v < 0 ? -v : v];
1915 * add free decision to decisionq, increase level and
1916 * propagate decision, return if no conflict.
1917 * in conflict case, analyze conflict rule, add resulting
1918 * rule to learnt rule set, make decision from learnt
1919 * rule (always unit) and re-propagate.
1921 * returns the new solver level or 0 if unsolvable
1926 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1928 Pool *pool = solv->pool;
1937 solv->decisionmap[decision] = level;
1939 solv->decisionmap[-decision] = -level;
1940 queue_push(&solv->decisionq, decision);
1941 queue_push(&solv->decisionq_why, 0);
1945 r = propagate(solv, level);
1949 return analyze_unsolvable(solv, r, disablerules);
1950 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1951 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1952 assert(l > 0 && l < level);
1953 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
1955 revert(solv, level);
1956 r = addrule(solv, p, d); /* p requires d */
1958 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1959 queue_push(&solv->learnt_why, why);
1962 /* at least 2 literals, needs watches */
1963 watch2onhighest(solv, r);
1964 addwatches(solv, r);
1966 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1967 queue_push(&solv->decisionq, p);
1968 queue_push(&solv->decisionq_why, r - solv->rules);
1969 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1971 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
1972 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
1973 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
1974 printrule(solv, SAT_DEBUG_ANALYZE, r);
1982 * install best package from the queue. We add an extra package, inst, if
1983 * provided. See comment in weak install section.
1985 * returns the new solver level or 0 if unsolvable
1989 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
1991 Pool *pool = solv->pool;
1995 if (dq->count > 1 || inst)
1996 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
2001 /* choose the supplemented one */
2002 for (i = 0; i < dq->count; i++)
2003 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
2007 for (i = 1; i < dq->count; i++)
2008 queue_push(&solv->branches, dq->elements[i]);
2009 queue_push(&solv->branches, -level);
2013 p = dq->elements[i];
2015 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
2017 return setpropagatelearn(solv, level, p, disablerules);
2021 /*-----------------------------------------------------------------*/
2022 /* Main solver interface */
2027 * create solver structure
2029 * pool: all available solvables
2030 * installed: installed Solvables
2033 * Upon solving, rules are created to flag the Solvables
2034 * of the 'installed' Repo as installed.
2038 solver_create(Pool *pool, Repo *installed)
2041 solv = (Solver *)sat_calloc(1, sizeof(Solver));
2043 solv->installed = installed;
2045 queue_init(&solv->ruletojob);
2046 queue_init(&solv->decisionq);
2047 queue_init(&solv->decisionq_why);
2048 queue_init(&solv->problems);
2049 queue_init(&solv->suggestions);
2050 queue_init(&solv->learnt_why);
2051 queue_init(&solv->learnt_pool);
2052 queue_init(&solv->branches);
2053 queue_init(&solv->covenantq);
2055 map_init(&solv->recommendsmap, pool->nsolvables);
2056 map_init(&solv->suggestsmap, pool->nsolvables);
2057 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
2058 solv->recommends_index = 0;
2060 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2062 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
2063 memset(solv->rules, 0, sizeof(Rule));
2074 solver_free(Solver *solv)
2076 queue_free(&solv->ruletojob);
2077 queue_free(&solv->decisionq);
2078 queue_free(&solv->decisionq_why);
2079 queue_free(&solv->learnt_why);
2080 queue_free(&solv->learnt_pool);
2081 queue_free(&solv->problems);
2082 queue_free(&solv->suggestions);
2083 queue_free(&solv->branches);
2084 queue_free(&solv->covenantq);
2086 map_free(&solv->recommendsmap);
2087 map_free(&solv->suggestsmap);
2088 map_free(&solv->noupdate);
2090 sat_free(solv->decisionmap);
2091 sat_free(solv->rules);
2092 sat_free(solv->watches);
2093 sat_free(solv->weaksystemrules);
2094 sat_free(solv->obsoletes);
2095 sat_free(solv->obsoletes_data);
2100 /*-------------------------------------------------------*/
2105 * all rules have been set up, now actually run the solver
2110 run_solver(Solver *solv, int disablerules, int doweak)
2118 Pool *pool = solv->pool;
2121 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2123 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2124 for (i = 0; i < solv->nrules; i++)
2125 printrule(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2128 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2130 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2131 printdecisions(solv);
2133 /* start SAT algorithm */
2135 systemlevel = level + 1;
2136 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2147 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2148 if ((r = propagate(solv, level)) != 0)
2150 if (analyze_unsolvable(solv, r, disablerules))
2158 * installed packages
2161 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2163 if (!solv->updatesystem)
2165 /* try to keep as many packages as possible */
2166 POOL_DEBUG(SAT_DEBUG_STATS, "installing system packages\n");
2167 for (i = solv->installed->start, n = 0; ; i++)
2169 if (n == solv->installed->nsolvables)
2171 if (i == solv->installed->end)
2172 i = solv->installed->start;
2173 s = pool->solvables + i;
2174 if (s->repo != solv->installed)
2177 if (solv->decisionmap[i] != 0)
2179 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2181 level = setpropagatelearn(solv, level, i, disablerules);
2187 if (level <= olevel)
2191 if (solv->weaksystemrules)
2193 POOL_DEBUG(SAT_DEBUG_STATS, "installing weak system packages\n");
2194 for (i = solv->installed->start; i < solv->installed->end; i++)
2196 if (pool->solvables[i].repo != solv->installed)
2198 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
2200 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2201 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2204 if (solv->weaksystemrules[i - solv->installed->start])
2206 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
2207 while ((p = *dp++) != 0)
2209 if (solv->decisionmap[p] > 0)
2211 if (solv->decisionmap[p] == 0)
2215 continue; /* update package already installed */
2217 if (!dq.count && solv->decisionmap[i] != 0)
2220 /* FIXME: i is handled a bit different because we do not want
2221 * to have it pruned just because it is not recommened.
2222 * we should not prune installed packages instead */
2223 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2229 if (level <= olevel)
2232 if (i < solv->installed->end)
2235 systemlevel = level;
2242 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unresolved rules\n");
2243 for (i = 1, n = 1; ; i++, n++)
2245 if (n == solv->nrules)
2247 if (i == solv->nrules)
2249 r = solv->rules + i;
2250 if (!r->w1) /* ignore disabled rules */
2255 /* binary or unary rule */
2256 /* need two positive undecided literals */
2257 if (r->p < 0 || r->w2 <= 0)
2259 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2261 queue_push(&dq, r->p);
2262 queue_push(&dq, r->w2);
2267 * all negative literals are installed
2268 * no positive literal is installed
2269 * i.e. the rule is not fulfilled and we
2270 * just need to decide on the positive literals
2274 if (solv->decisionmap[-r->p] <= 0)
2279 if (solv->decisionmap[r->p] > 0)
2281 if (solv->decisionmap[r->p] == 0)
2282 queue_push(&dq, r->p);
2284 dp = pool->whatprovidesdata + r->d;
2285 while ((p = *dp++) != 0)
2289 if (solv->decisionmap[-p] <= 0)
2294 if (solv->decisionmap[p] > 0)
2296 if (solv->decisionmap[p] == 0)
2303 /* dq.count < 2 cannot happen as this means that
2304 * the rule is unit */
2305 assert(dq.count > 1);
2306 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2308 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2309 printrule(solv, SAT_DEBUG_PROPAGATE, r);
2313 level = selectandinstall(solv, level, &dq, 0, disablerules);
2319 if (level < systemlevel)
2322 } /* for(), decide */
2324 if (n != solv->nrules) /* continue if level < systemlevel */
2327 if (doweak && !solv->problems.count)
2331 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
2332 if (!solv->dosplitprovides && !REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2334 for (i = 1; i < solv->decisionq.count; i++)
2336 p = solv->decisionq.elements[i];
2337 if (p > 0 && pool->solvables[p].repo == solv->installed)
2338 solv->decisionmap[p] = -solv->decisionmap[p];
2342 for (i = 1; i < pool->nsolvables; i++)
2344 if (solv->decisionmap[i] < 0)
2346 if (solv->decisionmap[i] > 0)
2348 Id *recp, rec, *pp, p;
2349 s = pool->solvables + i;
2350 /* installed, check for recommends */
2351 /* XXX need to special case AND ? */
2354 recp = s->repo->idarraydata + s->recommends;
2355 while ((rec = *recp++) != 0)
2358 FOR_PROVIDES(p, pp, rec)
2360 if (solv->decisionmap[p] > 0)
2365 else if (solv->decisionmap[p] == 0)
2367 queue_pushunique(&dq, p);
2375 s = pool->solvables + i;
2376 if (!s->supplements && !s->freshens)
2378 if (!pool_installable(pool, s))
2380 if (solver_is_supplementing(solv, s))
2381 queue_pushunique(&dq, i);
2384 if (!solv->dosplitprovides && !REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2386 for (i = 1; i < solv->decisionq.count; i++)
2388 p = solv->decisionq.elements[i];
2389 if (p > 0 && pool->solvables[p].repo == solv->installed)
2390 solv->decisionmap[p] = -solv->decisionmap[p];
2396 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2398 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2399 level = setpropagatelearn(solv, level, p, 0);
2404 if (solv->solution_callback)
2406 solv->solution_callback(solv, solv->solution_callback_data);
2407 if (solv->branches.count)
2409 int i = solv->branches.count - 1;
2410 int l = -solv->branches.elements[i];
2412 if (solv->branches.elements[i - 1] < 0)
2414 p = solv->branches.elements[i];
2415 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
2417 for (j = i + 1; j < solv->branches.count; j++)
2418 queue_push(&dq, solv->branches.elements[j]);
2419 solv->branches.count = i;
2421 revert(solv, level);
2423 for (j = 0; j < dq.count; j++)
2424 queue_push(&solv->branches, dq.elements[j]);
2426 level = setpropagatelearn(solv, level, p, disablerules);
2434 /* all branches done, we're finally finished */
2438 /* minimization step */
2439 if (solv->branches.count)
2441 int l = 0, lasti = -1, lastl = -1;
2443 for (i = solv->branches.count - 1; i >= 0; i--)
2445 p = solv->branches.elements[i];
2448 else if (p > 0 && solv->decisionmap[p] > l + 1)
2456 /* kill old solvable so that we do not loop */
2457 p = solv->branches.elements[lasti];
2458 solv->branches.elements[lasti] = 0;
2459 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
2462 revert(solv, level);
2464 level = setpropagatelearn(solv, level, p, disablerules);
2481 * at this point, all rules that led to conflicts are disabled.
2482 * we re-enable all rules of a problem set but rule "sug", then
2483 * continue to disable more rules until there as again a solution.
2486 /* FIXME: think about conflicting assertions */
2489 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2491 Pool *pool = solv->pool;
2498 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2500 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
2501 for (i = 0; problem[i]; i++)
2503 if (problem[i] == sug)
2504 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
2505 printproblem(solv, problem[i]);
2508 queue_init(&disabled);
2509 queue_empty(refined);
2510 queue_push(refined, sug);
2512 /* re-enable all problem rules with the exception of "sug" */
2516 for (i = 0; problem[i]; i++)
2517 if (problem[i] != sug)
2518 enableproblem(solv, problem[i]);
2521 disableupdaterules(solv, job, -(sug + 1));
2525 /* re-enable as many weak rules as possible */
2526 for (i = solv->weakrules; i < solv->learntrules; i++)
2528 r = solv->rules + i;
2530 enablerule(solv, r);
2533 queue_empty(&solv->problems);
2534 revert(solv, 1); /* XXX move to reset_solver? */
2537 if (!solv->problems.count)
2538 run_solver(solv, 0, 0);
2540 if (!solv->problems.count)
2542 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
2543 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2544 printdecisions(solv);
2545 break; /* great, no more problems */
2547 disabledcnt = disabled.count;
2548 /* start with 1 to skip over proof index */
2549 for (i = 1; i < solv->problems.count - 1; i++)
2551 /* ignore solutions in refined */
2552 v = solv->problems.elements[i];
2554 break; /* end of problem reached */
2555 for (j = 0; problem[j]; j++)
2556 if (problem[j] != sug && problem[j] == v)
2560 queue_push(&disabled, v);
2562 if (disabled.count == disabledcnt)
2564 /* no solution found, this was an invalid suggestion! */
2565 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
2569 if (disabled.count == disabledcnt + 1)
2571 /* just one suggestion, add it to refined list */
2572 v = disabled.elements[disabledcnt];
2573 queue_push(refined, v);
2574 disableproblem(solv, v);
2576 disableupdaterules(solv, job, -(v + 1));
2580 /* more than one solution, disable all */
2581 /* do not push anything on refine list */
2582 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2584 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
2585 for (i = disabledcnt; i < disabled.count; i++)
2586 printproblem(solv, disabled.elements[i]);
2588 for (i = disabledcnt; i < disabled.count; i++)
2589 disableproblem(solv, disabled.elements[i]);
2592 /* all done, get us back into the same state as before */
2593 /* enable refined rules again */
2594 for (i = 0; i < disabled.count; i++)
2595 enableproblem(solv, disabled.elements[i]);
2596 /* disable problem rules again */
2597 for (i = 0; problem[i]; i++)
2598 disableproblem(solv, problem[i]);
2599 disableupdaterules(solv, job, -1);
2600 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
2604 problems_to_solutions(Solver *solv, Queue *job)
2606 Pool *pool = solv->pool;
2614 if (!solv->problems.count)
2616 queue_clone(&problems, &solv->problems);
2617 queue_init(&solution);
2618 queue_init(&solutions);
2619 /* copy over proof index */
2620 queue_push(&solutions, problems.elements[0]);
2621 problem = problems.elements + 1;
2622 for (i = 1; i < problems.count; i++)
2624 Id v = problems.elements[i];
2627 /* mark end of this problem */
2628 queue_push(&solutions, 0);
2629 queue_push(&solutions, 0);
2630 if (i + 1 == problems.count)
2632 /* copy over proof of next problem */
2633 queue_push(&solutions, problems.elements[i + 1]);
2635 problem = problems.elements + i + 1;
2638 refine_suggestion(solv, job, problem, v, &solution);
2639 if (!solution.count)
2640 continue; /* this solution didn't work out */
2642 for (j = 0; j < solution.count; j++)
2644 why = solution.elements[j];
2645 /* must be either job descriptor or system rule */
2646 assert(why < 0 || (why >= solv->systemrules && why < solv->weakrules));
2648 printproblem(solv, why);
2652 /* job descriptor */
2653 queue_push(&solutions, 0);
2654 queue_push(&solutions, -why);
2658 /* system rule, find replacement package */
2660 p = solv->installed->start + (why - solv->systemrules);
2661 if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
2663 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
2666 if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
2668 if (solv->decisionmap[*dp] > 0)
2675 queue_push(&solutions, p);
2676 queue_push(&solutions, rp);
2679 /* mark end of this solution */
2680 queue_push(&solutions, 0);
2681 queue_push(&solutions, 0);
2683 queue_free(&solution);
2684 queue_free(&problems);
2685 /* copy queue over to solutions */
2686 queue_free(&solv->problems);
2687 queue_clone(&solv->problems, &solutions);
2689 /* bring solver back into problem state */
2690 revert(solv, 1); /* XXX move to reset_solver? */
2693 assert(solv->problems.count == solutions.count);
2694 queue_free(&solutions);
2698 solver_next_problem(Solver *solv, Id problem)
2702 return solv->problems.count ? 1 : 0;
2703 pp = solv->problems.elements + problem;
2704 while (pp[0] || pp[1])
2708 while (pp[0] || pp[1])
2713 problem = pp - solv->problems.elements;
2714 if (problem >= solv->problems.count)
2720 solver_next_solution(Solver *solv, Id problem, Id solution)
2726 pp = solv->problems.elements + solution;
2727 return pp[0] || pp[1] ? solution : 0;
2729 pp = solv->problems.elements + solution;
2730 while (pp[0] || pp[1])
2733 solution = pp - solv->problems.elements;
2734 return pp[0] || pp[1] ? solution : 0;
2738 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
2741 element = element ? element + 2 : solution;
2742 pp = solv->problems.elements + element;
2743 if (!(pp[0] || pp[1]))
2752 * create obsoletesmap from solver decisions
2753 * required for decision handling
2757 create_decisions_obsoletesmap(Solver *solv)
2759 Pool *pool = solv->pool;
2760 Repo *installed = solv->installed;
2761 Id p, *obsoletesmap = NULL;
2765 obsoletesmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2768 for (i = 0; i < solv->decisionq.count; i++)
2772 n = solv->decisionq.elements[i];
2775 if (n == SYSTEMSOLVABLE)
2777 s = pool->solvables + n;
2778 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2780 FOR_PROVIDES(p, pp, s->name)
2781 if (s->name == pool->solvables[p].name)
2783 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2785 obsoletesmap[p] = n;
2790 for (i = 0; i < solv->decisionq.count; i++)
2795 n = solv->decisionq.elements[i];
2798 if (n == SYSTEMSOLVABLE)
2800 s = pool->solvables + n;
2801 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2805 obsp = s->repo->idarraydata + s->obsoletes;
2806 while ((obs = *obsp++) != 0)
2807 FOR_PROVIDES(p, pp, obs)
2809 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2811 obsoletesmap[p] = n;
2817 return obsoletesmap;
2826 printdecisions(Solver *solv)
2828 Pool *pool = solv->pool;
2829 Repo *installed = solv->installed;
2830 Id p, *obsoletesmap = create_decisions_obsoletesmap( solv );
2834 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
2836 /* print solvables to be erased */
2840 FOR_REPO_SOLVABLES(installed, p, s)
2842 if (solv->decisionmap[p] >= 0)
2844 if (obsoletesmap[p])
2846 POOL_DEBUG(SAT_DEBUG_RESULT, "erase %s\n", solvable2str(pool, s));
2850 /* print solvables to be installed */
2852 for (i = 0; i < solv->decisionq.count; i++)
2855 p = solv->decisionq.elements[i];
2858 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2861 s = pool->solvables + p;
2862 POOL_DEBUG(SAT_DEBUG_SCHUBI, "level of %s is %d\n", solvable2str(pool, s), p);
2866 if (p == SYSTEMSOLVABLE)
2868 POOL_DEBUG(SAT_DEBUG_SCHUBI, "SYSTEMSOLVABLE\n");
2871 s = pool->solvables + p;
2872 if (installed && s->repo == installed)
2875 if (!obsoletesmap[p])
2877 POOL_DEBUG(SAT_DEBUG_RESULT, "install %s", solvable2str(pool, s));
2881 POOL_DEBUG(SAT_DEBUG_RESULT, "update %s", solvable2str(pool, s));
2882 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
2883 for (j = installed->start; j < installed->end; j++)
2884 if (obsoletesmap[j] == p)
2885 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
2886 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
2888 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
2891 sat_free(obsoletesmap);
2893 if (solv->suggestions.count)
2895 POOL_DEBUG(SAT_DEBUG_RESULT, "\nsuggested packages:\n");
2896 for (i = 0; i < solv->suggestions.count; i++)
2898 s = pool->solvables + solv->suggestions.elements[i];
2899 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
2902 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
2905 /* this is basically the reverse of addrpmrulesforsolvable */
2907 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
2909 Pool *pool = solv->pool;
2910 Repo *installed = solv->installed;
2914 Id p, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
2916 assert(rid < solv->weakrules);
2917 if (rid >= solv->systemrules)
2920 *sourcep = solv->installed->start + (rid - solv->systemrules);
2922 return SOLVER_PROBLEM_UPDATE_RULE;
2924 if (rid >= solv->jobrules)
2927 r = solv->rules + rid;
2928 p = solv->ruletojob.elements[rid - solv->jobrules];
2929 *depp = job->elements[p + 1];
2931 *targetp = job->elements[p];
2932 if (r->d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE)
2933 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
2934 return SOLVER_PROBLEM_JOB_RULE;
2938 /* a rpm rule assertion */
2939 assert(rid != -SYSTEMSOLVABLE);
2940 s = pool->solvables - rid;
2941 if (installed && !solv->fixsystem && s->repo == installed)
2943 assert(!dontfix); /* dontfix packages never have a neg assertion */
2944 /* see why the package is not installable */
2945 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
2946 return SOLVER_PROBLEM_NOT_INSTALLABLE;
2947 /* check requires */
2948 assert(s->requires);
2949 reqp = s->repo->idarraydata + s->requires;
2950 while ((req = *reqp++) != 0)
2952 if (req == SOLVABLE_PREREQMARKER)
2954 dp = pool_whatprovides(pool, req);
2962 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
2964 r = solv->rules + rid;
2966 if (r->d == 0 && r->w2 == 0)
2968 /* an assertion. we don't store them as rpm rules, so
2972 s = pool->solvables - r->p;
2973 if (installed && !solv->fixsystem && s->repo == installed)
2975 if (r->d == 0 && r->w2 < 0)
2977 /* a package conflict */
2978 Solvable *s2 = pool->solvables - r->w2;
2981 if (installed && !solv->fixsystem && s2->repo == installed)
2984 /* if both packages have the same name and at least one of them
2985 * is not installed, they conflict */
2986 if (s->name == s2->name && (!installed || (s->repo != installed || s2->repo != installed)))
2991 return SOLVER_PROBLEM_SAME_NAME;
2994 /* check conflicts in both directions */
2997 conp = s->repo->idarraydata + s->conflicts;
2998 while ((con = *conp++) != 0)
3000 FOR_PROVIDES(p, pp, con)
3002 if (dontfix && pool->solvables[p].repo == installed)
3009 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3015 conp = s2->repo->idarraydata + s2->conflicts;
3016 while ((con = *conp++) != 0)
3018 FOR_PROVIDES(p, pp, con)
3020 if (dontfix2 && pool->solvables[p].repo == installed)
3027 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3031 /* check obsoletes in both directions */
3032 if ((!installed || s->repo != installed) && s->obsoletes)
3034 obsp = s->repo->idarraydata + s->obsoletes;
3035 while ((obs = *obsp++) != 0)
3037 FOR_PROVIDES(p, pp, obs)
3044 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3048 if ((!installed || s2->repo != installed) && s2->obsoletes)
3050 obsp = s2->repo->idarraydata + s2->obsoletes;
3051 while ((obs = *obsp++) != 0)
3053 FOR_PROVIDES(p, pp, obs)
3060 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3064 /* all cases checked, can't happen */
3067 /* simple requires */
3068 assert(s->requires);
3069 reqp = s->repo->idarraydata + s->requires;
3070 while ((req = *reqp++) != 0)
3072 if (req == SOLVABLE_PREREQMARKER)
3074 dp = pool_whatprovides(pool, req);
3077 if (*dp == r->w2 && dp[1] == 0)
3080 else if (dp - pool->whatprovidesdata == r->d)
3087 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
3091 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3094 Id lreqr, lconr, lsysr, ljobr;
3098 lreqr = lconr = lsysr = ljobr = 0;
3099 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3101 if (rid >= solv->learntrules)
3102 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3103 else if (rid >= solv->systemrules)
3108 else if (rid >= solv->jobrules)
3115 r = solv->rules + rid;
3116 if (!r->d && r->w2 < 0)
3129 /* assertion, counts as require rule */
3130 /* ignore system solvable as we need useful info */
3131 if (rid == -SYSTEMSOLVABLE)
3133 if (!*reqrp || !reqassert)
3140 if (!*reqrp && lreqr)
3142 if (!*conrp && lconr)
3144 if (!*jobrp && ljobr)
3146 if (!*sysrp && lsysr)
3151 solver_findproblemrule(Solver *solv, Id problem)
3153 Id reqr, conr, sysr, jobr;
3154 Id idx = solv->problems.elements[problem - 1];
3155 reqr = conr = sysr = jobr = 0;
3156 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3169 printprobleminfo(Solver *solv, Queue *job, Id problem)
3171 Pool *pool = solv->pool;
3173 Id dep, source, target;
3176 probr = solver_findproblemrule(solv, problem);
3177 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
3179 case SOLVER_PROBLEM_UPDATE_RULE:
3180 s = pool_id2solvable(pool, source);
3181 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
3183 case SOLVER_PROBLEM_JOB_RULE:
3184 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
3186 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
3187 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
3189 case SOLVER_PROBLEM_NOT_INSTALLABLE:
3190 s = pool_id2solvable(pool, source);
3191 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
3193 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
3194 s = pool_id2solvable(pool, source);
3195 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
3197 case SOLVER_PROBLEM_SAME_NAME:
3198 s = pool_id2solvable(pool, source);
3199 s2 = pool_id2solvable(pool, target);
3200 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
3202 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
3203 s = pool_id2solvable(pool, source);
3204 s2 = pool_id2solvable(pool, target);
3205 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3207 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
3208 s = pool_id2solvable(pool, source);
3209 s2 = pool_id2solvable(pool, target);
3210 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3212 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
3213 s = pool_id2solvable(pool, source);
3214 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
3220 printsolutions(Solver *solv, Queue *job)
3222 Pool *pool = solv->pool;
3225 Id problem, solution, element;
3228 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
3231 while ((problem = solver_next_problem(solv, problem)) != 0)
3233 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
3234 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
3235 printprobleminfo(solv, job, problem);
3236 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3238 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
3241 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
3245 /* job, rp is index into job queue */
3246 what = job->elements[rp];
3247 switch (job->elements[rp - 1])
3249 case SOLVER_INSTALL_SOLVABLE:
3250 s = pool->solvables + what;
3251 if (solv->installed && s->repo == solv->installed)
3252 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, s));
3254 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solvable2str(pool, s));
3256 case SOLVER_ERASE_SOLVABLE:
3257 s = pool->solvables + what;
3258 if (solv->installed && s->repo == solv->installed)
3259 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solvable2str(pool, s));
3261 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, s));
3263 case SOLVER_INSTALL_SOLVABLE_NAME:
3264 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", id2str(pool, what));
3266 case SOLVER_ERASE_SOLVABLE_NAME:
3267 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", id2str(pool, what));
3269 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3270 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable providing %s\n", dep2str(pool, what));
3272 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3273 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables providing %s\n", dep2str(pool, what));
3275 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3276 s = pool->solvables + what;
3277 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solvable2str(pool, s));
3280 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
3286 /* policy, replace p with rp */
3287 s = pool->solvables + p;
3288 sd = rp ? pool->solvables + rp : 0;
3292 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
3294 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3297 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
3299 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3302 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
3305 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));
3307 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));
3311 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3315 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
3320 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3326 /* create reverse obsoletes map for installed solvables
3328 * for each installed solvable find which packages with *different* names
3329 * obsolete the solvable.
3330 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3334 create_obsolete_index(Solver *solv)
3336 Pool *pool = solv->pool;
3338 Repo *installed = solv->installed;
3339 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3342 if (!installed || !installed->nsolvables)
3344 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
3345 for (i = 1; i < pool->nsolvables; i++)
3347 s = pool->solvables + i;
3348 if (s->repo == installed)
3352 if (!pool_installable(pool, s))
3354 obsp = s->repo->idarraydata + s->obsoletes;
3355 while ((obs = *obsp++) != 0)
3356 FOR_PROVIDES(p, pp, obs)
3358 if (pool->solvables[p].repo != installed)
3360 if (pool->solvables[p].name == s->name)
3362 obsoletes[p - installed->start]++;
3366 for (i = 0; i < installed->nsolvables; i++)
3369 n += obsoletes[i] + 1;
3372 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
3373 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
3374 for (i = pool->nsolvables - 1; i > 0; i--)
3376 s = pool->solvables + i;
3377 if (s->repo == installed)
3381 if (!pool_installable(pool, s))
3383 obsp = s->repo->idarraydata + s->obsoletes;
3384 while ((obs = *obsp++) != 0)
3385 FOR_PROVIDES(p, pp, obs)
3387 if (pool->solvables[p].repo != installed)
3389 if (pool->solvables[p].name == s->name)
3391 p -= installed->start;
3392 if (obsoletes_data[obsoletes[p]] != i)
3393 obsoletes_data[--obsoletes[p]] = i;
3399 /*-----------------------------------------------------------------*/
3409 solver_solve(Solver *solv, Queue *job)
3411 Pool *pool = solv->pool;
3412 Repo *installed = solv->installed;
3415 Map addedmap; /* '1' == have rpm-rules for solvable */
3416 Id how, what, p, *pp, d;
3420 /* create whatprovides if not already there */
3421 if (!pool->whatprovides)
3422 pool_createwhatprovides(pool);
3424 /* create obsolete index if needed */
3425 if (solv->noupdateprovide)
3426 create_obsolete_index(solv);
3429 * create basic rule set of all involved packages
3430 * use addedmap bitmap to make sure we don't create rules twice
3434 map_init(&addedmap, pool->nsolvables);
3438 * always install our system solvable
3440 MAPSET(&addedmap, SYSTEMSOLVABLE);
3441 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3442 queue_push(&solv->decisionq_why, 0);
3443 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3446 * create rules for all package that could be involved with the solving
3447 * so called: rpm rules
3452 oldnrules = solv->nrules;
3453 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
3454 FOR_REPO_SOLVABLES(installed, p, s)
3455 addrpmrulesforsolvable(solv, s, &addedmap);
3456 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3457 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
3458 oldnrules = solv->nrules;
3459 FOR_REPO_SOLVABLES(installed, p, s)
3460 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3461 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3464 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
3465 oldnrules = solv->nrules;
3466 for (i = 0; i < job->count; i += 2)
3468 how = job->elements[i];
3469 what = job->elements[i + 1];
3473 case SOLVER_INSTALL_SOLVABLE:
3474 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3476 case SOLVER_INSTALL_SOLVABLE_NAME:
3477 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3478 FOR_PROVIDES(p, pp, what)
3480 /* if by name, ensure that the name matches */
3481 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3483 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3486 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3487 /* dont allow downgrade */
3488 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3492 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3494 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
3496 oldnrules = solv->nrules;
3497 addrpmrulesforweak(solv, &addedmap);
3498 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3500 IF_POOLDEBUG (SAT_DEBUG_STATS)
3502 int possible = 0, installable = 0;
3503 for (i = 1; i < pool->nsolvables; i++)
3505 if (pool_installable(pool, pool->solvables + i))
3507 if (MAPTST(&addedmap, i))
3510 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving (rules has been generated for)\n", possible, installable);
3514 * first pass done, we now have all the rpm rules we need.
3515 * unify existing rules before going over all job rules and
3517 * at this point the system is always solvable,
3518 * as an empty system (remove all packages) is a valid solution
3521 unifyrules(solv); /* remove duplicate rpm rules */
3522 solv->directdecisions = solv->decisionq.count;
3524 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
3525 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3526 printdecisions (solv);
3529 * now add all job rules
3532 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
3534 solv->jobrules = solv->nrules;
3536 for (i = 0; i < job->count; i += 2)
3538 oldnrules = solv->nrules;
3540 how = job->elements[i];
3541 what = job->elements[i + 1];
3544 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3545 s = pool->solvables + what;
3546 POOL_DEBUG(SAT_DEBUG_JOB, "job: install solvable %s\n", solvable2str(pool, s));
3547 addrule(solv, what, 0); /* install by Id */
3548 queue_push(&solv->ruletojob, i);
3550 case SOLVER_ERASE_SOLVABLE:
3551 s = pool->solvables + what;
3552 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase solvable %s\n", solvable2str(pool, s));
3553 addrule(solv, -what, 0); /* remove by Id */
3554 queue_push(&solv->ruletojob, i);
3556 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3557 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3558 if (how == SOLVER_INSTALL_SOLVABLE_NAME)
3559 POOL_DEBUG(SAT_DEBUG_JOB, "job: install name %s\n", id2str(pool, what));
3560 if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3561 POOL_DEBUG(SAT_DEBUG_JOB, "job: install provides %s\n", dep2str(pool, what));
3563 FOR_PROVIDES(p, pp, what)
3565 /* if by name, ensure that the name matches */
3566 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3572 /* no provider, make this an impossible rule */
3573 queue_push(&q, -SYSTEMSOLVABLE);
3576 p = queue_shift(&q); /* get first provider */
3578 d = 0; /* single provider ? -> make assertion */
3580 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3581 addrule(solv, p, d); /* add 'requires' rule */
3582 queue_push(&solv->ruletojob, i);
3584 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3585 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3586 if (how == SOLVER_ERASE_SOLVABLE_NAME)
3587 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase name %s\n", id2str(pool, what));
3588 if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3589 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase provides %s\n", dep2str(pool, what));
3590 FOR_PROVIDES(p, pp, what)
3592 /* if by name, ensure that the name matches */
3593 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
3595 addrule(solv, -p, 0); /* add 'remove' rule */
3596 queue_push(&solv->ruletojob, i);
3599 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3600 s = pool->solvables + what;
3601 POOL_DEBUG(SAT_DEBUG_JOB, "job: update %s\n", solvable2str(pool, s));
3602 addupdaterule(solv, s, 0);
3603 queue_push(&solv->ruletojob, i);
3606 IF_POOLDEBUG (SAT_DEBUG_JOB)
3609 if (solv->nrules == oldnrules)
3610 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created");
3611 for (j = oldnrules; j < solv->nrules; j++)
3613 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
3614 printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
3618 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3621 * now add system rules
3625 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add system rules ***\n");
3628 solv->systemrules = solv->nrules;
3631 * create rules for updating installed solvables
3635 if (installed && !solv->allowuninstall)
3636 { /* loop over all installed solvables */
3637 /* we create all update rules, but disable some later on depending on the job */
3638 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3640 /* no system rules for patch atoms */
3641 if (s->freshens && !s->supplements)
3643 const char *name = id2str(pool, s->name);
3644 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
3646 addrule(solv, 0, 0);
3650 if (s->repo == installed)
3651 addupdaterule(solv, s, 0); /* allowall = 0 */
3653 addrule(solv, 0, 0); /* create dummy rule */
3655 /* consistency check: we added a rule for _every_ system solvable */
3656 assert(solv->nrules - solv->systemrules == installed->end - installed->start);
3659 /* create special weak system rules */
3660 /* those are used later on to keep a version of the installed packages in
3662 if (installed && installed->nsolvables)
3664 solv->weaksystemrules = sat_calloc(installed->end - installed->start, sizeof(Id));
3665 FOR_REPO_SOLVABLES(installed, p, s)
3667 policy_findupdatepackages(solv, s, &q, 1);
3669 solv->weaksystemrules[p - installed->start] = pool_queuetowhatprovides(pool, &q);
3673 /* free unneeded memory */
3674 map_free(&addedmap);
3677 solv->weakrules = solv->nrules;
3679 /* try real hard to keep packages installed */
3682 FOR_REPO_SOLVABLES(installed, p, s)
3684 /* FIXME: can't work with refine_suggestion! */
3685 /* need to always add the rule but disable it */
3686 if (MAPTST(&solv->noupdate, p - installed->start))
3688 d = solv->weaksystemrules[p - installed->start];
3689 addrule(solv, p, d);
3693 /* all new rules are learnt after this point */
3694 solv->learntrules = solv->nrules;
3696 /* disable system rules that conflict with our job */
3697 disableupdaterules(solv, job, -1);
3699 /* make decisions based on job/system assertions */
3700 makeruledecisions(solv);
3702 /* create watches chains */
3705 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
3708 run_solver(solv, 1, 1);
3710 /* find suggested packages */
3711 if (!solv->problems.count)
3713 Id sug, *sugp, p, *pp;
3715 /* create map of all suggests that are still open */
3716 solv->recommends_index = -1;
3717 MAPZERO(&solv->suggestsmap);
3718 for (i = 0; i < solv->decisionq.count; i++)
3720 p = solv->decisionq.elements[i];
3723 s = pool->solvables + p;
3726 sugp = s->repo->idarraydata + s->suggests;
3727 while ((sug = *sugp++) != 0)
3729 FOR_PROVIDES(p, pp, sug)
3730 if (solv->decisionmap[p] > 0)
3733 continue; /* already fulfilled */
3734 FOR_PROVIDES(p, pp, sug)
3735 MAPSET(&solv->suggestsmap, p);
3739 for (i = 1; i < pool->nsolvables; i++)
3741 if (solv->decisionmap[i] != 0)
3743 s = pool->solvables + i;
3744 if (!MAPTST(&solv->suggestsmap, i))
3748 if (!pool_installable(pool, s))
3750 if (!solver_is_enhancing(solv, s))
3753 queue_push(&solv->suggestions, i);
3755 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
3758 if (solv->problems.count)
3759 problems_to_solutions(solv, job);