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 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1586 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1597 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1599 vv = v > 0 ? v : -v;
1600 l = solv->decisionmap[vv];
1601 if (l != 1 && l != -1)
1611 else if (r.count == 1 && r.elements[0] < 0)
1612 *dr = r.elements[0];
1614 *dr = pool_queuetowhatprovides(pool, &r);
1615 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1617 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1618 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
1619 for (i = 0; i < r.count; i++)
1620 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
1622 /* push end marker on learnt reasons stack */
1623 queue_push(&solv->learnt_pool, 0);
1632 * reset the solver decisions to right after the rpm rules.
1633 * called after rules have been enabled/disabled
1637 reset_solver(Solver *solv)
1639 Pool *pool = solv->pool;
1643 /* rewind decisions to direct rpm rule assertions */
1644 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
1646 v = solv->decisionq.elements[i];
1647 solv->decisionmap[v > 0 ? v : -v] = 0;
1650 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
1652 solv->decisionq_why.count = solv->directdecisions;
1653 solv->decisionq.count = solv->directdecisions;
1654 solv->recommends_index = -1;
1655 solv->propagate_index = 0;
1657 /* adapt learnt rule status to new set of enabled/disabled rules */
1658 enabledisablelearntrules(solv);
1660 /* redo all job/system decisions */
1661 makeruledecisions(solv);
1662 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
1664 /* recreate watch chains */
1670 * analyze_unsolvable_rule
1674 analyze_unsolvable_rule(Solver *solv, Rule *r)
1676 Pool *pool = solv->pool;
1678 Id why = r - solv->rules;
1679 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1680 printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1681 if (solv->learntrules && why >= solv->learntrules)
1683 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1684 if (solv->learnt_pool.elements[i] > 0)
1685 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i]);
1688 /* do not add rpm rules to problem */
1689 if (why < solv->jobrules)
1691 /* turn rule into problem */
1692 if (why >= solv->jobrules && why < solv->systemrules)
1693 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1694 /* return if problem already countains our rule */
1695 if (solv->problems.count)
1697 for (i = solv->problems.count - 1; i >= 0; i--)
1698 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1700 else if (solv->problems.elements[i] == why)
1703 queue_push(&solv->problems, why);
1708 * analyze_unsolvable
1710 * return: 1 - disabled some rules, try again
1715 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1717 Pool *pool = solv->pool;
1719 Map seen; /* global to speed things up? */
1722 Id *decisionmap = solv->decisionmap;
1723 int oldproblemcount;
1724 int oldlearntpoolcount;
1727 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1728 oldproblemcount = solv->problems.count;
1729 oldlearntpoolcount = solv->learnt_pool.count;
1731 /* make room for proof index */
1732 /* must update it later, as analyze_unsolvable_rule would confuse
1733 * it with a rule index if we put the real value in already */
1734 queue_push(&solv->problems, 0);
1737 map_init(&seen, pool->nsolvables);
1738 queue_push(&solv->learnt_pool, r - solv->rules);
1739 analyze_unsolvable_rule(solv, r);
1740 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1751 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1753 vv = v > 0 ? v : -v;
1754 l = solv->decisionmap[vv];
1759 idx = solv->decisionq.count;
1762 v = solv->decisionq.elements[--idx];
1763 vv = v > 0 ? v : -v;
1764 if (!MAPTST(&seen, vv))
1766 why = solv->decisionq_why.elements[idx];
1769 /* level 1 and no why, must be an rpm assertion */
1770 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1772 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "RPM ");
1773 printruleelement(solv, SAT_DEBUG_UNSOLVABLE, 0, v);
1775 /* this is the only positive rpm assertion */
1776 if (v == SYSTEMSOLVABLE)
1779 queue_push(&solv->learnt_pool, v);
1782 queue_push(&solv->learnt_pool, why);
1783 r = solv->rules + why;
1784 analyze_unsolvable_rule(solv, r);
1785 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1796 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1798 vv = v > 0 ? v : -v;
1799 l = solv->decisionmap[vv];
1806 queue_push(&solv->problems, 0); /* mark end of this problem */
1809 if (solv->weakrules != solv->learntrules)
1811 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1813 why = solv->problems.elements[i];
1814 if (why < solv->weakrules || why >= solv->learntrules)
1816 if (!lastweak || lastweak < why)
1822 /* disable last weak rule */
1823 solv->problems.count = oldproblemcount;
1824 solv->learnt_pool.count = oldlearntpoolcount;
1825 r = solv->rules + lastweak;
1826 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling weak ");
1827 printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
1828 disablerule(solv, r);
1834 queue_push(&solv->learnt_pool, 0);
1835 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1839 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1840 disableproblem(solv, solv->problems.elements[i]);
1844 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1849 /*-----------------------------------------------------------------*/
1850 /* Decision revert */
1854 * revert decision at level
1858 revert(Solver *solv, int level)
1860 Pool *pool = solv->pool;
1862 while (solv->decisionq.count)
1864 v = solv->decisionq.elements[solv->decisionq.count - 1];
1865 vv = v > 0 ? v : -v;
1866 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1868 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1869 solv->decisionmap[vv] = 0;
1870 solv->decisionq.count--;
1871 solv->decisionq_why.count--;
1872 solv->propagate_index = solv->decisionq.count;
1874 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1876 solv->branches.count--;
1877 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1878 solv->branches.count--;
1880 solv->recommends_index = -1;
1885 * watch2onhighest - put watch2 on literal with highest level
1889 watch2onhighest(Solver *solv, Rule *r)
1895 return; /* binary rule, both watches are set */
1896 dp = solv->pool->whatprovidesdata + r->d;
1897 while ((v = *dp++) != 0)
1899 l = solv->decisionmap[v < 0 ? -v : v];
1914 * add free decision to decisionq, increase level and
1915 * propagate decision, return if no conflict.
1916 * in conflict case, analyze conflict rule, add resulting
1917 * rule to learnt rule set, make decision from learnt
1918 * rule (always unit) and re-propagate.
1920 * returns the new solver level or 0 if unsolvable
1925 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1927 Pool *pool = solv->pool;
1936 solv->decisionmap[decision] = level;
1938 solv->decisionmap[-decision] = -level;
1939 queue_push(&solv->decisionq, decision);
1940 queue_push(&solv->decisionq_why, 0);
1944 r = propagate(solv, level);
1948 return analyze_unsolvable(solv, r, disablerules);
1949 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1950 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1951 assert(l > 0 && l < level);
1952 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
1954 revert(solv, level);
1955 r = addrule(solv, p, d); /* p requires d */
1957 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1958 queue_push(&solv->learnt_why, why);
1961 /* at least 2 literals, needs watches */
1962 watch2onhighest(solv, r);
1963 addwatches(solv, r);
1965 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1966 queue_push(&solv->decisionq, p);
1967 queue_push(&solv->decisionq_why, r - solv->rules);
1968 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1970 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
1971 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
1972 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
1973 printrule(solv, SAT_DEBUG_ANALYZE, r);
1981 * install best package from the queue. We add an extra package, inst, if
1982 * provided. See comment in weak install section.
1984 * returns the new solver level or 0 if unsolvable
1988 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
1990 Pool *pool = solv->pool;
1994 if (dq->count > 1 || inst)
1995 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
2000 /* choose the supplemented one */
2001 for (i = 0; i < dq->count; i++)
2002 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
2006 for (i = 1; i < dq->count; i++)
2007 queue_push(&solv->branches, dq->elements[i]);
2008 queue_push(&solv->branches, -level);
2012 p = dq->elements[i];
2014 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
2016 return setpropagatelearn(solv, level, p, disablerules);
2020 /*-----------------------------------------------------------------*/
2021 /* Main solver interface */
2026 * create solver structure
2028 * pool: all available solvables
2029 * installed: installed Solvables
2032 * Upon solving, rules are created to flag the Solvables
2033 * of the 'installed' Repo as installed.
2037 solver_create(Pool *pool, Repo *installed)
2040 solv = (Solver *)sat_calloc(1, sizeof(Solver));
2042 solv->installed = installed;
2044 queue_init(&solv->ruletojob);
2045 queue_init(&solv->decisionq);
2046 queue_init(&solv->decisionq_why);
2047 queue_init(&solv->problems);
2048 queue_init(&solv->suggestions);
2049 queue_init(&solv->learnt_why);
2050 queue_init(&solv->learnt_pool);
2051 queue_init(&solv->branches);
2052 queue_init(&solv->covenantq);
2054 map_init(&solv->recommendsmap, pool->nsolvables);
2055 map_init(&solv->suggestsmap, pool->nsolvables);
2056 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
2057 solv->recommends_index = 0;
2059 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2061 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
2062 memset(solv->rules, 0, sizeof(Rule));
2073 solver_free(Solver *solv)
2075 queue_free(&solv->ruletojob);
2076 queue_free(&solv->decisionq);
2077 queue_free(&solv->decisionq_why);
2078 queue_free(&solv->learnt_why);
2079 queue_free(&solv->learnt_pool);
2080 queue_free(&solv->problems);
2081 queue_free(&solv->suggestions);
2082 queue_free(&solv->branches);
2083 queue_free(&solv->covenantq);
2085 map_free(&solv->recommendsmap);
2086 map_free(&solv->suggestsmap);
2087 map_free(&solv->noupdate);
2089 sat_free(solv->decisionmap);
2090 sat_free(solv->rules);
2091 sat_free(solv->watches);
2092 sat_free(solv->weaksystemrules);
2093 sat_free(solv->obsoletes);
2094 sat_free(solv->obsoletes_data);
2099 /*-------------------------------------------------------*/
2104 * all rules have been set up, now actually run the solver
2109 run_solver(Solver *solv, int disablerules, int doweak)
2117 Pool *pool = solv->pool;
2120 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2122 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2123 for (i = 0; i < solv->nrules; i++)
2124 printrule(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2127 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2129 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2130 printdecisions(solv);
2132 /* start SAT algorithm */
2134 systemlevel = level + 1;
2135 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2146 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2147 if ((r = propagate(solv, level)) != 0)
2149 if (analyze_unsolvable(solv, r, disablerules))
2157 * installed packages
2160 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2162 if (!solv->updatesystem)
2164 /* try to keep as many packages as possible */
2165 POOL_DEBUG(SAT_DEBUG_STATS, "installing system packages\n");
2166 for (i = solv->installed->start, n = 0; ; i++)
2168 if (n == solv->installed->nsolvables)
2170 if (i == solv->installed->end)
2171 i = solv->installed->start;
2172 s = pool->solvables + i;
2173 if (s->repo != solv->installed)
2176 if (solv->decisionmap[i] != 0)
2178 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2180 level = setpropagatelearn(solv, level, i, disablerules);
2186 if (level <= olevel)
2190 if (solv->weaksystemrules)
2192 POOL_DEBUG(SAT_DEBUG_STATS, "installing weak system packages\n");
2193 for (i = solv->installed->start; i < solv->installed->end; i++)
2195 if (pool->solvables[i].repo != solv->installed)
2197 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
2199 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2200 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2203 if (solv->weaksystemrules[i - solv->installed->start])
2205 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
2206 while ((p = *dp++) != 0)
2208 if (solv->decisionmap[p] > 0)
2210 if (solv->decisionmap[p] == 0)
2214 continue; /* update package already installed */
2216 if (!dq.count && solv->decisionmap[i] != 0)
2219 /* FIXME: i is handled a bit different because we do not want
2220 * to have it pruned just because it is not recommened.
2221 * we should not prune installed packages instead */
2222 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2228 if (level <= olevel)
2231 if (i < solv->installed->end)
2234 systemlevel = level;
2241 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unresolved rules\n");
2242 for (i = 1, n = 1; ; i++, n++)
2244 if (n == solv->nrules)
2246 if (i == solv->nrules)
2248 r = solv->rules + i;
2249 if (!r->w1) /* ignore disabled rules */
2254 /* binary or unary rule */
2255 /* need two positive undecided literals */
2256 if (r->p < 0 || r->w2 <= 0)
2258 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2260 queue_push(&dq, r->p);
2261 queue_push(&dq, r->w2);
2266 * all negative literals are installed
2267 * no positive literal is installed
2268 * i.e. the rule is not fulfilled and we
2269 * just need to decide on the positive literals
2273 if (solv->decisionmap[-r->p] <= 0)
2278 if (solv->decisionmap[r->p] > 0)
2280 if (solv->decisionmap[r->p] == 0)
2281 queue_push(&dq, r->p);
2283 dp = pool->whatprovidesdata + r->d;
2284 while ((p = *dp++) != 0)
2288 if (solv->decisionmap[-p] <= 0)
2293 if (solv->decisionmap[p] > 0)
2295 if (solv->decisionmap[p] == 0)
2302 /* dq.count < 2 cannot happen as this means that
2303 * the rule is unit */
2304 assert(dq.count > 1);
2305 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2307 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2308 printrule(solv, SAT_DEBUG_PROPAGATE, r);
2312 level = selectandinstall(solv, level, &dq, 0, disablerules);
2318 if (level < systemlevel)
2321 } /* for(), decide */
2323 if (n != solv->nrules) /* continue if level < systemlevel */
2326 if (doweak && !solv->problems.count)
2330 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
2331 if (!REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2333 for (i = 0; i < solv->decisionq.count; i++)
2335 p = solv->decisionq.elements[i];
2336 if (p > 0 && pool->solvables[p].repo == solv->installed)
2337 solv->decisionmap[p] = -solv->decisionmap[p];
2341 for (i = 1; i < pool->nsolvables; i++)
2343 if (solv->decisionmap[i] < 0)
2345 if (solv->decisionmap[i] > 0)
2347 Id *recp, rec, *pp, p;
2348 s = pool->solvables + i;
2349 /* installed, check for recommends */
2350 /* XXX need to special case AND ? */
2353 recp = s->repo->idarraydata + s->recommends;
2354 while ((rec = *recp++) != 0)
2357 FOR_PROVIDES(p, pp, rec)
2359 if (solv->decisionmap[p] > 0)
2364 else if (solv->decisionmap[p] == 0)
2366 queue_pushunique(&dq, p);
2374 s = pool->solvables + i;
2375 if (!s->supplements && !s->freshens)
2377 if (!pool_installable(pool, s))
2379 if (solver_is_supplementing(solv, s))
2380 queue_pushunique(&dq, i);
2383 if (!REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2385 for (i = 0; i < solv->decisionq.count; i++)
2387 p = solv->decisionq.elements[i];
2388 if (p > 0 && pool->solvables[p].repo == solv->installed)
2389 solv->decisionmap[p] = -solv->decisionmap[p];
2395 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2397 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2398 level = setpropagatelearn(solv, level, p, 0);
2403 if (solv->solution_callback)
2405 solv->solution_callback(solv, solv->solution_callback_data);
2406 if (solv->branches.count)
2408 int i = solv->branches.count - 1;
2409 int l = -solv->branches.elements[i];
2411 if (solv->branches.elements[i - 1] < 0)
2413 p = solv->branches.elements[i];
2414 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
2416 for (j = i + 1; j < solv->branches.count; j++)
2417 queue_push(&dq, solv->branches.elements[j]);
2418 solv->branches.count = i;
2420 revert(solv, level);
2422 for (j = 0; j < dq.count; j++)
2423 queue_push(&solv->branches, dq.elements[j]);
2425 level = setpropagatelearn(solv, level, p, disablerules);
2433 /* all branches done, we're finally finished */
2437 /* minimization step */
2438 if (solv->branches.count)
2440 int l = 0, lasti = -1, lastl = -1;
2442 for (i = solv->branches.count - 1; i >= 0; i--)
2444 p = solv->branches.elements[i];
2447 else if (p > 0 && solv->decisionmap[p] > l + 1)
2455 /* kill old solvable so that we do not loop */
2456 p = solv->branches.elements[lasti];
2457 solv->branches.elements[lasti] = 0;
2458 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
2461 revert(solv, level);
2463 level = setpropagatelearn(solv, level, p, disablerules);
2480 * at this point, all rules that led to conflicts are disabled.
2481 * we re-enable all rules of a problem set but rule "sug", then
2482 * continue to disable more rules until there as again a solution.
2485 /* FIXME: think about conflicting assertions */
2488 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2490 Pool *pool = solv->pool;
2497 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2499 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
2500 for (i = 0; problem[i]; i++)
2502 if (problem[i] == sug)
2503 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
2504 printproblem(solv, problem[i]);
2507 queue_init(&disabled);
2508 queue_empty(refined);
2509 queue_push(refined, sug);
2511 /* re-enable all problem rules with the exception of "sug" */
2515 for (i = 0; problem[i]; i++)
2516 if (problem[i] != sug)
2517 enableproblem(solv, problem[i]);
2520 disableupdaterules(solv, job, -(sug + 1));
2524 /* re-enable as many weak rules as possible */
2525 for (i = solv->weakrules; i < solv->learntrules; i++)
2527 r = solv->rules + i;
2529 enablerule(solv, r);
2532 queue_empty(&solv->problems);
2533 revert(solv, 1); /* XXX move to reset_solver? */
2536 if (!solv->problems.count)
2537 run_solver(solv, 0, 0);
2539 if (!solv->problems.count)
2541 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
2542 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2543 printdecisions(solv);
2544 break; /* great, no more problems */
2546 disabledcnt = disabled.count;
2547 /* start with 1 to skip over proof index */
2548 for (i = 1; i < solv->problems.count - 1; i++)
2550 /* ignore solutions in refined */
2551 v = solv->problems.elements[i];
2553 break; /* end of problem reached */
2554 for (j = 0; problem[j]; j++)
2555 if (problem[j] != sug && problem[j] == v)
2559 queue_push(&disabled, v);
2561 if (disabled.count == disabledcnt)
2563 /* no solution found, this was an invalid suggestion! */
2564 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
2568 if (disabled.count == disabledcnt + 1)
2570 /* just one suggestion, add it to refined list */
2571 v = disabled.elements[disabledcnt];
2572 queue_push(refined, v);
2573 disableproblem(solv, v);
2575 disableupdaterules(solv, job, -(v + 1));
2579 /* more than one solution, disable all */
2580 /* do not push anything on refine list */
2581 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2583 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
2584 for (i = disabledcnt; i < disabled.count; i++)
2585 printproblem(solv, disabled.elements[i]);
2587 for (i = disabledcnt; i < disabled.count; i++)
2588 disableproblem(solv, disabled.elements[i]);
2591 /* all done, get us back into the same state as before */
2592 /* enable refined rules again */
2593 for (i = 0; i < disabled.count; i++)
2594 enableproblem(solv, disabled.elements[i]);
2595 /* disable problem rules again */
2596 for (i = 0; problem[i]; i++)
2597 disableproblem(solv, problem[i]);
2598 disableupdaterules(solv, job, -1);
2599 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
2603 problems_to_solutions(Solver *solv, Queue *job)
2605 Pool *pool = solv->pool;
2613 if (!solv->problems.count)
2615 queue_clone(&problems, &solv->problems);
2616 queue_init(&solution);
2617 queue_init(&solutions);
2618 /* copy over proof index */
2619 queue_push(&solutions, problems.elements[0]);
2620 problem = problems.elements + 1;
2621 for (i = 1; i < problems.count; i++)
2623 Id v = problems.elements[i];
2626 /* mark end of this problem */
2627 queue_push(&solutions, 0);
2628 queue_push(&solutions, 0);
2629 if (i + 1 == problems.count)
2631 /* copy over proof of next problem */
2632 queue_push(&solutions, problems.elements[i + 1]);
2634 problem = problems.elements + i + 1;
2637 refine_suggestion(solv, job, problem, v, &solution);
2638 if (!solution.count)
2639 continue; /* this solution didn't work out */
2641 for (j = 0; j < solution.count; j++)
2643 why = solution.elements[j];
2644 /* must be either job descriptor or system rule */
2645 assert(why < 0 || (why >= solv->systemrules && why < solv->weakrules));
2647 printproblem(solv, why);
2651 /* job descriptor */
2652 queue_push(&solutions, 0);
2653 queue_push(&solutions, -why);
2657 /* system rule, find replacement package */
2659 p = solv->installed->start + (why - solv->systemrules);
2660 if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
2662 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
2665 if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
2667 if (solv->decisionmap[*dp] > 0)
2674 queue_push(&solutions, p);
2675 queue_push(&solutions, rp);
2678 /* mark end of this solution */
2679 queue_push(&solutions, 0);
2680 queue_push(&solutions, 0);
2682 queue_free(&solution);
2683 queue_free(&problems);
2684 /* copy queue over to solutions */
2685 queue_free(&solv->problems);
2686 queue_clone(&solv->problems, &solutions);
2688 /* bring solver back into problem state */
2689 revert(solv, 1); /* XXX move to reset_solver? */
2692 assert(solv->problems.count == solutions.count);
2693 queue_free(&solutions);
2697 solver_next_problem(Solver *solv, Id problem)
2701 return solv->problems.count ? 1 : 0;
2702 pp = solv->problems.elements + problem;
2703 while (pp[0] || pp[1])
2707 while (pp[0] || pp[1])
2712 problem = pp - solv->problems.elements;
2713 if (problem >= solv->problems.count)
2719 solver_next_solution(Solver *solv, Id problem, Id solution)
2725 pp = solv->problems.elements + solution;
2726 return pp[0] || pp[1] ? solution : 0;
2728 pp = solv->problems.elements + solution;
2729 while (pp[0] || pp[1])
2732 solution = pp - solv->problems.elements;
2733 return pp[0] || pp[1] ? solution : 0;
2737 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
2740 element = element ? element + 2 : solution;
2741 pp = solv->problems.elements + element;
2742 if (!(pp[0] || pp[1]))
2751 * create obsoletesmap from solver decisions
2752 * required for decision handling
2756 create_decisions_obsoletesmap(Solver *solv)
2758 Pool *pool = solv->pool;
2759 Repo *installed = solv->installed;
2760 Id p, *obsoletesmap = NULL;
2764 obsoletesmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2767 for (i = 0; i < solv->decisionq.count; i++)
2771 n = solv->decisionq.elements[i];
2774 if (n == SYSTEMSOLVABLE)
2776 s = pool->solvables + n;
2777 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2779 FOR_PROVIDES(p, pp, s->name)
2780 if (s->name == pool->solvables[p].name)
2782 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2784 obsoletesmap[p] = n;
2789 for (i = 0; i < solv->decisionq.count; i++)
2794 n = solv->decisionq.elements[i];
2797 if (n == SYSTEMSOLVABLE)
2799 s = pool->solvables + n;
2800 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2804 obsp = s->repo->idarraydata + s->obsoletes;
2805 while ((obs = *obsp++) != 0)
2806 FOR_PROVIDES(p, pp, obs)
2808 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2810 obsoletesmap[p] = n;
2816 return obsoletesmap;
2825 printdecisions(Solver *solv)
2827 Pool *pool = solv->pool;
2828 Repo *installed = solv->installed;
2829 Id p, *obsoletesmap = create_decisions_obsoletesmap( solv );
2833 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
2835 /* print solvables to be erased */
2839 FOR_REPO_SOLVABLES(installed, p, s)
2841 if (solv->decisionmap[p] >= 0)
2843 if (obsoletesmap[p])
2845 POOL_DEBUG(SAT_DEBUG_RESULT, "erase %s\n", solvable2str(pool, s));
2849 /* print solvables to be installed */
2851 for (i = 0; i < solv->decisionq.count; i++)
2854 p = solv->decisionq.elements[i];
2857 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2860 s = pool->solvables + p;
2861 POOL_DEBUG(SAT_DEBUG_SCHUBI, "level of %s is %d\n", solvable2str(pool, s), p);
2865 if (p == SYSTEMSOLVABLE)
2867 POOL_DEBUG(SAT_DEBUG_SCHUBI, "SYSTEMSOLVABLE\n");
2870 s = pool->solvables + p;
2871 if (installed && s->repo == installed)
2874 if (!obsoletesmap[p])
2876 POOL_DEBUG(SAT_DEBUG_RESULT, "install %s", solvable2str(pool, s));
2880 POOL_DEBUG(SAT_DEBUG_RESULT, "update %s", solvable2str(pool, s));
2881 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
2882 for (j = installed->start; j < installed->end; j++)
2883 if (obsoletesmap[j] == p)
2884 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
2885 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
2887 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
2890 sat_free(obsoletesmap);
2892 if (solv->suggestions.count)
2894 POOL_DEBUG(SAT_DEBUG_RESULT, "\nsuggested packages:\n");
2895 for (i = 0; i < solv->suggestions.count; i++)
2897 s = pool->solvables + solv->suggestions.elements[i];
2898 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
2901 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
2904 /* this is basically the reverse of addrpmrulesforsolvable */
2906 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
2908 Pool *pool = solv->pool;
2909 Repo *installed = solv->installed;
2913 Id p, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
2915 assert(rid < solv->weakrules);
2916 if (rid >= solv->systemrules)
2919 *sourcep = solv->installed->start + (rid - solv->systemrules);
2921 return SOLVER_PROBLEM_UPDATE_RULE;
2923 if (rid >= solv->jobrules)
2926 r = solv->rules + rid;
2927 p = solv->ruletojob.elements[rid - solv->jobrules];
2928 *depp = job->elements[p + 1];
2930 *targetp = job->elements[p];
2931 if (r->d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE)
2932 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
2933 return SOLVER_PROBLEM_JOB_RULE;
2937 /* a rpm rule assertion */
2938 assert(rid != -SYSTEMSOLVABLE);
2939 s = pool->solvables - rid;
2940 if (installed && !solv->fixsystem && s->repo == installed)
2942 assert(!dontfix); /* dontfix packages never have a neg assertion */
2943 /* see why the package is not installable */
2944 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
2945 return SOLVER_PROBLEM_NOT_INSTALLABLE;
2946 /* check requires */
2947 assert(s->requires);
2948 reqp = s->repo->idarraydata + s->requires;
2949 while ((req = *reqp++) != 0)
2951 if (req == SOLVABLE_PREREQMARKER)
2953 dp = pool_whatprovides(pool, req);
2961 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
2963 r = solv->rules + rid;
2965 if (r->d == 0 && r->w2 == 0)
2967 /* an assertion. we don't store them as rpm rules, so
2971 s = pool->solvables - r->p;
2972 if (installed && !solv->fixsystem && s->repo == installed)
2974 if (r->d == 0 && r->w2 < 0)
2976 /* a package conflict */
2977 Solvable *s2 = pool->solvables - r->w2;
2980 if (installed && !solv->fixsystem && s2->repo == installed)
2983 /* if both packages have the same name and at least one of them
2984 * is not installed, they conflict */
2985 if (s->name == s2->name && (!installed || (s->repo != installed || s2->repo != installed)))
2990 return SOLVER_PROBLEM_SAME_NAME;
2993 /* check conflicts in both directions */
2996 conp = s->repo->idarraydata + s->conflicts;
2997 while ((con = *conp++) != 0)
2999 FOR_PROVIDES(p, pp, con)
3001 if (dontfix && pool->solvables[p].repo == installed)
3008 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3014 conp = s2->repo->idarraydata + s2->conflicts;
3015 while ((con = *conp++) != 0)
3017 FOR_PROVIDES(p, pp, con)
3019 if (dontfix2 && pool->solvables[p].repo == installed)
3026 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3030 /* check obsoletes in both directions */
3031 if ((!installed || s->repo != installed) && s->obsoletes)
3033 obsp = s->repo->idarraydata + s->obsoletes;
3034 while ((obs = *obsp++) != 0)
3036 FOR_PROVIDES(p, pp, obs)
3043 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3047 if ((!installed || s2->repo != installed) && s2->obsoletes)
3049 obsp = s2->repo->idarraydata + s2->obsoletes;
3050 while ((obs = *obsp++) != 0)
3052 FOR_PROVIDES(p, pp, obs)
3059 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3063 /* all cases checked, can't happen */
3066 /* simple requires */
3067 assert(s->requires);
3068 reqp = s->repo->idarraydata + s->requires;
3069 while ((req = *reqp++) != 0)
3071 if (req == SOLVABLE_PREREQMARKER)
3073 dp = pool_whatprovides(pool, req);
3076 if (*dp == r->w2 && dp[1] == 0)
3079 else if (dp - pool->whatprovidesdata == r->d)
3086 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
3090 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3093 Id lreqr, lconr, lsysr, ljobr;
3097 lreqr = lconr = lsysr = ljobr = 0;
3098 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3100 if (rid >= solv->learntrules)
3101 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3102 else if (rid >= solv->systemrules)
3107 else if (rid >= solv->jobrules)
3114 r = solv->rules + rid;
3115 if (!r->d && r->w2 < 0)
3128 /* assertion, counts as require rule */
3129 /* ignore system solvable as we need useful info */
3130 if (rid == -SYSTEMSOLVABLE)
3132 if (!*reqrp || !reqassert)
3139 if (!*reqrp && lreqr)
3141 if (!*conrp && lconr)
3143 if (!*jobrp && ljobr)
3145 if (!*sysrp && lsysr)
3150 solver_findproblemrule(Solver *solv, Id problem)
3152 Id reqr, conr, sysr, jobr;
3153 Id idx = solv->problems.elements[problem - 1];
3154 reqr = conr = sysr = jobr = 0;
3155 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3168 printprobleminfo(Solver *solv, Queue *job, Id problem)
3170 Pool *pool = solv->pool;
3172 Id dep, source, target;
3175 probr = solver_findproblemrule(solv, problem);
3176 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
3178 case SOLVER_PROBLEM_UPDATE_RULE:
3179 s = pool_id2solvable(pool, source);
3180 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
3182 case SOLVER_PROBLEM_JOB_RULE:
3183 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
3185 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
3186 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
3188 case SOLVER_PROBLEM_NOT_INSTALLABLE:
3189 s = pool_id2solvable(pool, source);
3190 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
3192 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
3193 s = pool_id2solvable(pool, source);
3194 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
3196 case SOLVER_PROBLEM_SAME_NAME:
3197 s = pool_id2solvable(pool, source);
3198 s2 = pool_id2solvable(pool, target);
3199 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
3201 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
3202 s = pool_id2solvable(pool, source);
3203 s2 = pool_id2solvable(pool, target);
3204 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3206 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
3207 s = pool_id2solvable(pool, source);
3208 s2 = pool_id2solvable(pool, target);
3209 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3211 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
3212 s = pool_id2solvable(pool, source);
3213 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
3219 printsolutions(Solver *solv, Queue *job)
3221 Pool *pool = solv->pool;
3224 Id problem, solution, element;
3227 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
3230 while ((problem = solver_next_problem(solv, problem)) != 0)
3232 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
3233 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
3234 printprobleminfo(solv, job, problem);
3235 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3237 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
3240 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
3244 /* job, rp is index into job queue */
3245 what = job->elements[rp];
3246 switch (job->elements[rp - 1])
3248 case SOLVER_INSTALL_SOLVABLE:
3249 s = pool->solvables + what;
3250 if (solv->installed && s->repo == solv->installed)
3251 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, s));
3253 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solvable2str(pool, s));
3255 case SOLVER_ERASE_SOLVABLE:
3256 s = pool->solvables + what;
3257 if (solv->installed && s->repo == solv->installed)
3258 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solvable2str(pool, s));
3260 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, s));
3262 case SOLVER_INSTALL_SOLVABLE_NAME:
3263 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", id2str(pool, what));
3265 case SOLVER_ERASE_SOLVABLE_NAME:
3266 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", id2str(pool, what));
3268 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3269 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable providing %s\n", dep2str(pool, what));
3271 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3272 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables providing %s\n", dep2str(pool, what));
3274 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3275 s = pool->solvables + what;
3276 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solvable2str(pool, s));
3279 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
3285 /* policy, replace p with rp */
3286 s = pool->solvables + p;
3287 sd = rp ? pool->solvables + rp : 0;
3291 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
3293 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3296 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, pool, s, sd))
3298 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3301 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv,pool, s, sd))
3304 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));
3306 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));
3310 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3314 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
3319 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3325 /* create reverse obsoletes map for installed solvables
3327 * for each installed solvable find which packages with *different* names
3328 * obsolete the solvable.
3329 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3333 create_obsolete_index(Solver *solv)
3335 Pool *pool = solv->pool;
3337 Repo *installed = solv->installed;
3338 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3341 if (!installed || !installed->nsolvables)
3343 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
3344 for (i = 1; i < pool->nsolvables; i++)
3346 s = pool->solvables + i;
3347 if (s->repo == installed)
3351 if (!pool_installable(pool, s))
3353 obsp = s->repo->idarraydata + s->obsoletes;
3354 while ((obs = *obsp++) != 0)
3355 FOR_PROVIDES(p, pp, obs)
3357 if (pool->solvables[p].repo != installed)
3359 if (pool->solvables[p].name == s->name)
3361 obsoletes[p - installed->start]++;
3365 for (i = 0; i < installed->nsolvables; i++)
3368 n += obsoletes[i] + 1;
3371 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
3372 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
3373 for (i = pool->nsolvables - 1; i > 0; i--)
3375 s = pool->solvables + i;
3376 if (s->repo == installed)
3380 if (!pool_installable(pool, s))
3382 obsp = s->repo->idarraydata + s->obsoletes;
3383 while ((obs = *obsp++) != 0)
3384 FOR_PROVIDES(p, pp, obs)
3386 if (pool->solvables[p].repo != installed)
3388 if (pool->solvables[p].name == s->name)
3390 p -= installed->start;
3391 if (obsoletes_data[obsoletes[p]] != i)
3392 obsoletes_data[--obsoletes[p]] = i;
3398 /*-----------------------------------------------------------------*/
3408 solver_solve(Solver *solv, Queue *job)
3410 Pool *pool = solv->pool;
3411 Repo *installed = solv->installed;
3414 Map addedmap; /* '1' == have rpm-rules for solvable */
3415 Id how, what, p, *pp, d;
3419 /* create whatprovides if not already there */
3420 if (!pool->whatprovides)
3421 pool_createwhatprovides(pool);
3423 /* create obsolete index if needed */
3424 if (solv->noupdateprovide)
3425 create_obsolete_index(solv);
3428 * create basic rule set of all involved packages
3429 * use addedmap bitmap to make sure we don't create rules twice
3433 map_init(&addedmap, pool->nsolvables);
3437 * always install our system solvable
3439 MAPSET(&addedmap, SYSTEMSOLVABLE);
3440 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3441 queue_push(&solv->decisionq_why, 0);
3442 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3445 * create rules for all package that could be involved with the solving
3446 * so called: rpm rules
3451 oldnrules = solv->nrules;
3452 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
3453 FOR_REPO_SOLVABLES(installed, p, s)
3454 addrpmrulesforsolvable(solv, s, &addedmap);
3455 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3456 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
3457 oldnrules = solv->nrules;
3458 FOR_REPO_SOLVABLES(installed, p, s)
3459 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3460 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3463 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
3464 oldnrules = solv->nrules;
3465 for (i = 0; i < job->count; i += 2)
3467 how = job->elements[i];
3468 what = job->elements[i + 1];
3472 case SOLVER_INSTALL_SOLVABLE:
3473 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3475 case SOLVER_INSTALL_SOLVABLE_NAME:
3476 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3477 FOR_PROVIDES(p, pp, what)
3479 /* if by name, ensure that the name matches */
3480 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3482 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3485 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3486 /* dont allow downgrade */
3487 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3491 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3493 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
3495 oldnrules = solv->nrules;
3496 addrpmrulesforweak(solv, &addedmap);
3497 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3499 IF_POOLDEBUG (SAT_DEBUG_STATS)
3501 int possible = 0, installable = 0;
3502 for (i = 1; i < pool->nsolvables; i++)
3504 if (pool_installable(pool, pool->solvables + i))
3506 if (MAPTST(&addedmap, i))
3509 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving (rules has been generated for)\n", possible, installable);
3513 * first pass done, we now have all the rpm rules we need.
3514 * unify existing rules before going over all job rules and
3516 * at this point the system is always solvable,
3517 * as an empty system (remove all packages) is a valid solution
3520 unifyrules(solv); /* remove duplicate rpm rules */
3521 solv->directdecisions = solv->decisionq.count;
3523 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
3524 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3525 printdecisions (solv);
3528 * now add all job rules
3531 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
3533 solv->jobrules = solv->nrules;
3535 for (i = 0; i < job->count; i += 2)
3537 oldnrules = solv->nrules;
3539 how = job->elements[i];
3540 what = job->elements[i + 1];
3543 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3544 s = pool->solvables + what;
3545 POOL_DEBUG(SAT_DEBUG_JOB, "job: install solvable %s\n", solvable2str(pool, s));
3546 addrule(solv, what, 0); /* install by Id */
3547 queue_push(&solv->ruletojob, i);
3549 case SOLVER_ERASE_SOLVABLE:
3550 s = pool->solvables + what;
3551 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase solvable %s\n", solvable2str(pool, s));
3552 addrule(solv, -what, 0); /* remove by Id */
3553 queue_push(&solv->ruletojob, i);
3555 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3556 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3557 if (how == SOLVER_INSTALL_SOLVABLE_NAME)
3558 POOL_DEBUG(SAT_DEBUG_JOB, "job: install name %s\n", id2str(pool, what));
3559 if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3560 POOL_DEBUG(SAT_DEBUG_JOB, "job: install provides %s\n", dep2str(pool, what));
3562 FOR_PROVIDES(p, pp, what)
3564 /* if by name, ensure that the name matches */
3565 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3571 /* no provider, make this an impossible rule */
3572 queue_push(&q, -SYSTEMSOLVABLE);
3575 p = queue_shift(&q); /* get first provider */
3577 d = 0; /* single provider ? -> make assertion */
3579 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3580 addrule(solv, p, d); /* add 'requires' rule */
3581 queue_push(&solv->ruletojob, i);
3583 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3584 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3585 if (how == SOLVER_ERASE_SOLVABLE_NAME)
3586 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase name %s\n", id2str(pool, what));
3587 if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3588 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase provides %s\n", dep2str(pool, what));
3589 FOR_PROVIDES(p, pp, what)
3591 /* if by name, ensure that the name matches */
3592 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
3594 addrule(solv, -p, 0); /* add 'remove' rule */
3595 queue_push(&solv->ruletojob, i);
3598 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3599 s = pool->solvables + what;
3600 POOL_DEBUG(SAT_DEBUG_JOB, "job: update %s\n", solvable2str(pool, s));
3601 addupdaterule(solv, s, 0);
3602 queue_push(&solv->ruletojob, i);
3605 IF_POOLDEBUG (SAT_DEBUG_JOB)
3608 if (solv->nrules == oldnrules)
3609 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created");
3610 for (j = oldnrules; j < solv->nrules; j++)
3612 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
3613 printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
3617 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3620 * now add system rules
3624 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add system rules ***\n");
3627 solv->systemrules = solv->nrules;
3630 * create rules for updating installed solvables
3634 if (installed && !solv->allowuninstall)
3635 { /* loop over all installed solvables */
3636 /* we create all update rules, but disable some later on depending on the job */
3637 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3639 /* no system rules for patch atoms */
3640 if (s->freshens && !s->supplements)
3642 const char *name = id2str(pool, s->name);
3643 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
3645 addrule(solv, 0, 0);
3649 if (s->repo == installed)
3650 addupdaterule(solv, s, 0); /* allowall = 0 */
3652 addrule(solv, 0, 0); /* create dummy rule */
3654 /* consistency check: we added a rule for _every_ system solvable */
3655 assert(solv->nrules - solv->systemrules == installed->end - installed->start);
3658 /* create special weak system rules */
3659 /* those are used later on to keep a version of the installed packages in
3661 if (installed && installed->nsolvables)
3663 solv->weaksystemrules = sat_calloc(installed->end - installed->start, sizeof(Id));
3664 FOR_REPO_SOLVABLES(installed, p, s)
3666 policy_findupdatepackages(solv, s, &q, 1);
3668 solv->weaksystemrules[p - installed->start] = pool_queuetowhatprovides(pool, &q);
3672 /* free unneeded memory */
3673 map_free(&addedmap);
3676 solv->weakrules = solv->nrules;
3678 /* try real hard to keep packages installed */
3681 FOR_REPO_SOLVABLES(installed, p, s)
3683 /* FIXME: can't work with refine_suggestion! */
3684 /* need to always add the rule but disable it */
3685 if (MAPTST(&solv->noupdate, p - installed->start))
3687 d = solv->weaksystemrules[p - installed->start];
3688 addrule(solv, p, d);
3692 /* all new rules are learnt after this point */
3693 solv->learntrules = solv->nrules;
3695 /* disable system rules that conflict with our job */
3696 disableupdaterules(solv, job, -1);
3698 /* make decisions based on job/system assertions */
3699 makeruledecisions(solv);
3701 /* create watches chains */
3704 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
3707 run_solver(solv, 1, 1);
3709 /* find suggested packages */
3710 if (!solv->problems.count)
3712 Id sug, *sugp, p, *pp;
3714 /* create map of all suggests that are still open */
3715 solv->recommends_index = -1;
3716 MAPZERO(&solv->suggestsmap);
3717 for (i = 0; i < solv->decisionq.count; i++)
3719 p = solv->decisionq.elements[i];
3722 s = pool->solvables + p;
3725 sugp = s->repo->idarraydata + s->suggests;
3726 while ((sug = *sugp++) != 0)
3728 FOR_PROVIDES(p, pp, sug)
3729 if (solv->decisionmap[p] > 0)
3732 continue; /* already fulfilled */
3733 FOR_PROVIDES(p, pp, sug)
3734 MAPSET(&solv->suggestsmap, p);
3738 for (i = 1; i < pool->nsolvables; i++)
3740 if (solv->decisionmap[i] != 0)
3742 s = pool->solvables + i;
3743 if (!MAPTST(&solv->suggestsmap, i))
3747 if (!pool_installable(pool, s))
3749 if (!solver_is_enhancing(solv, s))
3752 queue_push(&solv->suggestions, i);
3754 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
3757 if (solv->problems.count)
3758 problems_to_solutions(solv, job);