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
26 #define RULES_BLOCK 63
30 solver_dep_installed(Solver *solv, Id dep)
32 /* disable for now, splitprovides don't work anyway and it breaks
35 Pool *pool = solv->pool;
40 Reldep *rd = GETRELDEP(pool, dep);
41 if (rd->flags == REL_AND)
43 if (!solver_dep_installed(solv, rd->name))
45 return solver_dep_installed(solv, rd->evr);
47 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
48 return solver_dep_installed(solv, rd->evr);
50 FOR_PROVIDES(p, pp, dep)
52 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
60 /* this mirrors solver_dep_fulfilled but uses map m instead of the decisionmap */
62 dep_possible(Solver *solv, Id dep, Map *m)
64 Pool *pool = solv->pool;
69 Reldep *rd = GETRELDEP(pool, dep);
70 if (rd->flags == REL_AND)
72 if (!dep_possible(solv, rd->name, m))
74 return dep_possible(solv, rd->evr, m);
76 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
77 return solver_dep_installed(solv, rd->evr);
79 FOR_PROVIDES(p, pp, dep)
87 /*-----------------------------------------------------------------*/
94 printruleelement(Solver *solv, Rule *r, Id v)
96 Pool *pool = solv->pool;
100 s = pool->solvables + -v;
101 printf(" !%s-%s.%s [%d]", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), -v);
105 s = pool->solvables + v;
106 printf(" %s-%s.%s [%d]", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), v);
115 if (solv->decisionmap[s - pool->solvables] > 0)
116 printf(" Install.level%d", solv->decisionmap[s - pool->solvables]);
117 if (solv->decisionmap[s - pool->solvables] < 0)
118 printf(" Conflict.level%d", -solv->decisionmap[s - pool->solvables]);
120 printf(" (disabled)");
130 printrule(Solver *solv, Rule *r)
135 if (r >= solv->rules && r < solv->rules + solv->nrules) /* r is a solver rule */
136 printf("Rule #%d:\n", (int)(r - solv->rules));
138 printf("Rule:\n"); /* r is any rule */
143 else if (r->d == ID_NULL)
150 v = solv->pool->whatprovidesdata[r->d + i - 1];
153 printruleelement(solv, r, v);
155 printf(" next: %d %d\n", r->n1, r->n2);
159 /*-----------------------------------------------------------------*/
165 static Pool *unifyrules_sortcmp_data;
168 * compare rules for unification sort
172 unifyrules_sortcmp(const void *ap, const void *bp)
174 Pool *pool = unifyrules_sortcmp_data;
175 Rule *a = (Rule *)ap;
176 Rule *b = (Rule *)bp;
182 return x; /* p differs */
185 if (a->d == 0 && b->d == 0)
186 return a->w2 - b->w2; /* assertion: return w2 diff */
188 if (a->d == 0) /* a is assertion, b not */
190 x = a->w2 - pool->whatprovidesdata[b->d];
194 if (b->d == 0) /* b is assertion, a not */
196 x = pool->whatprovidesdata[a->d] - b->w2;
200 /* compare whatprovidesdata */
201 ad = pool->whatprovidesdata + a->d;
202 bd = pool->whatprovidesdata + b->d;
204 if ((x = *ad++ - *bd++) != 0)
215 unifyrules(Solver *solv)
220 if (solv->nrules <= 1) /* nothing to unify */
223 if (solv->pool->verbose > 3)
224 printf ("----- unifyrules -----\n");
226 /* sort rules first */
227 unifyrules_sortcmp_data = solv->pool;
228 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
235 for (i = j = 1, ir = solv->rules + 1; i < solv->nrules; i++, ir++)
237 if (jr && !unifyrules_sortcmp(ir, jr))
238 continue; /* prune! */
239 jr = solv->rules + j++; /* keep! */
244 /* reduced count from nrules to j rules */
245 if (solv->pool->verbose) printf("pruned rules from %d to %d\n", solv->nrules, j);
247 /* adapt rule buffer */
249 solv->rules = (Rule *)xrealloc(solv->rules, ((solv->nrules + RULES_BLOCK) & ~RULES_BLOCK) * sizeof(Rule));
251 if (solv->pool->verbose)
258 for (i = 1; i < solv->nrules; i++)
265 dp = solv->pool->whatprovidesdata + r->d;
270 printf(" binary: %d\n", binr);
271 printf(" normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
274 if (solv->pool->verbose > 3)
275 printf ("----- unifyrules end -----\n");
285 hashrule(Solver *solv, Id p, Id d, int n)
287 unsigned int x = (unsigned int)p;
291 return (x * 37) ^ (unsigned int)d;
292 dp = solv->pool->whatprovidesdata + d;
294 x = (x * 37) ^ (unsigned int)*dp++;
302 * p = direct literal; always < 0 for installed rpm rules
303 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
306 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
308 * p < 0 : pkg id of A
309 * d > 0 : Offset in whatprovidesdata (list of providers of b)
311 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
312 * p < 0 : pkg id of A
313 * d < 0 : Id of solvable (e.g. B1)
315 * d == 0: unary rule, assertion => (A) or (-A)
317 * Install: p > 0, d = 0 (A) user requested install
318 * Remove: p < 0, d = 0 (-A) user requested remove
319 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
320 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
321 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
322 * ? p > 0, d < 0 (A|-B)
323 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
327 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
328 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
329 * every other : w1 = p, w2 = whatprovidesdata[d];
330 * Disabled rule: w1 = 0
332 * always returns a rule for non-rpm rules
336 addrule(Solver *solv, Id p, Id d)
341 int n = 0; /* number of literals in rule - 1
342 0 = direct assertion (single literal)
346 /* it often happenes that requires lead to adding the same rpm rule
347 * multiple times, so we prune those duplicates right away to make
348 * the work for unifyrules a bit easier */
350 if (solv->nrules && !solv->jobrules)
352 r = solv->rules + solv->nrules - 1; /* get the last added rule */
353 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
359 /* always a binary rule */
361 return 0; /* ignore self conflict */
366 for (dp = solv->pool->whatprovidesdata + d; *dp; dp++, n++)
368 return 0; /* rule is self-fulfilling */
373 if (n == 0 && !solv->jobrules)
375 /* this is a rpm rule assertion, we do not have to allocate it */
376 /* it can be identified by a level of 1 and a zero reason */
377 /* we must not drop those rules from the decisionq when rewinding! */
380 if (solv->decisionmap[-p] > 0 || solv->decisionmap[-p] < -1)
382 if (solv->decisionmap[-p])
383 return 0; /* already got that one */
384 queue_push(&solv->decisionq, p);
385 queue_push(&solv->decisionq_why, 0);
386 solv->decisionmap[-p] = -1;
391 /* smallest literal first so we can find dups */
395 n = 1; /* re-set n, was used as temp var */
398 /* check if the last added rule is exactly the same as what we're looking for. */
399 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
402 if (r && n > 1 && r->d && r->p == p)
407 dp2 = solv->pool->whatprovidesdata + r->d;
408 for (dp = solv->pool->whatprovidesdata + d; *dp; dp++, dp2++)
419 /* check and extend rule buffer */
420 if ((solv->nrules & RULES_BLOCK) == 0)
422 solv->rules = (Rule *)xrealloc(solv->rules, (solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
425 r = solv->rules + solv->nrules++; /* point to rule space */
430 /* direct assertion, no watch needed */
446 r->w2 = solv->pool->whatprovidesdata[d];
451 if (solv->pool->verbose > 3)
453 printf (" Add rule: ");
461 disablerule(Solver *solv, Rule *r)
467 enablerule(Solver *solv, Rule *r)
469 if (r->d == 0 || r->w2 != r->p)
472 r->w1 = solv->pool->whatprovidesdata[r->d];
476 /**********************************************************************************/
478 /* a problem is an item on the solver's problem list. It can either be >0, in that
479 * case it is a system (upgrade) rule, or it can be <0, which makes it refer to a job
480 * consisting of multiple job rules.
484 disableproblem(Solver *solv, Id v)
492 disablerule(solv, solv->rules + v);
496 jp = solv->ruletojob.elements;
497 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
499 disablerule(solv, r);
503 enableproblem(Solver *solv, Id v)
511 enablerule(solv, solv->rules + v);
515 jp = solv->ruletojob.elements;
516 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
522 printproblem(Solver *solv, Id v)
529 printrule(solv, solv->rules + v);
533 printf("JOB %d\n", v);
534 jp = solv->ruletojob.elements;
535 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
547 /************************************************************************/
549 /* go through system and job rules and add direct assertions
550 * to the decisionqueue. If we find a conflict, disable rules and
551 * add them to problem queue.
552 * (disablerules is always true for the cases when we get called)
555 makeruledecisions(Solver *solv)
562 if (solv->pool->verbose > 3)
563 printf ("----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
565 decisionstart = solv->decisionq.count;
566 /* rpm rules don't have assertions, so we can start with the job
568 for (ri = solv->jobrules, r = solv->rules + ri; ri < solv->nrules; ri++, r++)
570 if (!r->w1 || r->w2) /* disabled or no assertion */
574 if (solv->decisionmap[vv] == 0)
576 queue_push(&solv->decisionq, v);
577 queue_push(&solv->decisionq_why, r - solv->rules);
578 solv->decisionmap[vv] = v > 0 ? 1 : -1;
579 if (solv->pool->verbose > 3)
581 Solvable *s = solv->pool->solvables + vv;
583 printf("removing %s-%s.%s\n", id2str(solv->pool, s->name), id2str(solv->pool, s->evr), id2str(solv->pool, s->arch));
585 printf("installing %s-%s.%s\n", id2str(solv->pool, s->name), id2str(solv->pool, s->evr), id2str(solv->pool, s->arch));
589 if (v > 0 && solv->decisionmap[vv] > 0)
591 if (v < 0 && solv->decisionmap[vv] < 0)
593 /* found a conflict! */
594 if (ri >= solv->learntrules)
596 /* cannot happen, as this would mean that the problem
597 * was not solvable, so we wouldn't have created the
598 * learnt rule at all */
601 /* if we are weak, just disable ourself */
602 if (ri >= solv->weakrules)
604 printf("conflict, but I am weak, disabling ");
606 disablerule(solv, r);
610 /* only job and system rules left */
611 for (i = 0; i < solv->decisionq.count; i++)
612 if (solv->decisionq.elements[i] == -v)
614 if (i == solv->decisionq.count)
616 if (solv->decisionq_why.elements[i] == 0)
618 /* conflict with rpm rule, need only disable our rule */
619 if (v < 0 && v != -SYSTEMSOLVABLE)
622 queue_push(&solv->problems, solv->learnt_pool.count);
623 queue_push(&solv->learnt_pool, ri);
624 queue_push(&solv->learnt_pool, v != -SYSTEMSOLVABLE ? -v : v);
625 queue_push(&solv->learnt_pool, 0);
626 printf("conflict with rpm rule, disabling rule #%d\n", ri);
627 if (ri < solv->systemrules)
628 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
629 queue_push(&solv->problems, v);
630 disableproblem(solv, v);
631 queue_push(&solv->problems, 0);
635 queue_push(&solv->problems, solv->learnt_pool.count);
636 queue_push(&solv->learnt_pool, ri);
637 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
638 queue_push(&solv->learnt_pool, 0);
640 /* conflict with another job or system rule */
641 printf("conflicting system/job rules over literal %d\n", vv);
642 /* push all of our rules asserting this literal on the problem stack */
643 for (i = solv->jobrules, rr = solv->rules + i; i < solv->nrules; i++, rr++)
645 if (!rr->w1 || rr->w2)
647 if (rr->p != v && rr->p != -v)
649 printf(" - disabling rule #%d\n", i);
651 if (i < solv->systemrules)
652 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
653 queue_push(&solv->problems, v);
654 disableproblem(solv, v);
656 queue_push(&solv->problems, 0);
659 while (solv->decisionq.count > decisionstart)
661 v = solv->decisionq.elements[--solv->decisionq.count];
662 --solv->decisionq_why.count;
664 solv->decisionmap[vv] = 0;
666 ri = solv->jobrules - 1;
667 r = solv->rules + ri;
670 if (solv->pool->verbose > 3)
671 printf ("----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
675 * we have enabled or disabled some of our rules. We now reenable all
676 * of our learnt rules but the ones that were learnt from rules that
680 enabledisablelearntrules(Solver *solv)
682 Pool *pool = solv->pool;
688 printf("enabledisablelearntrules called\n");
689 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
691 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
692 while ((why = *whyp++) != 0)
694 if (why < 0 || why >= i)
695 abort(); /* cannot reference newer learnt rules */
696 if (!solv->rules[why].w1)
699 /* why != 0: we found a disabled rule, disable the learnt rule */
704 printf("disabling learnt ");
707 disablerule(solv, r);
709 else if (!why && !r->w1)
713 printf("re-enabling learnt ");
722 /* FIXME: bad code ahead, replace as soon as possible */
724 disableupdaterules(Solver *solv, Queue *job, int jobidx)
726 Pool *pool = solv->pool;
728 Id how, what, p, *pp;
734 installed = solv->installed;
740 how = job->elements[jobidx];
743 case SOLVER_INSTALL_SOLVABLE:
744 case SOLVER_ERASE_SOLVABLE:
745 case SOLVER_ERASE_SOLVABLE_NAME:
746 case SOLVER_ERASE_SOLVABLE_PROVIDES:
752 /* go through all enabled job rules */
753 MAPZERO(&solv->noupdate);
754 for (i = solv->jobrules; i < solv->systemrules; i++)
757 if (!r->w1) /* disabled? */
759 j = solv->ruletojob.elements[i - solv->jobrules];
763 how = job->elements[j];
764 what = job->elements[j + 1];
767 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
768 s = pool->solvables + what;
769 FOR_PROVIDES(p, pp, s->name)
771 if (pool->solvables[p].name != s->name)
773 if (pool->solvables[p].repo == installed)
774 MAPSET(&solv->noupdate, p - installed->start);
777 case SOLVER_ERASE_SOLVABLE:
778 s = pool->solvables + what;
779 if (s->repo == installed)
780 MAPSET(&solv->noupdate, what - installed->start);
782 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
783 case SOLVER_ERASE_SOLVABLE_PROVIDES:
784 FOR_PROVIDES(p, pp, what)
786 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
788 if (pool->solvables[p].repo == installed)
789 MAPSET(&solv->noupdate, p - installed->start);
797 /* fixup update rule status */
798 if (solv->allowuninstall)
799 return; /* no update rules at all */
803 /* we just disabled job #jobidx. enable all update rules
804 * that aren't disabled by the remaining job rules */
805 how = job->elements[jobidx];
806 what = job->elements[jobidx + 1];
809 case SOLVER_INSTALL_SOLVABLE:
810 s = pool->solvables + what;
811 FOR_PROVIDES(p, pp, s->name)
813 if (pool->solvables[p].name != s->name)
815 if (pool->solvables[p].repo != installed)
817 if (MAPTST(&solv->noupdate, p - installed->start))
819 r = solv->rules + solv->systemrules + (p - installed->start);
825 printf("@@@ re-enabling ");
830 case SOLVER_ERASE_SOLVABLE:
831 s = pool->solvables + what;
832 if (s->repo != installed)
834 if (MAPTST(&solv->noupdate, what - installed->start))
836 r = solv->rules + solv->systemrules + (what - installed->start);
842 printf("@@@ re-enabling ");
846 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
847 case SOLVER_ERASE_SOLVABLE_PROVIDES:
848 FOR_PROVIDES(p, pp, what)
850 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
852 if (pool->solvables[p].repo != installed)
854 if (MAPTST(&solv->noupdate, p - installed->start))
856 r = solv->rules + solv->systemrules + (p - installed->start);
862 printf("@@@ re-enabling ");
873 for (i = 0; i < installed->nsolvables; i++)
875 r = solv->rules + solv->systemrules + i;
876 if (r->w1 && MAPTST(&solv->noupdate, i))
877 disablerule(solv, r); /* was enabled, need to disable */
883 * add (install) rules for solvable
884 * for unfulfilled requirements, conflicts, obsoletes,....
885 * add a negative assertion for solvables that are not installable
889 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
891 Pool *pool = solv->pool;
892 Repo *installed = solv->installed;
906 if (solv->pool->verbose > 3)
907 printf ("----- addrpmrulesforsolvable -----\n");
909 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
910 queue_push(&q, s - pool->solvables); /* push solvable Id */
916 * s: Pointer to solvable
920 if (MAPTST(m, n)) /* continue if already done */
924 s = pool->solvables + n; /* s = Solvable in question */
927 if (installed /* Installed system available */
928 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
929 && s->repo == installed) /* solvable is installed? */
931 dontfix = 1; /* dont care about broken rpm deps */
934 if (!dontfix && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
937 printf("package %s-%s.%s [%d] is not installable\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), (Id)(s - pool->solvables));
938 addrule(solv, -n, 0); /* uninstallable */
941 /*-----------------------------------------
942 * check requires of s
947 reqp = s->repo->idarraydata + s->requires;
948 while ((req = *reqp++) != 0) /* go throw all requires */
950 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
953 dp = GET_PROVIDESP(req, p); /* get providers of req; p is a dummy only */
955 if (*dp == SYSTEMSOLVABLE) /* always installed */
960 /* the strategy here is to not insist on dependencies
961 * that are already broken. so if we find one provider
962 * that was already installed, we know that the
963 * dependency was not broken before so we enforce it */
964 for (i = 0; (p = dp[i]) != 0; i++) /* for all providers */
966 if (pool->solvables[p].repo == installed)
967 break; /* provider was installed */
969 if (!p) /* previously broken dependency */
972 printf("ignoring broken requires %s of installed package %s-%s.%s\n", dep2str(pool, req), id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
979 /* nothing provides req! */
981 printf("package %s-%s.%s [%d] is not installable (%s)\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), (Id)(s - pool->solvables), dep2str(pool, req));
982 addrule(solv, -n, 0); /* mark requestor as uninstallable */
986 if (pool->verbose > 2)
988 printf(" %s-%s.%s requires %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), dep2str(pool, req));
989 for (i = 0; dp[i]; i++)
990 printf(" provided by %s-%s.%s\n", id2str(pool, pool->solvables[dp[i]].name), id2str(pool, pool->solvables[dp[i]].evr), id2str(pool, pool->solvables[dp[i]].arch));
993 /* add 'requires' dependency */
994 /* rule: (-requestor|provider1|provider2|...|providerN) */
995 addrule(solv, -n, dp - pool->whatprovidesdata);
997 /* descend the dependency tree */
998 for (; *dp; dp++) /* loop through all providers */
1000 if (!MAPTST(m, *dp))
1001 queue_push(&q, *dp);
1004 } /* while, requirements of n */
1006 } /* if, requirements */
1008 /* that's all we check for src packages */
1009 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1012 /*-----------------------------------------
1013 * check conflicts of s
1018 conp = s->repo->idarraydata + s->conflicts;
1019 while ((con = *conp++) != 0)
1021 FOR_PROVIDES(p, pp, con)
1023 /* dontfix: dont care about conflicts with already installed packs */
1024 if (dontfix && pool->solvables[p].repo == installed)
1026 /* rule: -n|-p: either solvable _or_ provider of conflict */
1027 addrule(solv, -n, -p);
1032 /*-----------------------------------------
1033 * check obsoletes if not installed
1035 if (!installed || pool->solvables[n].repo != installed)
1036 { /* not installed */
1039 obsp = s->repo->idarraydata + s->obsoletes;
1040 while ((obs = *obsp++) != 0)
1042 FOR_PROVIDES(p, pp, obs)
1043 addrule(solv, -n, -p);
1046 FOR_PROVIDES(p, pp, s->name)
1048 if (s->name == pool->solvables[p].name)
1049 addrule(solv, -n, -p);
1053 /*-----------------------------------------
1054 * add recommends to the rule list
1058 recp = s->repo->idarraydata + s->recommends;
1059 while ((rec = *recp++) != 0)
1061 FOR_PROVIDES(p, pp, rec)
1068 sugp = s->repo->idarraydata + s->suggests;
1069 while ((sug = *sugp++) != 0)
1071 FOR_PROVIDES(p, pp, sug)
1078 if (solv->pool->verbose > 3)
1079 printf ("----- addrpmrulesforsolvable end -----\n");
1084 addrpmrulesforweak(Solver *solv, Map *m)
1086 Pool *pool = solv->pool;
1091 if (solv->pool->verbose > 3)
1092 printf ("----- addrpmrulesforweak -----\n");
1093 for (i = n = 1; n < pool->nsolvables; i++, n++)
1095 if (i == pool->nsolvables)
1099 s = pool->solvables + i;
1100 if (!pool_installable(pool, s))
1105 supp = s->repo->idarraydata + s->supplements;
1106 while ((sup = *supp++) != ID_NULL)
1107 if (dep_possible(solv, sup, m))
1110 if (!sup && s->freshens)
1112 supp = s->repo->idarraydata + s->freshens;
1113 while ((sup = *supp++) != ID_NULL)
1114 if (dep_possible(solv, sup, m))
1117 if (!sup && s->enhances)
1119 supp = s->repo->idarraydata + s->enhances;
1120 while ((sup = *supp++) != ID_NULL)
1121 if (dep_possible(solv, sup, m))
1126 addrpmrulesforsolvable(solv, s, m);
1129 if (solv->pool->verbose > 3)
1130 printf ("----- addrpmrulesforweak end -----\n");
1134 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
1136 Pool *pool = solv->pool;
1141 if (solv->pool->verbose > 3)
1142 printf ("----- addrpmrulesforupdaters -----\n");
1144 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1145 policy_findupdatepackages(solv, s, &qs, allowall);
1146 if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
1147 addrpmrulesforsolvable(solv, s, m);
1148 for (i = 0; i < qs.count; i++)
1149 if (!MAPTST(m, qs.elements[i]))
1150 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1153 if (solv->pool->verbose > 3)
1154 printf ("----- addrpmrulesforupdaters -----\n");
1159 * add rule for update
1160 * (A|A1|A2|A3...) An = update candidates for A
1162 * s = (installed) solvable
1166 addupdaterule(Solver *solv, Solvable *s, int allowall)
1168 /* installed packages get a special upgrade allowed rule */
1169 Pool *pool = solv->pool;
1174 if (solv->pool->verbose > 3)
1175 printf ("----- addupdaterule -----\n");
1177 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1178 policy_findupdatepackages(solv, s, &qs, allowall);
1179 if (qs.count == 0) /* no updaters found */
1182 d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
1184 addrule(solv, s - pool->solvables, d); /* allow update of s */
1185 if (solv->pool->verbose > 3)
1186 printf ("----- addupdaterule end -----\n");
1190 /*-----------------------------------------------------------------*/
1197 * initial setup for all watches
1201 makewatches(Solver *solv)
1205 int nsolvables = solv->pool->nsolvables;
1207 xfree(solv->watches);
1208 /* lower half for removals, upper half for installs */
1209 solv->watches = (Id *)xcalloc(2 * nsolvables, sizeof(Id));
1211 /* do it reverse so rpm rules get triggered first */
1212 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1214 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1217 if (!r->w1 /* rule is disabled */
1218 || !r->w2) /* rule is assertion */
1221 /* see addwatches(solv, r) */
1222 r->n1 = solv->watches[nsolvables + r->w1];
1223 solv->watches[nsolvables + r->w1] = r - solv->rules;
1225 r->n2 = solv->watches[nsolvables + r->w2];
1226 solv->watches[nsolvables + r->w2] = r - solv->rules;
1232 * add watches (for rule)
1236 addwatches(Solver *solv, Rule *r)
1238 int nsolvables = solv->pool->nsolvables;
1240 r->n1 = solv->watches[nsolvables + r->w1];
1241 solv->watches[nsolvables + r->w1] = r - solv->rules;
1243 r->n2 = solv->watches[nsolvables + r->w2];
1244 solv->watches[nsolvables + r->w2] = r - solv->rules;
1248 /*-----------------------------------------------------------------*/
1249 /* rule propagation */
1251 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1256 * propagate decision to all rules
1260 propagate(Solver *solv, int level)
1262 Pool *pool = solv->pool;
1267 Id *decisionmap = solv->decisionmap;
1268 Id *watches = solv->watches + pool->nsolvables;
1270 if (solv->pool->verbose > 3)
1271 printf ("----- propagate -----\n");
1273 while (solv->propagate_index < solv->decisionq.count)
1275 /* negate because our watches trigger if literal goes FALSE */
1276 pkg = -solv->decisionq.elements[solv->propagate_index++];
1277 if (pool->verbose > 3)
1279 printf("popagate for decision %d level %d\n", -pkg, level);
1280 printruleelement(solv, 0, -pkg);
1283 for (rp = watches + pkg; *rp; rp = nrp)
1285 r = solv->rules + *rp;
1287 if (pool->verbose > 3)
1289 printf(" watch triggered ");
1303 /* if clause is TRUE, nothing to do */
1304 if (DECISIONMAP_TRUE(ow))
1309 /* not a binary clause, check if we need to move our watch */
1310 /* search for a literal that is not ow and not false */
1311 /* (true is also ok, in that case the rule is fulfilled) */
1312 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1315 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1316 if (p != ow && !DECISIONMAP_TRUE(-p))
1320 /* p is free to watch, move watch to p */
1321 if (pool->verbose > 3)
1324 printf(" -> move w%d to %s-%s.%s\n", (pkg == r->w1 ? 1 : 2), id2str(pool, pool->solvables[p].name), id2str(pool, pool->solvables[p].evr), id2str(pool, pool->solvables[p].arch));
1326 printf(" -> move w%d to !%s-%s.%s\n", (pkg == r->w1 ? 1 : 2), id2str(pool, pool->solvables[-p].name), id2str(pool, pool->solvables[-p].evr), id2str(pool, pool->solvables[-p].arch));
1340 watches[p] = r - solv->rules;
1344 /* unit clause found, set other watch to TRUE */
1345 if (DECISIONMAP_TRUE(-ow))
1346 return r; /* eek, a conflict! */
1347 if (pool->verbose > 2)
1353 decisionmap[ow] = level;
1355 decisionmap[-ow] = -level;
1356 queue_push(&solv->decisionq, ow);
1357 queue_push(&solv->decisionq_why, r - solv->rules);
1358 if (pool->verbose > 3)
1360 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1362 printf(" -> decided to install %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1364 printf(" -> decided to conflict %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1368 if (solv->pool->verbose > 3)
1369 printf ("----- propagate end-----\n");
1371 return 0; /* all is well */
1375 /*-----------------------------------------------------------------*/
1384 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *why)
1386 Pool *pool = solv->pool;
1389 Map seen; /* global? */
1393 int learnt_why = solv->learnt_pool.count;
1394 Id *decisionmap = solv->decisionmap;
1398 if (pool->verbose > 1) printf("ANALYZE at %d ----------------------\n", level);
1399 map_init(&seen, pool->nsolvables);
1400 idx = solv->decisionq.count;
1403 if (pool->verbose > 1)
1405 if (c - solv->rules >= solv->learntrules)
1407 else if (c - solv->rules >= solv->weakrules)
1409 else if (c - solv->rules >= solv->systemrules)
1411 else if (c - solv->rules >= solv->jobrules)
1415 queue_push(&solv->learnt_pool, c - solv->rules);
1416 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1427 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1429 vv = v > 0 ? v : -v;
1430 if (MAPTST(&seen, vv))
1432 l = solv->decisionmap[vv];
1439 for (j = 0; j < solv->decisionq.count; j++)
1440 if (solv->decisionq.elements[j] == v)
1442 if (j == solv->decisionq.count)
1444 queue_push(&rulq, -(j + 1));
1446 continue; /* initial setting */
1450 num++; /* need to do this one as well */
1454 if (pool->verbose > 3)
1456 printf("PUSH %d ", v);
1457 printruleelement(solv, 0, v);
1463 if (pool->verbose > 3)
1464 printf("num = %d\n", num);
1469 v = solv->decisionq.elements[--idx];
1470 vv = v > 0 ? v : -v;
1471 if (MAPTST(&seen, vv))
1474 c = solv->rules + solv->decisionq_why.elements[idx];
1482 else if (r.count == 1 && r.elements[0] < 0)
1483 *dr = r.elements[0];
1485 *dr = pool_queuetowhatprovides(pool, &r);
1486 if (pool->verbose > 1)
1488 printf("learned rule for level %d (am %d)\n", rlevel, level);
1489 printruleelement(solv, 0, -v);
1490 for (i = 0; i < r.count; i++)
1493 printruleelement(solv, 0, v);
1497 queue_push(&solv->learnt_pool, 0);
1498 if (pool->verbose > 3)
1500 for (i = learnt_why; solv->learnt_pool.elements[i]; i++)
1502 printf("learnt_why ");
1503 printrule(solv, solv->rules + solv->learnt_pool.elements[i]);
1514 * reset the solver decisions to right after the rpm rules.
1515 * called after rules have been enabled/disabled
1519 reset_solver(Solver *solv)
1524 enabledisablelearntrules(solv);
1526 /* redo all direct rpm rule decisions */
1527 /* we break at the first decision with a why attached, this is
1528 * either a job/system rule assertion or a propagated decision */
1529 for (i = 0; i < solv->decisionq.count; i++)
1531 v = solv->decisionq.elements[i];
1532 solv->decisionmap[v > 0 ? v : -v] = 0;
1534 for (i = 0; i < solv->decisionq_why.count; i++)
1535 if (solv->decisionq_why.elements[i])
1539 v = solv->decisionq.elements[i];
1540 solv->decisionmap[v > 0 ? v : -v] = v > 0 ? 1 : -1;
1543 if (solv->pool->verbose > 1)
1544 printf("decisions done reduced from %d to %d\n", solv->decisionq.count, i);
1546 solv->decisionq_why.count = i;
1547 solv->decisionq.count = i;
1548 solv->recommends_index = -1;
1549 solv->propagate_index = 0;
1551 /* redo all job/system decisions */
1552 makeruledecisions(solv);
1553 if (solv->pool->verbose > 1)
1554 printf("decisions so far: %d\n", solv->decisionq.count);
1555 /* recreate watch chains */
1561 * analyze_unsolvable_rule
1565 analyze_unsolvable_rule(Solver *solv, Rule *r)
1568 Id why = r - solv->rules;
1569 if (solv->pool->verbose > 1)
1571 if (why >= solv->jobrules && why < solv->systemrules)
1573 if (why >= solv->systemrules && why < solv->weakrules)
1574 printf("SYSTEM %d ", why - solv->systemrules);
1575 if (why >= solv->weakrules && why < solv->learntrules)
1577 if (solv->learntrules && why >= solv->learntrules)
1581 if (solv->learntrules && why >= solv->learntrules)
1583 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1584 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i]);
1587 /* do not add rpm rules to problem */
1588 if (why < solv->jobrules)
1590 /* turn rule into problem */
1591 if (why >= solv->jobrules && why < solv->systemrules)
1592 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1593 /* return if problem already countains our rule */
1594 if (solv->problems.count)
1596 for (i = solv->problems.count - 1; i >= 0; i--)
1597 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1599 else if (solv->problems.elements[i] == why)
1602 queue_push(&solv->problems, why);
1607 * analyze_unsolvable
1609 * return: 1 - disabled some rules, try again
1614 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1616 Pool *pool = solv->pool;
1618 Map seen; /* global to speed things up? */
1621 Id *decisionmap = solv->decisionmap;
1622 int oldproblemcount;
1623 int oldlearntpoolcount;
1626 if (pool->verbose > 1)
1627 printf("ANALYZE UNSOLVABLE ----------------------\n");
1628 oldproblemcount = solv->problems.count;
1629 oldlearntpoolcount = solv->learnt_pool.count;
1631 /* make room for proof index */
1632 /* must update it later, as analyze_unsolvable_rule would confuse
1633 * it with a rule index if we put the real value in already */
1634 queue_push(&solv->problems, 0);
1637 map_init(&seen, pool->nsolvables);
1638 queue_push(&solv->learnt_pool, r - solv->rules);
1639 analyze_unsolvable_rule(solv, r);
1640 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1651 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1653 vv = v > 0 ? v : -v;
1654 l = solv->decisionmap[vv];
1659 idx = solv->decisionq.count;
1662 v = solv->decisionq.elements[--idx];
1663 vv = v > 0 ? v : -v;
1664 if (!MAPTST(&seen, vv))
1666 why = solv->decisionq_why.elements[idx];
1669 /* level 1 and no why, must be an rpm assertion */
1670 if (pool->verbose > 3)
1673 printruleelement(solv, 0, v);
1675 /* this is the only positive rpm assertion */
1676 if (v == SYSTEMSOLVABLE)
1680 queue_push(&solv->learnt_pool, v);
1683 r = solv->rules + why;
1684 queue_push(&solv->learnt_pool, why);
1685 analyze_unsolvable_rule(solv, r);
1686 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1697 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1699 vv = v > 0 ? v : -v;
1700 l = solv->decisionmap[vv];
1707 queue_push(&solv->problems, 0); /* mark end of this problem */
1710 if (solv->weakrules != solv->learntrules)
1712 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1714 why = solv->problems.elements[i];
1715 if (why < solv->weakrules || why >= solv->learntrules)
1717 if (!lastweak || lastweak < why)
1723 /* disable last weak rule */
1724 solv->problems.count = oldproblemcount;
1725 solv->learnt_pool.count = oldlearntpoolcount;
1726 r = solv->rules + lastweak;
1727 printf("disabling weak ");
1729 disablerule(solv, r);
1735 queue_push(&solv->learnt_pool, 0);
1736 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1740 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1741 disableproblem(solv, solv->problems.elements[i]);
1746 printf("UNSOLVABLE\n");
1751 /*-----------------------------------------------------------------*/
1752 /* Decision revert */
1756 * revert decision at level
1760 revert(Solver *solv, int level)
1763 while (solv->decisionq.count)
1765 v = solv->decisionq.elements[solv->decisionq.count - 1];
1766 vv = v > 0 ? v : -v;
1767 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1769 if (solv->pool->verbose > 3)
1770 printf("reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1771 solv->decisionmap[vv] = 0;
1772 solv->decisionq.count--;
1773 solv->decisionq_why.count--;
1774 solv->propagate_index = solv->decisionq.count;
1776 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1778 solv->branches.count--;
1779 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1780 solv->branches.count--;
1782 solv->recommends_index = -1;
1787 * watch2onhighest - put watch2 on literal with highest level
1791 watch2onhighest(Solver *solv, Rule *r)
1797 return; /* binary rule, both watches are set */
1798 dp = solv->pool->whatprovidesdata + r->d;
1799 while ((v = *dp++) != 0)
1801 l = solv->decisionmap[v < 0 ? -v : v];
1816 * add free decision to decision q, increase level
1817 * propagate decision, return if no conflict.
1818 * in conflict case, analyze conflict rule, add resulting
1819 * rule to learnt rule set, make decision from learnt
1820 * rule (always unit) and re-propagate.
1824 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1834 solv->decisionmap[decision] = level;
1836 solv->decisionmap[-decision] = -level;
1837 queue_push(&solv->decisionq, decision);
1838 queue_push(&solv->decisionq_why, 0);
1842 r = propagate(solv, level);
1846 return analyze_unsolvable(solv, r, disablerules);
1847 printf("conflict with rule #%d\n", (int)(r - solv->rules));
1848 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1849 if (l >= level || l <= 0)
1851 printf("reverting decisions (level %d -> %d)\n", level, l);
1853 revert(solv, level);
1854 r = addrule(solv, p, d); /* p requires d */
1857 if (solv->learnt_why.count != (r - solv->rules) - solv->learntrules)
1859 printf("%d %d\n", solv->learnt_why.count, (int)(r - solv->rules) - solv->learntrules);
1862 queue_push(&solv->learnt_why, why);
1865 /* at least 2 literals, needs watches */
1866 watch2onhighest(solv, r);
1867 addwatches(solv, r);
1869 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1870 queue_push(&solv->decisionq, p);
1871 queue_push(&solv->decisionq_why, r - solv->rules);
1872 if (solv->pool->verbose > 1)
1874 printf("decision: ");
1875 printruleelement(solv, 0, p);
1876 printf("new rule: ");
1885 * install best package from the queue. We add an extra package, inst, if
1886 * provided. See comment in weak install section.
1889 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
1891 Pool *pool = solv->pool;
1895 if (dq->count > 1 || inst)
1896 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
1901 /* choose the supplemented one */
1902 for (i = 0; i < dq->count; i++)
1903 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1907 for (i = 1; i < dq->count; i++)
1908 queue_push(&solv->branches, dq->elements[i]);
1909 queue_push(&solv->branches, -level);
1913 p = dq->elements[i];
1915 if (pool->verbose > 3)
1917 Solvable *s = pool->solvables + p;
1918 printf("installing %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1921 return setpropagatelearn(solv, level, p, disablerules);
1925 /*-----------------------------------------------------------------*/
1926 /* Main solver interface */
1931 * create solver structure
1933 * pool: all available solvables
1934 * installed: installed Solvables
1937 * Upon solving, rules are created to flag the Solvables
1938 * of the 'installed' Repo as installed.
1942 solver_create(Pool *pool, Repo *installed)
1945 solv = (Solver *)xcalloc(1, sizeof(Solver));
1947 solv->installed = installed;
1949 queue_init(&solv->ruletojob);
1950 queue_init(&solv->decisionq);
1951 queue_init(&solv->decisionq_why);
1952 queue_init(&solv->problems);
1953 queue_init(&solv->suggestions);
1954 queue_init(&solv->learnt_why);
1955 queue_init(&solv->learnt_pool);
1956 queue_init(&solv->branches);
1958 map_init(&solv->recommendsmap, pool->nsolvables);
1959 map_init(&solv->suggestsmap, pool->nsolvables);
1960 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
1961 solv->recommends_index = 0;
1963 solv->decisionmap = (Id *)xcalloc(pool->nsolvables, sizeof(Id));
1964 solv->rules = (Rule *)xmalloc((solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
1965 memset(solv->rules, 0, sizeof(Rule));
1977 solver_free(Solver *solv)
1979 queue_free(&solv->ruletojob);
1980 queue_free(&solv->decisionq);
1981 queue_free(&solv->decisionq_why);
1982 queue_free(&solv->learnt_why);
1983 queue_free(&solv->learnt_pool);
1984 queue_free(&solv->problems);
1985 queue_free(&solv->suggestions);
1986 queue_free(&solv->branches);
1988 map_free(&solv->recommendsmap);
1989 map_free(&solv->suggestsmap);
1990 map_free(&solv->noupdate);
1991 xfree(solv->decisionmap);
1993 xfree(solv->watches);
1994 xfree(solv->weaksystemrules);
1995 xfree(solv->obsoletes);
1996 xfree(solv->obsoletes_data);
2001 /*-------------------------------------------------------*/
2006 * all rules have been set up, now actually run the solver
2011 run_solver(Solver *solv, int disablerules, int doweak)
2019 Pool *pool = solv->pool;
2022 if (pool->verbose > 3)
2024 printf("number of rules: %d\n", solv->nrules);
2025 for (i = 0; i < solv->nrules; i++)
2026 printrule(solv, solv->rules + i);
2029 /* create watches chains */
2032 if (pool->verbose) printf("initial decisions: %d\n", solv->decisionq.count);
2033 if (pool->verbose > 3)
2034 printdecisions(solv);
2036 /* start SAT algorithm */
2038 systemlevel = level + 1;
2039 if (pool->verbose) printf("solving...\n");
2050 if (pool->verbose) printf("propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2051 if ((r = propagate(solv, level)) != 0)
2053 if (analyze_unsolvable(solv, r, disablerules))
2061 * installed packages
2064 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2066 if (!solv->updatesystem)
2068 /* try to keep as many packages as possible */
2069 if (pool->verbose) printf("installing system packages\n");
2070 for (i = solv->installed->start, n = 0; ; i++)
2072 if (n == solv->installed->nsolvables)
2074 if (i == solv->installed->end)
2075 i = solv->installed->start;
2076 s = pool->solvables + i;
2077 if (s->repo != solv->installed)
2080 if (solv->decisionmap[i] != 0)
2082 if (pool->verbose > 3)
2083 printf("keeping %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2085 level = setpropagatelearn(solv, level, i, disablerules);
2091 if (level <= olevel)
2095 if (solv->weaksystemrules)
2097 if (pool->verbose) printf("installing weak system packages\n");
2098 for (i = solv->installed->start; i < solv->installed->end; i++)
2100 if (pool->solvables[i].repo != solv->installed)
2102 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
2104 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2105 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2108 if (solv->weaksystemrules[i - solv->installed->start])
2110 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
2111 while ((p = *dp++) != 0)
2113 if (solv->decisionmap[p] > 0)
2115 if (solv->decisionmap[p] == 0)
2119 continue; /* update package already installed */
2121 if (!dq.count && solv->decisionmap[i] != 0)
2124 /* FIXME: i is handled a bit different because we do not want
2125 * to have it pruned just because it is not recommened.
2126 * we should not prune installed packages instead */
2127 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2133 if (level <= olevel)
2136 if (i < solv->installed->end)
2139 systemlevel = level;
2146 if (pool->verbose) printf("deciding unresolved rules\n");
2147 for (i = 1, n = 1; ; i++, n++)
2149 if (n == solv->nrules)
2151 if (i == solv->nrules)
2153 r = solv->rules + i;
2159 /* binary or unary rule */
2160 /* need two positive undecided literals */
2161 if (r->p < 0 || r->w2 <= 0)
2163 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2165 queue_push(&dq, r->p);
2166 queue_push(&dq, r->w2);
2171 * all negative literals are installed
2172 * no positive literal is installed
2173 * i.e. the rule is not fulfilled and we
2174 * just need to decide on the positive literals
2178 if (solv->decisionmap[-r->p] <= 0)
2183 if (solv->decisionmap[r->p] > 0)
2185 if (solv->decisionmap[r->p] == 0)
2186 queue_push(&dq, r->p);
2188 dp = pool->whatprovidesdata + r->d;
2189 while ((p = *dp++) != 0)
2193 if (solv->decisionmap[-p] <= 0)
2198 if (solv->decisionmap[p] > 0)
2200 if (solv->decisionmap[p] == 0)
2209 /* cannot happen as this means that
2210 * the rule is unit */
2214 if (pool->verbose > 2)
2218 level = selectandinstall(solv, level, &dq, 0, disablerules);
2224 if (level < systemlevel)
2227 } /* for(), decide */
2229 if (n != solv->nrules) /* continue if level < systemlevel */
2232 if (doweak && !solv->problems.count)
2236 if (pool->verbose) printf("installing recommended packages\n");
2238 for (i = 1; i < pool->nsolvables; i++)
2240 if (solv->decisionmap[i] < 0)
2242 if (solv->decisionmap[i] > 0)
2244 Id *recp, rec, *pp, p;
2245 s = pool->solvables + i;
2246 /* installed, check for recommends */
2247 /* XXX need to special case AND ? */
2250 recp = s->repo->idarraydata + s->recommends;
2251 while ((rec = *recp++) != 0)
2254 FOR_PROVIDES(p, pp, rec)
2256 if (solv->decisionmap[p] > 0)
2261 else if (solv->decisionmap[p] == 0)
2263 queue_pushunique(&dq, p);
2271 s = pool->solvables + i;
2272 if (!s->supplements && !s->freshens)
2274 if (!pool_installable(pool, s))
2276 if (solver_is_supplementing(solv, s))
2277 queue_pushunique(&dq, i);
2283 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2285 s = pool->solvables + p;
2286 if (pool->verbose > 0)
2287 printf("installing recommended %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2288 level = setpropagatelearn(solv, level, p, 0);
2293 if (solv->solution_callback)
2295 solv->solution_callback(solv, solv->solution_callback_data);
2296 if (solv->branches.count)
2298 int i = solv->branches.count - 1;
2299 int l = -solv->branches.elements[i];
2301 if (solv->branches.elements[i - 1] < 0)
2303 p = solv->branches.elements[i];
2304 if (pool->verbose > 0)
2306 s = pool->solvables + p;
2307 printf("branching with %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2310 for (j = i + 1; j < solv->branches.count; j++)
2311 queue_push(&dq, solv->branches.elements[j]);
2312 solv->branches.count = i;
2314 revert(solv, level);
2316 for (j = 0; j < dq.count; j++)
2317 queue_push(&solv->branches, dq.elements[j]);
2319 level = setpropagatelearn(solv, level, p, disablerules);
2327 /* all branches done, we're finally finished */
2331 /* minimization step */
2332 if (solv->branches.count)
2334 int l = 0, lasti = -1, lastl = -1;
2336 for (i = solv->branches.count - 1; i >= 0; i--)
2338 p = solv->branches.elements[i];
2341 else if (p > 0 && solv->decisionmap[p] > l + 1)
2349 /* kill old solvable so that we do not loop */
2350 p = solv->branches.elements[lasti];
2351 solv->branches.elements[lasti] = 0;
2352 s = pool->solvables + p;
2353 if (pool->verbose > 0)
2354 printf("minimizing %d -> %d with %s-%s.%s\n", solv->decisionmap[p], l, id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2357 revert(solv, level);
2359 level = setpropagatelearn(solv, level, p, disablerules);
2376 * at this point, all rules that led to conflicts are disabled.
2377 * we re-enable all rules of a problem set but rule "sug", then
2378 * continue to disable more rules until there as again a solution.
2381 /* FIXME: think about conflicting assertions */
2384 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2386 Pool *pool = solv->pool;
2395 printf("refine_suggestion start\n");
2396 for (i = 0; problem[i]; i++)
2398 if (problem[i] == sug)
2400 printproblem(solv, problem[i]);
2403 queue_init(&disabled);
2404 queue_empty(refined);
2405 queue_push(refined, sug);
2407 /* re-enable all problem rules with the exception of "sug" */
2411 for (i = 0; problem[i]; i++)
2412 if (problem[i] != sug)
2413 enableproblem(solv, problem[i]);
2416 disableupdaterules(solv, job, -(sug + 1));
2420 /* re-enable as many weak rules as possible */
2421 for (i = solv->weakrules; i < solv->learntrules; i++)
2423 r = solv->rules + i;
2425 enablerule(solv, r);
2428 queue_empty(&solv->problems);
2429 revert(solv, 1); /* XXX move to reset_solver? */
2432 run_solver(solv, 0, 0);
2433 if (!solv->problems.count)
2436 printf("no more problems!\n");
2437 if (pool->verbose > 3)
2438 printdecisions(solv);
2439 break; /* great, no more problems */
2441 disabledcnt = disabled.count;
2442 /* skip over proof index */
2443 for (i = 1; i < solv->problems.count - 1; i++)
2445 /* ignore solutions in refined */
2446 v = solv->problems.elements[i];
2448 break; /* end of problem reached */
2449 for (j = 0; problem[j]; j++)
2450 if (problem[j] != sug && problem[j] == v)
2454 queue_push(&disabled, v);
2456 if (disabled.count == disabledcnt)
2458 /* no solution found, this was an invalid suggestion! */
2460 printf("no solution found!\n");
2464 if (disabled.count == disabledcnt + 1)
2466 /* just one suggestion, add it to refined list */
2467 v = disabled.elements[disabledcnt];
2468 queue_push(refined, v);
2469 disableproblem(solv, v);
2471 disableupdaterules(solv, job, -(v + 1));
2475 /* more than one solution, disable all */
2476 /* do not push anything on refine list */
2477 if (pool->verbose > 1)
2479 printf("more than one solution found:\n");
2480 for (i = disabledcnt; i < disabled.count; i++)
2481 printproblem(solv, disabled.elements[i]);
2483 for (i = disabledcnt; i < disabled.count; i++)
2484 disableproblem(solv, disabled.elements[i]);
2487 /* all done, get us back into the same state as before */
2488 /* enable refined rules again */
2489 for (i = 0; i < disabled.count; i++)
2490 enableproblem(solv, disabled.elements[i]);
2491 /* disable problem rules again */
2492 for (i = 0; problem[i]; i++)
2493 disableproblem(solv, problem[i]);
2495 printf("refine_suggestion end\n");
2499 problems_to_solutions(Solver *solv, Queue *job)
2501 Pool *pool = solv->pool;
2509 if (!solv->problems.count)
2511 queue_clone(&problems, &solv->problems);
2512 queue_init(&solution);
2513 queue_init(&solutions);
2514 /* copy over proof index */
2515 queue_push(&solutions, problems.elements[0]);
2516 problem = problems.elements + 1;
2517 for (i = 1; i < problems.count; i++)
2519 Id v = problems.elements[i];
2522 /* mark end of this problem */
2523 queue_push(&solutions, 0);
2524 queue_push(&solutions, 0);
2525 if (i + 1 == problems.count)
2527 /* copy over proof of next problem */
2528 queue_push(&solutions, problems.elements[i + 1]);
2530 problem = problems.elements + i + 1;
2533 refine_suggestion(solv, job, problem, v, &solution);
2534 if (!solution.count)
2535 continue; /* this solution didn't work out */
2537 for (j = 0; j < solution.count; j++)
2539 why = solution.elements[j];
2541 printproblem(solv, why);
2545 queue_push(&solutions, 0);
2546 queue_push(&solutions, -why);
2548 else if (why >= solv->systemrules && why < solv->weakrules)
2551 p = solv->installed->start + (why - solv->systemrules);
2552 if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
2554 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
2557 if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
2559 if (solv->decisionmap[*dp] > 0)
2566 queue_push(&solutions, p);
2567 queue_push(&solutions, rp);
2572 /* mark end of this solution */
2573 queue_push(&solutions, 0);
2574 queue_push(&solutions, 0);
2576 queue_free(&solution);
2577 queue_free(&problems);
2578 /* copy queue over to solutions */
2579 queue_free(&solv->problems);
2580 queue_clone(&solv->problems, &solutions);
2581 queue_free(&solutions);
2592 printdecisions(Solver *solv)
2594 Pool *pool = solv->pool;
2595 Repo *installed = solv->installed;
2596 Id p, *obsoletesmap;
2600 obsoletesmap = (Id *)xcalloc(pool->nsolvables, sizeof(Id));
2603 for (i = 0; i < solv->decisionq.count; i++)
2607 n = solv->decisionq.elements[i];
2610 if (n == SYSTEMSOLVABLE)
2612 s = pool->solvables + n;
2613 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2615 FOR_PROVIDES(p, pp, s->name)
2616 if (s->name == pool->solvables[p].name)
2618 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2620 obsoletesmap[p] = n;
2625 for (i = 0; i < solv->decisionq.count; i++)
2630 n = solv->decisionq.elements[i];
2633 if (n == SYSTEMSOLVABLE)
2635 s = pool->solvables + n;
2636 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2640 obsp = s->repo->idarraydata + s->obsoletes;
2641 while ((obs = *obsp++) != 0)
2642 FOR_PROVIDES(p, pp, obs)
2644 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2646 obsoletesmap[p] = n;
2653 /* print solvables to be erased */
2657 for (i = installed->start; i < installed->end; i++)
2659 s = pool->solvables + i;
2660 if (s->repo != installed)
2662 if (solv->decisionmap[i] >= 0)
2664 if (obsoletesmap[i])
2666 printf("erase %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2670 /* print solvables to be installed */
2672 for (i = 0; i < solv->decisionq.count; i++)
2675 p = solv->decisionq.elements[i];
2678 if (p == SYSTEMSOLVABLE)
2680 s = pool->solvables + p;
2681 if (installed && s->repo == installed)
2684 if (!obsoletesmap[p])
2686 printf("install %s-%s.%s", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2690 printf("update %s-%s.%s (obsoletes", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2691 for (j = installed->start; j < installed->end; j++)
2693 if (obsoletesmap[j] != p)
2695 s = pool->solvables + j;
2696 printf(" %s-%s.%s", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2703 xfree(obsoletesmap);
2705 if (solv->suggestions.count)
2707 printf("\nsuggested packages:\n");
2708 for (i = 0; i < solv->suggestions.count; i++)
2710 s = pool->solvables + solv->suggestions.elements[i];
2711 printf("- %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2717 printconflicts(Solver *solv, Solvable *s, Id pc)
2719 Pool *pool = solv->pool;
2720 Solvable *sc = pool->solvables + pc;
2721 Id p, *pp, con, *conp, obs, *obsp;
2726 conp = s->repo->idarraydata + s->conflicts;
2727 while ((con = *conp++) != 0)
2729 FOR_PROVIDES(p, pp, con)
2733 printf("packags %s-%s.%s conflicts with %s, which is provided by %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), dep2str(pool, con), id2str(pool, sc->name), id2str(pool, sc->evr), id2str(pool, sc->arch));
2738 if (s->obsoletes && (!solv->installed || s->repo != solv->installed))
2740 obsp = s->repo->idarraydata + s->obsoletes;
2741 while ((obs = *obsp++) != 0)
2743 FOR_PROVIDES(p, pp, obs)
2747 printf("packags %s-%s.%s obsolets %s, which is provided by %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), dep2str(pool, obs), id2str(pool, sc->name), id2str(pool, sc->evr), id2str(pool, sc->arch));
2756 printprobleminfo(Solver *solv, Queue *job, Id idx)
2758 Pool *pool = solv->pool;
2763 rn = solv->learnt_pool.elements[idx];
2766 p = rn; /* fake a negative assertion rule */
2771 r = solv->rules + rn;
2775 if (!r || r->w2 == 0)
2781 if (p == -SYSTEMSOLVABLE)
2785 /* we tried to deinstall the system solvable. must be a job. */
2786 if (rn < solv->jobrules || rn >= solv->systemrules)
2788 ji = solv->ruletojob.elements[rn - solv->jobrules];
2789 what = job->elements[ji + 1];
2790 switch (job->elements[ji])
2792 case SOLVER_INSTALL_SOLVABLE_NAME:
2793 printf("no solvable exists with name %s\n", dep2str(pool, what));
2795 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
2796 printf("no solvable provides %s\n", dep2str(pool, what));
2799 printf("unknown job\n");
2804 if (p > 0 && solv->learnt_pool.elements[idx + 1] == -p)
2806 /* we conflicted with a direct rpm assertion */
2807 /* print other rule */
2811 if (rn >= solv->jobrules)
2813 printf("some job/system/learnt rule\n");
2819 /* negative assertion, i.e. package is not installable */
2820 s = pool->solvables + (-p);
2823 reqp = s->repo->idarraydata + s->requires;
2824 while ((req = *reqp++) != 0)
2826 if (req == SOLVABLE_PREREQMARKER)
2828 dp = GET_PROVIDESP(req, p);
2831 printf("package %s-%s.%s requires %s, but no package provides it\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), dep2str(pool, req));
2836 printf("package %s-%s.%s is not installable\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2840 if (rn >= solv->learntrules)
2842 /* learnt rule, ignore for now */
2843 printf("some learnt rule...\n");
2847 if (rn >= solv->systemrules)
2849 /* system rule, ignore for now */
2850 printf("some system rule...\n");
2854 if (rn >= solv->jobrules)
2856 /* job rule, ignore for now */
2857 printf("some job rule...\n");
2861 /* only rpm rules left... */
2866 if (d == 0 && r->w2 < 0)
2870 sp = pool->solvables + (-p);
2871 sd = pool->solvables + (-d);
2872 if (sp->name == sd->name)
2874 printf("cannot install both %s-%s.%s and %s-%s.%s\n", id2str(pool, sp->name), id2str(pool, sp->evr), id2str(pool, sp->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
2878 printconflicts(solv, pool->solvables + (-p), -d);
2879 printconflicts(solv, pool->solvables + (-d), -p);
2884 /* find requires of p that corresponds with our rule */
2886 s = pool->solvables + (-p);
2887 reqp = s->repo->idarraydata + s->requires;
2888 while ((req = *reqp++) != 0)
2890 if (req == SOLVABLE_PREREQMARKER)
2892 dp = GET_PROVIDESP(req, p);
2895 if (*dp == r->w2 && dp[1] == 0)
2898 else if (dp - pool->whatprovidesdata == d)
2903 printf("req not found\n");
2906 printf("package %s-%s.%s requires %s, but none of its providers can be installed\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), dep2str(pool, req));
2911 printsolutions(Solver *solv, Queue *job)
2913 Pool *pool = solv->pool;
2919 printf("Encountered problems! Here are the solutions:\n\n");
2921 for (i = 0; i < solv->problems.count; )
2923 printf("Problem %d:\n", pcnt++);
2924 printf("====================================\n");
2925 printprobleminfo(solv, job, solv->problems.elements[i++]);
2929 if (solv->problems.elements[i] == 0 && solv->problems.elements[i + 1] == 0)
2931 /* end of solutions for this problems reached */
2937 p = solv->problems.elements[i];
2938 rp = solv->problems.elements[i + 1];
2940 if (p == 0 && rp == 0)
2942 /* end of this solution reached */
2948 /* job, p is index into job queue */
2949 what = job->elements[rp];
2950 switch (job->elements[rp - 1])
2952 case SOLVER_INSTALL_SOLVABLE:
2953 s = pool->solvables + what;
2954 if (solv->installed && s->repo == solv->installed)
2955 printf("- do not keep %s-%s.%s installed\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2957 printf("- do not install %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2959 case SOLVER_ERASE_SOLVABLE:
2960 s = pool->solvables + what;
2961 if (solv->installed && s->repo == solv->installed)
2962 printf("- do not deinstall %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2964 printf("- do not forbid installation of %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2966 case SOLVER_INSTALL_SOLVABLE_NAME:
2967 printf("- do not install %s\n", id2str(pool, what));
2969 case SOLVER_ERASE_SOLVABLE_NAME:
2970 printf("- do not deinstall %s\n", id2str(pool, what));
2972 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
2973 printf("- do not install a solvable providing %s\n", dep2str(pool, what));
2975 case SOLVER_ERASE_SOLVABLE_PROVIDES:
2976 printf("- do not deinstall all solvables providing %s\n", dep2str(pool, what));
2978 case SOLVER_INSTALL_SOLVABLE_UPDATE:
2979 s = pool->solvables + what;
2980 printf("- do not install most recent version of %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool
2984 printf("- do something different\n");
2990 /* policy, replace p with rp */
2991 s = pool->solvables + p;
2992 sd = rp ? pool->solvables + rp : 0;
2996 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr) > 0)
2998 printf("- allow downgrade of %s-%s.%s to %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
3001 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(pool, s, sd))
3003 printf("- allow architecture change of %s-%s.%s to %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
3006 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(pool, s, sd))
3009 printf("- allow vendor change from '%s' (%s-%s.%s) to '%s' (%s-%s.%s)\n", id2str(pool, s->vendor), id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->vendor), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
3011 printf("- allow vendor change from '%s' (%s-%s.%s) to no vendor (%s-%s.%s)\n", id2str(pool, s->vendor), id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
3015 printf("- allow replacement of %s-%s.%s with %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
3019 printf("- allow deinstallation of %s-%s.%s [%d]\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), (Id)(s - pool->solvables));
3029 /* for each installed solvable find which packages with *different* names
3030 * obsolete the solvable.
3031 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3035 create_obsolete_index(Solver *solv)
3037 Pool *pool = solv->pool;
3039 Repo *installed = solv->installed;
3040 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3043 if (!installed || !installed->nsolvables)
3045 /* create reverse obsoletes map for installed solvables */
3046 solv->obsoletes = obsoletes = xcalloc(installed->end - installed->start, sizeof(Id));
3047 for (i = 1; i < pool->nsolvables; i++)
3049 s = pool->solvables + i;
3050 if (s->repo == installed)
3054 if (!pool_installable(pool, s))
3056 obsp = s->repo->idarraydata + s->obsoletes;
3057 while ((obs = *obsp++) != 0)
3058 FOR_PROVIDES(p, pp, obs)
3060 if (pool->solvables[p].repo != installed)
3062 if (pool->solvables[p].name == s->name)
3064 obsoletes[p - installed->start]++;
3068 for (i = 0; i < installed->nsolvables; i++)
3071 n += obsoletes[i] + 1;
3074 solv->obsoletes_data = obsoletes_data = xcalloc(n + 1, sizeof(Id));
3075 if (pool->verbose) printf("obsoletes data: %d entries\n", n + 1);
3076 for (i = pool->nsolvables - 1; i > 0; i--)
3078 s = pool->solvables + i;
3079 if (s->repo == installed)
3083 if (!pool_installable(pool, s))
3085 obsp = s->repo->idarraydata + s->obsoletes;
3086 while ((obs = *obsp++) != 0)
3087 FOR_PROVIDES(p, pp, obs)
3089 if (pool->solvables[p].repo != installed)
3091 if (pool->solvables[p].name == s->name)
3093 p -= installed->start;
3094 if (obsoletes_data[obsoletes[p]] != i)
3095 obsoletes_data[--obsoletes[p]] = i;
3101 /*-----------------------------------------------------------------*/
3111 solve(Solver *solv, Queue *job)
3113 Pool *pool = solv->pool;
3114 Repo *installed = solv->installed;
3117 Map addedmap; /* '1' == have rule for solvable */
3118 Id how, what, p, *pp, d;
3122 /* create obsolete index if needed */
3123 if (solv->noupdateprovide)
3124 create_obsolete_index(solv);
3127 * create basic rule set of all involved packages
3128 * use addedmap bitmap to make sure we don't create rules twice
3132 map_init(&addedmap, pool->nsolvables);
3136 * always install our system solvable
3138 MAPSET(&addedmap, SYSTEMSOLVABLE);
3139 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3140 queue_push(&solv->decisionq_why, 0);
3141 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3144 * create rules for all package that could be involved with the solving
3145 * so called: rpm rules
3150 oldnrules = solv->nrules;
3151 if (pool->verbose > 3)
3152 printf ("*** create rpm rules for installed solvables ***\n");
3153 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3154 if (s->repo == installed)
3155 addrpmrulesforsolvable(solv, s, &addedmap);
3157 printf("added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3158 if (pool->verbose > 3)
3159 printf ("*** create rpm rules for updaters of installed solvables ***\n");
3160 oldnrules = solv->nrules;
3161 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3162 if (s->repo == installed)
3163 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3165 printf("added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3168 if (solv->pool->verbose > 3)
3169 printf ("*** create rpm rules for packages involved with a job ***\n");
3170 oldnrules = solv->nrules;
3171 for (i = 0; i < job->count; i += 2)
3173 how = job->elements[i];
3174 what = job->elements[i + 1];
3178 case SOLVER_INSTALL_SOLVABLE:
3179 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3181 case SOLVER_INSTALL_SOLVABLE_NAME:
3182 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3183 FOR_PROVIDES(p, pp, what)
3185 /* if by name, ensure that the name matches */
3186 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3188 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3191 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3192 /* dont allow downgrade */
3193 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3198 printf("added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3200 if (solv->pool->verbose > 3)
3201 printf ("*** create rpm rules for recommended/suggested packages ***\n");
3203 oldnrules = solv->nrules;
3204 addrpmrulesforweak(solv, &addedmap);
3206 printf("added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3211 int possible = 0, installable = 0;
3212 for (i = 1; i < pool->nsolvables; i++)
3214 if (pool_installable(pool, pool->solvables + i))
3216 if (MAPTST(&addedmap, i))
3219 printf("%d of %d installable solvables considered for solving\n", possible, installable);
3224 * first pass done, we now have all the rpm rules we need.
3225 * unify existing rules before going over all job rules and
3227 * at this point the system is always solvable,
3228 * as an empty system (remove all packages) is a valid solution
3231 unifyrules(solv); /* remove duplicate rpm rules */
3233 if (pool->verbose) printf("decisions so far: %d\n", solv->decisionq.count);
3234 if (pool->verbose > 3)
3235 printdecisions (solv);
3238 * now add all job rules
3241 if (solv->pool->verbose > 3)
3242 printf ("*** Add JOB rules ***\n");
3244 solv->jobrules = solv->nrules;
3246 for (i = 0; i < job->count; i += 2)
3248 how = job->elements[i];
3249 what = job->elements[i + 1];
3252 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3253 s = pool->solvables + what;
3255 printf("job: install solvable %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
3256 addrule(solv, what, 0); /* install by Id */
3257 queue_push(&solv->ruletojob, i);
3259 case SOLVER_ERASE_SOLVABLE:
3260 s = pool->solvables + what;
3262 printf("job: erase solvable %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
3263 addrule(solv, -what, 0); /* remove by Id */
3264 queue_push(&solv->ruletojob, i);
3266 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3267 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3268 if (pool->verbose && how == SOLVER_INSTALL_SOLVABLE_NAME)
3269 printf("job: install name %s\n", id2str(pool, what));
3270 if (pool->verbose && how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3271 printf("job: install provides %s\n", dep2str(pool, what));
3273 FOR_PROVIDES(p, pp, what)
3275 /* if by name, ensure that the name matches */
3276 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3282 /* no provider, make this an impossible rule */
3283 queue_push(&q, -SYSTEMSOLVABLE);
3286 p = queue_shift(&q); /* get first provider */
3288 d = 0; /* single provider ? -> make assertion */
3290 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3291 addrule(solv, p, d); /* add 'requires' rule */
3292 queue_push(&solv->ruletojob, i);
3294 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3295 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3296 if (pool->verbose && how == SOLVER_ERASE_SOLVABLE_NAME)
3297 printf("job: erase name %s\n", id2str(pool, what));
3298 if (pool->verbose && how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3299 printf("job: erase provides %s\n", dep2str(pool, what));
3300 FOR_PROVIDES(p, pp, what)
3302 /* if by name, ensure that the name matches */
3303 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
3305 addrule(solv, -p, 0); /* add 'remove' rule */
3306 queue_push(&solv->ruletojob, i);
3309 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3310 s = pool->solvables + what;
3312 printf("job: update %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
3313 addupdaterule(solv, s, 0);
3314 queue_push(&solv->ruletojob, i);
3319 if (solv->ruletojob.count != solv->nrules - solv->jobrules)
3323 * now add system rules
3327 if (solv->pool->verbose > 3)
3328 printf ("*** Add system rules ***\n");
3331 solv->systemrules = solv->nrules;
3334 * create rules for updating installed solvables
3338 if (installed && !solv->allowuninstall)
3339 { /* loop over all installed solvables */
3340 /* we create all update rules, but disable some later on depending on the job */
3341 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3342 if (s->repo == installed)
3343 addupdaterule(solv, s, 0); /* allowall = 0 */
3345 addupdaterule(solv, 0, 0); /* create dummy rule; allowall = 0 */
3346 /* consistency check: we added a rule for _every_ system solvable */
3347 if (solv->nrules - solv->systemrules != installed->end - installed->start)
3351 /* create special weak system rules */
3352 /* those are used later on to keep a version of the installed packages in
3354 if (installed && installed->nsolvables)
3356 solv->weaksystemrules = xcalloc(installed->end - installed->start, sizeof(Id));
3357 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3358 if (s->repo == installed)
3360 policy_findupdatepackages(solv, s, &q, 1);
3362 solv->weaksystemrules[i - installed->start] = pool_queuetowhatprovides(pool, &q);
3366 /* free unneeded memory */
3367 map_free(&addedmap);
3370 solv->weakrules = solv->nrules;
3372 /* try real hard to keep packages installed */
3375 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3376 if (s->repo == installed)
3378 /* FIXME: can't work with refine_suggestion! */
3379 /* need to always add the rule but disable it */
3380 if (MAPTST(&solv->noupdate, i - installed->start))
3382 d = solv->weaksystemrules[i - installed->start];
3383 addrule(solv, i, d);
3387 /* all new rules are learnt after this point */
3388 solv->learntrules = solv->nrules;
3395 disableupdaterules(solv, job, -1);
3396 makeruledecisions(solv);
3398 if (pool->verbose) printf("problems so far: %d\n", solv->problems.count);
3400 run_solver(solv, 1, 1);
3402 /* find suggested packages */
3403 if (!solv->problems.count)
3405 Id sug, *sugp, p, *pp;
3407 /* create map of all suggests that are still open */
3408 solv->recommends_index = -1;
3409 MAPZERO(&solv->suggestsmap);
3410 for (i = 0; i < solv->decisionq.count; i++)
3412 p = solv->decisionq.elements[i];
3415 s = pool->solvables + p;
3418 sugp = s->repo->idarraydata + s->suggests;
3419 while ((sug = *sugp++) != 0)
3421 FOR_PROVIDES(p, pp, sug)
3422 if (solv->decisionmap[p] > 0)
3425 continue; /* already fulfilled */
3426 FOR_PROVIDES(p, pp, sug)
3427 MAPSET(&solv->suggestsmap, p);
3431 for (i = 1; i < pool->nsolvables; i++)
3433 if (solv->decisionmap[i] != 0)
3435 s = pool->solvables + i;
3436 if (!MAPTST(&solv->suggestsmap, i))
3440 if (!pool_installable(pool, s))
3442 if (!solver_is_enhancing(solv, s))
3445 queue_push(&solv->suggestions, i);
3447 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
3450 if (solv->problems.count)
3451 problems_to_solutions(solv, job);