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
27 #define RULES_BLOCK 63
28 #define REGARD_RECOMMENDS_OF_INSTALLED_ITEMS 0
32 solver_splitprovides(Solver *solv, Id dep)
34 Pool *pool = solv->pool;
39 if (!solv->dosplitprovides || !solv->installed)
43 rd = GETRELDEP(pool, dep);
44 if (rd->flags != REL_WITH)
46 FOR_PROVIDES(p, pp, dep)
48 s = pool->solvables + p;
49 if (s->repo == solv->installed && s->name == rd->name)
56 solver_dep_installed(Solver *solv, Id dep)
59 Pool *pool = solv->pool;
64 Reldep *rd = GETRELDEP(pool, dep);
65 if (rd->flags == REL_AND)
67 if (!solver_dep_installed(solv, rd->name))
69 return solver_dep_installed(solv, rd->evr);
71 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
72 return solver_dep_installed(solv, rd->evr);
74 FOR_PROVIDES(p, pp, dep)
76 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
84 /* this mirrors solver_dep_fulfilled but uses map m instead of the decisionmap */
86 dep_possible(Solver *solv, Id dep, Map *m)
88 Pool *pool = solv->pool;
93 Reldep *rd = GETRELDEP(pool, dep);
94 if (rd->flags == REL_AND)
96 if (!dep_possible(solv, rd->name, m))
98 return dep_possible(solv, rd->evr, m);
100 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
101 return solver_splitprovides(solv, rd->evr);
102 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
103 return solver_dep_installed(solv, rd->evr);
105 FOR_PROVIDES(p, pp, dep)
113 /*-----------------------------------------------------------------*/
120 printruleelement(Solver *solv, int type, Rule *r, Id v)
122 Pool *pool = solv->pool;
126 s = pool->solvables + -v;
127 POOL_DEBUG(type, " !%s [%d]", solvable2str(pool, s), -v);
131 s = pool->solvables + v;
132 POOL_DEBUG(type, " %s [%d]", solvable2str(pool, s), v);
137 POOL_DEBUG(type, " (w1)");
139 POOL_DEBUG(type, " (w2)");
141 if (solv->decisionmap[s - pool->solvables] > 0)
142 POOL_DEBUG(type, " Install.level%d", solv->decisionmap[s - pool->solvables]);
143 if (solv->decisionmap[s - pool->solvables] < 0)
144 POOL_DEBUG(type, " Conflict.level%d", -solv->decisionmap[s - pool->solvables]);
145 POOL_DEBUG(type, "\n");
154 printrule(Solver *solv, int type, Rule *r)
156 Pool *pool = solv->pool;
160 if (r >= solv->rules && r < solv->rules + solv->nrules) /* r is a solver rule */
161 POOL_DEBUG(type, "Rule #%d:", (int)(r - solv->rules));
163 POOL_DEBUG(type, "Rule:"); /* r is any rule */
165 POOL_DEBUG(type, " (disabled)");
166 POOL_DEBUG(type, "\n");
170 /* print direct literal */
172 else if (r->d == ID_NULL)
176 /* binary rule --> print w2 as second literal */
180 /* every other which is in d */
181 v = solv->pool->whatprovidesdata[r->d + i - 1];
184 printruleelement(solv, type, r, v);
186 POOL_DEBUG(type, " next rules: %d %d\n", r->n1, r->n2);
190 printruleclass(Solver *solv, int type, Rule *r)
192 Pool *pool = solv->pool;
193 if (r - solv->rules >= solv->learntrules)
194 POOL_DEBUG(type, "LEARNT ");
195 else if (r - solv->rules >= solv->weakrules)
196 POOL_DEBUG(type, "WEAK ");
197 else if (r - solv->rules >= solv->systemrules)
198 POOL_DEBUG(type, "SYSTEM ");
199 else if (r - solv->rules >= solv->jobrules)
200 POOL_DEBUG(type, "JOB ");
201 printrule(solv, type, r);
205 /*-----------------------------------------------------------------*/
211 static Pool *unifyrules_sortcmp_data;
214 * compare rules for unification sort
218 unifyrules_sortcmp(const void *ap, const void *bp)
220 Pool *pool = unifyrules_sortcmp_data;
221 Rule *a = (Rule *)ap;
222 Rule *b = (Rule *)bp;
228 return x; /* p differs */
231 if (a->d == 0 && b->d == 0)
232 return a->w2 - b->w2; /* assertion: return w2 diff */
234 if (a->d == 0) /* a is assertion, b not */
236 x = a->w2 - pool->whatprovidesdata[b->d];
240 if (b->d == 0) /* b is assertion, a not */
242 x = pool->whatprovidesdata[a->d] - b->w2;
246 /* compare whatprovidesdata */
247 ad = pool->whatprovidesdata + a->d;
248 bd = pool->whatprovidesdata + b->d;
250 if ((x = *ad++ - *bd++) != 0)
261 unifyrules(Solver *solv)
263 Pool *pool = solv->pool;
267 if (solv->nrules <= 1) /* nothing to unify */
270 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
272 /* sort rules first */
273 unifyrules_sortcmp_data = solv->pool;
274 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
281 for (i = j = 1, ir = solv->rules + 1; i < solv->nrules; i++, ir++)
283 if (jr && !unifyrules_sortcmp(ir, jr))
284 continue; /* prune! */
285 jr = solv->rules + j++; /* keep! */
290 /* reduced count from nrules to j rules */
291 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
293 /* adapt rule buffer */
295 solv->rules = (Rule *)sat_realloc(solv->rules, ((solv->nrules + RULES_BLOCK) & ~RULES_BLOCK) * sizeof(Rule));
296 IF_POOLDEBUG (SAT_DEBUG_STATS)
303 for (i = 1; i < solv->nrules; i++)
310 dp = solv->pool->whatprovidesdata + r->d;
315 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
316 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
318 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
328 hashrule(Solver *solv, Id p, Id d, int n)
330 unsigned int x = (unsigned int)p;
334 return (x * 37) ^ (unsigned int)d;
335 dp = solv->pool->whatprovidesdata + d;
337 x = (x * 37) ^ (unsigned int)*dp++;
345 * p = direct literal; always < 0 for installed rpm rules
346 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
349 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
351 * p < 0 : pkg id of A
352 * d > 0 : Offset in whatprovidesdata (list of providers of b)
354 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
355 * p < 0 : pkg id of A
356 * d < 0 : Id of solvable (e.g. B1)
358 * d == 0: unary rule, assertion => (A) or (-A)
360 * Install: p > 0, d = 0 (A) user requested install
361 * Remove: p < 0, d = 0 (-A) user requested remove
362 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
363 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
364 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
365 * ? p > 0, d < 0 (A|-B)
366 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
370 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
371 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
372 * every other : w1 = p, w2 = whatprovidesdata[d];
373 * Disabled rule: w1 = 0
375 * always returns a rule for non-rpm rules
379 addrule(Solver *solv, Id p, Id d)
381 Pool *pool = solv->pool;
385 int n = 0; /* number of literals in rule - 1
386 0 = direct assertion (single literal)
390 /* it often happenes that requires lead to adding the same rpm rule
391 * multiple times, so we prune those duplicates right away to make
392 * the work for unifyrules a bit easier */
394 if (solv->nrules && !solv->jobrules)
396 r = solv->rules + solv->nrules - 1; /* get the last added rule */
397 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
403 /* always a binary rule */
405 return 0; /* ignore self conflict */
410 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
412 return 0; /* rule is self-fulfilling */
414 d = dp[-1]; /* take single literal */
417 if (n == 0 && !solv->jobrules)
419 /* this is a rpm rule assertion, we do not have to allocate it */
420 /* it can be identified by a level of 1 and a zero reason */
421 /* we must not drop those rules from the decisionq when rewinding! */
423 assert(solv->decisionmap[-p] == 0 || solv->decisionmap[-p] == -1);
424 if (solv->decisionmap[-p])
425 return 0; /* already got that one */
426 queue_push(&solv->decisionq, p);
427 queue_push(&solv->decisionq_why, 0);
428 solv->decisionmap[-p] = -1;
433 /* smallest literal first so we can find dups */
437 n = 1; /* re-set n, was used as temp var */
440 /* check if the last added rule is exactly the same as what we're looking for. */
441 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
442 return r; /* binary rule */
444 if (r && n > 1 && r->d && r->p == p)
446 /* Rule where d is an offset in whatprovidesdata */
450 dp2 = pool->whatprovidesdata + r->d;
451 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
462 /* check and extend rule buffer */
463 if ((solv->nrules & RULES_BLOCK) == 0)
465 solv->rules = (Rule *)sat_realloc(solv->rules, (solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
468 r = solv->rules + solv->nrules++; /* point to rule space */
473 /* direct assertion, no watch needed */
489 r->w2 = pool->whatprovidesdata[d];
494 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
496 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
497 printrule(solv, SAT_DEBUG_RULE_CREATION, r);
504 disablerule(Solver *solv, Rule *r)
510 enablerule(Solver *solv, Rule *r)
512 if (r->d == 0 || r->w2 != r->p)
515 r->w1 = solv->pool->whatprovidesdata[r->d];
519 /**********************************************************************************/
521 /* a problem is an item on the solver's problem list. It can either be >0, in that
522 * case it is a system (upgrade) rule, or it can be <0, which makes it refer to a job
523 * consisting of multiple job rules.
527 disableproblem(Solver *solv, Id v)
535 disablerule(solv, solv->rules + v);
539 jp = solv->ruletojob.elements;
540 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
542 disablerule(solv, r);
546 enableproblem(Solver *solv, Id v)
554 enablerule(solv, solv->rules + v);
558 jp = solv->ruletojob.elements;
559 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
565 printproblem(Solver *solv, Id v)
567 Pool *pool = solv->pool;
573 printrule(solv, SAT_DEBUG_SOLUTIONS, solv->rules + v);
577 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "JOB %d\n", v);
578 jp = solv->ruletojob.elements;
579 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
582 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "- ");
583 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
585 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "ENDJOB\n");
591 /************************************************************************/
593 /* go through system and job rules and add direct assertions
594 * to the decisionqueue. If we find a conflict, disable rules and
595 * add them to problem queue.
598 makeruledecisions(Solver *solv)
600 Pool *pool = solv->pool;
606 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
608 decisionstart = solv->decisionq.count;
609 /* rpm rules don't have assertions, so we can start with the job
611 for (ri = solv->jobrules, r = solv->rules + ri; ri < solv->nrules; ri++, r++)
613 if (!r->w1 || r->w2) /* disabled or no assertion */
617 if (solv->decisionmap[vv] == 0)
619 queue_push(&solv->decisionq, v);
620 queue_push(&solv->decisionq_why, r - solv->rules);
621 solv->decisionmap[vv] = v > 0 ? 1 : -1;
622 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
624 Solvable *s = solv->pool->solvables + vv;
626 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
628 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
632 if (v > 0 && solv->decisionmap[vv] > 0)
634 if (v < 0 && solv->decisionmap[vv] < 0)
636 /* found a conflict! */
637 /* ri >= learntrules cannot happen, as this would mean that the
638 * problem was not solvable, so we wouldn't have created the
639 * learnt rule at all */
640 assert(ri < solv->learntrules);
641 /* if we are weak, just disable ourself */
642 if (ri >= solv->weakrules)
644 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
645 printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
646 disablerule(solv, r);
650 /* only job and system rules left in the decisionq*/
651 /* find the decision which is the "opposite" of the jobrule */
652 for (i = 0; i < solv->decisionq.count; i++)
653 if (solv->decisionq.elements[i] == -v)
655 assert(i < solv->decisionq.count);
656 if (solv->decisionq_why.elements[i] == 0)
658 /* conflict with rpm rule, need only disable our rule */
659 assert(v > 0 || v == -SYSTEMSOLVABLE);
661 queue_push(&solv->problems, solv->learnt_pool.count);
662 queue_push(&solv->learnt_pool, ri);
663 queue_push(&solv->learnt_pool, v != -SYSTEMSOLVABLE ? -v : v);
664 queue_push(&solv->learnt_pool, 0);
665 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
666 if (ri < solv->systemrules)
667 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
670 queue_push(&solv->problems, v);
671 queue_push(&solv->problems, 0);
672 disableproblem(solv, v);
676 /* conflict with another job or system rule */
678 queue_push(&solv->problems, solv->learnt_pool.count);
679 queue_push(&solv->learnt_pool, ri);
680 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
681 queue_push(&solv->learnt_pool, 0);
683 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting system/job assertions over literal %d\n", vv);
684 /* push all of our rules asserting this literal on the problem stack */
685 for (i = solv->jobrules, rr = solv->rules + i; i < solv->nrules; i++, rr++)
687 if (!rr->w1 || rr->w2)
689 if (rr->p != vv && rr->p != -vv)
691 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
693 if (i < solv->systemrules)
694 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
695 queue_push(&solv->problems, v);
696 disableproblem(solv, v);
698 queue_push(&solv->problems, 0);
701 while (solv->decisionq.count > decisionstart)
703 v = solv->decisionq.elements[--solv->decisionq.count];
704 --solv->decisionq_why.count;
706 solv->decisionmap[vv] = 0;
708 ri = solv->jobrules - 1;
709 r = solv->rules + ri;
712 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
716 * we have enabled or disabled some of our rules. We now reenable all
717 * of our learnt rules but the ones that were learnt from rules that
721 enabledisablelearntrules(Solver *solv)
723 Pool *pool = solv->pool;
728 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
729 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
731 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
732 while ((why = *whyp++) != 0)
735 continue; /* rpm assertion */
737 if (!solv->rules[why].w1)
740 /* why != 0: we found a disabled rule, disable the learnt rule */
743 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
745 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling learnt ");
746 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
748 disablerule(solv, r);
750 else if (!why && !r->w1)
752 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
754 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling learnt ");
755 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
763 /* FIXME: bad code ahead, replace as soon as possible */
765 disableupdaterules(Solver *solv, Queue *job, int jobidx)
767 Pool *pool = solv->pool;
769 Id how, what, p, *pp;
775 installed = solv->installed;
781 how = job->elements[jobidx];
784 case SOLVER_INSTALL_SOLVABLE:
785 case SOLVER_ERASE_SOLVABLE:
786 case SOLVER_ERASE_SOLVABLE_NAME:
787 case SOLVER_ERASE_SOLVABLE_PROVIDES:
793 /* go through all enabled job rules */
794 MAPZERO(&solv->noupdate);
795 for (i = solv->jobrules; i < solv->systemrules; i++)
798 if (!r->w1) /* disabled? */
800 j = solv->ruletojob.elements[i - solv->jobrules];
804 how = job->elements[j];
805 what = job->elements[j + 1];
808 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
809 s = pool->solvables + what;
810 FOR_PROVIDES(p, pp, s->name)
812 if (pool->solvables[p].name != s->name)
814 if (pool->solvables[p].repo == installed)
815 MAPSET(&solv->noupdate, p - installed->start);
818 case SOLVER_ERASE_SOLVABLE:
819 s = pool->solvables + what;
820 if (s->repo == installed)
821 MAPSET(&solv->noupdate, what - installed->start);
823 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
824 case SOLVER_ERASE_SOLVABLE_PROVIDES:
825 FOR_PROVIDES(p, pp, what)
827 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
829 if (pool->solvables[p].repo == installed)
830 MAPSET(&solv->noupdate, p - installed->start);
838 /* fixup update rule status */
839 if (solv->allowuninstall)
840 return; /* no update rules at all */
844 /* we just disabled job #jobidx. enable all update rules
845 * that aren't disabled by the remaining job rules */
846 how = job->elements[jobidx];
847 what = job->elements[jobidx + 1];
850 case SOLVER_INSTALL_SOLVABLE:
851 s = pool->solvables + what;
852 FOR_PROVIDES(p, pp, s->name)
854 if (pool->solvables[p].name != s->name)
856 if (pool->solvables[p].repo != installed)
858 if (MAPTST(&solv->noupdate, p - installed->start))
860 r = solv->rules + solv->systemrules + (p - installed->start);
864 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
866 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
867 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
871 case SOLVER_ERASE_SOLVABLE:
872 s = pool->solvables + what;
873 if (s->repo != installed)
875 if (MAPTST(&solv->noupdate, what - installed->start))
877 r = solv->rules + solv->systemrules + (what - installed->start);
881 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
883 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
884 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
887 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
888 case SOLVER_ERASE_SOLVABLE_PROVIDES:
889 FOR_PROVIDES(p, pp, what)
891 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
893 if (pool->solvables[p].repo != installed)
895 if (MAPTST(&solv->noupdate, p - installed->start))
897 r = solv->rules + solv->systemrules + (p - installed->start);
901 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
903 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
904 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
914 for (i = 0; i < installed->nsolvables; i++)
916 r = solv->rules + solv->systemrules + i;
917 if (r->w1 && MAPTST(&solv->noupdate, i))
918 disablerule(solv, r); /* was enabled, need to disable */
924 * add (install) rules for solvable
925 * for unfulfilled requirements, conflicts, obsoletes,....
926 * add a negative assertion for solvables that are not installable
930 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
932 Pool *pool = solv->pool;
933 Repo *installed = solv->installed;
947 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
949 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
950 queue_push(&q, s - pool->solvables); /* push solvable Id */
956 * s: Pointer to solvable
960 if (MAPTST(m, n)) /* continue if already done */
964 s = pool->solvables + n; /* s = Solvable in question */
967 if (installed /* Installed system available */
968 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
969 && s->repo == installed) /* solvable is installed? */
971 dontfix = 1; /* dont care about broken rpm deps */
974 if (!dontfix && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
976 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
977 addrule(solv, -n, 0); /* uninstallable */
980 /*-----------------------------------------
981 * check requires of s
986 reqp = s->repo->idarraydata + s->requires;
987 while ((req = *reqp++) != 0) /* go throw all requires */
989 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
992 dp = pool_whatprovides(pool, req);
994 if (*dp == SYSTEMSOLVABLE) /* always installed */
999 /* the strategy here is to not insist on dependencies
1000 * that are already broken. so if we find one provider
1001 * that was already installed, we know that the
1002 * dependency was not broken before so we enforce it */
1003 for (i = 0; (p = dp[i]) != 0; i++) /* for all providers */
1005 if (pool->solvables[p].repo == installed)
1006 break; /* provider was installed */
1008 if (!p) /* previously broken dependency */
1010 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1017 /* nothing provides req! */
1018 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1019 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1023 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1025 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1026 for (i = 0; dp[i]; i++)
1027 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1030 /* add 'requires' dependency */
1031 /* rule: (-requestor|provider1|provider2|...|providerN) */
1032 addrule(solv, -n, dp - pool->whatprovidesdata);
1034 /* descend the dependency tree */
1035 for (; *dp; dp++) /* loop through all providers */
1037 if (!MAPTST(m, *dp))
1038 queue_push(&q, *dp);
1041 } /* while, requirements of n */
1043 } /* if, requirements */
1045 /* that's all we check for src packages */
1046 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1049 /*-----------------------------------------
1050 * check conflicts of s
1055 conp = s->repo->idarraydata + s->conflicts;
1056 while ((con = *conp++) != 0)
1058 FOR_PROVIDES(p, pp, con)
1060 /* dontfix: dont care about conflicts with already installed packs */
1061 if (dontfix && pool->solvables[p].repo == installed)
1063 /* rule: -n|-p: either solvable _or_ provider of conflict */
1064 addrule(solv, -n, -p);
1069 /*-----------------------------------------
1070 * check obsoletes if not installed
1072 if (!installed || pool->solvables[n].repo != installed)
1073 { /* not installed */
1076 obsp = s->repo->idarraydata + s->obsoletes;
1077 while ((obs = *obsp++) != 0)
1079 FOR_PROVIDES(p, pp, obs)
1080 addrule(solv, -n, -p);
1083 FOR_PROVIDES(p, pp, s->name)
1085 if (s->name == pool->solvables[p].name)
1086 addrule(solv, -n, -p);
1090 /*-----------------------------------------
1091 * add recommends to the rule list
1095 recp = s->repo->idarraydata + s->recommends;
1096 while ((rec = *recp++) != 0)
1098 FOR_PROVIDES(p, pp, rec)
1105 sugp = s->repo->idarraydata + s->suggests;
1106 while ((sug = *sugp++) != 0)
1108 FOR_PROVIDES(p, pp, sug)
1115 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1119 addrpmrulesforweak(Solver *solv, Map *m)
1121 Pool *pool = solv->pool;
1126 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1127 for (i = n = 1; n < pool->nsolvables; i++, n++)
1129 if (i == pool->nsolvables)
1133 s = pool->solvables + i;
1134 if (!pool_installable(pool, s))
1139 supp = s->repo->idarraydata + s->supplements;
1140 while ((sup = *supp++) != ID_NULL)
1141 if (dep_possible(solv, sup, m))
1144 if (!sup && s->freshens)
1146 supp = s->repo->idarraydata + s->freshens;
1147 while ((sup = *supp++) != ID_NULL)
1148 if (dep_possible(solv, sup, m))
1151 if (!sup && s->enhances)
1153 supp = s->repo->idarraydata + s->enhances;
1154 while ((sup = *supp++) != ID_NULL)
1155 if (dep_possible(solv, sup, m))
1160 addrpmrulesforsolvable(solv, s, m);
1163 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1167 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
1169 Pool *pool = solv->pool;
1174 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1176 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1177 policy_findupdatepackages(solv, s, &qs, allowall);
1178 if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
1179 addrpmrulesforsolvable(solv, s, m);
1180 for (i = 0; i < qs.count; i++)
1181 if (!MAPTST(m, qs.elements[i]))
1182 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1185 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1189 * add rule for update
1190 * (A|A1|A2|A3...) An = update candidates for A
1192 * s = (installed) solvable
1196 addupdaterule(Solver *solv, Solvable *s, int allowall)
1198 /* installed packages get a special upgrade allowed rule */
1199 Pool *pool = solv->pool;
1204 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1206 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1207 policy_findupdatepackages(solv, s, &qs, allowall);
1208 if (qs.count == 0) /* no updaters found */
1211 d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
1213 addrule(solv, s - pool->solvables, d); /* allow update of s */
1214 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1218 /*-----------------------------------------------------------------*/
1227 printWatches(Solver *solv, int type)
1229 Pool *pool = solv->pool;
1232 POOL_DEBUG(type, "Watches: \n");
1234 for (counter = -(pool->nsolvables); counter <= pool->nsolvables; counter ++)
1236 POOL_DEBUG(type, " solvable [%d] -- rule [%d]\n", counter, solv->watches[counter+pool->nsolvables]);
1243 * initial setup for all watches
1247 makewatches(Solver *solv)
1251 int nsolvables = solv->pool->nsolvables;
1253 sat_free(solv->watches);
1254 /* lower half for removals, upper half for installs */
1255 solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
1257 /* do it reverse so rpm rules get triggered first */
1258 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1260 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1263 if (!r->w1 /* rule is disabled */
1264 || !r->w2) /* rule is assertion */
1267 /* see addwatches(solv, r) */
1268 r->n1 = solv->watches[nsolvables + r->w1];
1269 solv->watches[nsolvables + r->w1] = r - solv->rules;
1271 r->n2 = solv->watches[nsolvables + r->w2];
1272 solv->watches[nsolvables + r->w2] = r - solv->rules;
1278 * add watches (for rule)
1282 addwatches(Solver *solv, Rule *r)
1284 int nsolvables = solv->pool->nsolvables;
1286 r->n1 = solv->watches[nsolvables + r->w1];
1287 solv->watches[nsolvables + r->w1] = r - solv->rules;
1289 r->n2 = solv->watches[nsolvables + r->w2];
1290 solv->watches[nsolvables + r->w2] = r - solv->rules;
1294 /*-----------------------------------------------------------------*/
1295 /* rule propagation */
1297 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1302 * propagate decision to all rules
1303 * return : 0 = everything is OK
1304 * watched rule = there is a conflict
1308 propagate(Solver *solv, int level)
1310 Pool *pool = solv->pool;
1315 Id *decisionmap = solv->decisionmap;
1316 Id *watches = solv->watches + pool->nsolvables;
1318 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1320 while (solv->propagate_index < solv->decisionq.count)
1322 /* negate because our watches trigger if literal goes FALSE */
1323 pkg = -solv->decisionq.elements[solv->propagate_index++];
1324 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1326 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "popagate for decision %d level %d\n", -pkg, level);
1327 printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1329 printWatches(solv, SAT_DEBUG_SCHUBI);
1332 for (rp = watches + pkg; *rp; rp = nrp)
1334 r = solv->rules + *rp;
1336 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1338 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1339 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1344 ow = r->w2; /* regard the second watchpoint to come to a solution */
1349 ow = r->w1; /* regard the first watchpoint to come to a solution */
1352 /* if clause is TRUE, nothing to do */
1353 if (DECISIONMAP_TRUE(ow))
1358 /* not a binary clause, check if we need to move our watch */
1359 /* search for a literal that is not ow and not false */
1360 /* (true is also ok, in that case the rule is fulfilled) */
1361 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1364 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1365 if (p != ow && !DECISIONMAP_TRUE(-p))
1369 /* p is free to watch, move watch to p */
1370 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1373 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1375 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1389 watches[p] = r - solv->rules;
1393 /* unit clause found, set other watch to TRUE */
1394 if (DECISIONMAP_TRUE(-ow))
1395 return r; /* eek, a conflict! */
1396 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1398 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
1399 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1402 decisionmap[ow] = level;
1404 decisionmap[-ow] = -level;
1405 queue_push(&solv->decisionq, ow);
1406 queue_push(&solv->decisionq_why, r - solv->rules);
1407 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1409 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1411 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
1413 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
1417 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
1419 return 0; /* all is well */
1423 /*-----------------------------------------------------------------*/
1432 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
1434 Pool *pool = solv->pool;
1437 Map seen; /* global? */
1440 int num = 0, l1num = 0;
1441 int learnt_why = solv->learnt_pool.count;
1442 Id *decisionmap = solv->decisionmap;
1446 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
1447 map_init(&seen, pool->nsolvables);
1448 idx = solv->decisionq.count;
1451 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1452 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1453 queue_push(&solv->learnt_pool, c - solv->rules);
1454 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1455 /* go through all literals of the rule */
1467 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1469 vv = v > 0 ? v : -v;
1470 if (MAPTST(&seen, vv))
1472 l = solv->decisionmap[vv];
1477 /* a level 1 literal, mark it for later */
1478 MAPSET(&seen, vv); /* mark for scanning in level 1 phase */
1484 num++; /* need to do this one as well */
1495 v = solv->decisionq.elements[--idx];
1496 vv = v > 0 ? v : -v;
1497 if (MAPTST(&seen, vv))
1500 c = solv->rules + solv->decisionq_why.elements[idx];
1505 *pr = -v; /* so that v doesn't get lost */
1507 /* add involved level 1 rules */
1510 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1514 v = solv->decisionq.elements[--idx];
1515 vv = v > 0 ? v : -v;
1516 if (!MAPTST(&seen, vv))
1518 why = solv->decisionq_why.elements[idx];
1521 queue_push(&solv->learnt_pool, -vv);
1522 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1524 POOL_DEBUG(SAT_DEBUG_ANALYZE, "RPM ASSERT Rule:\n");
1525 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, v);
1529 queue_push(&solv->learnt_pool, why);
1530 c = solv->rules + why;
1531 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1532 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1543 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1545 vv = v > 0 ? v : -v;
1546 l = solv->decisionmap[vv];
1547 if (l != 1 && l != -1)
1557 else if (r.count == 1 && r.elements[0] < 0)
1558 *dr = r.elements[0];
1560 *dr = pool_queuetowhatprovides(pool, &r);
1561 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1563 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1564 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
1565 for (i = 0; i < r.count; i++)
1566 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
1568 /* push end marker on learnt reasons stack */
1569 queue_push(&solv->learnt_pool, 0);
1578 * reset the solver decisions to right after the rpm rules.
1579 * called after rules have been enabled/disabled
1583 reset_solver(Solver *solv)
1585 Pool *pool = solv->pool;
1589 /* rewind decisions to direct rpm rule assertions */
1590 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
1592 v = solv->decisionq.elements[i];
1593 solv->decisionmap[v > 0 ? v : -v] = 0;
1596 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
1598 solv->decisionq_why.count = solv->directdecisions;
1599 solv->decisionq.count = solv->directdecisions;
1600 solv->recommends_index = -1;
1601 solv->propagate_index = 0;
1603 /* adapt learnt rule status to new set of enabled/disabled rules */
1604 enabledisablelearntrules(solv);
1606 /* redo all job/system decisions */
1607 makeruledecisions(solv);
1608 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
1610 /* recreate watch chains */
1616 * analyze_unsolvable_rule
1620 analyze_unsolvable_rule(Solver *solv, Rule *r)
1622 Pool *pool = solv->pool;
1624 Id why = r - solv->rules;
1625 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1626 printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1627 if (solv->learntrules && why >= solv->learntrules)
1629 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1630 if (solv->learnt_pool.elements[i] > 0)
1631 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i]);
1634 /* do not add rpm rules to problem */
1635 if (why < solv->jobrules)
1637 /* turn rule into problem */
1638 if (why >= solv->jobrules && why < solv->systemrules)
1639 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1640 /* return if problem already countains our rule */
1641 if (solv->problems.count)
1643 for (i = solv->problems.count - 1; i >= 0; i--)
1644 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1646 else if (solv->problems.elements[i] == why)
1649 queue_push(&solv->problems, why);
1654 * analyze_unsolvable
1656 * return: 1 - disabled some rules, try again
1661 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1663 Pool *pool = solv->pool;
1665 Map seen; /* global to speed things up? */
1668 Id *decisionmap = solv->decisionmap;
1669 int oldproblemcount;
1670 int oldlearntpoolcount;
1673 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1674 oldproblemcount = solv->problems.count;
1675 oldlearntpoolcount = solv->learnt_pool.count;
1677 /* make room for proof index */
1678 /* must update it later, as analyze_unsolvable_rule would confuse
1679 * it with a rule index if we put the real value in already */
1680 queue_push(&solv->problems, 0);
1683 map_init(&seen, pool->nsolvables);
1684 queue_push(&solv->learnt_pool, r - solv->rules);
1685 analyze_unsolvable_rule(solv, r);
1686 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1697 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1699 vv = v > 0 ? v : -v;
1700 l = solv->decisionmap[vv];
1705 idx = solv->decisionq.count;
1708 v = solv->decisionq.elements[--idx];
1709 vv = v > 0 ? v : -v;
1710 if (!MAPTST(&seen, vv))
1712 why = solv->decisionq_why.elements[idx];
1715 /* level 1 and no why, must be an rpm assertion */
1716 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1718 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "RPM ");
1719 printruleelement(solv, SAT_DEBUG_UNSOLVABLE, 0, v);
1721 /* this is the only positive rpm assertion */
1722 if (v == SYSTEMSOLVABLE)
1725 queue_push(&solv->learnt_pool, v);
1728 queue_push(&solv->learnt_pool, why);
1729 r = solv->rules + why;
1730 analyze_unsolvable_rule(solv, r);
1731 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1742 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1744 vv = v > 0 ? v : -v;
1745 l = solv->decisionmap[vv];
1752 queue_push(&solv->problems, 0); /* mark end of this problem */
1755 if (solv->weakrules != solv->learntrules)
1757 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1759 why = solv->problems.elements[i];
1760 if (why < solv->weakrules || why >= solv->learntrules)
1762 if (!lastweak || lastweak < why)
1768 /* disable last weak rule */
1769 solv->problems.count = oldproblemcount;
1770 solv->learnt_pool.count = oldlearntpoolcount;
1771 r = solv->rules + lastweak;
1772 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling weak ");
1773 printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
1774 disablerule(solv, r);
1780 queue_push(&solv->learnt_pool, 0);
1781 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1785 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1786 disableproblem(solv, solv->problems.elements[i]);
1790 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1795 /*-----------------------------------------------------------------*/
1796 /* Decision revert */
1800 * revert decision at level
1804 revert(Solver *solv, int level)
1806 Pool *pool = solv->pool;
1808 while (solv->decisionq.count)
1810 v = solv->decisionq.elements[solv->decisionq.count - 1];
1811 vv = v > 0 ? v : -v;
1812 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1814 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1815 solv->decisionmap[vv] = 0;
1816 solv->decisionq.count--;
1817 solv->decisionq_why.count--;
1818 solv->propagate_index = solv->decisionq.count;
1820 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1822 solv->branches.count--;
1823 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1824 solv->branches.count--;
1826 solv->recommends_index = -1;
1831 * watch2onhighest - put watch2 on literal with highest level
1835 watch2onhighest(Solver *solv, Rule *r)
1841 return; /* binary rule, both watches are set */
1842 dp = solv->pool->whatprovidesdata + r->d;
1843 while ((v = *dp++) != 0)
1845 l = solv->decisionmap[v < 0 ? -v : v];
1860 * add free decision to decisionq, increase level and
1861 * propagate decision, return if no conflict.
1862 * in conflict case, analyze conflict rule, add resulting
1863 * rule to learnt rule set, make decision from learnt
1864 * rule (always unit) and re-propagate.
1866 * returns the new solver level or 0 if unsolvable
1871 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1873 Pool *pool = solv->pool;
1882 solv->decisionmap[decision] = level;
1884 solv->decisionmap[-decision] = -level;
1885 queue_push(&solv->decisionq, decision);
1886 queue_push(&solv->decisionq_why, 0);
1890 r = propagate(solv, level);
1894 return analyze_unsolvable(solv, r, disablerules);
1895 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1896 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1897 assert(l > 0 && l < level);
1898 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
1900 revert(solv, level);
1901 r = addrule(solv, p, d); /* p requires d */
1903 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1904 queue_push(&solv->learnt_why, why);
1907 /* at least 2 literals, needs watches */
1908 watch2onhighest(solv, r);
1909 addwatches(solv, r);
1911 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1912 queue_push(&solv->decisionq, p);
1913 queue_push(&solv->decisionq_why, r - solv->rules);
1914 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1916 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
1917 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
1918 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
1919 printrule(solv, SAT_DEBUG_ANALYZE, r);
1927 * install best package from the queue. We add an extra package, inst, if
1928 * provided. See comment in weak install section.
1930 * returns the new solver level or 0 if unsolvable
1934 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
1936 Pool *pool = solv->pool;
1940 if (dq->count > 1 || inst)
1941 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
1946 /* choose the supplemented one */
1947 for (i = 0; i < dq->count; i++)
1948 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1952 for (i = 1; i < dq->count; i++)
1953 queue_push(&solv->branches, dq->elements[i]);
1954 queue_push(&solv->branches, -level);
1958 p = dq->elements[i];
1960 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
1962 return setpropagatelearn(solv, level, p, disablerules);
1966 /*-----------------------------------------------------------------*/
1967 /* Main solver interface */
1972 * create solver structure
1974 * pool: all available solvables
1975 * installed: installed Solvables
1978 * Upon solving, rules are created to flag the Solvables
1979 * of the 'installed' Repo as installed.
1983 solver_create(Pool *pool, Repo *installed)
1986 solv = (Solver *)sat_calloc(1, sizeof(Solver));
1988 solv->installed = installed;
1990 queue_init(&solv->ruletojob);
1991 queue_init(&solv->decisionq);
1992 queue_init(&solv->decisionq_why);
1993 queue_init(&solv->problems);
1994 queue_init(&solv->suggestions);
1995 queue_init(&solv->learnt_why);
1996 queue_init(&solv->learnt_pool);
1997 queue_init(&solv->branches);
1999 map_init(&solv->recommendsmap, pool->nsolvables);
2000 map_init(&solv->suggestsmap, pool->nsolvables);
2001 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
2002 solv->recommends_index = 0;
2004 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2005 solv->rules = (Rule *)sat_malloc((solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
2006 memset(solv->rules, 0, sizeof(Rule));
2018 solver_free(Solver *solv)
2020 queue_free(&solv->ruletojob);
2021 queue_free(&solv->decisionq);
2022 queue_free(&solv->decisionq_why);
2023 queue_free(&solv->learnt_why);
2024 queue_free(&solv->learnt_pool);
2025 queue_free(&solv->problems);
2026 queue_free(&solv->suggestions);
2027 queue_free(&solv->branches);
2029 map_free(&solv->recommendsmap);
2030 map_free(&solv->suggestsmap);
2031 map_free(&solv->noupdate);
2033 sat_free(solv->decisionmap);
2034 sat_free(solv->rules);
2035 sat_free(solv->watches);
2036 sat_free(solv->weaksystemrules);
2037 sat_free(solv->obsoletes);
2038 sat_free(solv->obsoletes_data);
2043 /*-------------------------------------------------------*/
2048 * all rules have been set up, now actually run the solver
2053 run_solver(Solver *solv, int disablerules, int doweak)
2061 Pool *pool = solv->pool;
2064 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2066 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2067 for (i = 0; i < solv->nrules; i++)
2068 printrule(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2071 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2073 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2074 printdecisions(solv);
2076 /* start SAT algorithm */
2078 systemlevel = level + 1;
2079 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2090 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2091 if ((r = propagate(solv, level)) != 0)
2093 if (analyze_unsolvable(solv, r, disablerules))
2101 * installed packages
2104 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2106 if (!solv->updatesystem)
2108 /* try to keep as many packages as possible */
2109 POOL_DEBUG(SAT_DEBUG_STATS, "installing system packages\n");
2110 for (i = solv->installed->start, n = 0; ; i++)
2112 if (n == solv->installed->nsolvables)
2114 if (i == solv->installed->end)
2115 i = solv->installed->start;
2116 s = pool->solvables + i;
2117 if (s->repo != solv->installed)
2120 if (solv->decisionmap[i] != 0)
2122 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2124 level = setpropagatelearn(solv, level, i, disablerules);
2130 if (level <= olevel)
2134 if (solv->weaksystemrules)
2136 POOL_DEBUG(SAT_DEBUG_STATS, "installing weak system packages\n");
2137 for (i = solv->installed->start; i < solv->installed->end; i++)
2139 if (pool->solvables[i].repo != solv->installed)
2141 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
2143 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2144 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2147 if (solv->weaksystemrules[i - solv->installed->start])
2149 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
2150 while ((p = *dp++) != 0)
2152 if (solv->decisionmap[p] > 0)
2154 if (solv->decisionmap[p] == 0)
2158 continue; /* update package already installed */
2160 if (!dq.count && solv->decisionmap[i] != 0)
2163 /* FIXME: i is handled a bit different because we do not want
2164 * to have it pruned just because it is not recommened.
2165 * we should not prune installed packages instead */
2166 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2172 if (level <= olevel)
2175 if (i < solv->installed->end)
2178 systemlevel = level;
2185 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unresolved rules\n");
2186 for (i = 1, n = 1; ; i++, n++)
2188 if (n == solv->nrules)
2190 if (i == solv->nrules)
2192 r = solv->rules + i;
2193 if (!r->w1) /* ignore disabled rules */
2198 /* binary or unary rule */
2199 /* need two positive undecided literals */
2200 if (r->p < 0 || r->w2 <= 0)
2202 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2204 queue_push(&dq, r->p);
2205 queue_push(&dq, r->w2);
2210 * all negative literals are installed
2211 * no positive literal is installed
2212 * i.e. the rule is not fulfilled and we
2213 * just need to decide on the positive literals
2217 if (solv->decisionmap[-r->p] <= 0)
2222 if (solv->decisionmap[r->p] > 0)
2224 if (solv->decisionmap[r->p] == 0)
2225 queue_push(&dq, r->p);
2227 dp = pool->whatprovidesdata + r->d;
2228 while ((p = *dp++) != 0)
2232 if (solv->decisionmap[-p] <= 0)
2237 if (solv->decisionmap[p] > 0)
2239 if (solv->decisionmap[p] == 0)
2246 /* dq.count < 2 cannot happen as this means that
2247 * the rule is unit */
2248 assert(dq.count > 1);
2249 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2251 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2252 printrule(solv, SAT_DEBUG_PROPAGATE, r);
2256 level = selectandinstall(solv, level, &dq, 0, disablerules);
2262 if (level < systemlevel)
2265 } /* for(), decide */
2267 if (n != solv->nrules) /* continue if level < systemlevel */
2270 if (doweak && !solv->problems.count)
2274 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
2275 if (!REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2277 for (i = 0; i < solv->decisionq.count; i++)
2279 p = solv->decisionq.elements[i];
2280 if (p > 0 && pool->solvables[p].repo == solv->installed)
2281 solv->decisionmap[p] = -solv->decisionmap[p];
2285 for (i = 1; i < pool->nsolvables; i++)
2287 if (solv->decisionmap[i] < 0)
2289 if (solv->decisionmap[i] > 0)
2291 Id *recp, rec, *pp, p;
2292 s = pool->solvables + i;
2293 /* installed, check for recommends */
2294 /* XXX need to special case AND ? */
2297 recp = s->repo->idarraydata + s->recommends;
2298 while ((rec = *recp++) != 0)
2301 FOR_PROVIDES(p, pp, rec)
2303 if (solv->decisionmap[p] > 0)
2308 else if (solv->decisionmap[p] == 0)
2310 queue_pushunique(&dq, p);
2318 s = pool->solvables + i;
2319 if (!s->supplements && !s->freshens)
2321 if (!pool_installable(pool, s))
2323 if (solver_is_supplementing(solv, s))
2324 queue_pushunique(&dq, i);
2327 if (!REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2329 for (i = 0; i < solv->decisionq.count; i++)
2331 p = solv->decisionq.elements[i];
2332 if (p > 0 && pool->solvables[p].repo == solv->installed)
2333 solv->decisionmap[p] = -solv->decisionmap[p];
2339 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2341 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2342 level = setpropagatelearn(solv, level, p, 0);
2347 if (solv->solution_callback)
2349 solv->solution_callback(solv, solv->solution_callback_data);
2350 if (solv->branches.count)
2352 int i = solv->branches.count - 1;
2353 int l = -solv->branches.elements[i];
2355 if (solv->branches.elements[i - 1] < 0)
2357 p = solv->branches.elements[i];
2358 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
2360 for (j = i + 1; j < solv->branches.count; j++)
2361 queue_push(&dq, solv->branches.elements[j]);
2362 solv->branches.count = i;
2364 revert(solv, level);
2366 for (j = 0; j < dq.count; j++)
2367 queue_push(&solv->branches, dq.elements[j]);
2369 level = setpropagatelearn(solv, level, p, disablerules);
2377 /* all branches done, we're finally finished */
2381 /* minimization step */
2382 if (solv->branches.count)
2384 int l = 0, lasti = -1, lastl = -1;
2386 for (i = solv->branches.count - 1; i >= 0; i--)
2388 p = solv->branches.elements[i];
2391 else if (p > 0 && solv->decisionmap[p] > l + 1)
2399 /* kill old solvable so that we do not loop */
2400 p = solv->branches.elements[lasti];
2401 solv->branches.elements[lasti] = 0;
2402 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
2405 revert(solv, level);
2407 level = setpropagatelearn(solv, level, p, disablerules);
2424 * at this point, all rules that led to conflicts are disabled.
2425 * we re-enable all rules of a problem set but rule "sug", then
2426 * continue to disable more rules until there as again a solution.
2429 /* FIXME: think about conflicting assertions */
2432 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2434 Pool *pool = solv->pool;
2441 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2443 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
2444 for (i = 0; problem[i]; i++)
2446 if (problem[i] == sug)
2447 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
2448 printproblem(solv, problem[i]);
2451 queue_init(&disabled);
2452 queue_empty(refined);
2453 queue_push(refined, sug);
2455 /* re-enable all problem rules with the exception of "sug" */
2459 for (i = 0; problem[i]; i++)
2460 if (problem[i] != sug)
2461 enableproblem(solv, problem[i]);
2464 disableupdaterules(solv, job, -(sug + 1));
2468 /* re-enable as many weak rules as possible */
2469 for (i = solv->weakrules; i < solv->learntrules; i++)
2471 r = solv->rules + i;
2473 enablerule(solv, r);
2476 queue_empty(&solv->problems);
2477 revert(solv, 1); /* XXX move to reset_solver? */
2480 if (!solv->problems.count)
2481 run_solver(solv, 0, 0);
2483 if (!solv->problems.count)
2485 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
2486 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2487 printdecisions(solv);
2488 break; /* great, no more problems */
2490 disabledcnt = disabled.count;
2491 /* start with 1 to skip over proof index */
2492 for (i = 1; i < solv->problems.count - 1; i++)
2494 /* ignore solutions in refined */
2495 v = solv->problems.elements[i];
2497 break; /* end of problem reached */
2498 for (j = 0; problem[j]; j++)
2499 if (problem[j] != sug && problem[j] == v)
2503 queue_push(&disabled, v);
2505 if (disabled.count == disabledcnt)
2507 /* no solution found, this was an invalid suggestion! */
2508 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
2512 if (disabled.count == disabledcnt + 1)
2514 /* just one suggestion, add it to refined list */
2515 v = disabled.elements[disabledcnt];
2516 queue_push(refined, v);
2517 disableproblem(solv, v);
2519 disableupdaterules(solv, job, -(v + 1));
2523 /* more than one solution, disable all */
2524 /* do not push anything on refine list */
2525 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2527 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
2528 for (i = disabledcnt; i < disabled.count; i++)
2529 printproblem(solv, disabled.elements[i]);
2531 for (i = disabledcnt; i < disabled.count; i++)
2532 disableproblem(solv, disabled.elements[i]);
2535 /* all done, get us back into the same state as before */
2536 /* enable refined rules again */
2537 for (i = 0; i < disabled.count; i++)
2538 enableproblem(solv, disabled.elements[i]);
2539 /* disable problem rules again */
2540 for (i = 0; problem[i]; i++)
2541 disableproblem(solv, problem[i]);
2542 disableupdaterules(solv, job, -1);
2543 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
2547 problems_to_solutions(Solver *solv, Queue *job)
2549 Pool *pool = solv->pool;
2557 if (!solv->problems.count)
2559 queue_clone(&problems, &solv->problems);
2560 queue_init(&solution);
2561 queue_init(&solutions);
2562 /* copy over proof index */
2563 queue_push(&solutions, problems.elements[0]);
2564 problem = problems.elements + 1;
2565 for (i = 1; i < problems.count; i++)
2567 Id v = problems.elements[i];
2570 /* mark end of this problem */
2571 queue_push(&solutions, 0);
2572 queue_push(&solutions, 0);
2573 if (i + 1 == problems.count)
2575 /* copy over proof of next problem */
2576 queue_push(&solutions, problems.elements[i + 1]);
2578 problem = problems.elements + i + 1;
2581 refine_suggestion(solv, job, problem, v, &solution);
2582 if (!solution.count)
2583 continue; /* this solution didn't work out */
2585 for (j = 0; j < solution.count; j++)
2587 why = solution.elements[j];
2588 /* must be either job descriptor or system rule */
2589 assert(why < 0 || (why >= solv->systemrules && why < solv->weakrules));
2591 printproblem(solv, why);
2595 /* job descriptor */
2596 queue_push(&solutions, 0);
2597 queue_push(&solutions, -why);
2601 /* system rule, find replacement package */
2603 p = solv->installed->start + (why - solv->systemrules);
2604 if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
2606 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
2609 if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
2611 if (solv->decisionmap[*dp] > 0)
2618 queue_push(&solutions, p);
2619 queue_push(&solutions, rp);
2622 /* mark end of this solution */
2623 queue_push(&solutions, 0);
2624 queue_push(&solutions, 0);
2626 queue_free(&solution);
2627 queue_free(&problems);
2628 /* copy queue over to solutions */
2629 queue_free(&solv->problems);
2630 queue_clone(&solv->problems, &solutions);
2632 /* bring solver back into problem state */
2633 revert(solv, 1); /* XXX move to reset_solver? */
2636 assert(solv->problems.count == solutions.count);
2637 queue_free(&solutions);
2641 solver_next_problem(Solver *solv, Id problem)
2645 return solv->problems.count ? 1 : 0;
2646 pp = solv->problems.elements + problem;
2647 while (pp[0] || pp[1])
2651 while (pp[0] || pp[1])
2656 problem = pp - solv->problems.elements;
2657 if (problem >= solv->problems.count)
2663 solver_next_solution(Solver *solv, Id problem, Id solution)
2669 pp = solv->problems.elements + solution;
2670 return pp[0] || pp[1] ? solution : 0;
2672 pp = solv->problems.elements + solution;
2673 while (pp[0] || pp[1])
2676 solution = pp - solv->problems.elements;
2677 return pp[0] || pp[1] ? solution : 0;
2681 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
2684 element = element ? element + 2 : solution;
2685 pp = solv->problems.elements + element;
2686 if (!(pp[0] || pp[1]))
2695 * create obsoletesmap from solver decisions
2696 * required for decision handling
2700 create_obsoletesmap(Solver *solv)
2702 Pool *pool = solv->pool;
2703 Repo *installed = solv->installed;
2704 Id p, *obsoletesmap = NULL;
2708 obsoletesmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2711 for (i = 0; i < solv->decisionq.count; i++)
2715 n = solv->decisionq.elements[i];
2718 if (n == SYSTEMSOLVABLE)
2720 s = pool->solvables + n;
2721 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2723 FOR_PROVIDES(p, pp, s->name)
2724 if (s->name == pool->solvables[p].name)
2726 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2728 obsoletesmap[p] = n;
2733 for (i = 0; i < solv->decisionq.count; i++)
2738 n = solv->decisionq.elements[i];
2741 if (n == SYSTEMSOLVABLE)
2743 s = pool->solvables + n;
2744 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2748 obsp = s->repo->idarraydata + s->obsoletes;
2749 while ((obs = *obsp++) != 0)
2750 FOR_PROVIDES(p, pp, obs)
2752 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2754 obsoletesmap[p] = n;
2760 return obsoletesmap;
2769 printdecisions(Solver *solv)
2771 Pool *pool = solv->pool;
2772 Repo *installed = solv->installed;
2773 Id p, *obsoletesmap = create_obsoletesmap( solv );
2777 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
2779 /* print solvables to be erased */
2783 FOR_REPO_SOLVABLES(installed, p, s)
2785 if (solv->decisionmap[p] >= 0)
2787 if (obsoletesmap[p])
2789 POOL_DEBUG(SAT_DEBUG_RESULT, "erase %s\n", solvable2str(pool, s));
2793 /* print solvables to be installed */
2795 for (i = 0; i < solv->decisionq.count; i++)
2798 p = solv->decisionq.elements[i];
2801 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2804 s = pool->solvables + p;
2805 POOL_DEBUG(SAT_DEBUG_SCHUBI, "level of %s is %d\n", solvable2str(pool, s), p);
2809 if (p == SYSTEMSOLVABLE)
2811 POOL_DEBUG(SAT_DEBUG_SCHUBI, "SYSTEMSOLVABLE\n");
2814 s = pool->solvables + p;
2815 if (installed && s->repo == installed)
2818 if (!obsoletesmap[p])
2820 POOL_DEBUG(SAT_DEBUG_RESULT, "install %s", solvable2str(pool, s));
2824 POOL_DEBUG(SAT_DEBUG_RESULT, "update %s", solvable2str(pool, s));
2825 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
2826 for (j = installed->start; j < installed->end; j++)
2827 if (obsoletesmap[j] == p)
2828 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
2829 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
2831 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
2834 sat_free(obsoletesmap);
2836 if (solv->suggestions.count)
2838 POOL_DEBUG(SAT_DEBUG_RESULT, "\nsuggested packages:\n");
2839 for (i = 0; i < solv->suggestions.count; i++)
2841 s = pool->solvables + solv->suggestions.elements[i];
2842 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
2845 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
2848 /* this is basically the reverse of addrpmrulesforsolvable */
2850 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
2852 Pool *pool = solv->pool;
2853 Repo *installed = solv->installed;
2857 Id p, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
2859 assert(rid < solv->weakrules);
2860 if (rid >= solv->systemrules)
2863 *sourcep = solv->installed->start + (rid - solv->systemrules);
2865 return SOLVER_PROBLEM_UPDATE_RULE;
2867 if (rid >= solv->jobrules)
2870 r = solv->rules + rid;
2871 p = solv->ruletojob.elements[rid - solv->jobrules];
2872 *depp = job->elements[p + 1];
2874 *targetp = job->elements[p];
2875 if (r->d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE)
2876 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
2877 return SOLVER_PROBLEM_JOB_RULE;
2881 /* a rpm rule assertion */
2882 assert(rid != -SYSTEMSOLVABLE);
2883 s = pool->solvables - rid;
2884 if (installed && !solv->fixsystem && s->repo == installed)
2886 assert(!dontfix); /* dontfix packages never have a neg assertion */
2887 /* see why the package is not installable */
2888 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
2889 return SOLVER_PROBLEM_NOT_INSTALLABLE;
2890 /* check requires */
2891 assert(s->requires);
2892 reqp = s->repo->idarraydata + s->requires;
2893 while ((req = *reqp++) != 0)
2895 if (req == SOLVABLE_PREREQMARKER)
2897 dp = pool_whatprovides(pool, req);
2905 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
2907 r = solv->rules + rid;
2909 if (r->d == 0 && r->w2 == 0)
2911 /* an assertion. we don't store them as rpm rules, so
2915 s = pool->solvables - r->p;
2916 if (installed && !solv->fixsystem && s->repo == installed)
2918 if (r->d == 0 && r->w2 < 0)
2920 /* a package conflict */
2921 Solvable *s2 = pool->solvables - r->w2;
2924 if (installed && !solv->fixsystem && s2->repo == installed)
2927 /* if both packages have the same name and at least one of them
2928 * is not installed, they conflict */
2929 if (s->name == s2->name && (!installed || (s->repo != installed || s2->repo != installed)))
2934 return SOLVER_PROBLEM_SAME_NAME;
2937 /* check conflicts in both directions */
2940 conp = s->repo->idarraydata + s->conflicts;
2941 while ((con = *conp++) != 0)
2943 FOR_PROVIDES(p, pp, con)
2945 if (dontfix && pool->solvables[p].repo == installed)
2952 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
2958 conp = s2->repo->idarraydata + s2->conflicts;
2959 while ((con = *conp++) != 0)
2961 FOR_PROVIDES(p, pp, con)
2963 if (dontfix2 && pool->solvables[p].repo == installed)
2970 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
2974 /* check obsoletes in both directions */
2975 if ((!installed || s->repo != installed) && s->obsoletes)
2977 obsp = s->repo->idarraydata + s->obsoletes;
2978 while ((obs = *obsp++) != 0)
2980 FOR_PROVIDES(p, pp, obs)
2987 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
2991 if ((!installed || s2->repo != installed) && s2->obsoletes)
2993 obsp = s2->repo->idarraydata + s2->obsoletes;
2994 while ((obs = *obsp++) != 0)
2996 FOR_PROVIDES(p, pp, obs)
3003 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3007 /* all cases checked, can't happen */
3010 /* simple requires */
3011 assert(s->requires);
3012 reqp = s->repo->idarraydata + s->requires;
3013 while ((req = *reqp++) != 0)
3015 if (req == SOLVABLE_PREREQMARKER)
3017 dp = pool_whatprovides(pool, req);
3020 if (*dp == r->w2 && dp[1] == 0)
3023 else if (dp - pool->whatprovidesdata == r->d)
3030 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
3034 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3037 Id lreqr, lconr, lsysr, ljobr;
3041 lreqr = lconr = lsysr = ljobr = 0;
3042 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3044 if (rid >= solv->learntrules)
3045 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3046 else if (rid >= solv->systemrules)
3051 else if (rid >= solv->jobrules)
3058 r = solv->rules + rid;
3059 if (!r->d && r->w2 < 0)
3072 /* assertion, counts as require rule */
3073 /* ignore system solvable as we need useful info */
3074 if (rid == -SYSTEMSOLVABLE)
3076 if (!*reqrp || !reqassert)
3083 if (!*reqrp && lreqr)
3085 if (!*conrp && lconr)
3087 if (!*jobrp && ljobr)
3089 if (!*sysrp && lsysr)
3094 solver_findproblemrule(Solver *solv, Id problem)
3096 Id reqr, conr, sysr, jobr;
3097 Id idx = solv->problems.elements[problem - 1];
3098 reqr = conr = sysr = jobr = 0;
3099 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3112 printprobleminfo(Solver *solv, Queue *job, Id problem)
3114 Pool *pool = solv->pool;
3116 Id dep, source, target;
3119 probr = solver_findproblemrule(solv, problem);
3120 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
3122 case SOLVER_PROBLEM_UPDATE_RULE:
3123 s = pool_id2solvable(pool, source);
3124 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
3126 case SOLVER_PROBLEM_JOB_RULE:
3127 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
3129 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
3130 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
3132 case SOLVER_PROBLEM_NOT_INSTALLABLE:
3133 s = pool_id2solvable(pool, source);
3134 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
3136 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
3137 s = pool_id2solvable(pool, source);
3138 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
3140 case SOLVER_PROBLEM_SAME_NAME:
3141 s = pool_id2solvable(pool, source);
3142 s2 = pool_id2solvable(pool, target);
3143 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
3145 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
3146 s = pool_id2solvable(pool, source);
3147 s2 = pool_id2solvable(pool, target);
3148 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3150 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
3151 s = pool_id2solvable(pool, source);
3152 s2 = pool_id2solvable(pool, target);
3153 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3155 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
3156 s = pool_id2solvable(pool, source);
3157 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
3163 printsolutions(Solver *solv, Queue *job)
3165 Pool *pool = solv->pool;
3168 Id problem, solution, element;
3171 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
3174 while ((problem = solver_next_problem(solv, problem)) != 0)
3176 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
3177 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
3178 printprobleminfo(solv, job, problem);
3179 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3181 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
3184 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
3188 /* job, rp is index into job queue */
3189 what = job->elements[rp];
3190 switch (job->elements[rp - 1])
3192 case SOLVER_INSTALL_SOLVABLE:
3193 s = pool->solvables + what;
3194 if (solv->installed && s->repo == solv->installed)
3195 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, s));
3197 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solvable2str(pool, s));
3199 case SOLVER_ERASE_SOLVABLE:
3200 s = pool->solvables + what;
3201 if (solv->installed && s->repo == solv->installed)
3202 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solvable2str(pool, s));
3204 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, s));
3206 case SOLVER_INSTALL_SOLVABLE_NAME:
3207 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", id2str(pool, what));
3209 case SOLVER_ERASE_SOLVABLE_NAME:
3210 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", id2str(pool, what));
3212 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3213 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable providing %s\n", dep2str(pool, what));
3215 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3216 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables providing %s\n", dep2str(pool, what));
3218 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3219 s = pool->solvables + what;
3220 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solvable2str(pool, s));
3223 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
3229 /* policy, replace p with rp */
3230 s = pool->solvables + p;
3231 sd = rp ? pool->solvables + rp : 0;
3235 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
3237 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3240 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(pool, s, sd))
3242 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3245 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(pool, s, sd))
3248 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));
3250 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));
3254 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3258 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
3263 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3269 /* for each installed solvable find which packages with *different* names
3270 * obsolete the solvable.
3271 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3275 create_obsolete_index(Solver *solv)
3277 Pool *pool = solv->pool;
3279 Repo *installed = solv->installed;
3280 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3283 if (!installed || !installed->nsolvables)
3285 /* create reverse obsoletes map for installed solvables */
3286 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
3287 for (i = 1; i < pool->nsolvables; i++)
3289 s = pool->solvables + i;
3290 if (s->repo == installed)
3294 if (!pool_installable(pool, s))
3296 obsp = s->repo->idarraydata + s->obsoletes;
3297 while ((obs = *obsp++) != 0)
3298 FOR_PROVIDES(p, pp, obs)
3300 if (pool->solvables[p].repo != installed)
3302 if (pool->solvables[p].name == s->name)
3304 obsoletes[p - installed->start]++;
3308 for (i = 0; i < installed->nsolvables; i++)
3311 n += obsoletes[i] + 1;
3314 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
3315 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
3316 for (i = pool->nsolvables - 1; i > 0; i--)
3318 s = pool->solvables + i;
3319 if (s->repo == installed)
3323 if (!pool_installable(pool, s))
3325 obsp = s->repo->idarraydata + s->obsoletes;
3326 while ((obs = *obsp++) != 0)
3327 FOR_PROVIDES(p, pp, obs)
3329 if (pool->solvables[p].repo != installed)
3331 if (pool->solvables[p].name == s->name)
3333 p -= installed->start;
3334 if (obsoletes_data[obsoletes[p]] != i)
3335 obsoletes_data[--obsoletes[p]] = i;
3341 /*-----------------------------------------------------------------*/
3351 solver_solve(Solver *solv, Queue *job)
3353 Pool *pool = solv->pool;
3354 Repo *installed = solv->installed;
3357 Map addedmap; /* '1' == have rpm-rules for solvable */
3358 Id how, what, p, *pp, d;
3362 /* create whatprovides if not already there */
3363 if (!pool->whatprovides)
3364 pool_createwhatprovides(pool);
3366 /* create obsolete index if needed */
3367 if (solv->noupdateprovide)
3368 create_obsolete_index(solv);
3371 * create basic rule set of all involved packages
3372 * use addedmap bitmap to make sure we don't create rules twice
3376 map_init(&addedmap, pool->nsolvables);
3380 * always install our system solvable
3382 MAPSET(&addedmap, SYSTEMSOLVABLE);
3383 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3384 queue_push(&solv->decisionq_why, 0);
3385 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3388 * create rules for all package that could be involved with the solving
3389 * so called: rpm rules
3394 oldnrules = solv->nrules;
3395 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
3396 FOR_REPO_SOLVABLES(installed, p, s)
3397 addrpmrulesforsolvable(solv, s, &addedmap);
3398 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3399 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
3400 oldnrules = solv->nrules;
3401 FOR_REPO_SOLVABLES(installed, p, s)
3402 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3403 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3406 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
3407 oldnrules = solv->nrules;
3408 for (i = 0; i < job->count; i += 2)
3410 how = job->elements[i];
3411 what = job->elements[i + 1];
3415 case SOLVER_INSTALL_SOLVABLE:
3416 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3418 case SOLVER_INSTALL_SOLVABLE_NAME:
3419 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3420 FOR_PROVIDES(p, pp, what)
3422 /* if by name, ensure that the name matches */
3423 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3425 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3428 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3429 /* dont allow downgrade */
3430 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3434 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3436 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
3438 oldnrules = solv->nrules;
3439 addrpmrulesforweak(solv, &addedmap);
3440 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3442 IF_POOLDEBUG (SAT_DEBUG_STATS)
3444 int possible = 0, installable = 0;
3445 for (i = 1; i < pool->nsolvables; i++)
3447 if (pool_installable(pool, pool->solvables + i))
3449 if (MAPTST(&addedmap, i))
3452 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving (rules has been generated for)\n", possible, installable);
3456 * first pass done, we now have all the rpm rules we need.
3457 * unify existing rules before going over all job rules and
3459 * at this point the system is always solvable,
3460 * as an empty system (remove all packages) is a valid solution
3463 unifyrules(solv); /* remove duplicate rpm rules */
3464 solv->directdecisions = solv->decisionq.count;
3466 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
3467 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3468 printdecisions (solv);
3471 * now add all job rules
3474 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
3476 solv->jobrules = solv->nrules;
3478 for (i = 0; i < job->count; i += 2)
3480 oldnrules = solv->nrules;
3482 how = job->elements[i];
3483 what = job->elements[i + 1];
3486 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3487 s = pool->solvables + what;
3488 POOL_DEBUG(SAT_DEBUG_JOB, "job: install solvable %s\n", solvable2str(pool, s));
3489 addrule(solv, what, 0); /* install by Id */
3490 queue_push(&solv->ruletojob, i);
3492 case SOLVER_ERASE_SOLVABLE:
3493 s = pool->solvables + what;
3494 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase solvable %s\n", solvable2str(pool, s));
3495 addrule(solv, -what, 0); /* remove by Id */
3496 queue_push(&solv->ruletojob, i);
3498 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3499 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3500 if (how == SOLVER_INSTALL_SOLVABLE_NAME)
3501 POOL_DEBUG(SAT_DEBUG_JOB, "job: install name %s\n", id2str(pool, what));
3502 if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3503 POOL_DEBUG(SAT_DEBUG_JOB, "job: install provides %s\n", dep2str(pool, what));
3505 FOR_PROVIDES(p, pp, what)
3507 /* if by name, ensure that the name matches */
3508 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3514 /* no provider, make this an impossible rule */
3515 queue_push(&q, -SYSTEMSOLVABLE);
3518 p = queue_shift(&q); /* get first provider */
3520 d = 0; /* single provider ? -> make assertion */
3522 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3523 addrule(solv, p, d); /* add 'requires' rule */
3524 queue_push(&solv->ruletojob, i);
3526 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3527 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3528 if (how == SOLVER_ERASE_SOLVABLE_NAME)
3529 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase name %s\n", id2str(pool, what));
3530 if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3531 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase provides %s\n", dep2str(pool, what));
3532 FOR_PROVIDES(p, pp, what)
3534 /* if by name, ensure that the name matches */
3535 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
3537 addrule(solv, -p, 0); /* add 'remove' rule */
3538 queue_push(&solv->ruletojob, i);
3541 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3542 s = pool->solvables + what;
3543 POOL_DEBUG(SAT_DEBUG_JOB, "job: update %s\n", solvable2str(pool, s));
3544 addupdaterule(solv, s, 0);
3545 queue_push(&solv->ruletojob, i);
3548 IF_POOLDEBUG (SAT_DEBUG_JOB)
3551 if (solv->nrules == oldnrules)
3552 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created");
3553 for (j = oldnrules; j < solv->nrules; j++)
3555 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
3556 printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
3560 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3563 * now add system rules
3567 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add system rules ***\n");
3570 solv->systemrules = solv->nrules;
3573 * create rules for updating installed solvables
3577 if (installed && !solv->allowuninstall)
3578 { /* loop over all installed solvables */
3579 /* we create all update rules, but disable some later on depending on the job */
3580 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3581 if (s->repo == installed)
3582 addupdaterule(solv, s, 0); /* allowall = 0 */
3584 addupdaterule(solv, 0, 0); /* create dummy rule; allowall = 0 */
3585 /* consistency check: we added a rule for _every_ system solvable */
3586 assert(solv->nrules - solv->systemrules == installed->end - installed->start);
3589 /* create special weak system rules */
3590 /* those are used later on to keep a version of the installed packages in
3592 if (installed && installed->nsolvables)
3594 solv->weaksystemrules = sat_calloc(installed->end - installed->start, sizeof(Id));
3595 FOR_REPO_SOLVABLES(installed, p, s)
3597 policy_findupdatepackages(solv, s, &q, 1);
3599 solv->weaksystemrules[p - installed->start] = pool_queuetowhatprovides(pool, &q);
3603 /* free unneeded memory */
3604 map_free(&addedmap);
3607 solv->weakrules = solv->nrules;
3609 /* try real hard to keep packages installed */
3612 FOR_REPO_SOLVABLES(installed, p, s)
3614 /* FIXME: can't work with refine_suggestion! */
3615 /* need to always add the rule but disable it */
3616 if (MAPTST(&solv->noupdate, p - installed->start))
3618 d = solv->weaksystemrules[p - installed->start];
3619 addrule(solv, p, d);
3623 /* all new rules are learnt after this point */
3624 solv->learntrules = solv->nrules;
3626 /* disable system rules that conflict with our job */
3627 disableupdaterules(solv, job, -1);
3629 /* make decisions based on job/system assertions */
3630 makeruledecisions(solv);
3632 /* create watches chains */
3635 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
3638 run_solver(solv, 1, 1);
3640 /* find suggested packages */
3641 if (!solv->problems.count)
3643 Id sug, *sugp, p, *pp;
3645 /* create map of all suggests that are still open */
3646 solv->recommends_index = -1;
3647 MAPZERO(&solv->suggestsmap);
3648 for (i = 0; i < solv->decisionq.count; i++)
3650 p = solv->decisionq.elements[i];
3653 s = pool->solvables + p;
3656 sugp = s->repo->idarraydata + s->suggests;
3657 while ((sug = *sugp++) != 0)
3659 FOR_PROVIDES(p, pp, sug)
3660 if (solv->decisionmap[p] > 0)
3663 continue; /* already fulfilled */
3664 FOR_PROVIDES(p, pp, sug)
3665 MAPSET(&solv->suggestsmap, p);
3669 for (i = 1; i < pool->nsolvables; i++)
3671 if (solv->decisionmap[i] != 0)
3673 s = pool->solvables + i;
3674 if (!MAPTST(&solv->suggestsmap, i))
3678 if (!pool_installable(pool, s))
3680 if (!solver_is_enhancing(solv, s))
3683 queue_push(&solv->suggestions, i);
3685 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
3688 if (solv->problems.count)
3689 problems_to_solutions(solv, job);