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 1
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 Id p = r - solv->rules;
197 if (p < solv->learntrules)
198 if (MAPTST(&solv->weakrulemap, p))
199 POOL_DEBUG(type, "WEAK ");
200 if (p >= solv->learntrules)
201 POOL_DEBUG(type, "LEARNT ");
202 else if (p >= solv->systemrules)
203 POOL_DEBUG(type, "SYSTEM ");
204 else if (p >= solv->jobrules)
205 POOL_DEBUG(type, "JOB ");
206 printrule(solv, type, r);
210 /*-----------------------------------------------------------------*/
216 static Pool *unifyrules_sortcmp_data;
219 * compare rules for unification sort
223 unifyrules_sortcmp(const void *ap, const void *bp)
225 Pool *pool = unifyrules_sortcmp_data;
226 Rule *a = (Rule *)ap;
227 Rule *b = (Rule *)bp;
233 return x; /* p differs */
236 if (a->d == 0 && b->d == 0)
237 return a->w2 - b->w2; /* assertion: return w2 diff */
239 if (a->d == 0) /* a is assertion, b not */
241 x = a->w2 - pool->whatprovidesdata[b->d];
245 if (b->d == 0) /* b is assertion, a not */
247 x = pool->whatprovidesdata[a->d] - b->w2;
251 /* compare whatprovidesdata */
252 ad = pool->whatprovidesdata + a->d;
253 bd = pool->whatprovidesdata + b->d;
255 if ((x = *ad++ - *bd++) != 0)
266 unifyrules(Solver *solv)
268 Pool *pool = solv->pool;
272 if (solv->nrules <= 1) /* nothing to unify */
275 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
277 /* sort rules first */
278 unifyrules_sortcmp_data = solv->pool;
279 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
286 for (i = j = 1, ir = solv->rules + 1; i < solv->nrules; i++, ir++)
288 if (jr && !unifyrules_sortcmp(ir, jr))
289 continue; /* prune! */
290 jr = solv->rules + j++; /* keep! */
295 /* reduced count from nrules to j rules */
296 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
298 /* adapt rule buffer */
300 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
301 IF_POOLDEBUG (SAT_DEBUG_STATS)
308 for (i = 1; i < solv->nrules; i++)
315 dp = solv->pool->whatprovidesdata + r->d;
320 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
321 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
323 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
333 hashrule(Solver *solv, Id p, Id d, int n)
335 unsigned int x = (unsigned int)p;
339 return (x * 37) ^ (unsigned int)d;
340 dp = solv->pool->whatprovidesdata + d;
342 x = (x * 37) ^ (unsigned int)*dp++;
350 * p = direct literal; always < 0 for installed rpm rules
351 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
354 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
356 * p < 0 : pkg id of A
357 * d > 0 : Offset in whatprovidesdata (list of providers of b)
359 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
360 * p < 0 : pkg id of A
361 * d < 0 : Id of solvable (e.g. B1)
363 * d == 0: unary rule, assertion => (A) or (-A)
365 * Install: p > 0, d = 0 (A) user requested install
366 * Remove: p < 0, d = 0 (-A) user requested remove
367 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
368 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
369 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
370 * ? p > 0, d < 0 (A|-B)
371 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
375 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
376 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
377 * every other : w1 = p, w2 = whatprovidesdata[d];
378 * Disabled rule: w1 = 0
380 * always returns a rule for non-rpm rules
384 addrule(Solver *solv, Id p, Id d)
386 Pool *pool = solv->pool;
390 int n = 0; /* number of literals in rule - 1
391 0 = direct assertion (single literal)
395 /* it often happenes that requires lead to adding the same rpm rule
396 * multiple times, so we prune those duplicates right away to make
397 * the work for unifyrules a bit easier */
399 if (solv->nrules && !solv->jobrules)
401 r = solv->rules + solv->nrules - 1; /* get the last added rule */
402 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
408 /* always a binary rule */
410 return 0; /* ignore self conflict */
415 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
417 return 0; /* rule is self-fulfilling */
419 d = dp[-1]; /* take single literal */
423 if (n == 0 && !solv->jobrules)
425 /* this is a rpm rule assertion, we do not have to allocate it */
426 /* it can be identified by a level of 1 and a zero reason */
427 /* we must not drop those rules from the decisionq when rewinding! */
429 assert(solv->decisionmap[-p] == 0 || solv->decisionmap[-p] == -1);
430 if (solv->decisionmap[-p])
431 return 0; /* already got that one */
432 queue_push(&solv->decisionq, p);
433 queue_push(&solv->decisionq_why, 0);
434 solv->decisionmap[-p] = -1;
441 /* smallest literal first so we can find dups */
445 n = 1; /* re-set n, was used as temp var */
448 /* check if the last added rule is exactly the same as what we're looking for. */
449 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
450 return r; /* binary rule */
452 if (r && n > 1 && r->d && r->p == p)
454 /* Rule where d is an offset in whatprovidesdata */
458 dp2 = pool->whatprovidesdata + r->d;
459 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
470 /* extend rule buffer */
471 solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
472 r = solv->rules + solv->nrules++; /* point to rule space */
477 /* direct assertion, no watch needed */
493 r->w2 = pool->whatprovidesdata[d];
498 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
500 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
501 printrule(solv, SAT_DEBUG_RULE_CREATION, r);
508 disablerule(Solver *solv, Rule *r)
514 enablerule(Solver *solv, Rule *r)
516 if (r->d == 0 || r->w2 != r->p)
519 r->w1 = solv->pool->whatprovidesdata[r->d];
523 /**********************************************************************************/
525 /* a problem is an item on the solver's problem list. It can either be >0, in that
526 * case it is a system (upgrade) rule, or it can be <0, which makes it refer to a job
527 * consisting of multiple job rules.
531 disableproblem(Solver *solv, Id v)
539 disablerule(solv, solv->rules + v);
543 jp = solv->ruletojob.elements;
544 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
546 disablerule(solv, r);
550 enableproblem(Solver *solv, Id v)
558 enablerule(solv, solv->rules + v);
562 jp = solv->ruletojob.elements;
563 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
569 printproblem(Solver *solv, Id v)
571 Pool *pool = solv->pool;
577 printrule(solv, SAT_DEBUG_SOLUTIONS, solv->rules + v);
581 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "JOB %d\n", v);
582 jp = solv->ruletojob.elements;
583 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
586 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "- ");
587 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
589 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "ENDJOB\n");
595 /************************************************************************/
597 /* go through system and job rules and add direct assertions
598 * to the decisionqueue. If we find a conflict, disable rules and
599 * add them to problem queue.
602 makeruledecisions(Solver *solv)
604 Pool *pool = solv->pool;
610 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
612 decisionstart = solv->decisionq.count;
613 /* rpm rules don't have assertions, so we can start with the job
614 * rules (rpm assertions are not resulting in a rule, but cause a
615 * immediate decision) */
616 /* nowadays they can be weak, so start with rule 1 */
617 for (ri = 1, r = solv->rules + ri; ri < solv->nrules; ri++, r++)
619 if (!r->w1 || r->w2) /* disabled or no assertion */
621 /* do weak rules in phase 2 */
622 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
626 if (!solv->decisionmap[vv])
628 queue_push(&solv->decisionq, v);
629 queue_push(&solv->decisionq_why, r - solv->rules);
630 solv->decisionmap[vv] = v > 0 ? 1 : -1;
631 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
633 Solvable *s = solv->pool->solvables + vv;
635 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
637 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
641 if (v > 0 && solv->decisionmap[vv] > 0)
643 if (v < 0 && solv->decisionmap[vv] < 0)
645 /* found a conflict! */
646 if (ri >= solv->learntrules)
648 /* conflict with a learnt rule */
649 /* can happen when packages cannot be installed for
650 * multiple reasons. */
651 /* we disable the learnt rule in this case */
652 disablerule(solv, r);
655 /* only job and system rules left in the decisionq */
656 /* find the decision which is the "opposite" of the jobrule */
657 for (i = 0; i < solv->decisionq.count; i++)
658 if (solv->decisionq.elements[i] == -v)
660 assert(i < solv->decisionq.count);
662 if (solv->decisionq_why.elements[i] == 0)
664 /* conflict with rpm rule, need only disable our rule */
665 assert(v > 0 || v == -SYSTEMSOLVABLE);
667 queue_push(&solv->problems, solv->learnt_pool.count);
668 queue_push(&solv->learnt_pool, ri);
669 queue_push(&solv->learnt_pool, v != -SYSTEMSOLVABLE ? -v : v);
670 queue_push(&solv->learnt_pool, 0);
671 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
672 if (ri < solv->systemrules)
673 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
676 queue_push(&solv->problems, v);
677 queue_push(&solv->problems, 0);
678 disableproblem(solv, v);
681 if (solv->decisionq_why.elements[i] < solv->jobrules)
683 /* conflict with rpm rule assertion */
684 queue_push(&solv->problems, solv->learnt_pool.count);
685 queue_push(&solv->learnt_pool, ri);
686 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
687 queue_push(&solv->learnt_pool, 0);
688 assert(v > 0 || v == -SYSTEMSOLVABLE);
689 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
690 if (ri < solv->systemrules)
691 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
694 queue_push(&solv->problems, v);
695 queue_push(&solv->problems, 0);
696 disableproblem(solv, v);
700 /* conflict with another job or system rule */
702 queue_push(&solv->problems, solv->learnt_pool.count);
703 queue_push(&solv->learnt_pool, ri);
704 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
705 queue_push(&solv->learnt_pool, 0);
707 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting system/job assertions over literal %d\n", vv);
709 /* push all of our rules asserting this literal on the problem stack */
710 for (i = solv->jobrules, rr = solv->rules + i; i < solv->nrules; i++, rr++)
712 if (!rr->w1 || rr->w2)
714 if (rr->p != vv && rr->p != -vv)
716 if (i >= solv->learntrules)
718 if (MAPTST(&solv->weakrulemap, i))
720 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
722 if (i < solv->systemrules)
723 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
724 queue_push(&solv->problems, v);
725 disableproblem(solv, v);
727 queue_push(&solv->problems, 0);
730 while (solv->decisionq.count > decisionstart)
732 v = solv->decisionq.elements[--solv->decisionq.count];
733 --solv->decisionq_why.count;
735 solv->decisionmap[vv] = 0;
737 ri = solv->jobrules - 1;
738 r = solv->rules + ri;
741 /* phase 2: now do the weak assertions */
742 for (ri = 1, r = solv->rules + ri; ri < solv->learntrules; ri++, r++)
744 if (!r->w1 || r->w2) /* disabled or no assertion */
746 if (!MAPTST(&solv->weakrulemap, ri))
750 if (!solv->decisionmap[vv])
752 queue_push(&solv->decisionq, v);
753 queue_push(&solv->decisionq_why, r - solv->rules);
754 solv->decisionmap[vv] = v > 0 ? 1 : -1;
755 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
757 Solvable *s = solv->pool->solvables + vv;
759 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", solvable2str(solv->pool, s));
761 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", solvable2str(solv->pool, s));
765 if (v > 0 && solv->decisionmap[vv] > 0)
767 if (v < 0 && solv->decisionmap[vv] < 0)
769 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
770 printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
771 disablerule(solv, r);
774 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
778 * we have enabled or disabled some of our rules. We now reenable all
779 * of our learnt rules but the ones that were learnt from rules that
783 enabledisablelearntrules(Solver *solv)
785 Pool *pool = solv->pool;
790 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
791 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
793 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
794 while ((why = *whyp++) != 0)
798 continue; /* rpm assertion */
801 if (!solv->rules[why].w1)
804 /* why != 0: we found a disabled rule, disable the learnt rule */
807 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
809 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling ");
810 printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
812 disablerule(solv, r);
814 else if (!why && !r->w1)
816 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
818 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling ");
819 printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
827 /* FIXME: bad code ahead, replace as soon as possible */
829 disableupdaterules(Solver *solv, Queue *job, int jobidx)
831 Pool *pool = solv->pool;
833 Id name, how, what, p, *pp;
839 installed = solv->installed;
845 how = job->elements[jobidx] & ~SOLVER_WEAK;
848 case SOLVER_INSTALL_SOLVABLE:
849 case SOLVER_ERASE_SOLVABLE:
850 case SOLVER_ERASE_SOLVABLE_NAME:
851 case SOLVER_ERASE_SOLVABLE_PROVIDES:
857 /* go through all enabled job rules */
858 MAPZERO(&solv->noupdate);
859 for (i = solv->jobrules; i < solv->systemrules; i++)
862 if (!r->w1) /* disabled? */
864 j = solv->ruletojob.elements[i - solv->jobrules];
868 how = job->elements[j] & ~SOLVER_WEAK;
869 what = job->elements[j + 1];
872 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
873 s = pool->solvables + what;
874 FOR_PROVIDES(p, pp, s->name)
876 if (pool->solvables[p].name != s->name)
878 if (pool->solvables[p].repo == installed)
879 MAPSET(&solv->noupdate, p - installed->start);
882 case SOLVER_ERASE_SOLVABLE:
883 s = pool->solvables + what;
884 if (s->repo == installed)
885 MAPSET(&solv->noupdate, what - installed->start);
887 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
888 case SOLVER_ERASE_SOLVABLE_PROVIDES:
889 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
890 while (ISRELDEP(name))
892 Reldep *rd = GETRELDEP(pool, name);
895 FOR_PROVIDES(p, pp, what)
897 if (name && pool->solvables[p].name != name)
899 if (pool->solvables[p].repo == installed)
900 MAPSET(&solv->noupdate, p - installed->start);
908 /* fixup update rule status */
909 if (solv->allowuninstall)
910 return; /* no update rules at all */
914 /* we just disabled job #jobidx. enable all update rules
915 * that aren't disabled by the remaining job rules */
916 how = job->elements[jobidx] & ~SOLVER_WEAK;
917 what = job->elements[jobidx + 1];
920 case SOLVER_INSTALL_SOLVABLE:
921 s = pool->solvables + what;
922 FOR_PROVIDES(p, pp, s->name)
924 if (pool->solvables[p].name != s->name)
926 if (pool->solvables[p].repo != installed)
928 if (MAPTST(&solv->noupdate, p - installed->start))
930 r = solv->rules + solv->systemrules + (p - installed->start);
934 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
936 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
937 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
941 case SOLVER_ERASE_SOLVABLE:
942 s = pool->solvables + what;
943 if (s->repo != installed)
945 if (MAPTST(&solv->noupdate, what - installed->start))
947 r = solv->rules + solv->systemrules + (what - installed->start);
951 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
953 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
954 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
957 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
958 case SOLVER_ERASE_SOLVABLE_PROVIDES:
959 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
960 while (ISRELDEP(name))
962 Reldep *rd = GETRELDEP(pool, name);
965 FOR_PROVIDES(p, pp, what)
967 if (name && pool->solvables[p].name != name)
969 if (pool->solvables[p].repo != installed)
971 if (MAPTST(&solv->noupdate, p - installed->start))
973 r = solv->rules + solv->systemrules + (p - installed->start);
977 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
979 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
980 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
990 for (i = 0; i < installed->nsolvables; i++)
992 r = solv->rules + solv->systemrules + i;
993 if (r->w1 && MAPTST(&solv->noupdate, i))
994 disablerule(solv, r); /* was enabled, need to disable */
1000 addpatchatomrequires(Solver *solv, Solvable *s, Id *dp, Queue *q, Map *m)
1002 Pool *pool = solv->pool;
1003 Id fre, *frep, p, *pp, ndp;
1009 queue_init_buffer(&fq, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1010 queue_push(&fq, -(s - pool->solvables));
1012 queue_push(&fq, *dp);
1013 ndp = pool_queuetowhatprovides(pool, &fq);
1014 frep = s->repo->idarraydata + s->freshens;
1015 while ((fre = *frep++) != 0)
1017 FOR_PROVIDES(p, pp, fre)
1019 ps = pool->solvables + p;
1020 addrule(solv, -p, ndp);
1028 for (i = 1; i < fq.count; i++)
1040 * add (install) rules for solvable
1041 * for unfulfilled requirements, conflicts, obsoletes,....
1042 * add a negative assertion for solvables that are not installable
1046 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
1048 Pool *pool = solv->pool;
1049 Repo *installed = solv->installed;
1064 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
1066 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1067 queue_push(&q, s - pool->solvables); /* push solvable Id */
1073 * s: Pointer to solvable
1076 n = queue_shift(&q);
1077 if (MAPTST(m, n)) /* continue if already done */
1081 s = pool->solvables + n; /* s = Solvable in question */
1084 if (installed /* Installed system available */
1085 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
1086 && s->repo == installed) /* solvable is installed? */
1088 dontfix = 1; /* dont care about broken rpm deps */
1091 if (!dontfix && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
1093 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
1094 addrule(solv, -n, 0); /* uninstallable */
1098 if (s->freshens && !s->supplements)
1100 const char *name = id2str(pool, s->name);
1101 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
1105 /*-----------------------------------------
1106 * check requires of s
1111 reqp = s->repo->idarraydata + s->requires;
1112 while ((req = *reqp++) != 0) /* go throw all requires */
1114 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
1117 dp = pool_whatprovides(pool, req);
1119 if (*dp == SYSTEMSOLVABLE) /* always installed */
1125 addpatchatomrequires(solv, s, dp, &q, m);
1131 /* the strategy here is to not insist on dependencies
1132 * that are already broken. so if we find one provider
1133 * that was already installed, we know that the
1134 * dependency was not broken before so we enforce it */
1135 for (i = 0; (p = dp[i]) != 0; i++) /* for all providers */
1137 if (pool->solvables[p].repo == installed)
1138 break; /* provider was installed */
1140 if (!p) /* previously broken dependency */
1142 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1149 /* nothing provides req! */
1150 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1151 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1155 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1157 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1158 for (i = 0; dp[i]; i++)
1159 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1162 /* add 'requires' dependency */
1163 /* rule: (-requestor|provider1|provider2|...|providerN) */
1164 addrule(solv, -n, dp - pool->whatprovidesdata);
1166 /* descend the dependency tree */
1167 for (; *dp; dp++) /* loop through all providers */
1169 if (!MAPTST(m, *dp))
1170 queue_push(&q, *dp);
1173 } /* while, requirements of n */
1175 } /* if, requirements */
1177 /* that's all we check for src packages */
1178 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1181 /*-----------------------------------------
1182 * check conflicts of s
1187 conp = s->repo->idarraydata + s->conflicts;
1188 while ((con = *conp++) != 0)
1190 FOR_PROVIDES(p, pp, con)
1192 /* dontfix: dont care about conflicts with already installed packs */
1193 if (dontfix && pool->solvables[p].repo == installed)
1195 /* rule: -n|-p: either solvable _or_ provider of conflict */
1196 addrule(solv, -n, -p);
1201 /*-----------------------------------------
1202 * check obsoletes if not installed
1204 if (!installed || pool->solvables[n].repo != installed)
1205 { /* not installed */
1208 obsp = s->repo->idarraydata + s->obsoletes;
1209 while ((obs = *obsp++) != 0)
1211 FOR_PROVIDES(p, pp, obs)
1212 addrule(solv, -n, -p);
1215 FOR_PROVIDES(p, pp, s->name)
1217 if (s->name == pool->solvables[p].name)
1218 addrule(solv, -n, -p);
1222 /*-----------------------------------------
1223 * add recommends to the rule list
1227 recp = s->repo->idarraydata + s->recommends;
1228 while ((rec = *recp++) != 0)
1230 FOR_PROVIDES(p, pp, rec)
1237 sugp = s->repo->idarraydata + s->suggests;
1238 while ((sug = *sugp++) != 0)
1240 FOR_PROVIDES(p, pp, sug)
1247 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1251 addrpmrulesforweak(Solver *solv, Map *m)
1253 Pool *pool = solv->pool;
1258 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1259 for (i = n = 1; n < pool->nsolvables; i++, n++)
1261 if (i == pool->nsolvables)
1265 s = pool->solvables + i;
1266 if (!pool_installable(pool, s))
1271 supp = s->repo->idarraydata + s->supplements;
1272 while ((sup = *supp++) != ID_NULL)
1273 if (dep_possible(solv, sup, m))
1276 if (!sup && s->freshens)
1278 supp = s->repo->idarraydata + s->freshens;
1279 while ((sup = *supp++) != ID_NULL)
1280 if (dep_possible(solv, sup, m))
1283 if (!sup && s->enhances)
1285 supp = s->repo->idarraydata + s->enhances;
1286 while ((sup = *supp++) != ID_NULL)
1287 if (dep_possible(solv, sup, m))
1292 addrpmrulesforsolvable(solv, s, m);
1295 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1299 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
1301 Pool *pool = solv->pool;
1306 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1308 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1309 policy_findupdatepackages(solv, s, &qs, allowall);
1310 if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
1311 addrpmrulesforsolvable(solv, s, m);
1312 for (i = 0; i < qs.count; i++)
1313 if (!MAPTST(m, qs.elements[i]))
1314 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1317 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1321 * add rule for update
1322 * (A|A1|A2|A3...) An = update candidates for A
1324 * s = (installed) solvable
1328 addupdaterule(Solver *solv, Solvable *s, int allowall)
1330 /* installed packages get a special upgrade allowed rule */
1331 Pool *pool = solv->pool;
1336 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1338 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1339 policy_findupdatepackages(solv, s, &qs, allowall);
1340 if (qs.count == 0) /* no updaters found */
1343 d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
1345 addrule(solv, s - pool->solvables, d); /* allow update of s */
1346 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1350 /*-----------------------------------------------------------------*/
1359 printWatches(Solver *solv, int type)
1361 Pool *pool = solv->pool;
1364 POOL_DEBUG(type, "Watches: \n");
1366 for (counter = -(pool->nsolvables); counter <= pool->nsolvables; counter ++)
1368 POOL_DEBUG(type, " solvable [%d] -- rule [%d]\n", counter, solv->watches[counter+pool->nsolvables]);
1375 * initial setup for all watches
1379 makewatches(Solver *solv)
1383 int nsolvables = solv->pool->nsolvables;
1385 sat_free(solv->watches);
1386 /* lower half for removals, upper half for installs */
1387 solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
1389 /* do it reverse so rpm rules get triggered first */
1390 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1392 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1395 if (!r->w1 /* rule is disabled */
1396 || !r->w2) /* rule is assertion */
1399 /* see addwatches(solv, r) */
1400 r->n1 = solv->watches[nsolvables + r->w1];
1401 solv->watches[nsolvables + r->w1] = r - solv->rules;
1403 r->n2 = solv->watches[nsolvables + r->w2];
1404 solv->watches[nsolvables + r->w2] = r - solv->rules;
1410 * add watches (for rule)
1414 addwatches(Solver *solv, Rule *r)
1416 int nsolvables = solv->pool->nsolvables;
1418 r->n1 = solv->watches[nsolvables + r->w1];
1419 solv->watches[nsolvables + r->w1] = r - solv->rules;
1421 r->n2 = solv->watches[nsolvables + r->w2];
1422 solv->watches[nsolvables + r->w2] = r - solv->rules;
1426 /*-----------------------------------------------------------------*/
1427 /* rule propagation */
1429 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1434 * propagate decision to all rules
1435 * return : 0 = everything is OK
1436 * watched rule = there is a conflict
1440 propagate(Solver *solv, int level)
1442 Pool *pool = solv->pool;
1447 Id *decisionmap = solv->decisionmap;
1448 Id *watches = solv->watches + pool->nsolvables;
1450 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1452 while (solv->propagate_index < solv->decisionq.count)
1454 /* negate because our watches trigger if literal goes FALSE */
1455 pkg = -solv->decisionq.elements[solv->propagate_index++];
1456 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1458 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
1459 printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1461 printWatches(solv, SAT_DEBUG_SCHUBI);
1464 for (rp = watches + pkg; *rp; rp = nrp)
1466 r = solv->rules + *rp;
1468 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1470 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1471 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1476 ow = r->w2; /* regard the second watchpoint to come to a solution */
1481 ow = r->w1; /* regard the first watchpoint to come to a solution */
1484 /* if clause is TRUE, nothing to do */
1485 if (DECISIONMAP_TRUE(ow))
1490 /* not a binary clause, check if we need to move our watch */
1491 /* search for a literal that is not ow and not false */
1492 /* (true is also ok, in that case the rule is fulfilled) */
1493 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1496 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1497 if (p != ow && !DECISIONMAP_TRUE(-p))
1501 /* p is free to watch, move watch to p */
1502 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1505 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1507 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1521 watches[p] = r - solv->rules;
1525 /* unit clause found, set other watch to TRUE */
1526 if (DECISIONMAP_TRUE(-ow))
1527 return r; /* eek, a conflict! */
1528 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1530 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
1531 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1534 decisionmap[ow] = level;
1536 decisionmap[-ow] = -level;
1537 queue_push(&solv->decisionq, ow);
1538 queue_push(&solv->decisionq_why, r - solv->rules);
1539 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1541 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1543 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
1545 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
1549 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
1551 return 0; /* all is well */
1555 /*-----------------------------------------------------------------*/
1564 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
1566 Pool *pool = solv->pool;
1569 Map seen; /* global? */
1572 int num = 0, l1num = 0;
1573 int learnt_why = solv->learnt_pool.count;
1574 Id *decisionmap = solv->decisionmap;
1578 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
1579 map_init(&seen, pool->nsolvables);
1580 idx = solv->decisionq.count;
1583 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1584 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1585 queue_push(&solv->learnt_pool, c - solv->rules);
1586 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1587 /* go through all literals of the rule */
1599 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1601 vv = v > 0 ? v : -v;
1602 if (MAPTST(&seen, vv))
1604 l = solv->decisionmap[vv];
1609 /* a level 1 literal, mark it for later */
1610 MAPSET(&seen, vv); /* mark for scanning in level 1 phase */
1616 num++; /* need to do this one as well */
1627 v = solv->decisionq.elements[--idx];
1628 vv = v > 0 ? v : -v;
1629 if (MAPTST(&seen, vv))
1632 c = solv->rules + solv->decisionq_why.elements[idx];
1637 *pr = -v; /* so that v doesn't get lost */
1639 /* add involved level 1 rules */
1642 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1646 v = solv->decisionq.elements[--idx];
1647 vv = v > 0 ? v : -v;
1648 if (!MAPTST(&seen, vv))
1650 why = solv->decisionq_why.elements[idx];
1653 queue_push(&solv->learnt_pool, -vv);
1654 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1656 POOL_DEBUG(SAT_DEBUG_ANALYZE, "RPM ASSERT Rule:\n");
1657 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, v);
1661 queue_push(&solv->learnt_pool, why);
1662 c = solv->rules + why;
1663 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1664 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1665 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1676 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1678 vv = v > 0 ? v : -v;
1679 l = solv->decisionmap[vv];
1680 if (l != 1 && l != -1)
1690 else if (r.count == 1 && r.elements[0] < 0)
1691 *dr = r.elements[0];
1693 *dr = pool_queuetowhatprovides(pool, &r);
1694 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1696 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1697 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
1698 for (i = 0; i < r.count; i++)
1699 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
1701 /* push end marker on learnt reasons stack */
1702 queue_push(&solv->learnt_pool, 0);
1711 * reset the solver decisions to right after the rpm rules.
1712 * called after rules have been enabled/disabled
1716 reset_solver(Solver *solv)
1718 Pool *pool = solv->pool;
1722 /* rewind decisions to direct rpm rule assertions */
1723 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
1725 v = solv->decisionq.elements[i];
1726 solv->decisionmap[v > 0 ? v : -v] = 0;
1729 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
1731 solv->decisionq_why.count = solv->directdecisions;
1732 solv->decisionq.count = solv->directdecisions;
1733 solv->recommends_index = -1;
1734 solv->propagate_index = 0;
1736 /* adapt learnt rule status to new set of enabled/disabled rules */
1737 enabledisablelearntrules(solv);
1739 /* redo all job/system decisions */
1740 makeruledecisions(solv);
1741 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
1743 /* recreate watch chains */
1749 * analyze_unsolvable_rule
1753 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
1755 Pool *pool = solv->pool;
1757 Id why = r - solv->rules;
1759 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1760 printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1761 if (solv->learntrules && why >= solv->learntrules)
1763 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1764 if (solv->learnt_pool.elements[i] > 0)
1765 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp);
1768 if (MAPTST(&solv->weakrulemap, why))
1769 if (!*lastweakp || why > *lastweakp)
1771 /* do not add rpm rules to problem */
1772 if (why < solv->jobrules)
1774 /* turn rule into problem */
1775 if (why >= solv->jobrules && why < solv->systemrules)
1776 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1777 /* return if problem already countains our rule */
1778 if (solv->problems.count)
1780 for (i = solv->problems.count - 1; i >= 0; i--)
1781 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1783 else if (solv->problems.elements[i] == why)
1786 queue_push(&solv->problems, why);
1791 * analyze_unsolvable
1793 * return: 1 - disabled some rules, try again
1798 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1800 Pool *pool = solv->pool;
1802 Map seen; /* global to speed things up? */
1805 Id *decisionmap = solv->decisionmap;
1806 int oldproblemcount;
1807 int oldlearntpoolcount;
1810 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1811 oldproblemcount = solv->problems.count;
1812 oldlearntpoolcount = solv->learnt_pool.count;
1814 /* make room for proof index */
1815 /* must update it later, as analyze_unsolvable_rule would confuse
1816 * it with a rule index if we put the real value in already */
1817 queue_push(&solv->problems, 0);
1820 map_init(&seen, pool->nsolvables);
1821 queue_push(&solv->learnt_pool, r - solv->rules);
1823 analyze_unsolvable_rule(solv, r, &lastweak);
1824 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1835 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1837 vv = v > 0 ? v : -v;
1838 l = solv->decisionmap[vv];
1843 idx = solv->decisionq.count;
1846 v = solv->decisionq.elements[--idx];
1847 vv = v > 0 ? v : -v;
1848 if (!MAPTST(&seen, vv))
1850 why = solv->decisionq_why.elements[idx];
1855 /* level 1 and no why, must be an rpm assertion */
1856 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1858 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "RPM ");
1859 printruleelement(solv, SAT_DEBUG_UNSOLVABLE, 0, v);
1861 /* this is the only positive rpm assertion */
1862 if (v == SYSTEMSOLVABLE)
1865 queue_push(&solv->learnt_pool, v);
1869 queue_push(&solv->learnt_pool, why);
1870 r = solv->rules + why;
1871 analyze_unsolvable_rule(solv, r, &lastweak);
1872 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1883 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1885 vv = v > 0 ? v : -v;
1886 l = solv->decisionmap[vv];
1893 queue_push(&solv->problems, 0); /* mark end of this problem */
1897 /* disable last weak rule */
1898 solv->problems.count = oldproblemcount;
1899 solv->learnt_pool.count = oldlearntpoolcount;
1900 r = solv->rules + lastweak;
1901 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling ");
1902 printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1903 disablerule(solv, r);
1909 queue_push(&solv->learnt_pool, 0);
1910 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1914 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1915 disableproblem(solv, solv->problems.elements[i]);
1919 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1924 /*-----------------------------------------------------------------*/
1925 /* Decision revert */
1929 * revert decision at level
1933 revert(Solver *solv, int level)
1935 Pool *pool = solv->pool;
1937 while (solv->decisionq.count)
1939 v = solv->decisionq.elements[solv->decisionq.count - 1];
1940 vv = v > 0 ? v : -v;
1941 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1943 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1944 if (v > 0 && solv->recommendations.count && v == solv->recommendations.elements[solv->recommendations.count - 1])
1945 solv->recommendations.count--;
1946 solv->decisionmap[vv] = 0;
1947 solv->decisionq.count--;
1948 solv->decisionq_why.count--;
1949 solv->propagate_index = solv->decisionq.count;
1951 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1953 solv->branches.count--;
1954 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1955 solv->branches.count--;
1957 solv->recommends_index = -1;
1962 * watch2onhighest - put watch2 on literal with highest level
1966 watch2onhighest(Solver *solv, Rule *r)
1972 return; /* binary rule, both watches are set */
1973 dp = solv->pool->whatprovidesdata + r->d;
1974 while ((v = *dp++) != 0)
1976 l = solv->decisionmap[v < 0 ? -v : v];
1991 * add free decision to decisionq, increase level and
1992 * propagate decision, return if no conflict.
1993 * in conflict case, analyze conflict rule, add resulting
1994 * rule to learnt rule set, make decision from learnt
1995 * rule (always unit) and re-propagate.
1997 * returns the new solver level or 0 if unsolvable
2002 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
2004 Pool *pool = solv->pool;
2013 solv->decisionmap[decision] = level;
2015 solv->decisionmap[-decision] = -level;
2016 queue_push(&solv->decisionq, decision);
2017 queue_push(&solv->decisionq_why, 0);
2021 r = propagate(solv, level);
2025 return analyze_unsolvable(solv, r, disablerules);
2026 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
2027 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
2028 assert(l > 0 && l < level);
2029 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
2031 revert(solv, level);
2032 r = addrule(solv, p, d); /* p requires d */
2034 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
2035 queue_push(&solv->learnt_why, why);
2038 /* at least 2 literals, needs watches */
2039 watch2onhighest(solv, r);
2040 addwatches(solv, r);
2042 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
2043 queue_push(&solv->decisionq, p);
2044 queue_push(&solv->decisionq_why, r - solv->rules);
2045 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
2047 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
2048 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
2049 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
2050 printrule(solv, SAT_DEBUG_ANALYZE, r);
2058 * install best package from the queue. We add an extra package, inst, if
2059 * provided. See comment in weak install section.
2061 * returns the new solver level or 0 if unsolvable
2065 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
2067 Pool *pool = solv->pool;
2071 if (dq->count > 1 || inst)
2072 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
2077 /* choose the supplemented one */
2078 for (i = 0; i < dq->count; i++)
2079 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
2083 for (i = 1; i < dq->count; i++)
2084 queue_push(&solv->branches, dq->elements[i]);
2085 queue_push(&solv->branches, -level);
2089 p = dq->elements[i];
2091 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
2093 return setpropagatelearn(solv, level, p, disablerules);
2097 /*-----------------------------------------------------------------*/
2098 /* Main solver interface */
2103 * create solver structure
2105 * pool: all available solvables
2106 * installed: installed Solvables
2109 * Upon solving, rules are created to flag the Solvables
2110 * of the 'installed' Repo as installed.
2114 solver_create(Pool *pool, Repo *installed)
2117 solv = (Solver *)sat_calloc(1, sizeof(Solver));
2119 solv->installed = installed;
2121 queue_init(&solv->ruletojob);
2122 queue_init(&solv->decisionq);
2123 queue_init(&solv->decisionq_why);
2124 queue_init(&solv->problems);
2125 queue_init(&solv->suggestions);
2126 queue_init(&solv->recommendations);
2127 queue_init(&solv->learnt_why);
2128 queue_init(&solv->learnt_pool);
2129 queue_init(&solv->branches);
2130 queue_init(&solv->covenantq);
2131 queue_init(&solv->weakruleq);
2133 map_init(&solv->recommendsmap, pool->nsolvables);
2134 map_init(&solv->suggestsmap, pool->nsolvables);
2135 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
2136 solv->recommends_index = 0;
2138 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2140 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
2141 memset(solv->rules, 0, sizeof(Rule));
2152 solver_free(Solver *solv)
2154 queue_free(&solv->ruletojob);
2155 queue_free(&solv->decisionq);
2156 queue_free(&solv->decisionq_why);
2157 queue_free(&solv->learnt_why);
2158 queue_free(&solv->learnt_pool);
2159 queue_free(&solv->problems);
2160 queue_free(&solv->suggestions);
2161 queue_free(&solv->recommendations);
2162 queue_free(&solv->branches);
2163 queue_free(&solv->covenantq);
2164 queue_free(&solv->weakruleq);
2166 map_free(&solv->recommendsmap);
2167 map_free(&solv->suggestsmap);
2168 map_free(&solv->noupdate);
2169 map_free(&solv->weakrulemap);
2171 sat_free(solv->decisionmap);
2172 sat_free(solv->rules);
2173 sat_free(solv->watches);
2174 sat_free(solv->weaksystemrules);
2175 sat_free(solv->obsoletes);
2176 sat_free(solv->obsoletes_data);
2181 /*-------------------------------------------------------*/
2186 * all rules have been set up, now actually run the solver
2191 run_solver(Solver *solv, int disablerules, int doweak)
2199 Pool *pool = solv->pool;
2202 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2204 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2205 for (i = 1; i < solv->nrules; i++)
2206 printruleclass(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2209 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2211 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2212 printdecisions(solv);
2214 /* start SAT algorithm */
2216 systemlevel = level + 1;
2217 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2222 * here's the main loop:
2223 * 1) propagate new decisions (only needed for level 1)
2224 * 2) try to keep installed packages
2225 * 3) fulfill all unresolved rules
2226 * 4) install recommended packages
2227 * 5) minimalize solution if we had choices
2228 * if we encounter a problem, we rewind to a safe level and restart
2240 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2241 if ((r = propagate(solv, level)) != 0)
2243 if (analyze_unsolvable(solv, r, disablerules))
2251 * installed packages
2254 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2256 if (!solv->updatesystem)
2258 /* try to keep as many packages as possible */
2259 POOL_DEBUG(SAT_DEBUG_STATS, "installing system packages\n");
2260 for (i = solv->installed->start; i < solv->installed->end; i++)
2262 s = pool->solvables + i;
2263 if (s->repo != solv->installed)
2265 if (solv->decisionmap[i] != 0)
2267 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2269 level = setpropagatelearn(solv, level, i, disablerules);
2275 if (level <= olevel)
2278 if (i < solv->installed->end)
2281 if (solv->weaksystemrules)
2283 POOL_DEBUG(SAT_DEBUG_STATS, "installing weak system packages\n");
2284 for (i = solv->installed->start; i < solv->installed->end; i++)
2286 s = pool->solvables + i;
2287 if (s->repo != solv->installed)
2289 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
2291 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2292 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2295 if (solv->weaksystemrules[i - solv->installed->start])
2297 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
2298 while ((p = *dp++) != 0)
2300 if (solv->decisionmap[p] > 0)
2302 if (solv->decisionmap[p] == 0)
2306 continue; /* update package already installed */
2308 if (!dq.count && solv->decisionmap[i] != 0)
2311 /* FIXME: i is handled a bit different because we do not want
2312 * to have it pruned just because it is not recommened.
2313 * we should not prune installed packages instead */
2314 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2320 if (level <= olevel)
2323 if (i < solv->installed->end)
2326 systemlevel = level;
2333 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unresolved rules\n");
2334 for (i = 1, n = 1; ; i++, n++)
2336 if (n == solv->nrules)
2338 if (i == solv->nrules)
2340 r = solv->rules + i;
2341 if (!r->w1) /* ignore disabled rules */
2346 /* binary or unary rule */
2347 /* need two positive undecided literals */
2348 if (r->p < 0 || r->w2 <= 0)
2350 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2352 queue_push(&dq, r->p);
2353 queue_push(&dq, r->w2);
2358 * all negative literals are installed
2359 * no positive literal is installed
2360 * i.e. the rule is not fulfilled and we
2361 * just need to decide on the positive literals
2365 if (solv->decisionmap[-r->p] <= 0)
2370 if (solv->decisionmap[r->p] > 0)
2372 if (solv->decisionmap[r->p] == 0)
2373 queue_push(&dq, r->p);
2375 dp = pool->whatprovidesdata + r->d;
2376 while ((p = *dp++) != 0)
2380 if (solv->decisionmap[-p] <= 0)
2385 if (solv->decisionmap[p] > 0)
2387 if (solv->decisionmap[p] == 0)
2394 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2396 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2397 printruleclass(solv, SAT_DEBUG_PROPAGATE, r);
2399 /* dq.count < 2 cannot happen as this means that
2400 * the rule is unit */
2401 assert(dq.count > 1);
2404 level = selectandinstall(solv, level, &dq, 0, disablerules);
2410 if (level < systemlevel)
2413 } /* for(), decide */
2415 if (n != solv->nrules) /* continue if level < systemlevel */
2418 if (doweak && !solv->problems.count)
2422 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
2424 if (!solv->dosplitprovides && !REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2426 for (i = 1; i < solv->decisionq.count; i++)
2428 p = solv->decisionq.elements[i];
2429 if (p > 0 && pool->solvables[p].repo == solv->installed)
2430 solv->decisionmap[p] = -solv->decisionmap[p];
2435 for (i = 1; i < pool->nsolvables; i++)
2437 if (solv->decisionmap[i] < 0)
2439 if (solv->decisionmap[i] > 0)
2441 Id *recp, rec, *pp, p;
2442 s = pool->solvables + i;
2443 /* installed, check for recommends */
2444 /* XXX need to special case AND ? */
2447 recp = s->repo->idarraydata + s->recommends;
2448 while ((rec = *recp++) != 0)
2451 FOR_PROVIDES(p, pp, rec)
2453 if (solv->decisionmap[p] > 0)
2458 else if (solv->decisionmap[p] == 0)
2460 queue_pushunique(&dq, p);
2468 s = pool->solvables + i;
2469 if (!s->supplements && !s->freshens)
2471 if (!pool_installable(pool, s))
2473 if (solver_is_supplementing(solv, s))
2474 queue_pushunique(&dq, i);
2478 if (!solv->dosplitprovides && !REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2480 for (i = 1; i < solv->decisionq.count; i++)
2482 p = solv->decisionq.elements[i];
2483 if (p > 0 && pool->solvables[p].repo == solv->installed)
2484 solv->decisionmap[p] = -solv->decisionmap[p];
2491 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2493 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2494 queue_push(&solv->recommendations, p);
2495 level = setpropagatelearn(solv, level, p, 0);
2500 if (solv->solution_callback)
2502 solv->solution_callback(solv, solv->solution_callback_data);
2503 if (solv->branches.count)
2505 int i = solv->branches.count - 1;
2506 int l = -solv->branches.elements[i];
2508 if (solv->branches.elements[i - 1] < 0)
2510 p = solv->branches.elements[i];
2511 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
2513 for (j = i + 1; j < solv->branches.count; j++)
2514 queue_push(&dq, solv->branches.elements[j]);
2515 solv->branches.count = i;
2517 revert(solv, level);
2519 for (j = 0; j < dq.count; j++)
2520 queue_push(&solv->branches, dq.elements[j]);
2522 level = setpropagatelearn(solv, level, p, disablerules);
2530 /* all branches done, we're finally finished */
2534 /* minimization step */
2535 if (solv->branches.count)
2537 int l = 0, lasti = -1, lastl = -1;
2539 for (i = solv->branches.count - 1; i >= 0; i--)
2541 p = solv->branches.elements[i];
2544 else if (p > 0 && solv->decisionmap[p] > l + 1)
2552 /* kill old solvable so that we do not loop */
2553 p = solv->branches.elements[lasti];
2554 solv->branches.elements[lasti] = 0;
2555 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
2558 revert(solv, level);
2560 level = setpropagatelearn(solv, level, p, disablerules);
2571 POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
2578 * at this point, all rules that led to conflicts are disabled.
2579 * we re-enable all rules of a problem set but rule "sug", then
2580 * continue to disable more rules until there as again a solution.
2583 /* FIXME: think about conflicting assertions */
2586 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2588 Pool *pool = solv->pool;
2595 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2597 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
2598 for (i = 0; problem[i]; i++)
2600 if (problem[i] == sug)
2601 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
2602 printproblem(solv, problem[i]);
2605 queue_init(&disabled);
2606 queue_empty(refined);
2607 queue_push(refined, sug);
2609 /* re-enable all problem rules with the exception of "sug"(gests) */
2613 for (i = 0; problem[i]; i++)
2614 if (problem[i] != sug)
2615 enableproblem(solv, problem[i]);
2618 disableupdaterules(solv, job, -(sug + 1));
2622 /* re-enable as many weak rules as possible */
2623 for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++)
2627 if (!MAPTST(&solv->weakrulemap, i))
2629 enablerule(solv, r);
2632 queue_empty(&solv->problems);
2633 revert(solv, 1); /* XXX move to reset_solver? */
2636 if (!solv->problems.count)
2637 run_solver(solv, 0, 0);
2639 if (!solv->problems.count)
2641 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
2642 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2643 printdecisions(solv);
2644 break; /* great, no more problems */
2646 disabledcnt = disabled.count;
2647 /* start with 1 to skip over proof index */
2648 for (i = 1; i < solv->problems.count - 1; i++)
2650 /* ignore solutions in refined */
2651 v = solv->problems.elements[i];
2653 break; /* end of problem reached */
2654 for (j = 0; problem[j]; j++)
2655 if (problem[j] != sug && problem[j] == v)
2659 queue_push(&disabled, v);
2661 if (disabled.count == disabledcnt)
2663 /* no solution found, this was an invalid suggestion! */
2664 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
2668 if (disabled.count == disabledcnt + 1)
2670 /* just one suggestion, add it to refined list */
2671 v = disabled.elements[disabledcnt];
2672 queue_push(refined, v);
2673 disableproblem(solv, v);
2675 disableupdaterules(solv, job, -(v + 1));
2679 /* more than one solution, disable all */
2680 /* do not push anything on refine list */
2681 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2683 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
2684 for (i = disabledcnt; i < disabled.count; i++)
2685 printproblem(solv, disabled.elements[i]);
2687 for (i = disabledcnt; i < disabled.count; i++)
2688 disableproblem(solv, disabled.elements[i]);
2691 /* all done, get us back into the same state as before */
2692 /* enable refined rules again */
2693 for (i = 0; i < disabled.count; i++)
2694 enableproblem(solv, disabled.elements[i]);
2695 /* disable problem rules again */
2696 for (i = 0; problem[i]; i++)
2697 disableproblem(solv, problem[i]);
2698 disableupdaterules(solv, job, -1);
2699 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
2703 problems_to_solutions(Solver *solv, Queue *job)
2705 Pool *pool = solv->pool;
2713 if (!solv->problems.count)
2715 queue_clone(&problems, &solv->problems);
2716 queue_init(&solution);
2717 queue_init(&solutions);
2718 /* copy over proof index */
2719 queue_push(&solutions, problems.elements[0]);
2720 problem = problems.elements + 1;
2721 for (i = 1; i < problems.count; i++)
2723 Id v = problems.elements[i];
2726 /* mark end of this problem */
2727 queue_push(&solutions, 0);
2728 queue_push(&solutions, 0);
2729 if (i + 1 == problems.count)
2731 /* copy over proof of next problem */
2732 queue_push(&solutions, problems.elements[i + 1]);
2734 problem = problems.elements + i + 1;
2737 refine_suggestion(solv, job, problem, v, &solution);
2738 if (!solution.count)
2739 continue; /* this solution didn't work out */
2741 for (j = 0; j < solution.count; j++)
2743 why = solution.elements[j];
2744 /* must be either job descriptor or system rule */
2745 assert(why < 0 || (why >= solv->systemrules && why < solv->learntrules));
2747 printproblem(solv, why);
2751 /* job descriptor */
2752 queue_push(&solutions, 0);
2753 queue_push(&solutions, -why);
2757 /* system rule, find replacement package */
2759 p = solv->installed->start + (why - solv->systemrules);
2760 if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
2762 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
2765 if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
2767 if (solv->decisionmap[*dp] > 0)
2774 queue_push(&solutions, p);
2775 queue_push(&solutions, rp);
2778 /* mark end of this solution */
2779 queue_push(&solutions, 0);
2780 queue_push(&solutions, 0);
2782 queue_free(&solution);
2783 queue_free(&problems);
2784 /* copy queue over to solutions */
2785 queue_free(&solv->problems);
2786 queue_clone(&solv->problems, &solutions);
2788 printf("bring it back!\n");
2789 /* bring solver back into problem state */
2790 revert(solv, 1); /* XXX move to reset_solver? */
2793 printf("problems %d solutions %d\n", solv->problems.count, solutions.count);
2794 assert(solv->problems.count == solutions.count);
2795 queue_free(&solutions);
2799 solver_next_problem(Solver *solv, Id problem)
2803 return solv->problems.count ? 1 : 0;
2804 pp = solv->problems.elements + problem;
2805 while (pp[0] || pp[1])
2809 while (pp[0] || pp[1])
2814 problem = pp - solv->problems.elements;
2815 if (problem >= solv->problems.count)
2821 solver_next_solution(Solver *solv, Id problem, Id solution)
2827 pp = solv->problems.elements + solution;
2828 return pp[0] || pp[1] ? solution : 0;
2830 pp = solv->problems.elements + solution;
2831 while (pp[0] || pp[1])
2834 solution = pp - solv->problems.elements;
2835 return pp[0] || pp[1] ? solution : 0;
2839 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
2842 element = element ? element + 2 : solution;
2843 pp = solv->problems.elements + element;
2844 if (!(pp[0] || pp[1]))
2853 * create obsoletesmap from solver decisions
2854 * required for decision handling
2858 create_decisions_obsoletesmap(Solver *solv)
2860 Pool *pool = solv->pool;
2861 Repo *installed = solv->installed;
2862 Id p, *obsoletesmap = NULL;
2866 obsoletesmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2869 for (i = 0; i < solv->decisionq.count; i++)
2873 n = solv->decisionq.elements[i];
2876 if (n == SYSTEMSOLVABLE)
2878 s = pool->solvables + n;
2879 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2881 FOR_PROVIDES(p, pp, s->name)
2882 if (s->name == pool->solvables[p].name)
2884 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2886 obsoletesmap[p] = n;
2891 for (i = 0; i < solv->decisionq.count; i++)
2896 n = solv->decisionq.elements[i];
2899 if (n == SYSTEMSOLVABLE)
2901 s = pool->solvables + n;
2902 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2906 obsp = s->repo->idarraydata + s->obsoletes;
2907 while ((obs = *obsp++) != 0)
2908 FOR_PROVIDES(p, pp, obs)
2910 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2912 obsoletesmap[p] = n;
2918 return obsoletesmap;
2927 printdecisions(Solver *solv)
2929 Pool *pool = solv->pool;
2930 Repo *installed = solv->installed;
2931 Id p, *obsoletesmap = create_decisions_obsoletesmap( solv );
2935 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
2937 /* print solvables to be erased */
2941 FOR_REPO_SOLVABLES(installed, p, s)
2943 if (solv->decisionmap[p] >= 0)
2945 if (obsoletesmap[p])
2947 POOL_DEBUG(SAT_DEBUG_RESULT, "erase %s\n", solvable2str(pool, s));
2951 /* print solvables to be installed */
2953 for (i = 0; i < solv->decisionq.count; i++)
2956 p = solv->decisionq.elements[i];
2959 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2962 s = pool->solvables + p;
2963 POOL_DEBUG(SAT_DEBUG_SCHUBI, "level of %s is %d\n", solvable2str(pool, s), p);
2967 if (p == SYSTEMSOLVABLE)
2969 POOL_DEBUG(SAT_DEBUG_SCHUBI, "SYSTEMSOLVABLE\n");
2972 s = pool->solvables + p;
2973 if (installed && s->repo == installed)
2976 if (!obsoletesmap[p])
2978 POOL_DEBUG(SAT_DEBUG_RESULT, "install %s", solvable2str(pool, s));
2982 POOL_DEBUG(SAT_DEBUG_RESULT, "update %s", solvable2str(pool, s));
2983 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
2984 for (j = installed->start; j < installed->end; j++)
2985 if (obsoletesmap[j] == p)
2986 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
2987 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
2989 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
2992 sat_free(obsoletesmap);
2994 if (solv->recommendations.count)
2996 POOL_DEBUG(SAT_DEBUG_RESULT, "\nrecommended packages:\n");
2997 for (i = 0; i < solv->recommendations.count; i++)
2999 s = pool->solvables + solv->recommendations.elements[i];
3000 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
3004 if (solv->suggestions.count)
3006 POOL_DEBUG(SAT_DEBUG_RESULT, "\nsuggested packages:\n");
3007 for (i = 0; i < solv->suggestions.count; i++)
3009 s = pool->solvables + solv->suggestions.elements[i];
3010 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
3013 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
3016 /* this is basically the reverse of addrpmrulesforsolvable */
3018 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
3020 Pool *pool = solv->pool;
3021 Repo *installed = solv->installed;
3025 Id p, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
3028 if (rid >= solv->systemrules)
3031 *sourcep = solv->installed->start + (rid - solv->systemrules);
3033 return SOLVER_PROBLEM_UPDATE_RULE;
3035 if (rid >= solv->jobrules)
3038 r = solv->rules + rid;
3039 p = solv->ruletojob.elements[rid - solv->jobrules];
3040 *depp = job->elements[p + 1];
3042 *targetp = job->elements[p];
3043 if (r->d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE)
3044 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
3045 return SOLVER_PROBLEM_JOB_RULE;
3050 /*XXX OBSOLETE CODE */
3051 /* a rpm rule assertion */
3052 assert(rid != -SYSTEMSOLVABLE);
3053 s = pool->solvables - rid;
3054 if (installed && !solv->fixsystem && s->repo == installed)
3056 assert(!dontfix); /* dontfix packages never have a neg assertion */
3057 /* see why the package is not installable */
3058 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
3063 return SOLVER_PROBLEM_NOT_INSTALLABLE;
3065 /* check requires */
3066 assert(s->requires);
3067 reqp = s->repo->idarraydata + s->requires;
3068 while ((req = *reqp++) != 0)
3070 if (req == SOLVABLE_PREREQMARKER)
3072 dp = pool_whatprovides(pool, req);
3080 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
3083 r = solv->rules + rid;
3085 if (r->d == 0 && r->w2 == 0)
3087 /* a rpm rule assertion */
3088 s = pool->solvables - r->p;
3089 if (installed && !solv->fixsystem && s->repo == installed)
3091 assert(!dontfix); /* dontfix packages never have a neg assertion */
3094 /* see why the package is not installable */
3095 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
3098 return SOLVER_PROBLEM_NOT_INSTALLABLE;
3100 /* check requires */
3101 assert(s->requires);
3102 reqp = s->repo->idarraydata + s->requires;
3103 while ((req = *reqp++) != 0)
3105 if (req == SOLVABLE_PREREQMARKER)
3107 dp = pool_whatprovides(pool, req);
3113 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
3115 s = pool->solvables - r->p;
3116 if (installed && !solv->fixsystem && s->repo == installed)
3118 if (r->d == 0 && r->w2 < 0)
3120 /* a package conflict */
3121 Solvable *s2 = pool->solvables - r->w2;
3124 if (installed && !solv->fixsystem && s2->repo == installed)
3127 /* if both packages have the same name and at least one of them
3128 * is not installed, they conflict */
3129 if (s->name == s2->name && (!installed || (s->repo != installed || s2->repo != installed)))
3134 return SOLVER_PROBLEM_SAME_NAME;
3137 /* check conflicts in both directions */
3140 conp = s->repo->idarraydata + s->conflicts;
3141 while ((con = *conp++) != 0)
3143 FOR_PROVIDES(p, pp, con)
3145 if (dontfix && pool->solvables[p].repo == installed)
3152 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3158 conp = s2->repo->idarraydata + s2->conflicts;
3159 while ((con = *conp++) != 0)
3161 FOR_PROVIDES(p, pp, con)
3163 if (dontfix2 && pool->solvables[p].repo == installed)
3170 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3174 /* check obsoletes in both directions */
3175 if ((!installed || s->repo != installed) && s->obsoletes)
3177 obsp = s->repo->idarraydata + s->obsoletes;
3178 while ((obs = *obsp++) != 0)
3180 FOR_PROVIDES(p, pp, obs)
3187 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3191 if ((!installed || s2->repo != installed) && s2->obsoletes)
3193 obsp = s2->repo->idarraydata + s2->obsoletes;
3194 while ((obs = *obsp++) != 0)
3196 FOR_PROVIDES(p, pp, obs)
3203 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3207 /* all cases checked, can't happen */
3210 /* simple requires */
3211 assert(s->requires);
3212 reqp = s->repo->idarraydata + s->requires;
3213 while ((req = *reqp++) != 0)
3215 if (req == SOLVABLE_PREREQMARKER)
3217 dp = pool_whatprovides(pool, req);
3220 if (*dp == r->w2 && dp[1] == 0)
3223 else if (dp - pool->whatprovidesdata == r->d)
3230 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
3234 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3237 Id lreqr, lconr, lsysr, ljobr;
3241 lreqr = lconr = lsysr = ljobr = 0;
3242 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3245 if (rid >= solv->learntrules)
3246 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3247 else if (rid >= solv->systemrules)
3252 else if (rid >= solv->jobrules)
3259 r = solv->rules + rid;
3260 if (!r->d && r->w2 < 0)
3267 if (r->d == 0 && r->w2 == 0 && !reqassert)
3269 /* prefer assertions (XXX: bad idea?) */
3275 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed)
3277 /* prefer rules of installed packages */
3278 Id op = *reqrp >= 0 ? solv->rules[*reqrp].p : -*reqrp;
3279 if (op <= 0 || solv->pool->solvables[op].repo != solv->installed)
3288 /* assertion, counts as require rule */
3289 /* ignore system solvable as we need useful info */
3290 if (rid == -SYSTEMSOLVABLE)
3292 if (!*reqrp || !reqassert)
3297 else if (solv->installed && solv->pool->solvables[-rid].repo == solv->installed)
3299 /* prefer rules of installed packages */
3300 Id op = *reqrp >= 0 ? solv->rules[*reqrp].p : -*reqrp;
3301 if (op <= 0 || solv->pool->solvables[op].repo != solv->installed)
3307 if (!*reqrp && lreqr)
3309 if (!*conrp && lconr)
3311 if (!*jobrp && ljobr)
3313 if (!*sysrp && lsysr)
3318 solver_findproblemrule(Solver *solv, Id problem)
3320 Id reqr, conr, sysr, jobr;
3321 Id idx = solv->problems.elements[problem - 1];
3322 reqr = conr = sysr = jobr = 0;
3323 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3336 printprobleminfo(Solver *solv, Queue *job, Id problem)
3338 Pool *pool = solv->pool;
3340 Id dep, source, target;
3343 probr = solver_findproblemrule(solv, problem);
3344 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
3346 case SOLVER_PROBLEM_UPDATE_RULE:
3347 s = pool_id2solvable(pool, source);
3348 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
3350 case SOLVER_PROBLEM_JOB_RULE:
3351 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
3353 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
3354 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
3356 case SOLVER_PROBLEM_NOT_INSTALLABLE:
3357 s = pool_id2solvable(pool, source);
3358 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
3360 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
3361 s = pool_id2solvable(pool, source);
3362 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
3364 case SOLVER_PROBLEM_SAME_NAME:
3365 s = pool_id2solvable(pool, source);
3366 s2 = pool_id2solvable(pool, target);
3367 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
3369 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
3370 s = pool_id2solvable(pool, source);
3371 s2 = pool_id2solvable(pool, target);
3372 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3374 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
3375 s = pool_id2solvable(pool, source);
3376 s2 = pool_id2solvable(pool, target);
3377 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3379 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
3380 s = pool_id2solvable(pool, source);
3381 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
3387 printsolutions(Solver *solv, Queue *job)
3389 Pool *pool = solv->pool;
3391 Id p, rp, how, what;
3392 Id problem, solution, element;
3395 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
3398 while ((problem = solver_next_problem(solv, problem)) != 0)
3400 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
3401 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
3402 printprobleminfo(solv, job, problem);
3403 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3405 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
3408 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
3412 /* job, rp is index into job queue */
3413 how = job->elements[rp - 1] & ~SOLVER_WEAK;
3414 what = job->elements[rp];
3417 case SOLVER_INSTALL_SOLVABLE:
3418 s = pool->solvables + what;
3419 if (solv->installed && s->repo == solv->installed)
3420 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, s));
3422 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solvable2str(pool, s));
3424 case SOLVER_ERASE_SOLVABLE:
3425 s = pool->solvables + what;
3426 if (solv->installed && s->repo == solv->installed)
3427 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solvable2str(pool, s));
3429 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, s));
3431 case SOLVER_INSTALL_SOLVABLE_NAME:
3432 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", dep2str(pool, what));
3434 case SOLVER_ERASE_SOLVABLE_NAME:
3435 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", dep2str(pool, what));
3437 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3438 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable providing %s\n", dep2str(pool, what));
3440 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3441 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables providing %s\n", dep2str(pool, what));
3443 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3444 s = pool->solvables + what;
3445 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solvable2str(pool, s));
3448 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
3454 /* policy, replace p with rp */
3455 s = pool->solvables + p;
3456 sd = rp ? pool->solvables + rp : 0;
3460 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
3462 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3465 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
3467 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3470 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
3473 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));
3475 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));
3479 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3483 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
3488 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3494 /* create reverse obsoletes map for installed solvables
3496 * for each installed solvable find which packages with *different* names
3497 * obsolete the solvable.
3498 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3502 create_obsolete_index(Solver *solv)
3504 Pool *pool = solv->pool;
3506 Repo *installed = solv->installed;
3507 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3510 if (!installed || !installed->nsolvables)
3512 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
3513 for (i = 1; i < pool->nsolvables; i++)
3515 s = pool->solvables + i;
3516 if (s->repo == installed)
3520 if (!pool_installable(pool, s))
3522 obsp = s->repo->idarraydata + s->obsoletes;
3523 while ((obs = *obsp++) != 0)
3524 FOR_PROVIDES(p, pp, obs)
3526 if (pool->solvables[p].repo != installed)
3528 if (pool->solvables[p].name == s->name)
3530 obsoletes[p - installed->start]++;
3534 for (i = 0; i < installed->nsolvables; i++)
3537 n += obsoletes[i] + 1;
3540 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
3541 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
3542 for (i = pool->nsolvables - 1; i > 0; i--)
3544 s = pool->solvables + i;
3545 if (s->repo == installed)
3549 if (!pool_installable(pool, s))
3551 obsp = s->repo->idarraydata + s->obsoletes;
3552 while ((obs = *obsp++) != 0)
3553 FOR_PROVIDES(p, pp, obs)
3555 if (pool->solvables[p].repo != installed)
3557 if (pool->solvables[p].name == s->name)
3559 p -= installed->start;
3560 if (obsoletes_data[obsoletes[p]] != i)
3561 obsoletes_data[--obsoletes[p]] = i;
3567 /*-----------------------------------------------------------------*/
3577 solver_solve(Solver *solv, Queue *job)
3579 Pool *pool = solv->pool;
3580 Repo *installed = solv->installed;
3583 Map addedmap; /* '1' == have rpm-rules for solvable */
3584 Id how, what, weak, name, p, *pp, d;
3588 /* create whatprovides if not already there */
3589 if (!pool->whatprovides)
3590 pool_createwhatprovides(pool);
3592 /* create obsolete index if needed */
3593 if (solv->noupdateprovide)
3594 create_obsolete_index(solv);
3597 * create basic rule set of all involved packages
3598 * use addedmap bitmap to make sure we don't create rules twice
3602 map_init(&addedmap, pool->nsolvables);
3606 * always install our system solvable
3608 MAPSET(&addedmap, SYSTEMSOLVABLE);
3609 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3610 queue_push(&solv->decisionq_why, 0);
3611 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3614 * create rules for all package that could be involved with the solving
3615 * so called: rpm rules
3620 oldnrules = solv->nrules;
3621 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
3622 FOR_REPO_SOLVABLES(installed, p, s)
3623 addrpmrulesforsolvable(solv, s, &addedmap);
3624 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3625 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
3626 oldnrules = solv->nrules;
3627 FOR_REPO_SOLVABLES(installed, p, s)
3628 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3629 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3632 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
3633 oldnrules = solv->nrules;
3634 for (i = 0; i < job->count; i += 2)
3636 how = job->elements[i] & ~SOLVER_WEAK;
3637 what = job->elements[i + 1];
3641 case SOLVER_INSTALL_SOLVABLE:
3642 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3644 case SOLVER_INSTALL_SOLVABLE_NAME:
3645 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3646 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3647 while (ISRELDEP(name))
3649 Reldep *rd = GETRELDEP(pool, name);
3652 FOR_PROVIDES(p, pp, what)
3654 /* if by name, ensure that the name matches */
3655 if (name && pool->solvables[p].name != name)
3657 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3660 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3661 /* dont allow downgrade */
3662 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3666 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3668 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
3670 oldnrules = solv->nrules;
3671 addrpmrulesforweak(solv, &addedmap);
3672 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3674 IF_POOLDEBUG (SAT_DEBUG_STATS)
3676 int possible = 0, installable = 0;
3677 for (i = 1; i < pool->nsolvables; i++)
3679 if (pool_installable(pool, pool->solvables + i))
3681 if (MAPTST(&addedmap, i))
3684 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3688 * first pass done, we now have all the rpm rules we need.
3689 * unify existing rules before going over all job rules and
3691 * at this point the system is always solvable,
3692 * as an empty system (remove all packages) is a valid solution
3695 unifyrules(solv); /* remove duplicate rpm rules */
3696 solv->directdecisions = solv->decisionq.count;
3698 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
3699 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3700 printdecisions (solv);
3703 * now add all job rules
3706 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
3708 solv->jobrules = solv->nrules;
3710 for (i = 0; i < job->count; i += 2)
3712 oldnrules = solv->nrules;
3714 how = job->elements[i] & ~SOLVER_WEAK;
3715 weak = job->elements[i] & SOLVER_WEAK;
3716 what = job->elements[i + 1];
3719 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3720 s = pool->solvables + what;
3721 POOL_DEBUG(SAT_DEBUG_JOB, "job: install solvable %s\n", solvable2str(pool, s));
3722 addrule(solv, what, 0); /* install by Id */
3723 queue_push(&solv->ruletojob, i);
3725 queue_push(&solv->weakruleq, solv->nrules - 1);
3727 case SOLVER_ERASE_SOLVABLE:
3728 s = pool->solvables + what;
3729 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase solvable %s\n", solvable2str(pool, s));
3730 addrule(solv, -what, 0); /* remove by Id */
3731 queue_push(&solv->ruletojob, i);
3733 queue_push(&solv->weakruleq, solv->nrules - 1);
3735 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3736 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3737 if (how == SOLVER_INSTALL_SOLVABLE_NAME)
3738 POOL_DEBUG(SAT_DEBUG_JOB, "job: install name %s\n", dep2str(pool, what));
3739 if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3740 POOL_DEBUG(SAT_DEBUG_JOB, "job: install provides %s\n", dep2str(pool, what));
3742 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3743 while (ISRELDEP(name))
3745 Reldep *rd = GETRELDEP(pool, name);
3748 FOR_PROVIDES(p, pp, what)
3750 /* if by name, ensure that the name matches */
3751 if (name && pool->solvables[p].name != name)
3757 /* no provider, make this an impossible rule */
3758 queue_push(&q, -SYSTEMSOLVABLE);
3761 p = queue_shift(&q); /* get first provider */
3763 d = 0; /* single provider ? -> make assertion */
3765 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3766 addrule(solv, p, d); /* add 'requires' rule */
3767 queue_push(&solv->ruletojob, i);
3769 queue_push(&solv->weakruleq, solv->nrules - 1);
3771 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3772 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3773 if (how == SOLVER_ERASE_SOLVABLE_NAME)
3774 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase name %s\n", dep2str(pool, what));
3775 if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3776 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase provides %s\n", dep2str(pool, what));
3777 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
3778 while (ISRELDEP(name))
3780 Reldep *rd = GETRELDEP(pool, name);
3783 FOR_PROVIDES(p, pp, what)
3785 /* if by name, ensure that the name matches */
3786 if (name && pool->solvables[p].name != name)
3788 addrule(solv, -p, 0); /* add 'remove' rule */
3789 queue_push(&solv->ruletojob, i);
3791 queue_push(&solv->weakruleq, solv->nrules - 1);
3794 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3795 s = pool->solvables + what;
3796 POOL_DEBUG(SAT_DEBUG_JOB, "job: update %s\n", solvable2str(pool, s));
3797 addupdaterule(solv, s, 0);
3798 queue_push(&solv->ruletojob, i);
3800 queue_push(&solv->weakruleq, solv->nrules - 1);
3803 IF_POOLDEBUG (SAT_DEBUG_JOB)
3806 if (solv->nrules == oldnrules)
3807 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created\n");
3808 for (j = oldnrules; j < solv->nrules; j++)
3810 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
3811 printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
3815 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3818 * now add system rules
3822 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add system rules ***\n");
3825 solv->systemrules = solv->nrules;
3828 * create rules for updating installed solvables
3832 if (installed && !solv->allowuninstall)
3833 { /* loop over all installed solvables */
3834 /* we create all update rules, but disable some later on depending on the job */
3835 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3837 /* no system rules for patch atoms */
3838 if (s->freshens && !s->supplements)
3840 const char *name = id2str(pool, s->name);
3841 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
3843 addrule(solv, 0, 0);
3847 if (s->repo == installed)
3848 addupdaterule(solv, s, 0); /* allowall = 0 */
3850 addrule(solv, 0, 0); /* create dummy rule */
3852 /* consistency check: we added a rule for _every_ system solvable */
3853 assert(solv->nrules - solv->systemrules == installed->end - installed->start);
3856 /* create special weak system rules */
3857 /* those are used later on to keep a version of the installed packages in
3859 if (installed && installed->nsolvables)
3861 solv->weaksystemrules = sat_calloc(installed->end - installed->start, sizeof(Id));
3862 FOR_REPO_SOLVABLES(installed, p, s)
3864 policy_findupdatepackages(solv, s, &q, 1);
3866 solv->weaksystemrules[p - installed->start] = pool_queuetowhatprovides(pool, &q);
3870 /* free unneeded memory */
3871 map_free(&addedmap);
3874 /* create weak map */
3875 map_init(&solv->weakrulemap, solv->nrules);
3876 for (i = 0; i < solv->weakruleq.count; i++)
3878 p = solv->weakruleq.elements[i];
3879 MAPSET(&solv->weakrulemap, p);
3882 /* all new rules are learnt after this point */
3883 solv->learntrules = solv->nrules;
3885 /* disable system rules that conflict with our job */
3886 disableupdaterules(solv, job, -1);
3888 /* make decisions based on job/system assertions */
3889 makeruledecisions(solv);
3891 /* create watches chains */
3894 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
3897 run_solver(solv, 1, solv->dontinstallrecommended ? 0 : 1);
3899 /* find recommended packages */
3900 if (!solv->problems.count)
3902 Id rec, *recp, p, *pp;
3907 /* disable all weak erase rules */
3908 for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
3910 if (!MAPTST(&solv->weakrulemap, i))
3914 disablerule(solv, r);
3919 queue_clone(&olddecisions, &solv->decisionq);
3921 r = propagate(solv, 1);
3923 for (i = 0; i < olddecisions.count; i++)
3925 p = olddecisions.elements[i];
3928 if (solv->decisionmap[p] > 0)
3930 assert(solv->decisionmap[p] == 0);
3931 solv->decisionmap[p] = 1;
3932 queue_push(&solv->decisionq, p);
3933 queue_push(&solv->decisionq_why, 0);
3934 r = propagate(solv, 1);
3939 if (gotweak || solv->dontinstallrecommended)
3941 /* create map of all suggests that are still open */
3942 solv->recommends_index = -1;
3943 MAPZERO(&solv->recommendsmap);
3944 for (i = 0; i < solv->decisionq.count; i++)
3946 p = solv->decisionq.elements[i];
3949 s = pool->solvables + p;
3952 recp = s->repo->idarraydata + s->recommends;
3953 while ((rec = *recp++) != 0)
3955 FOR_PROVIDES(p, pp, rec)
3956 if (solv->decisionmap[p] > 0)
3959 continue; /* already fulfilled */
3960 FOR_PROVIDES(p, pp, rec)
3961 MAPSET(&solv->recommendsmap, p);
3965 for (i = 1; i < pool->nsolvables; i++)
3967 if (solv->decisionmap[i] != 0)
3969 s = pool->solvables + i;
3970 if (!MAPTST(&solv->recommendsmap, i))
3972 if (!s->supplements)
3974 if (!pool_installable(pool, s))
3976 if (!solver_is_supplementing(solv, s))
3979 if (solv->dontinstallrecommended)
3980 queue_push(&solv->recommendations, i);
3982 queue_pushunique(&solv->recommendations, i);
3984 /* we use MODE_SUGGEST here so that repo prio is ignored */
3985 policy_filter_unwanted(solv, &solv->recommendations, 0, POLICY_MODE_SUGGEST);
3989 queue_clone(&solv->decisionq, &olddecisions);
3990 queue_free(&olddecisions);
3991 /* XXX restore everything */
3995 /* find suggested packages */
3996 if (!solv->problems.count)
3998 Id sug, *sugp, p, *pp;
4000 /* create map of all suggests that are still open */
4001 solv->recommends_index = -1;
4002 MAPZERO(&solv->suggestsmap);
4003 for (i = 0; i < solv->decisionq.count; i++)
4005 p = solv->decisionq.elements[i];
4008 s = pool->solvables + p;
4011 sugp = s->repo->idarraydata + s->suggests;
4012 while ((sug = *sugp++) != 0)
4014 FOR_PROVIDES(p, pp, sug)
4015 if (solv->decisionmap[p] > 0)
4018 continue; /* already fulfilled */
4019 FOR_PROVIDES(p, pp, sug)
4020 MAPSET(&solv->suggestsmap, p);
4024 for (i = 1; i < pool->nsolvables; i++)
4026 if (solv->decisionmap[i] != 0)
4028 s = pool->solvables + i;
4029 if (!MAPTST(&solv->suggestsmap, i))
4033 if (!pool_installable(pool, s))
4035 if (!solver_is_enhancing(solv, s))
4038 queue_push(&solv->suggestions, i);
4040 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
4043 if (solv->problems.count)
4044 problems_to_solutions(solv, job);
4047 /***********************************************************************/
4050 solver_calc_changed_pkgs(Solver *solv, Queue *pkgs)
4052 Pool *pool = solv->pool;
4058 /* create list of solvables that have to be installed */
4059 /* (this is actually just a simple sort) */
4060 map_init(&installmap, pool->nsolvables);
4061 for (i = 1; i < solv->decisionq.count; i++)
4063 Id p = solv->decisionq.elements[i];
4066 s = pool->solvables + p;
4069 if (solv->installed && s->repo == solv->installed)
4071 MAPSET(&installmap, p);
4073 for (p = 1; p < pool->nsolvables; p++)
4074 if (MAPTST(&installmap, p))
4075 queue_push(pkgs, p);
4076 map_free(&installmap);
4077 /* run through erase solvable dudata */
4078 if (solv->installed)
4080 FOR_REPO_SOLVABLES(solv->installed, p, s)
4082 if (solv->decisionmap[p] < 0)
4083 queue_push(pkgs, -p);
4089 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
4093 solver_calc_changed_pkgs(solv, &pkgs);
4094 pool_calc_duchanges(solv->pool, &pkgs, mps, nmps);
4099 solver_calc_installsizechange(Solver *solv)
4104 solver_calc_changed_pkgs(solv, &pkgs);
4105 change = pool_calc_installsizechange(solv->pool, &pkgs);