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
33 solver_splitprovides(Solver *solv, Id dep)
35 Pool *pool = solv->pool;
40 if (!solv->dosplitprovides || !solv->installed)
44 rd = GETRELDEP(pool, dep);
45 if (rd->flags != REL_WITH)
47 FOR_PROVIDES(p, pp, dep)
49 s = pool->solvables + p;
50 if (s->repo == solv->installed && s->name == rd->name)
57 solver_dep_installed(Solver *solv, Id dep)
60 Pool *pool = solv->pool;
65 Reldep *rd = GETRELDEP(pool, dep);
66 if (rd->flags == REL_AND)
68 if (!solver_dep_installed(solv, rd->name))
70 return solver_dep_installed(solv, rd->evr);
72 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
73 return solver_dep_installed(solv, rd->evr);
75 FOR_PROVIDES(p, pp, dep)
77 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
85 /* this mirrors solver_dep_fulfilled but uses map m instead of the decisionmap */
87 dep_possible(Solver *solv, Id dep, Map *m)
89 Pool *pool = solv->pool;
94 Reldep *rd = GETRELDEP(pool, dep);
95 if (rd->flags == REL_AND)
97 if (!dep_possible(solv, rd->name, m))
99 return dep_possible(solv, rd->evr, m);
101 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
102 return solver_splitprovides(solv, rd->evr);
103 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
104 return solver_dep_installed(solv, rd->evr);
106 FOR_PROVIDES(p, pp, dep)
114 /*-----------------------------------------------------------------*/
121 printruleelement(Solver *solv, int type, Rule *r, Id v)
123 Pool *pool = solv->pool;
127 s = pool->solvables + -v;
128 POOL_DEBUG(type, " !%s [%d]", solvable2str(pool, s), -v);
132 s = pool->solvables + v;
133 POOL_DEBUG(type, " %s [%d]", solvable2str(pool, s), v);
138 POOL_DEBUG(type, " (w1)");
140 POOL_DEBUG(type, " (w2)");
142 if (solv->decisionmap[s - pool->solvables] > 0)
143 POOL_DEBUG(type, " Install.level%d", solv->decisionmap[s - pool->solvables]);
144 if (solv->decisionmap[s - pool->solvables] < 0)
145 POOL_DEBUG(type, " Conflict.level%d", -solv->decisionmap[s - pool->solvables]);
146 POOL_DEBUG(type, "\n");
155 printrule(Solver *solv, int type, Rule *r)
157 Pool *pool = solv->pool;
161 if (r >= solv->rules && r < solv->rules + solv->nrules) /* r is a solver rule */
162 POOL_DEBUG(type, "Rule #%d:", (int)(r - solv->rules));
164 POOL_DEBUG(type, "Rule:"); /* r is any rule */
166 POOL_DEBUG(type, " (disabled)");
167 POOL_DEBUG(type, "\n");
171 /* print direct literal */
173 else if (r->d == ID_NULL)
177 /* binary rule --> print w2 as second literal */
181 /* every other which is in d */
182 v = solv->pool->whatprovidesdata[r->d + i - 1];
185 printruleelement(solv, type, r, v);
187 POOL_DEBUG(type, " next rules: %d %d\n", r->n1, r->n2);
191 printruleclass(Solver *solv, int type, Rule *r)
193 Pool *pool = solv->pool;
194 Id p = r - solv->rules;
196 if (p < solv->learntrules)
197 if (MAPTST(&solv->weakrulemap, p))
198 POOL_DEBUG(type, "WEAK ");
199 if (p >= solv->learntrules)
200 POOL_DEBUG(type, "LEARNT ");
201 else if (p >= solv->systemrules)
202 POOL_DEBUG(type, "SYSTEM ");
203 else if (p >= solv->jobrules)
204 POOL_DEBUG(type, "JOB ");
205 printrule(solv, type, r);
209 /*-----------------------------------------------------------------*/
215 static Pool *unifyrules_sortcmp_data;
218 * compare rules for unification sort
222 unifyrules_sortcmp(const void *ap, const void *bp)
224 Pool *pool = unifyrules_sortcmp_data;
225 Rule *a = (Rule *)ap;
226 Rule *b = (Rule *)bp;
232 return x; /* p differs */
235 if (a->d == 0 && b->d == 0)
236 return a->w2 - b->w2; /* assertion: return w2 diff */
238 if (a->d == 0) /* a is assertion, b not */
240 x = a->w2 - pool->whatprovidesdata[b->d];
244 if (b->d == 0) /* b is assertion, a not */
246 x = pool->whatprovidesdata[a->d] - b->w2;
250 /* compare whatprovidesdata */
251 ad = pool->whatprovidesdata + a->d;
252 bd = pool->whatprovidesdata + b->d;
254 if ((x = *ad++ - *bd++) != 0)
265 unifyrules(Solver *solv)
267 Pool *pool = solv->pool;
271 if (solv->nrules <= 1) /* nothing to unify */
274 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
276 /* sort rules first */
277 unifyrules_sortcmp_data = solv->pool;
278 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
285 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
287 if (jr && !unifyrules_sortcmp(ir, jr))
288 continue; /* prune! */
289 jr = solv->rules + j++; /* keep! */
294 /* reduced count from nrules to j rules */
295 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
297 /* adapt rule buffer */
299 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
300 IF_POOLDEBUG (SAT_DEBUG_STATS)
307 for (i = 1; i < solv->nrules; i++)
314 dp = solv->pool->whatprovidesdata + r->d;
319 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
320 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
322 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
332 hashrule(Solver *solv, Id p, Id d, int n)
334 unsigned int x = (unsigned int)p;
338 return (x * 37) ^ (unsigned int)d;
339 dp = solv->pool->whatprovidesdata + d;
341 x = (x * 37) ^ (unsigned int)*dp++;
349 * p = direct literal; always < 0 for installed rpm rules
350 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
353 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
355 * p < 0 : pkg id of A
356 * d > 0 : Offset in whatprovidesdata (list of providers of b)
358 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
359 * p < 0 : pkg id of A
360 * d < 0 : Id of solvable (e.g. B1)
362 * d == 0: unary rule, assertion => (A) or (-A)
364 * Install: p > 0, d = 0 (A) user requested install
365 * Remove: p < 0, d = 0 (-A) user requested remove
366 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
367 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
368 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
369 * ? p > 0, d < 0 (A|-B)
370 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
374 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
375 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
376 * every other : w1 = p, w2 = whatprovidesdata[d];
377 * Disabled rule: w1 = 0
379 * always returns a rule for non-rpm rules
383 addrule(Solver *solv, Id p, Id d)
385 Pool *pool = solv->pool;
389 int n = 0; /* number of literals in rule - 1
390 0 = direct assertion (single literal)
394 /* it often happenes that requires lead to adding the same rpm rule
395 * multiple times, so we prune those duplicates right away to make
396 * the work for unifyrules a bit easier */
398 if (solv->nrules && !solv->jobrules)
400 r = solv->rules + solv->nrules - 1; /* get the last added rule */
401 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
407 /* always a binary rule */
409 return 0; /* ignore self conflict */
414 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
416 return 0; /* rule is self-fulfilling */
418 d = dp[-1]; /* take single literal */
422 if (n == 0 && !solv->jobrules)
424 /* this is a rpm rule assertion, we do not have to allocate it */
425 /* it can be identified by a level of 1 and a zero reason */
426 /* we must not drop those rules from the decisionq when rewinding! */
428 assert(solv->decisionmap[-p] == 0 || solv->decisionmap[-p] == -1);
429 if (solv->decisionmap[-p])
430 return 0; /* already got that one */
431 queue_push(&solv->decisionq, p);
432 queue_push(&solv->decisionq_why, 0);
433 solv->decisionmap[-p] = -1;
440 /* smallest literal first so we can find dups */
444 n = 1; /* re-set n, was used as temp var */
447 /* check if the last added rule is exactly the same as what we're looking for. */
448 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
449 return r; /* binary rule */
451 if (r && n > 1 && r->d && r->p == p)
453 /* Rule where d is an offset in whatprovidesdata */
457 dp2 = pool->whatprovidesdata + r->d;
458 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
469 /* extend rule buffer */
470 solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
471 r = solv->rules + solv->nrules++; /* point to rule space */
476 /* direct assertion, no watch needed */
492 r->w2 = pool->whatprovidesdata[d];
497 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
499 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
500 printrule(solv, SAT_DEBUG_RULE_CREATION, r);
507 disablerule(Solver *solv, Rule *r)
513 enablerule(Solver *solv, Rule *r)
515 if (r->d == 0 || r->w2 != r->p)
518 r->w1 = solv->pool->whatprovidesdata[r->d];
522 /**********************************************************************************/
524 /* a problem is an item on the solver's problem list. It can either be >0, in that
525 * case it is a system (upgrade) rule, or it can be <0, which makes it refer to a job
526 * consisting of multiple job rules.
530 disableproblem(Solver *solv, Id v)
538 disablerule(solv, solv->rules + v);
542 jp = solv->ruletojob.elements;
543 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
545 disablerule(solv, r);
549 enableproblem(Solver *solv, Id v)
557 enablerule(solv, solv->rules + v);
561 jp = solv->ruletojob.elements;
562 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
568 printproblem(Solver *solv, Id v)
570 Pool *pool = solv->pool;
576 printrule(solv, SAT_DEBUG_SOLUTIONS, solv->rules + v);
580 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "JOB %d\n", v);
581 jp = solv->ruletojob.elements;
582 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
585 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "- ");
586 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
588 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "ENDJOB\n");
594 /************************************************************************/
596 /* go through system and job rules and add direct assertions
597 * to the decisionqueue. If we find a conflict, disable rules and
598 * add them to problem queue.
601 makeruledecisions(Solver *solv)
603 Pool *pool = solv->pool;
609 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
611 decisionstart = solv->decisionq.count;
612 /* rpm rules don't have assertions, so we can start with the job
613 * rules (rpm assertions are not resulting in a rule, but cause a
614 * immediate decision) */
615 /* nowadays they can be weak, so start with rule 1 */
616 for (ri = 1, r = solv->rules + ri; ri < solv->nrules; ri++, r++)
618 if (!r->w1 || r->w2) /* disabled or no assertion */
620 /* do weak rules in phase 2 */
621 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
625 if (!solv->decisionmap[vv])
627 queue_push(&solv->decisionq, v);
628 queue_push(&solv->decisionq_why, r - solv->rules);
629 solv->decisionmap[vv] = v > 0 ? 1 : -1;
630 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
632 Solvable *s = solv->pool->solvables + vv;
634 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
636 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
640 if (v > 0 && solv->decisionmap[vv] > 0)
642 if (v < 0 && solv->decisionmap[vv] < 0)
644 /* found a conflict! */
645 if (ri >= solv->learntrules)
647 /* conflict with a learnt rule */
648 /* can happen when packages cannot be installed for
649 * multiple reasons. */
650 /* we disable the learnt rule in this case */
651 disablerule(solv, r);
654 /* only job and system rules left in the decisionq */
655 /* find the decision which is the "opposite" of the jobrule */
656 for (i = 0; i < solv->decisionq.count; i++)
657 if (solv->decisionq.elements[i] == -v)
659 assert(i < solv->decisionq.count);
660 if (v == -SYSTEMSOLVABLE) {
661 /* conflict with system solvable */
662 queue_push(&solv->problems, solv->learnt_pool.count);
663 queue_push(&solv->learnt_pool, ri);
664 queue_push(&solv->learnt_pool, 0);
665 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
666 if (ri < solv->systemrules)
667 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
670 queue_push(&solv->problems, v);
671 queue_push(&solv->problems, 0);
672 disableproblem(solv, v);
675 assert(solv->decisionq_why.elements[i]);
676 if (solv->decisionq_why.elements[i] < solv->jobrules)
678 /* conflict with rpm rule assertion */
679 queue_push(&solv->problems, solv->learnt_pool.count);
680 queue_push(&solv->learnt_pool, ri);
681 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
682 queue_push(&solv->learnt_pool, 0);
683 assert(v > 0 || v == -SYSTEMSOLVABLE);
684 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
685 if (ri < solv->systemrules)
686 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
689 queue_push(&solv->problems, v);
690 queue_push(&solv->problems, 0);
691 disableproblem(solv, v);
695 /* conflict with another job or system rule */
697 queue_push(&solv->problems, solv->learnt_pool.count);
698 queue_push(&solv->learnt_pool, ri);
699 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
700 queue_push(&solv->learnt_pool, 0);
702 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting system/job assertions over literal %d\n", vv);
704 /* push all of our rules asserting this literal on the problem stack */
705 for (i = solv->jobrules, rr = solv->rules + i; i < solv->nrules; i++, rr++)
707 if (!rr->w1 || rr->w2)
709 if (rr->p != vv && rr->p != -vv)
711 if (i >= solv->learntrules)
713 if (MAPTST(&solv->weakrulemap, i))
715 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
717 if (i < solv->systemrules)
718 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
719 queue_push(&solv->problems, v);
720 disableproblem(solv, v);
722 queue_push(&solv->problems, 0);
725 while (solv->decisionq.count > decisionstart)
727 v = solv->decisionq.elements[--solv->decisionq.count];
728 --solv->decisionq_why.count;
730 solv->decisionmap[vv] = 0;
732 ri = solv->jobrules - 1;
733 r = solv->rules + ri;
736 /* phase 2: now do the weak assertions */
737 for (ri = 1, r = solv->rules + ri; ri < solv->learntrules; ri++, r++)
739 if (!r->w1 || r->w2) /* disabled or no assertion */
741 if (!MAPTST(&solv->weakrulemap, ri))
745 if (!solv->decisionmap[vv])
747 queue_push(&solv->decisionq, v);
748 queue_push(&solv->decisionq_why, r - solv->rules);
749 solv->decisionmap[vv] = v > 0 ? 1 : -1;
750 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
752 Solvable *s = solv->pool->solvables + vv;
754 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", solvable2str(solv->pool, s));
756 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", solvable2str(solv->pool, s));
760 if (v > 0 && solv->decisionmap[vv] > 0)
762 if (v < 0 && solv->decisionmap[vv] < 0)
764 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
765 printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
766 disablerule(solv, r);
769 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
773 * we have enabled or disabled some of our rules. We now reenable all
774 * of our learnt rules but the ones that were learnt from rules that
778 enabledisablelearntrules(Solver *solv)
780 Pool *pool = solv->pool;
785 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
786 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
788 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
789 while ((why = *whyp++) != 0)
793 continue; /* rpm assertion */
796 if (!solv->rules[why].w1)
799 /* why != 0: we found a disabled rule, disable the learnt rule */
802 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
804 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling ");
805 printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
807 disablerule(solv, r);
809 else if (!why && !r->w1)
811 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
813 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling ");
814 printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
822 /* FIXME: bad code ahead, replace as soon as possible */
823 /* FIXME: should probably look at SOLVER_INSTALL_SOLVABLE_ONE_OF */
826 disableupdaterules(Solver *solv, Queue *job, int jobidx)
828 Pool *pool = solv->pool;
830 Id name, how, what, p, *pp;
836 installed = solv->installed;
842 how = job->elements[jobidx] & ~SOLVER_WEAK;
845 case SOLVER_INSTALL_SOLVABLE:
846 case SOLVER_ERASE_SOLVABLE:
847 case SOLVER_ERASE_SOLVABLE_NAME:
848 case SOLVER_ERASE_SOLVABLE_PROVIDES:
854 /* go through all enabled job rules */
855 MAPZERO(&solv->noupdate);
856 for (i = solv->jobrules; i < solv->systemrules; i++)
859 if (!r->w1) /* disabled? */
861 j = solv->ruletojob.elements[i - solv->jobrules];
865 how = job->elements[j] & ~SOLVER_WEAK;
866 what = job->elements[j + 1];
869 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
870 s = pool->solvables + what;
871 FOR_PROVIDES(p, pp, s->name)
873 if (pool->solvables[p].name != s->name)
875 if (pool->solvables[p].repo == installed)
876 MAPSET(&solv->noupdate, p - installed->start);
879 case SOLVER_ERASE_SOLVABLE:
880 s = pool->solvables + what;
881 if (s->repo == installed)
882 MAPSET(&solv->noupdate, what - installed->start);
884 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
885 case SOLVER_ERASE_SOLVABLE_PROVIDES:
886 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
887 while (ISRELDEP(name))
889 Reldep *rd = GETRELDEP(pool, name);
892 FOR_PROVIDES(p, pp, what)
894 if (name && pool->solvables[p].name != name)
896 if (pool->solvables[p].repo == installed)
897 MAPSET(&solv->noupdate, p - installed->start);
905 /* fixup update rule status */
906 if (solv->allowuninstall)
907 return; /* no update rules at all */
911 /* we just disabled job #jobidx. enable all update rules
912 * that aren't disabled by the remaining job rules */
913 how = job->elements[jobidx] & ~SOLVER_WEAK;
914 what = job->elements[jobidx + 1];
917 case SOLVER_INSTALL_SOLVABLE:
918 s = pool->solvables + what;
919 FOR_PROVIDES(p, pp, s->name)
921 if (pool->solvables[p].name != s->name)
923 if (pool->solvables[p].repo != installed)
925 if (MAPTST(&solv->noupdate, p - installed->start))
927 r = solv->rules + solv->systemrules + (p - installed->start);
931 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
933 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
934 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
938 case SOLVER_ERASE_SOLVABLE:
939 s = pool->solvables + what;
940 if (s->repo != installed)
942 if (MAPTST(&solv->noupdate, what - installed->start))
944 r = solv->rules + solv->systemrules + (what - installed->start);
948 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
950 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
951 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
954 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
955 case SOLVER_ERASE_SOLVABLE_PROVIDES:
956 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
957 while (ISRELDEP(name))
959 Reldep *rd = GETRELDEP(pool, name);
962 FOR_PROVIDES(p, pp, what)
964 if (name && pool->solvables[p].name != name)
966 if (pool->solvables[p].repo != installed)
968 if (MAPTST(&solv->noupdate, p - installed->start))
970 r = solv->rules + solv->systemrules + (p - installed->start);
974 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
976 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
977 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
987 for (i = 0; i < installed->nsolvables; i++)
989 r = solv->rules + solv->systemrules + i;
990 if (r->w1 && MAPTST(&solv->noupdate, i))
991 disablerule(solv, r); /* was enabled, need to disable */
997 addpatchatomrequires(Solver *solv, Solvable *s, Id *dp, Queue *q, Map *m)
999 Pool *pool = solv->pool;
1000 Id fre, *frep, p, *pp, ndp;
1006 queue_init_buffer(&fq, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1007 queue_push(&fq, -(s - pool->solvables));
1009 queue_push(&fq, *dp);
1010 ndp = pool_queuetowhatprovides(pool, &fq);
1011 frep = s->repo->idarraydata + s->freshens;
1012 while ((fre = *frep++) != 0)
1014 FOR_PROVIDES(p, pp, fre)
1016 ps = pool->solvables + p;
1017 addrule(solv, -p, ndp);
1025 for (i = 1; i < fq.count; i++)
1038 * add (install) rules for solvable
1039 * for unfulfilled requirements, conflicts, obsoletes,....
1040 * add a negative assertion for solvables that are not installable
1044 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
1046 Pool *pool = solv->pool;
1047 Repo *installed = solv->installed;
1062 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
1064 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1065 queue_push(&q, s - pool->solvables); /* push solvable Id */
1071 * s: Pointer to solvable
1074 n = queue_shift(&q);
1075 if (MAPTST(m, n)) /* continue if already done */
1079 s = pool->solvables + n; /* s = Solvable in question */
1082 if (installed /* Installed system available */
1083 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
1084 && s->repo == installed) /* solvable is installed? */
1086 dontfix = 1; /* dont care about broken rpm deps */
1089 if (!dontfix && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
1091 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
1092 addrule(solv, -n, 0); /* uninstallable */
1096 if (s->freshens && !s->supplements)
1098 const char *name = id2str(pool, s->name);
1099 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
1103 /*-----------------------------------------
1104 * check requires of s
1109 reqp = s->repo->idarraydata + s->requires;
1110 while ((req = *reqp++) != 0) /* go throw all requires */
1112 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
1115 dp = pool_whatprovides(pool, req);
1117 if (*dp == SYSTEMSOLVABLE) /* always installed */
1123 addpatchatomrequires(solv, s, dp, &q, m);
1129 /* the strategy here is to not insist on dependencies
1130 * that are already broken. so if we find one provider
1131 * that was already installed, we know that the
1132 * dependency was not broken before so we enforce it */
1133 for (i = 0; (p = dp[i]) != 0; i++) /* for all providers */
1135 if (pool->solvables[p].repo == installed)
1136 break; /* provider was installed */
1138 if (!p) /* previously broken dependency */
1140 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1147 /* nothing provides req! */
1148 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1149 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1153 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1155 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1156 for (i = 0; dp[i]; i++)
1157 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1160 /* add 'requires' dependency */
1161 /* rule: (-requestor|provider1|provider2|...|providerN) */
1162 addrule(solv, -n, dp - pool->whatprovidesdata);
1164 /* descend the dependency tree */
1165 for (; *dp; dp++) /* loop through all providers */
1167 if (!MAPTST(m, *dp))
1168 queue_push(&q, *dp);
1171 } /* while, requirements of n */
1173 } /* if, requirements */
1175 /* that's all we check for src packages */
1176 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1179 /*-----------------------------------------
1180 * check conflicts of s
1185 conp = s->repo->idarraydata + s->conflicts;
1186 while ((con = *conp++) != 0)
1188 FOR_PROVIDES(p, pp, con)
1190 /* dontfix: dont care about conflicts with already installed packs */
1191 if (dontfix && pool->solvables[p].repo == installed)
1193 /* rule: -n|-p: either solvable _or_ provider of conflict */
1194 addrule(solv, -n, -p);
1199 /*-----------------------------------------
1200 * check obsoletes if not installed
1202 if (!installed || pool->solvables[n].repo != installed)
1203 { /* not installed */
1206 obsp = s->repo->idarraydata + s->obsoletes;
1207 while ((obs = *obsp++) != 0)
1209 FOR_PROVIDES(p, pp, obs)
1210 addrule(solv, -n, -p);
1213 FOR_PROVIDES(p, pp, s->name)
1215 if (s->name == pool->solvables[p].name)
1216 addrule(solv, -n, -p);
1220 /*-----------------------------------------
1221 * add recommends to the rule list
1225 recp = s->repo->idarraydata + s->recommends;
1226 while ((rec = *recp++) != 0)
1228 FOR_PROVIDES(p, pp, rec)
1235 sugp = s->repo->idarraydata + s->suggests;
1236 while ((sug = *sugp++) != 0)
1238 FOR_PROVIDES(p, pp, sug)
1245 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1249 addrpmrulesforweak(Solver *solv, Map *m)
1251 Pool *pool = solv->pool;
1256 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1257 for (i = n = 1; n < pool->nsolvables; i++, n++)
1259 if (i == pool->nsolvables)
1263 s = pool->solvables + i;
1264 if (!pool_installable(pool, s))
1269 supp = s->repo->idarraydata + s->supplements;
1270 while ((sup = *supp++) != ID_NULL)
1271 if (dep_possible(solv, sup, m))
1274 if (!sup && s->freshens)
1276 supp = s->repo->idarraydata + s->freshens;
1277 while ((sup = *supp++) != ID_NULL)
1278 if (dep_possible(solv, sup, m))
1281 if (!sup && s->enhances)
1283 supp = s->repo->idarraydata + s->enhances;
1284 while ((sup = *supp++) != ID_NULL)
1285 if (dep_possible(solv, sup, m))
1290 addrpmrulesforsolvable(solv, s, m);
1293 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1297 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
1299 Pool *pool = solv->pool;
1304 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1306 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1307 policy_findupdatepackages(solv, s, &qs, allowall);
1308 if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
1309 addrpmrulesforsolvable(solv, s, m);
1310 for (i = 0; i < qs.count; i++)
1311 if (!MAPTST(m, qs.elements[i]))
1312 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1315 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1319 * add rule for update
1320 * (A|A1|A2|A3...) An = update candidates for A
1322 * s = (installed) solvable
1326 addupdaterule(Solver *solv, Solvable *s, int allowall)
1328 /* installed packages get a special upgrade allowed rule */
1329 Pool *pool = solv->pool;
1334 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1336 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1337 policy_findupdatepackages(solv, s, &qs, allowall);
1338 if (qs.count == 0) /* no updaters found */
1341 d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
1343 addrule(solv, s - pool->solvables, d); /* allow update of s */
1344 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1348 /*-----------------------------------------------------------------*/
1357 printWatches(Solver *solv, int type)
1359 Pool *pool = solv->pool;
1362 POOL_DEBUG(type, "Watches: \n");
1363 for (counter = -(pool->nsolvables - 1); counter < pool->nsolvables; counter++)
1364 POOL_DEBUG(type, " solvable [%d] -- rule [%d]\n", counter, solv->watches[counter + pool->nsolvables]);
1370 * initial setup for all watches
1374 makewatches(Solver *solv)
1378 int nsolvables = solv->pool->nsolvables;
1380 sat_free(solv->watches);
1381 /* lower half for removals, upper half for installs */
1382 solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
1384 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
1385 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1387 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1390 if (!r->w1 /* rule is disabled */
1391 || !r->w2) /* rule is assertion */
1394 /* see addwatches(solv, r) */
1395 r->n1 = solv->watches[nsolvables + r->w1];
1396 solv->watches[nsolvables + r->w1] = r - solv->rules;
1398 r->n2 = solv->watches[nsolvables + r->w2];
1399 solv->watches[nsolvables + r->w2] = r - solv->rules;
1405 * add watches (for rule)
1409 addwatches(Solver *solv, Rule *r)
1411 int nsolvables = solv->pool->nsolvables;
1413 r->n1 = solv->watches[nsolvables + r->w1];
1414 solv->watches[nsolvables + r->w1] = r - solv->rules;
1416 r->n2 = solv->watches[nsolvables + r->w2];
1417 solv->watches[nsolvables + r->w2] = r - solv->rules;
1421 /*-----------------------------------------------------------------*/
1422 /* rule propagation */
1424 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1425 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
1430 * propagate decision to all rules
1431 * return : 0 = everything is OK
1432 * watched rule = there is a conflict
1436 propagate(Solver *solv, int level)
1438 Pool *pool = solv->pool;
1443 Id *decisionmap = solv->decisionmap;
1444 Id *watches = solv->watches + pool->nsolvables;
1446 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1448 while (solv->propagate_index < solv->decisionq.count)
1450 /* negate because our watches trigger if literal goes FALSE */
1451 pkg = -solv->decisionq.elements[solv->propagate_index++];
1452 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1454 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
1455 printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1457 printWatches(solv, SAT_DEBUG_SCHUBI);
1460 for (rp = watches + pkg; *rp; rp = nrp)
1462 r = solv->rules + *rp;
1464 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1466 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1467 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1472 ow = r->w2; /* regard the second watchpoint to come to a solution */
1477 ow = r->w1; /* regard the first watchpoint to come to a solution */
1480 /* if clause is TRUE, nothing to do */
1481 if (DECISIONMAP_TRUE(ow))
1486 /* not a binary clause, check if we need to move our watch */
1487 /* search for a literal that is not ow and not false */
1488 /* (true is also ok, in that case the rule is fulfilled) */
1489 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1492 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1493 if (p != ow && !DECISIONMAP_TRUE(-p))
1497 /* p is free to watch, move watch to p */
1498 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1501 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1503 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1517 watches[p] = r - solv->rules;
1521 /* unit clause found, set other watch to TRUE */
1522 if (DECISIONMAP_TRUE(-ow))
1523 return r; /* eek, a conflict! */
1524 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1526 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
1527 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1530 decisionmap[ow] = level;
1532 decisionmap[-ow] = -level;
1533 queue_push(&solv->decisionq, ow);
1534 queue_push(&solv->decisionq_why, r - solv->rules);
1535 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1537 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1539 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
1541 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
1545 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
1547 return 0; /* all is well */
1551 /*-----------------------------------------------------------------*/
1560 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
1562 Pool *pool = solv->pool;
1565 Map seen; /* global? */
1568 int num = 0, l1num = 0;
1569 int learnt_why = solv->learnt_pool.count;
1570 Id *decisionmap = solv->decisionmap;
1574 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
1575 map_init(&seen, pool->nsolvables);
1576 idx = solv->decisionq.count;
1579 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1580 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1581 queue_push(&solv->learnt_pool, c - solv->rules);
1582 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1583 /* go through all literals of the rule */
1595 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1597 vv = v > 0 ? v : -v;
1598 if (MAPTST(&seen, vv))
1600 l = solv->decisionmap[vv];
1605 /* a level 1 literal, mark it for later */
1606 MAPSET(&seen, vv); /* mark for scanning in level 1 phase */
1612 num++; /* need to do this one as well */
1623 v = solv->decisionq.elements[--idx];
1624 vv = v > 0 ? v : -v;
1625 if (MAPTST(&seen, vv))
1628 c = solv->rules + solv->decisionq_why.elements[idx];
1633 *pr = -v; /* so that v doesn't get lost */
1635 /* add involved level 1 rules */
1638 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1642 v = solv->decisionq.elements[--idx];
1643 vv = v > 0 ? v : -v;
1644 if (!MAPTST(&seen, vv))
1646 why = solv->decisionq_why.elements[idx];
1649 queue_push(&solv->learnt_pool, -vv);
1650 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1652 POOL_DEBUG(SAT_DEBUG_ANALYZE, "RPM ASSERT Rule:\n");
1653 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, v);
1657 queue_push(&solv->learnt_pool, why);
1658 c = solv->rules + why;
1659 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1660 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1661 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1672 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1674 vv = v > 0 ? v : -v;
1675 l = solv->decisionmap[vv];
1676 if (l != 1 && l != -1)
1686 else if (r.count == 1 && r.elements[0] < 0)
1687 *dr = r.elements[0];
1689 *dr = pool_queuetowhatprovides(pool, &r);
1690 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1692 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1693 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
1694 for (i = 0; i < r.count; i++)
1695 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
1697 /* push end marker on learnt reasons stack */
1698 queue_push(&solv->learnt_pool, 0);
1707 * reset the solver decisions to right after the rpm rules.
1708 * called after rules have been enabled/disabled
1712 reset_solver(Solver *solv)
1714 Pool *pool = solv->pool;
1718 /* rewind decisions to direct rpm rule assertions */
1719 for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
1721 v = solv->decisionq.elements[i];
1722 solv->decisionmap[v > 0 ? v : -v] = 0;
1725 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
1727 solv->decisionq_why.count = solv->directdecisions;
1728 solv->decisionq.count = solv->directdecisions;
1729 solv->recommends_index = -1;
1730 solv->propagate_index = 0;
1732 /* adapt learnt rule status to new set of enabled/disabled rules */
1733 enabledisablelearntrules(solv);
1735 /* redo all job/system decisions */
1736 makeruledecisions(solv);
1737 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
1739 /* recreate watch chains */
1745 * analyze_unsolvable_rule
1749 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
1751 Pool *pool = solv->pool;
1753 Id why = r - solv->rules;
1755 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1756 printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1757 if (solv->learntrules && why >= solv->learntrules)
1759 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1760 if (solv->learnt_pool.elements[i] > 0)
1761 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp);
1764 if (MAPTST(&solv->weakrulemap, why))
1765 if (!*lastweakp || why > *lastweakp)
1767 /* do not add rpm rules to problem */
1768 if (why < solv->jobrules)
1770 /* turn rule into problem */
1771 if (why >= solv->jobrules && why < solv->systemrules)
1772 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1773 /* return if problem already countains our rule */
1774 if (solv->problems.count)
1776 for (i = solv->problems.count - 1; i >= 0; i--)
1777 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1779 else if (solv->problems.elements[i] == why)
1782 queue_push(&solv->problems, why);
1787 * analyze_unsolvable
1789 * return: 1 - disabled some rules, try again
1794 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1796 Pool *pool = solv->pool;
1798 Map seen; /* global to speed things up? */
1801 Id *decisionmap = solv->decisionmap;
1802 int oldproblemcount;
1803 int oldlearntpoolcount;
1806 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1807 oldproblemcount = solv->problems.count;
1808 oldlearntpoolcount = solv->learnt_pool.count;
1810 /* make room for proof index */
1811 /* must update it later, as analyze_unsolvable_rule would confuse
1812 * it with a rule index if we put the real value in already */
1813 queue_push(&solv->problems, 0);
1816 map_init(&seen, pool->nsolvables);
1817 queue_push(&solv->learnt_pool, r - solv->rules);
1819 analyze_unsolvable_rule(solv, r, &lastweak);
1820 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1831 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1833 vv = v > 0 ? v : -v;
1834 l = solv->decisionmap[vv];
1839 idx = solv->decisionq.count;
1842 v = solv->decisionq.elements[--idx];
1843 vv = v > 0 ? v : -v;
1844 if (!MAPTST(&seen, vv))
1846 why = solv->decisionq_why.elements[idx];
1847 queue_push(&solv->learnt_pool, why);
1848 r = solv->rules + why;
1849 analyze_unsolvable_rule(solv, r, &lastweak);
1850 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1861 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1863 vv = v > 0 ? v : -v;
1864 l = solv->decisionmap[vv];
1871 queue_push(&solv->problems, 0); /* mark end of this problem */
1875 /* disable last weak rule */
1876 solv->problems.count = oldproblemcount;
1877 solv->learnt_pool.count = oldlearntpoolcount;
1878 r = solv->rules + lastweak;
1879 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling ");
1880 printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1881 disablerule(solv, r);
1887 queue_push(&solv->learnt_pool, 0);
1888 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1892 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1893 disableproblem(solv, solv->problems.elements[i]);
1897 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1902 /*-----------------------------------------------------------------*/
1903 /* Decision revert */
1907 * revert decision at level
1911 revert(Solver *solv, int level)
1913 Pool *pool = solv->pool;
1915 while (solv->decisionq.count)
1917 v = solv->decisionq.elements[solv->decisionq.count - 1];
1918 vv = v > 0 ? v : -v;
1919 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1921 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1922 if (v > 0 && solv->recommendations.count && v == solv->recommendations.elements[solv->recommendations.count - 1])
1923 solv->recommendations.count--;
1924 solv->decisionmap[vv] = 0;
1925 solv->decisionq.count--;
1926 solv->decisionq_why.count--;
1927 solv->propagate_index = solv->decisionq.count;
1929 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1931 solv->branches.count--;
1932 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1933 solv->branches.count--;
1935 solv->recommends_index = -1;
1940 * watch2onhighest - put watch2 on literal with highest level
1944 watch2onhighest(Solver *solv, Rule *r)
1950 return; /* binary rule, both watches are set */
1951 dp = solv->pool->whatprovidesdata + r->d;
1952 while ((v = *dp++) != 0)
1954 l = solv->decisionmap[v < 0 ? -v : v];
1969 * add free decision to decisionq, increase level and
1970 * propagate decision, return if no conflict.
1971 * in conflict case, analyze conflict rule, add resulting
1972 * rule to learnt rule set, make decision from learnt
1973 * rule (always unit) and re-propagate.
1975 * returns the new solver level or 0 if unsolvable
1980 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1982 Pool *pool = solv->pool;
1991 solv->decisionmap[decision] = level;
1993 solv->decisionmap[-decision] = -level;
1994 queue_push(&solv->decisionq, decision);
1995 queue_push(&solv->decisionq_why, 0);
1999 r = propagate(solv, level);
2003 return analyze_unsolvable(solv, r, disablerules);
2004 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
2005 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
2006 assert(l > 0 && l < level);
2007 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
2009 revert(solv, level);
2010 r = addrule(solv, p, d); /* p requires d */
2012 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
2013 queue_push(&solv->learnt_why, why);
2016 /* at least 2 literals, needs watches */
2017 watch2onhighest(solv, r);
2018 addwatches(solv, r);
2020 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
2021 queue_push(&solv->decisionq, p);
2022 queue_push(&solv->decisionq_why, r - solv->rules);
2023 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
2025 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
2026 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
2027 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
2028 printrule(solv, SAT_DEBUG_ANALYZE, r);
2036 * install best package from the queue. We add an extra package, inst, if
2037 * provided. See comment in weak install section.
2039 * returns the new solver level or 0 if unsolvable
2043 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
2045 Pool *pool = solv->pool;
2049 if (dq->count > 1 || inst)
2050 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
2055 /* choose the supplemented one */
2056 for (i = 0; i < dq->count; i++)
2057 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
2061 for (i = 1; i < dq->count; i++)
2062 queue_push(&solv->branches, dq->elements[i]);
2063 queue_push(&solv->branches, -level);
2067 p = dq->elements[i];
2069 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
2071 return setpropagatelearn(solv, level, p, disablerules);
2075 /*-----------------------------------------------------------------*/
2076 /* Main solver interface */
2081 * create solver structure
2083 * pool: all available solvables
2084 * installed: installed Solvables
2087 * Upon solving, rules are created to flag the Solvables
2088 * of the 'installed' Repo as installed.
2092 solver_create(Pool *pool, Repo *installed)
2095 solv = (Solver *)sat_calloc(1, sizeof(Solver));
2097 solv->installed = installed;
2099 queue_init(&solv->ruletojob);
2100 queue_init(&solv->decisionq);
2101 queue_init(&solv->decisionq_why);
2102 queue_init(&solv->problems);
2103 queue_init(&solv->suggestions);
2104 queue_init(&solv->recommendations);
2105 queue_init(&solv->learnt_why);
2106 queue_init(&solv->learnt_pool);
2107 queue_init(&solv->branches);
2108 queue_init(&solv->covenantq);
2109 queue_init(&solv->weakruleq);
2111 map_init(&solv->recommendsmap, pool->nsolvables);
2112 map_init(&solv->suggestsmap, pool->nsolvables);
2113 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
2114 solv->recommends_index = 0;
2116 solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2118 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
2119 memset(solv->rules, 0, sizeof(Rule));
2130 solver_free(Solver *solv)
2132 queue_free(&solv->ruletojob);
2133 queue_free(&solv->decisionq);
2134 queue_free(&solv->decisionq_why);
2135 queue_free(&solv->learnt_why);
2136 queue_free(&solv->learnt_pool);
2137 queue_free(&solv->problems);
2138 queue_free(&solv->suggestions);
2139 queue_free(&solv->recommendations);
2140 queue_free(&solv->branches);
2141 queue_free(&solv->covenantq);
2142 queue_free(&solv->weakruleq);
2144 map_free(&solv->recommendsmap);
2145 map_free(&solv->suggestsmap);
2146 map_free(&solv->noupdate);
2147 map_free(&solv->weakrulemap);
2149 sat_free(solv->decisionmap);
2150 sat_free(solv->rules);
2151 sat_free(solv->watches);
2152 sat_free(solv->weaksystemrules);
2153 sat_free(solv->obsoletes);
2154 sat_free(solv->obsoletes_data);
2159 /*-------------------------------------------------------*/
2164 * all rules have been set up, now actually run the solver
2169 run_solver(Solver *solv, int disablerules, int doweak)
2177 Pool *pool = solv->pool;
2180 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2182 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2183 for (i = 1; i < solv->nrules; i++)
2184 printruleclass(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2187 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2189 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2190 printdecisions(solv);
2192 /* start SAT algorithm */
2194 systemlevel = level + 1;
2195 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2200 * here's the main loop:
2201 * 1) propagate new decisions (only needed for level 1)
2202 * 2) try to keep installed packages
2203 * 3) fulfill all unresolved rules
2204 * 4) install recommended packages
2205 * 5) minimalize solution if we had choices
2206 * if we encounter a problem, we rewind to a safe level and restart
2218 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2219 if ((r = propagate(solv, level)) != 0)
2221 if (analyze_unsolvable(solv, r, disablerules))
2229 * installed packages
2232 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2234 if (!solv->updatesystem)
2236 /* try to keep as many packages as possible */
2237 POOL_DEBUG(SAT_DEBUG_STATS, "installing system packages\n");
2238 for (i = solv->installed->start; i < solv->installed->end; i++)
2240 s = pool->solvables + i;
2241 if (s->repo != solv->installed)
2243 if (solv->decisionmap[i] != 0)
2245 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2247 level = setpropagatelearn(solv, level, i, disablerules);
2253 if (level <= olevel)
2256 if (i < solv->installed->end)
2259 if (solv->weaksystemrules)
2261 POOL_DEBUG(SAT_DEBUG_STATS, "installing weak system packages\n");
2262 for (i = solv->installed->start; i < solv->installed->end; i++)
2264 s = pool->solvables + i;
2265 if (s->repo != solv->installed)
2267 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
2269 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2270 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2273 if (solv->weaksystemrules[i - solv->installed->start])
2275 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
2276 while ((p = *dp++) != 0)
2278 if (solv->decisionmap[p] > 0)
2280 if (solv->decisionmap[p] == 0)
2284 continue; /* update package already installed */
2286 if (!dq.count && solv->decisionmap[i] != 0)
2289 /* FIXME: i is handled a bit different because we do not want
2290 * to have it pruned just because it is not recommened.
2291 * we should not prune installed packages instead */
2292 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2298 if (level <= olevel)
2301 if (i < solv->installed->end)
2304 systemlevel = level;
2311 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unresolved rules\n");
2312 for (i = 1, n = 1; ; i++, n++)
2314 if (n == solv->nrules)
2316 if (i == solv->nrules)
2318 r = solv->rules + i;
2319 if (!r->w1) /* ignore disabled rules */
2324 /* binary or unary rule */
2325 /* need two positive undecided literals */
2326 if (r->p < 0 || r->w2 <= 0)
2328 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2330 queue_push(&dq, r->p);
2331 queue_push(&dq, r->w2);
2336 * all negative literals are installed
2337 * no positive literal is installed
2338 * i.e. the rule is not fulfilled and we
2339 * just need to decide on the positive literals
2343 if (solv->decisionmap[-r->p] <= 0)
2348 if (solv->decisionmap[r->p] > 0)
2350 if (solv->decisionmap[r->p] == 0)
2351 queue_push(&dq, r->p);
2353 dp = pool->whatprovidesdata + r->d;
2354 while ((p = *dp++) != 0)
2358 if (solv->decisionmap[-p] <= 0)
2363 if (solv->decisionmap[p] > 0)
2365 if (solv->decisionmap[p] == 0)
2372 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2374 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2375 printruleclass(solv, SAT_DEBUG_PROPAGATE, r);
2377 /* dq.count < 2 cannot happen as this means that
2378 * the rule is unit */
2379 assert(dq.count > 1);
2382 level = selectandinstall(solv, level, &dq, 0, disablerules);
2388 if (level < systemlevel)
2391 } /* for(), decide */
2393 if (n != solv->nrules) /* continue if level < systemlevel */
2400 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
2402 for (i = 1; i < pool->nsolvables; i++)
2404 if (solv->decisionmap[i] < 0)
2406 if (solv->decisionmap[i] > 0)
2408 Id *recp, rec, *pp, p;
2409 s = pool->solvables + i;
2410 /* installed, check for recommends */
2411 /* XXX need to special case AND ? */
2414 recp = s->repo->idarraydata + s->recommends;
2415 while ((rec = *recp++) != 0)
2418 FOR_PROVIDES(p, pp, rec)
2420 if (solv->decisionmap[p] > 0)
2425 else if (solv->decisionmap[p] == 0)
2427 queue_pushunique(&dq, p);
2435 s = pool->solvables + i;
2436 if (!s->supplements && !s->freshens)
2438 if (!pool_installable(pool, s))
2440 if (solver_is_supplementing(solv, s))
2441 queue_pushunique(&dq, i);
2447 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2449 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2450 queue_push(&solv->recommendations, p);
2451 level = setpropagatelearn(solv, level, p, 0);
2456 if (solv->solution_callback)
2458 solv->solution_callback(solv, solv->solution_callback_data);
2459 if (solv->branches.count)
2461 int i = solv->branches.count - 1;
2462 int l = -solv->branches.elements[i];
2464 if (solv->branches.elements[i - 1] < 0)
2466 p = solv->branches.elements[i];
2467 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
2469 for (j = i + 1; j < solv->branches.count; j++)
2470 queue_push(&dq, solv->branches.elements[j]);
2471 solv->branches.count = i;
2473 revert(solv, level);
2475 for (j = 0; j < dq.count; j++)
2476 queue_push(&solv->branches, dq.elements[j]);
2478 level = setpropagatelearn(solv, level, p, disablerules);
2486 /* all branches done, we're finally finished */
2490 /* minimization step */
2491 if (solv->branches.count)
2493 int l = 0, lasti = -1, lastl = -1;
2495 for (i = solv->branches.count - 1; i >= 0; i--)
2497 p = solv->branches.elements[i];
2500 else if (p > 0 && solv->decisionmap[p] > l + 1)
2508 /* kill old solvable so that we do not loop */
2509 p = solv->branches.elements[lasti];
2510 solv->branches.elements[lasti] = 0;
2511 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
2514 revert(solv, level);
2516 level = setpropagatelearn(solv, level, p, disablerules);
2527 POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
2534 * at this point, all rules that led to conflicts are disabled.
2535 * we re-enable all rules of a problem set but rule "sug", then
2536 * continue to disable more rules until there as again a solution.
2539 /* FIXME: think about conflicting assertions */
2542 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2544 Pool *pool = solv->pool;
2551 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2553 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
2554 for (i = 0; problem[i]; i++)
2556 if (problem[i] == sug)
2557 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
2558 printproblem(solv, problem[i]);
2561 queue_init(&disabled);
2562 queue_empty(refined);
2563 queue_push(refined, sug);
2565 /* re-enable all problem rules with the exception of "sug"(gests) */
2569 for (i = 0; problem[i]; i++)
2570 if (problem[i] != sug)
2571 enableproblem(solv, problem[i]);
2574 disableupdaterules(solv, job, -(sug + 1));
2578 /* re-enable as many weak rules as possible */
2579 for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++)
2583 if (!MAPTST(&solv->weakrulemap, i))
2585 enablerule(solv, r);
2588 queue_empty(&solv->problems);
2589 revert(solv, 1); /* XXX move to reset_solver? */
2592 if (!solv->problems.count)
2593 run_solver(solv, 0, 0);
2595 if (!solv->problems.count)
2597 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
2598 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2599 printdecisions(solv);
2600 break; /* great, no more problems */
2602 disabledcnt = disabled.count;
2603 /* start with 1 to skip over proof index */
2604 for (i = 1; i < solv->problems.count - 1; i++)
2606 /* ignore solutions in refined */
2607 v = solv->problems.elements[i];
2609 break; /* end of problem reached */
2610 for (j = 0; problem[j]; j++)
2611 if (problem[j] != sug && problem[j] == v)
2615 queue_push(&disabled, v);
2617 if (disabled.count == disabledcnt)
2619 /* no solution found, this was an invalid suggestion! */
2620 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
2624 if (disabled.count == disabledcnt + 1)
2626 /* just one suggestion, add it to refined list */
2627 v = disabled.elements[disabledcnt];
2628 queue_push(refined, v);
2629 disableproblem(solv, v);
2631 disableupdaterules(solv, job, -(v + 1));
2635 /* more than one solution, disable all */
2636 /* do not push anything on refine list */
2637 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2639 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
2640 for (i = disabledcnt; i < disabled.count; i++)
2641 printproblem(solv, disabled.elements[i]);
2643 for (i = disabledcnt; i < disabled.count; i++)
2644 disableproblem(solv, disabled.elements[i]);
2647 /* all done, get us back into the same state as before */
2648 /* enable refined rules again */
2649 for (i = 0; i < disabled.count; i++)
2650 enableproblem(solv, disabled.elements[i]);
2651 /* disable problem rules again */
2652 for (i = 0; problem[i]; i++)
2653 disableproblem(solv, problem[i]);
2654 disableupdaterules(solv, job, -1);
2655 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
2659 problems_to_solutions(Solver *solv, Queue *job)
2661 Pool *pool = solv->pool;
2669 if (!solv->problems.count)
2671 queue_clone(&problems, &solv->problems);
2672 queue_init(&solution);
2673 queue_init(&solutions);
2674 /* copy over proof index */
2675 queue_push(&solutions, problems.elements[0]);
2676 problem = problems.elements + 1;
2677 for (i = 1; i < problems.count; i++)
2679 Id v = problems.elements[i];
2682 /* mark end of this problem */
2683 queue_push(&solutions, 0);
2684 queue_push(&solutions, 0);
2685 if (i + 1 == problems.count)
2687 /* copy over proof of next problem */
2688 queue_push(&solutions, problems.elements[i + 1]);
2690 problem = problems.elements + i + 1;
2693 refine_suggestion(solv, job, problem, v, &solution);
2694 if (!solution.count)
2695 continue; /* this solution didn't work out */
2697 for (j = 0; j < solution.count; j++)
2699 why = solution.elements[j];
2700 /* must be either job descriptor or system rule */
2701 assert(why < 0 || (why >= solv->systemrules && why < solv->learntrules));
2703 printproblem(solv, why);
2707 /* job descriptor */
2708 queue_push(&solutions, 0);
2709 queue_push(&solutions, -why);
2713 /* system rule, find replacement package */
2715 p = solv->installed->start + (why - solv->systemrules);
2716 if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
2718 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
2721 if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
2723 if (solv->decisionmap[*dp] > 0)
2730 queue_push(&solutions, p);
2731 queue_push(&solutions, rp);
2734 /* mark end of this solution */
2735 queue_push(&solutions, 0);
2736 queue_push(&solutions, 0);
2738 queue_free(&solution);
2739 queue_free(&problems);
2740 /* copy queue over to solutions */
2741 queue_free(&solv->problems);
2742 queue_clone(&solv->problems, &solutions);
2744 /* bring solver back into problem state */
2745 revert(solv, 1); /* XXX move to reset_solver? */
2748 assert(solv->problems.count == solutions.count);
2749 queue_free(&solutions);
2753 solver_next_problem(Solver *solv, Id problem)
2757 return solv->problems.count ? 1 : 0;
2758 pp = solv->problems.elements + problem;
2759 while (pp[0] || pp[1])
2763 while (pp[0] || pp[1])
2768 problem = pp - solv->problems.elements;
2769 if (problem >= solv->problems.count)
2775 solver_next_solution(Solver *solv, Id problem, Id solution)
2781 pp = solv->problems.elements + solution;
2782 return pp[0] || pp[1] ? solution : 0;
2784 pp = solv->problems.elements + solution;
2785 while (pp[0] || pp[1])
2788 solution = pp - solv->problems.elements;
2789 return pp[0] || pp[1] ? solution : 0;
2793 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
2796 element = element ? element + 2 : solution;
2797 pp = solv->problems.elements + element;
2798 if (!(pp[0] || pp[1]))
2807 * create obsoletesmap from solver decisions
2808 * required for decision handling
2810 * for solvables in installed repo:
2812 * p - one of the packages that obsolete us
2814 * n - number of packages this package obsoletes
2818 create_decisions_obsoletesmap(Solver *solv)
2820 Pool *pool = solv->pool;
2821 Repo *installed = solv->installed;
2822 Id p, *obsoletesmap = NULL;
2826 obsoletesmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
2829 for (i = 0; i < solv->decisionq.count; i++)
2833 n = solv->decisionq.elements[i];
2836 if (n == SYSTEMSOLVABLE)
2838 s = pool->solvables + n;
2839 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2841 FOR_PROVIDES(p, pp, s->name)
2842 if (s->name == pool->solvables[p].name)
2844 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2846 obsoletesmap[p] = n;
2851 for (i = 0; i < solv->decisionq.count; i++)
2856 n = solv->decisionq.elements[i];
2859 if (n == SYSTEMSOLVABLE)
2861 s = pool->solvables + n;
2862 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2866 obsp = s->repo->idarraydata + s->obsoletes;
2867 while ((obs = *obsp++) != 0)
2868 FOR_PROVIDES(p, pp, obs)
2870 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2872 obsoletesmap[p] = n;
2878 return obsoletesmap;
2886 printdecisions(Solver *solv)
2888 Pool *pool = solv->pool;
2889 Repo *installed = solv->installed;
2890 Id p, *obsoletesmap = create_decisions_obsoletesmap( solv );
2894 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2896 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
2897 for (i = 0; i < solv->decisionq.count; i++)
2899 p = solv->decisionq.elements[i];
2900 printruleelement(solv, SAT_DEBUG_SCHUBI, 0, p);
2902 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
2905 /* print solvables to be erased */
2909 FOR_REPO_SOLVABLES(installed, p, s)
2911 if (solv->decisionmap[p] >= 0)
2913 if (obsoletesmap[p])
2915 POOL_DEBUG(SAT_DEBUG_RESULT, "erase %s\n", solvable2str(pool, s));
2919 /* print solvables to be installed */
2921 for (i = 0; i < solv->decisionq.count; i++)
2924 p = solv->decisionq.elements[i];
2927 if (p == SYSTEMSOLVABLE)
2929 s = pool->solvables + p;
2930 if (installed && s->repo == installed)
2933 if (!obsoletesmap[p])
2935 POOL_DEBUG(SAT_DEBUG_RESULT, "install %s", solvable2str(pool, s));
2939 POOL_DEBUG(SAT_DEBUG_RESULT, "update %s", solvable2str(pool, s));
2940 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
2941 for (j = installed->start; j < installed->end; j++)
2942 if (obsoletesmap[j] == p)
2943 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
2944 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
2946 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
2949 sat_free(obsoletesmap);
2951 if (solv->recommendations.count)
2953 POOL_DEBUG(SAT_DEBUG_RESULT, "\nrecommended packages:\n");
2954 for (i = 0; i < solv->recommendations.count; i++)
2956 s = pool->solvables + solv->recommendations.elements[i];
2957 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
2961 if (solv->suggestions.count)
2963 POOL_DEBUG(SAT_DEBUG_RESULT, "\nsuggested packages:\n");
2964 for (i = 0; i < solv->suggestions.count; i++)
2966 s = pool->solvables + solv->suggestions.elements[i];
2967 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
2973 /* this is basically the reverse of addrpmrulesforsolvable */
2975 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
2977 Pool *pool = solv->pool;
2978 Repo *installed = solv->installed;
2982 Id p, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
2985 if (rid >= solv->systemrules)
2988 *sourcep = solv->installed->start + (rid - solv->systemrules);
2990 return SOLVER_PROBLEM_UPDATE_RULE;
2992 if (rid >= solv->jobrules)
2995 r = solv->rules + rid;
2996 p = solv->ruletojob.elements[rid - solv->jobrules];
2997 *depp = job->elements[p + 1];
2999 *targetp = job->elements[p];
3000 if (r->d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && job->elements[p] != SOLVER_INSTALL_SOLVABLE_ONE_OF)
3001 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
3002 return SOLVER_PROBLEM_JOB_RULE;
3004 r = solv->rules + rid;
3006 if (r->d == 0 && r->w2 == 0)
3008 /* a rpm rule assertion */
3009 s = pool->solvables - r->p;
3010 if (installed && !solv->fixsystem && s->repo == installed)
3012 assert(!dontfix); /* dontfix packages never have a neg assertion */
3015 /* see why the package is not installable */
3016 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
3019 return SOLVER_PROBLEM_NOT_INSTALLABLE;
3021 /* check requires */
3022 assert(s->requires);
3023 reqp = s->repo->idarraydata + s->requires;
3024 while ((req = *reqp++) != 0)
3026 if (req == SOLVABLE_PREREQMARKER)
3028 dp = pool_whatprovides(pool, req);
3034 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
3036 s = pool->solvables - r->p;
3037 if (installed && !solv->fixsystem && s->repo == installed)
3039 if (r->d == 0 && r->w2 < 0)
3041 /* a package conflict */
3042 Solvable *s2 = pool->solvables - r->w2;
3045 if (installed && !solv->fixsystem && s2->repo == installed)
3048 /* if both packages have the same name and at least one of them
3049 * is not installed, they conflict */
3050 if (s->name == s2->name && (!installed || (s->repo != installed || s2->repo != installed)))
3055 return SOLVER_PROBLEM_SAME_NAME;
3058 /* check conflicts in both directions */
3061 conp = s->repo->idarraydata + s->conflicts;
3062 while ((con = *conp++) != 0)
3064 FOR_PROVIDES(p, pp, con)
3066 if (dontfix && pool->solvables[p].repo == installed)
3073 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3079 conp = s2->repo->idarraydata + s2->conflicts;
3080 while ((con = *conp++) != 0)
3082 FOR_PROVIDES(p, pp, con)
3084 if (dontfix2 && pool->solvables[p].repo == installed)
3091 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3095 /* check obsoletes in both directions */
3096 if ((!installed || s->repo != installed) && s->obsoletes)
3098 obsp = s->repo->idarraydata + s->obsoletes;
3099 while ((obs = *obsp++) != 0)
3101 FOR_PROVIDES(p, pp, obs)
3108 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3112 if ((!installed || s2->repo != installed) && s2->obsoletes)
3114 obsp = s2->repo->idarraydata + s2->obsoletes;
3115 while ((obs = *obsp++) != 0)
3117 FOR_PROVIDES(p, pp, obs)
3124 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3128 /* all cases checked, can't happen */
3131 /* simple requires */
3132 assert(s->requires);
3133 reqp = s->repo->idarraydata + s->requires;
3134 while ((req = *reqp++) != 0)
3136 if (req == SOLVABLE_PREREQMARKER)
3138 dp = pool_whatprovides(pool, req);
3141 if (*dp == r->w2 && dp[1] == 0)
3144 else if (dp - pool->whatprovidesdata == r->d)
3151 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
3155 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3158 Id lreqr, lconr, lsysr, ljobr;
3162 lreqr = lconr = lsysr = ljobr = 0;
3163 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3166 if (rid >= solv->learntrules)
3167 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3168 else if (rid >= solv->systemrules)
3173 else if (rid >= solv->jobrules)
3180 r = solv->rules + rid;
3181 if (!r->d && r->w2 < 0)
3188 if (r->d == 0 && r->w2 == 0 && !reqassert)
3190 /* prefer assertions (XXX: bad idea?) */
3196 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed)
3198 /* prefer rules of installed packages */
3199 Id op = *reqrp >= 0 ? solv->rules[*reqrp].p : -*reqrp;
3200 if (op <= 0 || solv->pool->solvables[op].repo != solv->installed)
3206 if (!*reqrp && lreqr)
3208 if (!*conrp && lconr)
3210 if (!*jobrp && ljobr)
3212 if (!*sysrp && lsysr)
3217 * search for a rule that describes the problem to the
3218 * user. A pretty hopeless task, actually. We currently
3219 * prefer simple requires.
3222 solver_findproblemrule(Solver *solv, Id problem)
3224 Id reqr, conr, sysr, jobr;
3225 Id idx = solv->problems.elements[problem - 1];
3226 reqr = conr = sysr = jobr = 0;
3227 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3240 printprobleminfo(Solver *solv, Queue *job, Id problem)
3242 Pool *pool = solv->pool;
3244 Id dep, source, target;
3247 probr = solver_findproblemrule(solv, problem);
3248 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
3250 case SOLVER_PROBLEM_UPDATE_RULE:
3251 s = pool_id2solvable(pool, source);
3252 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
3254 case SOLVER_PROBLEM_JOB_RULE:
3255 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
3257 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
3258 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
3260 case SOLVER_PROBLEM_NOT_INSTALLABLE:
3261 s = pool_id2solvable(pool, source);
3262 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
3264 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
3265 s = pool_id2solvable(pool, source);
3266 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
3268 case SOLVER_PROBLEM_SAME_NAME:
3269 s = pool_id2solvable(pool, source);
3270 s2 = pool_id2solvable(pool, target);
3271 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
3273 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
3274 s = pool_id2solvable(pool, source);
3275 s2 = pool_id2solvable(pool, target);
3276 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3278 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
3279 s = pool_id2solvable(pool, source);
3280 s2 = pool_id2solvable(pool, target);
3281 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3283 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
3284 s = pool_id2solvable(pool, source);
3285 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
3291 printsolutions(Solver *solv, Queue *job)
3293 Pool *pool = solv->pool;
3295 Id p, rp, how, what;
3296 Id problem, solution, element;
3299 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
3302 while ((problem = solver_next_problem(solv, problem)) != 0)
3304 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
3305 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
3306 printprobleminfo(solv, job, problem);
3307 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3309 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
3312 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
3316 /* job, rp is index into job queue */
3317 how = job->elements[rp - 1] & ~SOLVER_WEAK;
3318 what = job->elements[rp];
3321 case SOLVER_INSTALL_SOLVABLE:
3322 s = pool->solvables + what;
3323 if (solv->installed && s->repo == solv->installed)
3324 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, s));
3326 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solvable2str(pool, s));
3328 case SOLVER_ERASE_SOLVABLE:
3329 s = pool->solvables + what;
3330 if (solv->installed && s->repo == solv->installed)
3331 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solvable2str(pool, s));
3333 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, s));
3335 case SOLVER_INSTALL_SOLVABLE_NAME:
3336 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", dep2str(pool, what));
3338 case SOLVER_ERASE_SOLVABLE_NAME:
3339 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", dep2str(pool, what));
3341 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3342 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable providing %s\n", dep2str(pool, what));
3344 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3345 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables providing %s\n", dep2str(pool, what));
3347 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3348 s = pool->solvables + what;
3349 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solvable2str(pool, s));
3352 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
3358 /* policy, replace p with rp */
3359 s = pool->solvables + p;
3360 sd = rp ? pool->solvables + rp : 0;
3364 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
3366 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3369 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
3371 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3374 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
3377 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));
3379 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));
3383 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3387 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
3392 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3398 /* create reverse obsoletes map for installed solvables
3400 * for each installed solvable find which packages with *different* names
3401 * obsolete the solvable.
3402 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3406 create_obsolete_index(Solver *solv)
3408 Pool *pool = solv->pool;
3410 Repo *installed = solv->installed;
3411 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3414 if (!installed || !installed->nsolvables)
3416 solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
3417 for (i = 1; i < pool->nsolvables; i++)
3419 s = pool->solvables + i;
3420 if (s->repo == installed)
3424 if (!pool_installable(pool, s))
3426 obsp = s->repo->idarraydata + s->obsoletes;
3427 while ((obs = *obsp++) != 0)
3428 FOR_PROVIDES(p, pp, obs)
3430 if (pool->solvables[p].repo != installed)
3432 if (pool->solvables[p].name == s->name)
3434 obsoletes[p - installed->start]++;
3438 for (i = 0; i < installed->nsolvables; i++)
3441 n += obsoletes[i] + 1;
3444 solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
3445 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
3446 for (i = pool->nsolvables - 1; i > 0; i--)
3448 s = pool->solvables + i;
3449 if (s->repo == installed)
3453 if (!pool_installable(pool, s))
3455 obsp = s->repo->idarraydata + s->obsoletes;
3456 while ((obs = *obsp++) != 0)
3457 FOR_PROVIDES(p, pp, obs)
3459 if (pool->solvables[p].repo != installed)
3461 if (pool->solvables[p].name == s->name)
3463 p -= installed->start;
3464 if (obsoletes_data[obsoletes[p]] != i)
3465 obsoletes_data[--obsoletes[p]] = i;
3471 removedisabledconflicts(Solver *solv, Queue *removed)
3473 Pool *pool = solv->pool;
3478 Id *decisionmap = solv->decisionmap;
3480 POOL_DEBUG(SAT_DEBUG_STATS, "removedisabledconflicts\n");
3481 queue_empty(removed);
3482 for (i = 0; i < solv->decisionq.count; i++)
3484 p = solv->decisionq.elements[i];
3487 /* a conflict. we never do conflicts on free decisions, so there
3488 * must have been an unit rule */
3489 why = solv->decisionq_why.elements[i];
3491 r = solv->rules + why;
3492 if (!r->w1 && decisionmap[-p])
3494 /* rule is now disabled, remove from decisionmap */
3495 POOL_DEBUG(SAT_DEBUG_STATS, "removing conflict for package %s[%d]\n", solvable2str(pool, pool->solvables - p), -p);
3496 queue_push(removed, -p);
3497 queue_push(removed, decisionmap[-p]);
3498 decisionmap[-p] = 0;
3501 if (!removed->count)
3503 /* we removed some confliced packages. some of them might still
3504 * be in conflict, so search for unit rules and re-conflict */
3506 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
3508 if (i == solv->nrules)
3511 r = solv->rules + i;
3517 if (r->p < 0 && !decisionmap[-r->p])
3523 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
3525 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
3530 if (r->p < 0 && decisionmap[-r->p] == 0)
3532 if (new || DECISIONMAP_FALSE(r->p))
3534 dp = pool->whatprovidesdata + r->d;
3535 while ((p = *dp++) != 0)
3537 if (new && p == new)
3539 if (p < 0 && decisionmap[-p] == 0)
3548 else if (!DECISIONMAP_FALSE(p))
3558 POOL_DEBUG(SAT_DEBUG_STATS, "re-conflicting package %s[%d]\n", solvable2str(pool, pool->solvables - new), -new);
3559 decisionmap[-new] = -1;
3560 n = 0; /* redo all rules */
3566 weaken_solvable_deps(Solver *solv, Id p)
3571 for (i = 1, r = solv->rules + i; i < solv->jobrules; i++, r++)
3575 if (r->d == 0 && r->w2 < 0)
3576 continue; /* conflict */
3577 queue_push(&solv->weakruleq, i);
3581 /*-----------------------------------------------------------------*/
3591 solver_solve(Solver *solv, Queue *job)
3593 Pool *pool = solv->pool;
3594 Repo *installed = solv->installed;
3597 Map addedmap; /* '1' == have rpm-rules for solvable */
3598 Id how, what, weak, name, p, *pp, d;
3604 /* create whatprovides if not already there */
3605 if (!pool->whatprovides)
3606 pool_createwhatprovides(pool);
3608 /* create obsolete index if needed */
3609 if (solv->noupdateprovide)
3610 create_obsolete_index(solv);
3613 * create basic rule set of all involved packages
3614 * use addedmap bitmap to make sure we don't create rules twice
3618 map_init(&addedmap, pool->nsolvables);
3622 * always install our system solvable
3624 MAPSET(&addedmap, SYSTEMSOLVABLE);
3625 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3626 queue_push(&solv->decisionq_why, 0);
3627 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3630 * create rules for all package that could be involved with the solving
3631 * so called: rpm rules
3636 oldnrules = solv->nrules;
3637 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
3638 FOR_REPO_SOLVABLES(installed, p, s)
3639 addrpmrulesforsolvable(solv, s, &addedmap);
3640 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3641 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
3642 oldnrules = solv->nrules;
3643 FOR_REPO_SOLVABLES(installed, p, s)
3644 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3645 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3648 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
3649 oldnrules = solv->nrules;
3650 for (i = 0; i < job->count; i += 2)
3652 how = job->elements[i] & ~SOLVER_WEAK;
3653 what = job->elements[i + 1];
3657 case SOLVER_INSTALL_SOLVABLE:
3658 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3660 case SOLVER_INSTALL_SOLVABLE_NAME:
3661 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3662 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3663 while (ISRELDEP(name))
3665 Reldep *rd = GETRELDEP(pool, name);
3668 FOR_PROVIDES(p, pp, what)
3670 /* if by name, ensure that the name matches */
3671 if (name && pool->solvables[p].name != name)
3673 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3676 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3677 /* dont allow downgrade */
3678 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3680 case SOLVER_INSTALL_SOLVABLE_ONE_OF:
3681 pp = pool->whatprovidesdata + what;
3682 while ((p = *pp++) != 0)
3683 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3687 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3689 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
3691 oldnrules = solv->nrules;
3692 addrpmrulesforweak(solv, &addedmap);
3693 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3695 IF_POOLDEBUG (SAT_DEBUG_STATS)
3697 int possible = 0, installable = 0;
3698 for (i = 1; i < pool->nsolvables; i++)
3700 if (pool_installable(pool, pool->solvables + i))
3702 if (MAPTST(&addedmap, i))
3705 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3709 * first pass done, we now have all the rpm rules we need.
3710 * unify existing rules before going over all job rules and
3712 * at this point the system is always solvable,
3713 * as an empty system (remove all packages) is a valid solution
3716 unifyrules(solv); /* remove duplicate rpm rules */
3717 solv->directdecisions = solv->decisionq.count;
3719 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
3720 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3721 printdecisions (solv);
3724 * now add all job rules
3727 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
3729 solv->jobrules = solv->nrules;
3731 for (i = 0; i < job->count; i += 2)
3733 oldnrules = solv->nrules;
3735 how = job->elements[i] & ~SOLVER_WEAK;
3736 weak = job->elements[i] & SOLVER_WEAK;
3737 what = job->elements[i + 1];
3740 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3741 s = pool->solvables + what;
3742 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall solvable %s\n", weak ? "weak " : "", solvable2str(pool, s));
3743 addrule(solv, what, 0); /* install by Id */
3744 queue_push(&solv->ruletojob, i);
3746 queue_push(&solv->weakruleq, solv->nrules - 1);
3748 case SOLVER_ERASE_SOLVABLE:
3749 s = pool->solvables + what;
3750 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase solvable %s\n", weak ? "weak " : "", solvable2str(pool, s));
3751 addrule(solv, -what, 0); /* remove by Id */
3752 queue_push(&solv->ruletojob, i);
3754 queue_push(&solv->weakruleq, solv->nrules - 1);
3756 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3757 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3758 if (how == SOLVER_INSTALL_SOLVABLE_NAME)
3759 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall name %s\n", weak ? "weak " : "", dep2str(pool, what));
3760 if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3761 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall provides %s\n", weak ? "weak " : "", dep2str(pool, what));
3763 name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
3764 while (ISRELDEP(name))
3766 Reldep *rd = GETRELDEP(pool, name);
3769 FOR_PROVIDES(p, pp, what)
3771 /* if by name, ensure that the name matches */
3772 if (name && pool->solvables[p].name != name)
3778 /* no provider, make this an impossible rule */
3779 queue_push(&q, -SYSTEMSOLVABLE);
3782 p = queue_shift(&q); /* get first provider */
3784 d = 0; /* single provider ? -> make assertion */
3786 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3787 addrule(solv, p, d); /* add 'requires' rule */
3788 queue_push(&solv->ruletojob, i);
3790 queue_push(&solv->weakruleq, solv->nrules - 1);
3792 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3793 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3794 if (how == SOLVER_ERASE_SOLVABLE_NAME)
3795 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase name %s\n", weak ? "weak " : "", dep2str(pool, what));
3796 if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3797 POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase provides %s\n", weak ? "weak " : "", dep2str(pool, what));
3798 name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
3799 while (ISRELDEP(name))
3801 Reldep *rd = GETRELDEP(pool, name);
3804 FOR_PROVIDES(p, pp, what)
3806 /* if by name, ensure that the name matches */
3807 if (name && pool->solvables[p].name != name)
3809 addrule(solv, -p, 0); /* add 'remove' rule */
3810 queue_push(&solv->ruletojob, i);
3812 queue_push(&solv->weakruleq, solv->nrules - 1);
3815 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3816 s = pool->solvables + what;
3817 POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solvable2str(pool, s));
3818 addupdaterule(solv, s, 0);
3819 queue_push(&solv->ruletojob, i);
3821 queue_push(&solv->weakruleq, solv->nrules - 1);
3823 case SOLVER_INSTALL_SOLVABLE_ONE_OF:
3824 POOL_DEBUG(SAT_DEBUG_JOB, "job: %sone of\n", weak ? "weak " : "");
3825 for (pp = pool->whatprovidesdata + what; *pp; pp++)
3826 POOL_DEBUG(SAT_DEBUG_JOB, " %s\n", solvable2str(pool, pool->solvables + *pp));
3827 addrule(solv, -SYSTEMSOLVABLE, what);
3828 queue_push(&solv->ruletojob, i);
3830 queue_push(&solv->weakruleq, solv->nrules - 1);
3832 case SOLVER_WEAKEN_SOLVABLE_DEPS:
3833 s = pool->solvables + what;
3834 POOL_DEBUG(SAT_DEBUG_JOB, "job: weaken deps %s\n", solvable2str(pool, s));
3835 weaken_solvable_deps(solv, what);
3838 IF_POOLDEBUG (SAT_DEBUG_JOB)
3841 if (solv->nrules == oldnrules)
3842 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created\n");
3843 for (j = oldnrules; j < solv->nrules; j++)
3845 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
3846 printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
3850 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3853 * now add system rules
3857 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add system rules ***\n");
3860 solv->systemrules = solv->nrules;
3863 * create rules for updating installed solvables
3867 if (installed && !solv->allowuninstall)
3868 { /* loop over all installed solvables */
3869 /* we create all update rules, but disable some later on depending on the job */
3870 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3872 /* no system rules for patch atoms */
3873 if (s->freshens && !s->supplements)
3875 const char *name = id2str(pool, s->name);
3876 if (name[0] == 'a' && !strncmp(name, "atom:", 5))
3878 addrule(solv, 0, 0);
3882 if (s->repo == installed)
3883 addupdaterule(solv, s, 0); /* allowall = 0 */
3885 addrule(solv, 0, 0); /* create dummy rule */
3887 /* consistency check: we added a rule for _every_ system solvable */
3888 assert(solv->nrules - solv->systemrules == installed->end - installed->start);
3891 /* create special weak system rules */
3892 /* those are used later on to keep a version of the installed packages in
3894 if (installed && installed->nsolvables)
3896 solv->weaksystemrules = sat_calloc(installed->end - installed->start, sizeof(Id));
3897 FOR_REPO_SOLVABLES(installed, p, s)
3899 policy_findupdatepackages(solv, s, &q, 1);
3901 solv->weaksystemrules[p - installed->start] = pool_queuetowhatprovides(pool, &q);
3905 /* free unneeded memory */
3906 map_free(&addedmap);
3909 /* create weak map */
3910 map_init(&solv->weakrulemap, solv->nrules);
3911 for (i = 0; i < solv->weakruleq.count; i++)
3913 p = solv->weakruleq.elements[i];
3914 MAPSET(&solv->weakrulemap, p);
3917 /* all new rules are learnt after this point */
3918 solv->learntrules = solv->nrules;
3920 /* disable system rules that conflict with our job */
3921 disableupdaterules(solv, job, -1);
3923 /* make decisions based on job/system assertions */
3924 makeruledecisions(solv);
3926 /* create watches chains */
3929 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
3932 run_solver(solv, 1, solv->dontinstallrecommended ? 0 : 1);
3936 /* disable all weak erase rules for recommened/suggestes search */
3937 for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
3939 if (!MAPTST(&solv->weakrulemap, i))
3943 disablerule(solv, r);
3948 enabledisablelearntrules(solv);
3949 removedisabledconflicts(solv, &redoq);
3952 /* find recommended packages */
3953 /* if q.count == 0 we already found all recommended in the
3955 if (redoq.count || solv->dontinstallrecommended)
3957 Id rec, *recp, p, *pp;
3959 /* create map of all suggests that are still open */
3960 solv->recommends_index = -1;
3961 MAPZERO(&solv->recommendsmap);
3962 for (i = 0; i < solv->decisionq.count; i++)
3964 p = solv->decisionq.elements[i];
3967 s = pool->solvables + p;
3970 recp = s->repo->idarraydata + s->recommends;
3971 while ((rec = *recp++) != 0)
3973 FOR_PROVIDES(p, pp, rec)
3974 if (solv->decisionmap[p] > 0)
3977 continue; /* p != 0: already fulfilled */
3978 FOR_PROVIDES(p, pp, rec)
3979 MAPSET(&solv->recommendsmap, p);
3983 for (i = 1; i < pool->nsolvables; i++)
3985 if (solv->decisionmap[i] != 0)
3987 s = pool->solvables + i;
3988 if (!MAPTST(&solv->recommendsmap, i))
3990 if (!s->supplements)
3992 if (!pool_installable(pool, s))
3994 if (!solver_is_supplementing(solv, s))
3997 if (solv->dontinstallrecommended)
3998 queue_push(&solv->recommendations, i);
4000 queue_pushunique(&solv->recommendations, i);
4002 /* we use MODE_SUGGEST here so that repo prio is ignored */
4003 policy_filter_unwanted(solv, &solv->recommendations, 0, POLICY_MODE_SUGGEST);
4006 /* find suggested packages */
4009 Id sug, *sugp, p, *pp;
4011 /* create map of all suggests that are still open */
4012 solv->recommends_index = -1;
4013 MAPZERO(&solv->suggestsmap);
4014 for (i = 0; i < solv->decisionq.count; i++)
4016 p = solv->decisionq.elements[i];
4019 s = pool->solvables + p;
4022 sugp = s->repo->idarraydata + s->suggests;
4023 while ((sug = *sugp++) != 0)
4025 FOR_PROVIDES(p, pp, sug)
4026 if (solv->decisionmap[p] > 0)
4029 continue; /* already fulfilled */
4030 FOR_PROVIDES(p, pp, sug)
4031 MAPSET(&solv->suggestsmap, p);
4035 for (i = 1; i < pool->nsolvables; i++)
4037 if (solv->decisionmap[i] != 0)
4039 s = pool->solvables + i;
4040 if (!MAPTST(&solv->suggestsmap, i))
4044 if (!pool_installable(pool, s))
4046 if (!solver_is_enhancing(solv, s))
4049 queue_push(&solv->suggestions, i);
4051 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
4056 /* restore decisionmap */
4057 for (i = 0; i < redoq.count; i += 2)
4058 solv->decisionmap[redoq.elements[i]] = redoq.elements[i + 1];
4062 if (solv->problems.count)
4064 int recocount = solv->recommendations.count;
4065 solv->recommendations.count = 0; /* so that revert() doesn't mess with it */
4066 queue_empty(&redoq);
4067 for (i = 0; i < solv->decisionq.count; i++)
4069 Id p = solv->decisionq.elements[i];
4070 queue_push(&redoq, p);
4071 queue_push(&redoq, solv->decisionq_why.elements[i]);
4072 queue_push(&redoq, solv->decisionmap[p > 0 ? p : -p]);
4074 problems_to_solutions(solv, job);
4075 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
4076 queue_empty(&solv->decisionq);
4077 queue_empty(&solv->decisionq_why);
4078 for (i = 0; i < redoq.count; i += 3)
4080 Id p = redoq.elements[i];
4081 queue_push(&solv->decisionq, p);
4082 queue_push(&solv->decisionq_why, redoq.elements[i + 1]);
4083 solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
4085 solv->recommendations.count = recocount;
4090 /***********************************************************************/
4093 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
4097 solver_create_state_maps(solv, &installedmap, 0);
4098 pool_calc_duchanges(solv->pool, solv->installed, &installedmap, mps, nmps);
4099 map_free(&installedmap);
4103 solver_calc_installsizechange(Solver *solv)
4108 solver_create_state_maps(solv, &installedmap, 0);
4109 change = pool_calc_installsizechange(solv->pool, solv->installed, &installedmap);
4110 map_free(&installedmap);