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 */
248 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; > 0 for learnt, < 0 for installed pkg (rpm)
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 : rule from rpm (installed pkg)
309 * d > 0 : Offset in whatprovidesdata (list of providers)
311 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
312 * d < 0: Id of solvable (e.g. B1)
314 * d == 0: unary rule, assertion => (A) or (-A)
316 * Install: p > 0, d = 0 (A) user requested install
317 * Remove: p < 0, d = 0 (-A) user requested remove
318 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
319 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
320 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider)
321 * ? p > 0, d < 0 (A|-B)
322 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
326 addrule(Solver *solv, Id p, Id d)
331 int n = 0; /* number of literals in rule - 1
332 0 = direct assertion (single literal)
336 /* it often happenes that requires lead to adding the same rpm rule
337 * multiple times, so we prune those duplicates right away to make
338 * the work for unifyrules a bit easier */
340 if (solv->nrules && !solv->jobrules)
342 r = solv->rules + solv->nrules - 1; /* get the last added rule */
343 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
350 return 0; /* ignore self conflict */
353 else if (d == 0) /* user requested */
357 for (dp = solv->pool->whatprovidesdata + d; *dp; dp++, n++)
359 return 0; /* rule is self-fulfilling */
364 if (n == 0) /* direct assertion */
368 /* this is a rpm rule assertion, we do not have to allocate it */
369 /* it can be identified by a level of 1 and a zero reason */
370 /* we must not drop those rules from the decisionq when rewinding! */
373 if (solv->decisionmap[-p] > 0 || solv->decisionmap[-p] < -1)
375 if (solv->decisionmap[-p])
377 queue_push(&solv->decisionq, p);
378 queue_push(&solv->decisionq_why, 0);
379 solv->decisionmap[-p] = -1;
383 else if (n == 1 && p > d)
385 /* smallest literal first so we can find dups */
389 n = 1; /* re-set n, was used as temp var */
392 /* check if the last added rule is exactly the same as what we're looking for. */
393 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
396 if (r && n > 1 && r->d && r->p == p)
401 dp2 = solv->pool->whatprovidesdata + r->d;
402 for (dp = solv->pool->whatprovidesdata + d; *dp; dp++, dp2++)
413 /* check and extend rule buffer */
414 if ((solv->nrules & RULES_BLOCK) == 0)
416 solv->rules = (Rule *)xrealloc(solv->rules, (solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
419 r = solv->rules + solv->nrules++; /* point to rule space */
424 /* direct assertion, no watch needed */
440 r->w2 = solv->pool->whatprovidesdata[d];
445 if (solv->pool->verbose > 3)
447 printf (" Add rule: ");
455 disablerule(Solver *solv, Rule *r)
461 enablerule(Solver *solv, Rule *r)
463 if (r->d == 0 || r->w2 != r->p)
466 r->w1 = solv->pool->whatprovidesdata[r->d];
470 /**********************************************************************************/
472 /* a problem is an item on the solver's problem list. It can either be >0, in that
473 * case it is a system (upgrade) rule, or it can be <0, which makes it refer to a job
474 * consisting of multiple job rules.
478 disableproblem(Solver *solv, Id v)
486 disablerule(solv, solv->rules + v);
490 jp = solv->ruletojob.elements;
491 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
493 disablerule(solv, r);
497 enableproblem(Solver *solv, Id v)
505 enablerule(solv, solv->rules + v);
509 jp = solv->ruletojob.elements;
510 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
516 printproblem(Solver *solv, Id v)
523 printrule(solv, solv->rules + v);
527 printf("JOB %d\n", v);
528 jp = solv->ruletojob.elements;
529 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
540 /**********************************************************************************/
542 /* go through system and job rules and add direct assertions
543 * to the decisionqueue. If we find a conflict, disable rules and
544 * add them to problem queue.
547 makeruledecisions(Solver *solv)
554 /* no learnt rules for now */
555 if (solv->learntrules && solv->learntrules != solv->nrules)
558 decisionstart = solv->decisionq.count;
559 /* the loop is over jobrules, system rules and weak rules */
560 for (ri = solv->jobrules, r = solv->rules + ri; ri < solv->nrules; ri++, r++)
566 if (solv->decisionmap[vv] == 0)
568 queue_push(&solv->decisionq, v);
569 queue_push(&solv->decisionq_why, r - solv->rules);
570 solv->decisionmap[vv] = v > 0 ? 1 : -1;
573 if (v > 0 && solv->decisionmap[vv] > 0)
575 if (v < 0 && solv->decisionmap[vv] < 0)
577 /* found a conflict! */
578 /* if we are weak, just disable ourself */
579 if (ri >= solv->weakrules)
581 printf("conflict, but I am weak, disabling ");
586 /* only job and system rules left */
587 for (i = 0; i < solv->decisionq.count; i++)
588 if (solv->decisionq.elements[i] == -v)
590 if (i == solv->decisionq.count)
592 if (solv->decisionq_why.elements[i] == 0)
594 /* conflict with rpm rule, need only disable our rule */
595 printf("conflict with rpm rule, disabling rule #%d\n", ri);
596 if (v < 0 && v != -SYSTEMSOLVABLE)
598 queue_push(&solv->problems, 0);
599 if (v == -SYSTEMSOLVABLE)
600 queue_push(&solv->problems, 0); /* sigh, we don't have a rule for that */
602 queue_push(&solv->problems, -v); /* sigh, we don't have a rule for that */
604 if (ri < solv->systemrules)
605 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
606 queue_push(&solv->problems, v);
607 disableproblem(solv, v);
608 queue_push(&solv->problems, 0);
611 /* conflict with another job or system rule */
612 /* remove old decision */
613 printf("conflicting system/job rules over literal %d\n", vv);
614 queue_push(&solv->problems, 0);
615 queue_push(&solv->problems, solv->decisionq_why.elements[i]);
616 /* push all of our rules asserting this literal on the problem stack */
617 for (i = solv->jobrules, rr = solv->rules + i; i < solv->nrules; i++, rr++)
619 if (!rr->w1 || rr->w2)
621 if (rr->p != v && rr->p != -v)
623 printf(" - disabling rule #%d\n", i);
625 if (i < solv->systemrules)
626 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
627 queue_push(&solv->problems, v);
628 disableproblem(solv, v);
630 queue_push(&solv->problems, 0);
633 while (solv->decisionq.count > decisionstart)
635 v = solv->decisionq.elements[--solv->decisionq.count];
636 --solv->decisionq_why.count;
638 solv->decisionmap[vv] = 0;
640 ri = solv->jobrules - 1;
641 r = solv->rules + ri;
646 /* FIXME: bad code ahead, replace as soon as possible */
648 disableupdaterules(Solver *solv, Queue *job, int jobidx)
650 Pool *pool = solv->pool;
652 Id how, what, p, *pp;
658 installed = solv->installed;
664 how = job->elements[jobidx];
667 case SOLVER_INSTALL_SOLVABLE:
668 case SOLVER_ERASE_SOLVABLE:
669 case SOLVER_ERASE_SOLVABLE_NAME:
670 case SOLVER_ERASE_SOLVABLE_PROVIDES:
676 /* go through all enabled job rules */
677 MAPZERO(&solv->noupdate);
678 for (i = solv->jobrules; i < solv->systemrules; i++)
681 if (!r->w1) /* disabled? */
683 j = solv->ruletojob.elements[i - solv->jobrules];
687 how = job->elements[j];
688 what = job->elements[j + 1];
691 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
692 s = pool->solvables + what;
693 FOR_PROVIDES(p, pp, s->name)
695 if (pool->solvables[p].name != s->name)
697 if (pool->solvables[p].repo == installed)
698 MAPSET(&solv->noupdate, p - installed->start);
701 case SOLVER_ERASE_SOLVABLE:
702 s = pool->solvables + what;
703 if (s->repo == installed)
704 MAPSET(&solv->noupdate, what - installed->start);
706 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
707 case SOLVER_ERASE_SOLVABLE_PROVIDES:
708 FOR_PROVIDES(p, pp, what)
710 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
712 if (pool->solvables[p].repo == installed)
713 MAPSET(&solv->noupdate, p - installed->start);
721 /* fixup update rule status */
722 if (solv->allowuninstall)
723 return; /* no update rules at all */
727 /* we just disabled job #jobidx. enable all update rules
728 * that aren't disabled by the remaining job rules */
729 how = job->elements[jobidx];
730 what = job->elements[jobidx + 1];
733 case SOLVER_INSTALL_SOLVABLE:
734 s = pool->solvables + what;
735 FOR_PROVIDES(p, pp, s->name)
737 if (pool->solvables[p].name != s->name)
739 if (pool->solvables[p].repo != installed)
741 if (MAPTST(&solv->noupdate, p - installed->start))
743 r = solv->rules + solv->systemrules + (p - installed->start);
749 printf("@@@ re-enabling ");
754 case SOLVER_ERASE_SOLVABLE:
755 s = pool->solvables + what;
756 if (s->repo != installed)
758 if (MAPTST(&solv->noupdate, what - installed->start))
760 r = solv->rules + solv->systemrules + (what - installed->start);
766 printf("@@@ re-enabling ");
770 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
771 case SOLVER_ERASE_SOLVABLE_PROVIDES:
772 FOR_PROVIDES(p, pp, what)
774 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
776 if (pool->solvables[p].repo != installed)
778 if (MAPTST(&solv->noupdate, p - installed->start))
780 r = solv->rules + solv->systemrules + (p - installed->start);
786 printf("@@@ re-enabling ");
797 for (i = 0; i < installed->nsolvables; i++)
799 r = solv->rules + solv->systemrules + i;
800 if (r->w1 && MAPTST(&solv->noupdate, i))
801 r->w1 = 0; /* was enabled, need to disable */
807 * add (install) rules for solvable
808 * for unfulfilled requirements, conflicts, obsoletes,....
809 * "unflag" a resolvable if it is not installable via "addrule(solv, -n, 0)"
813 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
815 Pool *pool = solv->pool;
816 Repo *installed = solv->installed;
830 if (solv->pool->verbose > 3)
831 printf ("----- addrpmrulesforsolvable -----\n");
833 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
834 queue_push(&q, s - pool->solvables); /* push solvable Id */
840 * s: Pointer to solvable
844 if (MAPTST(m, n)) /* continue if already done */
848 s = pool->solvables + n; /* s = Solvable in question */
851 if (installed /* Installed system available */
852 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
853 && s->repo == installed) /* solvable is installed? */
855 dontfix = 1; /* dont care about broken rpm deps */
858 /*-----------------------------------------
859 * check requires of s
864 reqp = s->repo->idarraydata + s->requires;
865 while ((req = *reqp++) != 0) /* go throw all requires */
867 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
870 dp = GET_PROVIDESP(req, p); /* get providers of req; p is a dummy only */
872 if (*dp == SYSTEMSOLVABLE) /* always installed */
877 /* the strategy here is to not insist on dependencies
878 * that are already broken. so if we find one provider
879 * that was already installed, we know that the
880 * dependency was not broken before so we enforce it */
881 for (i = 0; (p = dp[i]) != 0; i++) /* for all providers */
883 if (pool->solvables[p].repo == installed)
884 break; /* provider was installed */
886 if (!p) /* previously broken dependency */
889 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));
896 /* nothing provides req! */
898 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));
899 addrule(solv, -n, 0); /* mark requestor as uninstallable */
901 printf(">!> !unflag %s-%s.%s[%s]\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), repo_name(s->repo));
905 if (pool->verbose > 2)
907 printf(" %s-%s.%s requires %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), dep2str(pool, req));
908 for (i = 0; dp[i]; i++)
909 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));
912 /* add 'requires' dependency */
913 /* rule: (-requestor|provider1|provider2|...|providerN) */
914 addrule(solv, -n, dp - pool->whatprovidesdata);
916 /* descend the dependency tree */
917 for (; *dp; dp++) /* loop through all providers */
923 } /* while, requirements of n */
925 } /* if, requirements */
928 /*-----------------------------------------
929 * check conflicts of s
934 conp = s->repo->idarraydata + s->conflicts;
935 while ((con = *conp++) != 0)
937 FOR_PROVIDES(p, pp, con)
939 /* dontfix: dont care about conflicts with already installed packs */
940 if (dontfix && pool->solvables[p].repo == installed)
942 /* rule: -n|-p: either solvable _or_ provider of conflict */
943 addrule(solv, -n, -p);
948 /*-----------------------------------------
949 * check obsoletes if not installed
951 if (!installed || pool->solvables[n].repo != installed)
952 { /* not installed */
955 obsp = s->repo->idarraydata + s->obsoletes;
956 while ((obs = *obsp++) != 0)
958 FOR_PROVIDES(p, pp, obs)
959 addrule(solv, -n, -p);
962 FOR_PROVIDES(p, pp, s->name)
964 if (s->name == pool->solvables[p].name)
965 addrule(solv, -n, -p);
969 /*-----------------------------------------
970 * add recommends to the rule list
974 recp = s->repo->idarraydata + s->recommends;
975 while ((rec = *recp++) != 0)
977 FOR_PROVIDES(p, pp, rec)
984 sugp = s->repo->idarraydata + s->suggests;
985 while ((sug = *sugp++) != 0)
987 FOR_PROVIDES(p, pp, sug)
997 addrpmrulesforweak(Solver *solv, Map *m)
999 Pool *pool = solv->pool;
1004 if (pool->verbose) printf("----- addrpmrulesforweak ----- (nrules %d)\n", solv->nrules);
1005 for (i = n = 1; n < pool->nsolvables; i++, n++)
1007 if (i == pool->nsolvables)
1011 s = pool->solvables + i;
1012 if (!pool_installable(pool, s))
1017 supp = s->repo->idarraydata + s->supplements;
1018 while ((sup = *supp++) != ID_NULL)
1019 if (dep_possible(solv, sup, m))
1022 if (!sup && s->freshens)
1024 supp = s->repo->idarraydata + s->freshens;
1025 while ((sup = *supp++) != ID_NULL)
1026 if (dep_possible(solv, sup, m))
1029 if (!sup && s->enhances)
1031 supp = s->repo->idarraydata + s->enhances;
1032 while ((sup = *supp++) != ID_NULL)
1033 if (dep_possible(solv, sup, m))
1038 addrpmrulesforsolvable(solv, s, m);
1041 if (pool->verbose) printf("----- addrpmrulesforweak ----- done. (nrules%d)\n", solv->nrules);
1045 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
1047 Pool *pool = solv->pool;
1052 if (solv->pool->verbose > 3)
1053 printf ("----- addrpmrulesforupdaters -----\n");
1055 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1056 policy_findupdatepackages(solv, s, &qs, allowall);
1057 if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
1058 addrpmrulesforsolvable(solv, s, m);
1059 for (i = 0; i < qs.count; i++)
1060 if (!MAPTST(m, qs.elements[i]))
1061 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1066 * add rule for update
1067 * (A|A1|A2|A3...) An = update candidates for A
1069 * s = (installed) solvable
1073 addupdaterule(Solver *solv, Solvable *s, int allowall)
1075 /* installed packages get a special upgrade allowed rule */
1076 Pool *pool = solv->pool;
1081 if (solv->pool->verbose > 3)
1082 printf ("----- addupdaterule -----\n");
1084 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1085 policy_findupdatepackages(solv, s, &qs, allowall);
1086 if (qs.count == 0) /* no updaters found */
1089 d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
1091 addrule(solv, s - pool->solvables, d); /* allow update of s */
1095 /*-----------------------------------------------------------------*/
1102 * initial setup for all watches
1106 makewatches(Solver *solv)
1110 int nsolvables = solv->pool->nsolvables;
1112 xfree(solv->watches);
1113 /* lower half for removals, upper half for installs */
1114 solv->watches = (Id *)xcalloc(2 * nsolvables, sizeof(Id));
1116 /* do it reverse so rpm rules get triggered first */
1117 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1119 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1122 if (!r->w1 /* rule is disabled */
1123 || !r->w2) /* rule is assertion */
1126 /* see addwatches(solv, r) */
1127 r->n1 = solv->watches[nsolvables + r->w1];
1128 solv->watches[nsolvables + r->w1] = r - solv->rules;
1130 r->n2 = solv->watches[nsolvables + r->w2];
1131 solv->watches[nsolvables + r->w2] = r - solv->rules;
1137 * add watches (for rule)
1141 addwatches(Solver *solv, Rule *r)
1143 int nsolvables = solv->pool->nsolvables;
1145 r->n1 = solv->watches[nsolvables + r->w1];
1146 solv->watches[nsolvables + r->w1] = r - solv->rules;
1148 r->n2 = solv->watches[nsolvables + r->w2];
1149 solv->watches[nsolvables + r->w2] = r - solv->rules;
1153 /*-----------------------------------------------------------------*/
1154 /* rule propagation */
1156 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1161 * propagate decision to all rules
1165 propagate(Solver *solv, int level)
1167 Pool *pool = solv->pool;
1172 Id *decisionmap = solv->decisionmap;
1173 Id *watches = solv->watches + pool->nsolvables;
1175 while (solv->propagate_index < solv->decisionq.count)
1177 /* negate because our watches trigger if literal goes FALSE */
1178 pkg = -solv->decisionq.elements[solv->propagate_index++];
1179 if (pool->verbose > 3)
1181 printf("popagate for decision %d level %d\n", -pkg, level);
1182 printruleelement(solv, 0, -pkg);
1185 for (rp = watches + pkg; *rp; rp = nrp)
1187 r = solv->rules + *rp;
1189 if (pool->verbose > 3)
1191 printf(" watch triggered ");
1205 /* if clause is TRUE, nothing to do */
1206 if (DECISIONMAP_TRUE(ow))
1211 /* not a binary clause, check if we need to move our watch */
1212 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1215 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1216 if (p != ow && !DECISIONMAP_TRUE(-p))
1220 /* p is free to watch, move watch to p */
1221 if (pool->verbose > 3)
1224 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));
1226 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));
1240 watches[p] = r - solv->rules;
1244 /* unit clause found, set other watch to TRUE */
1245 if (DECISIONMAP_TRUE(-ow))
1246 return r; /* eek, a conflict! */
1247 if (pool->verbose > 2)
1253 decisionmap[ow] = level;
1255 decisionmap[-ow] = -level;
1256 queue_push(&solv->decisionq, ow);
1257 queue_push(&solv->decisionq_why, r - solv->rules);
1258 if (pool->verbose > 3)
1260 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1262 printf(" -> decided to install %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1264 printf(" -> decided to conflict %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1268 return 0; /* all is well */
1272 /*-----------------------------------------------------------------*/
1281 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *why)
1283 Pool *pool = solv->pool;
1286 Map seen; /* global? */
1290 int learnt_why = solv->learnt_pool.count;
1291 Id *decisionmap = solv->decisionmap;
1295 if (pool->verbose > 1) printf("ANALYZE at %d ----------------------\n", level);
1296 map_init(&seen, pool->nsolvables);
1297 idx = solv->decisionq.count;
1300 if (pool->verbose > 1) printrule(solv, c);
1301 queue_push(&solv->learnt_pool, c - solv->rules);
1302 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1313 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1315 vv = v > 0 ? v : -v;
1316 if (MAPTST(&seen, vv))
1318 l = solv->decisionmap[vv];
1325 for (j = 0; j < solv->decisionq.count; j++)
1326 if (solv->decisionq.elements[j] == v)
1328 if (j == solv->decisionq.count)
1330 queue_push(&rulq, -(j + 1));
1332 continue; /* initial setting */
1336 num++; /* need to do this one as well */
1340 if (pool->verbose > 3)
1342 printf("PUSH %d ", v);
1343 printruleelement(solv, 0, v);
1349 if (pool->verbose > 3)
1350 printf("num = %d\n", num);
1355 v = solv->decisionq.elements[--idx];
1356 vv = v > 0 ? v : -v;
1357 if (MAPTST(&seen, vv))
1360 c = solv->rules + solv->decisionq_why.elements[idx];
1368 else if (r.count == 1 && r.elements[0] < 0)
1369 *dr = r.elements[0];
1371 *dr = pool_queuetowhatprovides(pool, &r);
1372 if (pool->verbose > 1)
1374 printf("learned rule for level %d (am %d)\n", rlevel, level);
1375 printruleelement(solv, 0, -v);
1376 for (i = 0; i < r.count; i++)
1379 printruleelement(solv, 0, v);
1383 queue_push(&solv->learnt_pool, 0);
1384 if (pool->verbose > 3)
1386 for (i = learnt_why; solv->learnt_pool.elements[i]; i++)
1388 printf("learnt_why ");
1389 printrule(solv, solv->rules + solv->learnt_pool.elements[i]);
1400 * reset the solver decisions to right after the rpm rules.
1401 * called after rules have been enabled/disabled
1405 reset_solver(Solver *solv)
1410 /* delete all learnt rules */
1411 solv->nrules = solv->learntrules;
1412 queue_empty(&solv->learnt_why);
1413 queue_empty(&solv->learnt_pool);
1415 /* redo all direct rpm rule decisions */
1416 /* we break at the first decision with a why attached, this is
1417 * either a job/system rule assertion or a propagated decision */
1418 for (i = 0; i < solv->decisionq.count; i++)
1420 v = solv->decisionq.elements[i];
1421 solv->decisionmap[v > 0 ? v : -v] = 0;
1423 for (i = 0; i < solv->decisionq_why.count; i++)
1424 if (solv->decisionq_why.elements[i])
1428 v = solv->decisionq.elements[i];
1429 solv->decisionmap[v > 0 ? v : -v] = v > 0 ? 1 : -1;
1432 if (solv->pool->verbose > 1)
1433 printf("decisions done reduced from %d to %d\n", solv->decisionq.count, i);
1435 solv->decisionq_why.count = i;
1436 solv->decisionq.count = i;
1437 solv->recommends_index = -1;
1438 solv->propagate_index = 0;
1440 /* redo all job/system decisions */
1441 makeruledecisions(solv);
1442 if (solv->pool->verbose > 1)
1443 printf("decisions after adding job and system rules: %d\n", solv->decisionq.count);
1444 /* recreate watches */
1450 * analyze_unsolvable_rule
1454 analyze_unsolvable_rule(Solver *solv, Rule *r)
1457 Id why = r - solv->rules;
1458 if (solv->pool->verbose > 1)
1460 if (why >= solv->jobrules && why < solv->systemrules)
1462 if (why >= solv->systemrules && why < solv->weakrules)
1463 printf("SYSTEM %d ", why - solv->systemrules);
1464 if (why >= solv->weakrules && why < solv->learntrules)
1466 if (solv->learntrules && why >= solv->learntrules)
1470 if (solv->learntrules && why >= solv->learntrules)
1472 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1473 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i]);
1476 /* do not add rpm rules to problem */
1477 if (why < solv->jobrules)
1479 /* turn rule into problem */
1480 if (why >= solv->jobrules && why < solv->systemrules)
1481 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1482 /* return if problem already countains our rule */
1483 if (solv->problems.count)
1485 for (i = solv->problems.count - 1; i >= 0; i--)
1486 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1488 else if (solv->problems.elements[i] == why)
1491 queue_push(&solv->problems, why);
1496 * analyze_unsolvable
1498 * return: 1 - disabled some rules, try again
1503 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1505 Pool *pool = solv->pool;
1507 Map seen; /* global to speed things up? */
1510 Id *decisionmap = solv->decisionmap;
1511 int oldproblemcount;
1514 if (pool->verbose > 1)
1515 printf("ANALYZE UNSOLVABLE ----------------------\n");
1516 oldproblemcount = solv->problems.count;
1518 /* make room for conflicting rule */
1519 queue_push(&solv->problems, 0);
1520 queue_push(&solv->problems, 0);
1523 map_init(&seen, pool->nsolvables);
1524 analyze_unsolvable_rule(solv, r);
1525 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1536 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1538 vv = v > 0 ? v : -v;
1539 l = solv->decisionmap[vv];
1544 idx = solv->decisionq.count;
1547 v = solv->decisionq.elements[--idx];
1548 vv = v > 0 ? v : -v;
1549 if (!MAPTST(&seen, vv))
1551 why = solv->decisionq_why.elements[idx];
1554 if (pool->verbose > 3)
1557 printruleelement(solv, 0, v);
1561 r = solv->rules + why;
1562 analyze_unsolvable_rule(solv, r);
1563 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1574 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1576 vv = v > 0 ? v : -v;
1577 l = solv->decisionmap[vv];
1584 queue_push(&solv->problems, 0); /* mark end of this problem */
1587 if (solv->weakrules != solv->learntrules)
1589 for (i = oldproblemcount + 2; i < solv->problems.count - 1; i++)
1591 why = solv->problems.elements[i];
1592 if (why < solv->weakrules || why >= solv->learntrules)
1594 if (!lastweak || lastweak < why)
1600 /* disable last weak rule */
1601 solv->problems.count = oldproblemcount;
1602 r = solv->rules + lastweak;
1603 printf("disabling weak ");
1610 /* patch conflicting rule data */
1611 if (cr - solv->rules >= solv->learntrules)
1613 /* we have to store the rule internals for learnt rules
1614 * as they get freed for every solver run */
1615 solv->problems.elements[oldproblemcount] = cr->p;
1616 solv->problems.elements[oldproblemcount + 1] = cr->d;
1619 solv->problems.elements[oldproblemcount + 1] = cr - solv->rules;
1623 for (i = oldproblemcount + 2; i < solv->problems.count - 1; i++)
1624 disableproblem(solv, solv->problems.elements[i]);
1629 printf("UNSOLVABLE\n");
1634 /*-----------------------------------------------------------------*/
1635 /* Decision revert */
1639 * revert decision at level
1643 revert(Solver *solv, int level)
1646 while (solv->decisionq.count)
1648 v = solv->decisionq.elements[solv->decisionq.count - 1];
1649 vv = v > 0 ? v : -v;
1650 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1652 if (solv->pool->verbose > 3)
1653 printf("reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1654 solv->decisionmap[vv] = 0;
1655 solv->decisionq.count--;
1656 solv->decisionq_why.count--;
1657 solv->propagate_index = solv->decisionq.count;
1659 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1661 solv->branches.count--;
1662 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1663 solv->branches.count--;
1665 solv->recommends_index = -1;
1670 * watch2onhighest - put watch2 on literal with highest level
1674 watch2onhighest(Solver *solv, Rule *r)
1680 return; /* binary rule, both watches are set */
1681 dp = solv->pool->whatprovidesdata + r->d;
1682 while ((v = *dp++) != 0)
1684 l = solv->decisionmap[v < 0 ? -v : v];
1699 * add free decision to decision q, increase level
1700 * propagate decision, return if no conflict.
1701 * in conflict case, analyze conflict rule, add resulting
1702 * rule to learnt rule set, make decision from learnt
1703 * rule (always unit) and re-propagate.
1707 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1717 solv->decisionmap[decision] = level;
1719 solv->decisionmap[-decision] = -level;
1720 queue_push(&solv->decisionq, decision);
1721 queue_push(&solv->decisionq_why, 0);
1725 r = propagate(solv, level);
1729 return analyze_unsolvable(solv, r, disablerules);
1730 printf("conflict with rule #%d\n", (int)(r - solv->rules));
1731 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1732 if (l >= level || l <= 0)
1734 printf("reverting decisions (level %d -> %d)\n", level, l);
1736 revert(solv, level);
1737 r = addrule(solv, p, d); /* p requires d */
1740 if (solv->learnt_why.count != (r - solv->rules) - solv->learntrules)
1742 printf("%d %d\n", solv->learnt_why.count, (int)(r - solv->rules) - solv->learntrules);
1745 queue_push(&solv->learnt_why, why);
1748 /* at least 2 literals, needs watches */
1749 watch2onhighest(solv, r);
1750 addwatches(solv, r);
1752 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1753 queue_push(&solv->decisionq, p);
1754 queue_push(&solv->decisionq_why, r - solv->rules);
1755 if (solv->pool->verbose > 1)
1757 printf("decision: ");
1758 printruleelement(solv, 0, p);
1759 printf("new rule: ");
1768 * install best package from the queue. We add an extra package, inst, if
1769 * provided. See comment in weak install section.
1772 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
1774 Pool *pool = solv->pool;
1778 if (dq->count > 1 || inst)
1779 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
1784 /* choose the supplemented one */
1785 for (i = 0; i < dq->count; i++)
1786 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1790 for (i = 1; i < dq->count; i++)
1791 queue_push(&solv->branches, dq->elements[i]);
1792 queue_push(&solv->branches, -level);
1796 p = dq->elements[i];
1798 if (pool->verbose > 3)
1800 Solvable *s = pool->solvables + p;
1801 printf("installing %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1804 return setpropagatelearn(solv, level, p, disablerules);
1808 /*-----------------------------------------------------------------*/
1809 /* Main solver interface */
1814 * create solver structure
1816 * pool: all available solvables
1817 * installed: installed Solvables
1820 * Upon solving, rules are created to flag the Solvables
1821 * of the 'installed' Repo as installed.
1825 solver_create(Pool *pool, Repo *installed)
1828 solv = (Solver *)xcalloc(1, sizeof(Solver));
1830 solv->installed = installed;
1832 queue_init(&solv->ruletojob);
1833 queue_init(&solv->decisionq);
1834 queue_init(&solv->decisionq_why);
1835 queue_init(&solv->problems);
1836 queue_init(&solv->suggestions);
1837 queue_init(&solv->learnt_why);
1838 queue_init(&solv->learnt_pool);
1839 queue_init(&solv->branches);
1841 map_init(&solv->recommendsmap, pool->nsolvables);
1842 map_init(&solv->suggestsmap, pool->nsolvables);
1843 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
1844 solv->recommends_index = 0;
1846 solv->decisionmap = (Id *)xcalloc(pool->nsolvables, sizeof(Id));
1847 solv->rules = (Rule *)xmalloc((solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
1848 memset(solv->rules, 0, sizeof(Rule));
1860 solver_free(Solver *solv)
1862 queue_free(&solv->ruletojob);
1863 queue_free(&solv->decisionq);
1864 queue_free(&solv->decisionq_why);
1865 queue_free(&solv->learnt_why);
1866 queue_free(&solv->learnt_pool);
1867 queue_free(&solv->problems);
1868 queue_free(&solv->suggestions);
1869 queue_free(&solv->branches);
1871 map_free(&solv->recommendsmap);
1872 map_free(&solv->suggestsmap);
1873 map_free(&solv->noupdate);
1874 xfree(solv->decisionmap);
1876 xfree(solv->watches);
1877 xfree(solv->weaksystemrules);
1878 xfree(solv->obsoletes);
1879 xfree(solv->obsoletes_data);
1884 /*-------------------------------------------------------*/
1889 * all rules have been set up, now actually run the solver
1894 run_solver(Solver *solv, int disablerules, int doweak)
1902 Pool *pool = solv->pool;
1905 if (pool->verbose > 3)
1907 printf("number of rules: %d\n", solv->nrules);
1908 for (i = 0; i < solv->nrules; i++)
1909 printrule(solv, solv->rules + i);
1912 /* all new rules are learnt after this point */
1913 solv->learntrules = solv->nrules;
1914 /* crate watches lists */
1917 if (pool->verbose) printf("initial decisions: %d\n", solv->decisionq.count);
1919 /* start SAT algorithm */
1921 systemlevel = level + 1;
1922 if (pool->verbose) printf("solving...\n");
1933 if (pool->verbose) printf("propagating (%d %d)...\n", solv->propagate_index, solv->decisionq.count);
1934 if ((r = propagate(solv, level)) != 0)
1936 if (analyze_unsolvable(solv, r, disablerules))
1944 * installed packages
1947 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
1949 if (!solv->updatesystem)
1951 /* try to keep as many packages as possible */
1952 if (pool->verbose) printf("installing system packages\n");
1953 for (i = solv->installed->start, n = 0; ; i++)
1955 if (n == solv->installed->nsolvables)
1957 if (i == solv->installed->end)
1958 i = solv->installed->start;
1959 s = pool->solvables + i;
1960 if (s->repo != solv->installed)
1963 if (solv->decisionmap[i] != 0)
1965 if (pool->verbose > 3)
1966 printf("keeping %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1968 level = setpropagatelearn(solv, level, i, disablerules);
1974 if (level <= olevel)
1978 if (solv->weaksystemrules)
1980 if (pool->verbose) printf("installing weak system packages\n");
1981 for (i = solv->installed->start; i < solv->installed->end; i++)
1983 if (pool->solvables[i].repo != solv->installed)
1985 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
1987 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
1988 if (MAPTST(&solv->noupdate, i - solv->installed->start))
1991 if (solv->weaksystemrules[i - solv->installed->start])
1993 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
1994 while ((p = *dp++) != 0)
1996 if (solv->decisionmap[p] > 0)
1998 if (solv->decisionmap[p] == 0)
2002 continue; /* update package already installed */
2004 if (!dq.count && solv->decisionmap[i] != 0)
2007 /* FIXME: i is handled a bit different because we do not want
2008 * to have it pruned just because it is not recommened.
2009 * we should not prune installed packages instead */
2010 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2016 if (level <= olevel)
2019 if (i < solv->installed->end)
2022 systemlevel = level;
2029 if (pool->verbose) printf("deciding unresolved rules\n");
2030 for (i = 1, n = 1; ; i++, n++)
2032 if (n == solv->nrules)
2034 if (i == solv->nrules)
2036 r = solv->rules + i;
2042 /* binary or unary rule */
2043 /* need two positive undecided literals */
2044 if (r->p < 0 || r->w2 <= 0)
2046 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2048 queue_push(&dq, r->p);
2049 queue_push(&dq, r->w2);
2054 * all negative literals are installed
2055 * no positive literal is installed
2056 * i.e. the rule is not fulfilled and we
2057 * just need to decide on the positive literals
2061 if (solv->decisionmap[-r->p] <= 0)
2066 if (solv->decisionmap[r->p] > 0)
2068 if (solv->decisionmap[r->p] == 0)
2069 queue_push(&dq, r->p);
2071 dp = pool->whatprovidesdata + r->d;
2072 while ((p = *dp++) != 0)
2076 if (solv->decisionmap[-p] <= 0)
2081 if (solv->decisionmap[p] > 0)
2083 if (solv->decisionmap[p] == 0)
2092 /* cannot happen as this means that
2093 * the rule is unit */
2097 if (pool->verbose > 2)
2101 level = selectandinstall(solv, level, &dq, 0, disablerules);
2107 if (level < systemlevel)
2110 } /* for(), decide */
2112 if (n != solv->nrules) /* continue if level < systemlevel */
2115 if (doweak && !solv->problems.count)
2119 if (pool->verbose) printf("installing recommended packages\n");
2121 for (i = 1; i < pool->nsolvables; i++)
2123 if (solv->decisionmap[i] < 0)
2125 if (solv->decisionmap[i] > 0)
2127 Id *recp, rec, *pp, p;
2128 s = pool->solvables + i;
2129 /* installed, check for recommends */
2130 /* XXX need to special case AND ? */
2133 recp = s->repo->idarraydata + s->recommends;
2134 while ((rec = *recp++) != 0)
2137 FOR_PROVIDES(p, pp, rec)
2139 if (solv->decisionmap[p] > 0)
2144 else if (solv->decisionmap[p] == 0)
2146 queue_pushunique(&dq, p);
2154 s = pool->solvables + i;
2155 if (!s->supplements && !s->freshens)
2157 if (!pool_installable(pool, s))
2159 if (solver_is_supplementing(solv, s))
2160 queue_pushunique(&dq, i);
2166 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2168 s = pool->solvables + p;
2169 if (pool->verbose > 0)
2170 printf("installing recommended %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2171 level = setpropagatelearn(solv, level, p, 0);
2176 if (solv->solution_callback)
2178 solv->solution_callback(solv, solv->solution_callback_data);
2179 if (solv->branches.count)
2181 int i = solv->branches.count - 1;
2182 int l = -solv->branches.elements[i];
2184 if (solv->branches.elements[i - 1] < 0)
2186 p = solv->branches.elements[i];
2187 if (pool->verbose > 0)
2189 s = pool->solvables + p;
2190 printf("branching with %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2193 for (j = i + 1; j < solv->branches.count; j++)
2194 queue_push(&dq, solv->branches.elements[j]);
2195 solv->branches.count = i;
2197 revert(solv, level);
2199 for (j = 0; j < dq.count; j++)
2200 queue_push(&solv->branches, dq.elements[j]);
2202 level = setpropagatelearn(solv, level, p, disablerules);
2210 /* all branches done, we're finally finished */
2214 /* minimization step */
2215 if (solv->branches.count)
2217 int l = 0, lasti = -1, lastl = -1;
2219 for (i = solv->branches.count - 1; i >= 0; i--)
2221 p = solv->branches.elements[i];
2224 else if (p > 0 && solv->decisionmap[p] > l + 1)
2232 /* kill old solvable so that we do not loop */
2233 p = solv->branches.elements[lasti];
2234 solv->branches.elements[lasti] = 0;
2235 s = pool->solvables + p;
2236 if (pool->verbose > 0)
2237 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));
2240 revert(solv, level);
2242 level = setpropagatelearn(solv, level, p, disablerules);
2259 * at this point, all rules that led to conflicts are disabled.
2260 * we re-enable all rules of a problem set but rule "sug", then
2261 * continue to disable more rules until there as again a solution.
2264 /* FIXME: think about conflicting assertions */
2267 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2269 Pool *pool = solv->pool;
2278 printf("refine_suggestion start\n");
2279 for (i = 0; problem[i]; i++)
2281 if (problem[i] == sug)
2283 printproblem(solv, problem[i]);
2286 queue_init(&disabled);
2287 queue_empty(refined);
2288 queue_push(refined, sug);
2290 /* re-enable all problem rules with the exception of "sug" */
2294 for (i = 0; problem[i]; i++)
2295 if (problem[i] != sug)
2296 enableproblem(solv, problem[i]);
2299 disableupdaterules(solv, job, -(sug + 1));
2303 /* re-enable as many weak rules as possible */
2304 for (i = solv->weakrules; i < solv->learntrules; i++)
2306 r = solv->rules + i;
2308 enablerule(solv, r);
2311 queue_empty(&solv->problems);
2312 revert(solv, 1); /* XXX move to reset_solver? */
2314 run_solver(solv, 0, 0);
2315 if (!solv->problems.count)
2318 printf("no more problems!\n");
2319 if (pool->verbose > 3)
2320 printdecisions(solv);
2321 break; /* great, no more problems */
2323 disabledcnt = disabled.count;
2324 /* skip over problem rule */
2325 for (i = 2; i < solv->problems.count - 1; i++)
2327 /* ignore solutions in refined */
2328 v = solv->problems.elements[i];
2329 for (j = 0; problem[j]; j++)
2330 if (problem[j] != sug && problem[j] == v)
2334 queue_push(&disabled, v);
2336 if (disabled.count == disabledcnt)
2338 /* no solution found, this was an invalid suggestion! */
2340 printf("no solution found!\n");
2344 if (disabled.count == disabledcnt + 1)
2346 /* just one suggestion, add it to refined list */
2347 v = disabled.elements[disabledcnt];
2348 queue_push(refined, v);
2349 disableproblem(solv, v);
2351 disableupdaterules(solv, job, -(v + 1));
2355 /* more than one solution, disable all */
2356 /* do not push anything on refine list */
2357 if (pool->verbose > 1)
2359 printf("more than one solution found:\n");
2360 for (i = disabledcnt; i < disabled.count; i++)
2361 printproblem(solv, disabled.elements[i]);
2363 for (i = disabledcnt; i < disabled.count; i++)
2364 disableproblem(solv, disabled.elements[i]);
2367 /* all done, get us back into the same state as before */
2368 /* enable refined rules again */
2369 for (i = 0; i < disabled.count; i++)
2370 enableproblem(solv, disabled.elements[i]);
2371 /* disable problem rules again */
2372 for (i = 0; problem[i]; i++)
2373 disableproblem(solv, problem[i]);
2375 printf("refine_suggestion end\n");
2379 problems_to_solutions(Solver *solv, Queue *job)
2381 Pool *pool = solv->pool;
2389 if (!solv->problems.count)
2391 queue_clone(&problems, &solv->problems);
2392 queue_init(&solution);
2393 queue_init(&solutions);
2394 /* copy over problem rule */
2395 queue_push(&solutions, problems.elements[0]);
2396 queue_push(&solutions, problems.elements[1]);
2397 problem = problems.elements + 2;
2398 for (i = 2; i < problems.count; i++)
2400 Id v = problems.elements[i];
2403 /* mark end of this problem */
2404 queue_push(&solutions, 0);
2405 queue_push(&solutions, 0);
2406 if (i + 1 == problems.count)
2408 /* copy over problem rule of next problem */
2409 queue_push(&solutions, problems.elements[i + 1]);
2410 queue_push(&solutions, problems.elements[i + 2]);
2412 problem = problems.elements + i + 1;
2415 refine_suggestion(solv, job, problem, v, &solution);
2416 if (!solution.count)
2417 continue; /* this solution didn't work out */
2419 for (j = 0; j < solution.count; j++)
2421 why = solution.elements[j];
2423 printproblem(solv, why);
2427 queue_push(&solutions, 0);
2428 queue_push(&solutions, -why);
2430 else if (why >= solv->systemrules && why < solv->weakrules)
2433 p = solv->installed->start + (why - solv->systemrules);
2434 if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
2436 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
2439 if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
2441 if (solv->decisionmap[*dp] > 0)
2448 queue_push(&solutions, p);
2449 queue_push(&solutions, rp);
2454 /* mark end of this solution */
2455 queue_push(&solutions, 0);
2456 queue_push(&solutions, 0);
2458 queue_free(&solution);
2459 queue_free(&problems);
2460 /* copy queue over to solutions */
2461 queue_free(&solv->problems);
2462 queue_clone(&solv->problems, &solutions);
2463 queue_free(&solutions);
2473 id2rc(Solver *solv, Id id)
2476 if (solv->rc_output != 2)
2478 evr = id2str(solv->pool, id);
2479 if (*evr < '0' || *evr > '9')
2481 while (*evr >= '0' && *evr <= '9')
2489 printdecisions(Solver *solv)
2491 Pool *pool = solv->pool;
2492 Repo *installed = solv->installed;
2493 Id p, *obsoletesmap;
2497 obsoletesmap = (Id *)xcalloc(pool->nsolvables, sizeof(Id));
2500 for (i = 0; i < solv->decisionq.count; i++)
2504 n = solv->decisionq.elements[i];
2507 if (n == SYSTEMSOLVABLE)
2509 s = pool->solvables + n;
2510 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2512 FOR_PROVIDES(p, pp, s->name)
2513 if (s->name == pool->solvables[p].name)
2515 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2517 obsoletesmap[p] = n;
2522 for (i = 0; i < solv->decisionq.count; i++)
2527 n = solv->decisionq.elements[i];
2530 if (n == SYSTEMSOLVABLE)
2532 s = pool->solvables + n;
2533 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2537 obsp = s->repo->idarraydata + s->obsoletes;
2538 while ((obs = *obsp++) != 0)
2539 FOR_PROVIDES(p, pp, obs)
2541 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2543 obsoletesmap[p] = n;
2550 if (solv->rc_output)
2551 printf(">!> Solution #1:\n");
2553 int installs = 0, uninstalls = 0, upgrades = 0;
2555 /* print solvables to be erased */
2559 for (i = installed->start; i < installed->end; i++)
2561 s = pool->solvables + i;
2562 if (s->repo != installed)
2564 if (solv->decisionmap[i] > 0)
2566 if (obsoletesmap[i])
2568 if (solv->rc_output == 2)
2569 printf(">!> remove %s-%s%s\n", id2str(pool, s->name), id2rc(solv, s->evr), id2str(pool, s->evr));
2570 else if (solv->rc_output)
2571 printf(">!> remove %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2573 printf("erase %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2578 /* print solvables to be installed */
2580 for (i = 0; i < solv->decisionq.count; i++)
2583 p = solv->decisionq.elements[i];
2586 if (p == SYSTEMSOLVABLE)
2588 s = pool->solvables + p;
2589 if (installed && s->repo == installed)
2592 if (!obsoletesmap[p])
2594 if (solv->rc_output)
2596 printf("install %s-%s%s", id2str(pool, s->name), id2rc(solv, s->evr), id2str(pool, s->evr));
2597 if (solv->rc_output != 2)
2598 printf(".%s", id2str(pool, s->arch));
2601 else if (!solv->rc_output)
2603 printf("update %s-%s.%s (obsoletes", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2604 for (j = installed->start; j < installed->end; j++)
2606 if (obsoletesmap[j] != p)
2608 s = pool->solvables + j;
2609 printf(" %s-%s.%s", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2616 Solvable *f, *fn = 0;
2617 for (j = installed->start; j < installed->end; j++)
2619 if (obsoletesmap[j] != p)
2621 f = pool->solvables + j;
2622 if (fn || f->name != s->name)
2624 if (solv->rc_output == 2)
2625 printf(">!> remove %s-%s%s\n", id2str(pool, f->name), id2rc(solv, f->evr), id2str(pool, f->evr));
2626 else if (solv->rc_output)
2627 printf(">!> remove %s-%s.%s\n", id2str(pool, f->name), id2str(pool, f->evr), id2str(pool, f->arch));
2635 printf(">!> install %s-%s%s", id2str(pool, s->name), id2rc(solv, s->evr), id2str(pool, s->evr));
2636 if (solv->rc_output != 2)
2637 printf(".%s", id2str(pool, s->arch));
2642 if (solv->rc_output == 2)
2643 printf(">!> upgrade %s-%s => %s-%s%s", id2str(pool, fn->name), id2str(pool, fn->evr), id2str(pool, s->name), id2rc(solv, s->evr), id2str(pool, s->evr));
2645 printf(">!> upgrade %s-%s.%s => %s-%s.%s", id2str(pool, fn->name), id2str(pool, fn->evr), id2str(pool, fn->arch), id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2649 if (solv->rc_output)
2651 Repo *repo = s->repo;
2652 if (repo && strcmp(repo_name(repo), "locales"))
2653 printf("[%s]", repo_name(repo));
2658 if (solv->rc_output)
2659 printf(">!> installs=%d, upgrades=%d, uninstalls=%d\n", installs, upgrades, uninstalls);
2661 xfree(obsoletesmap);
2663 if (solv->suggestions.count)
2665 printf("\nsuggested packages:\n");
2666 for (i = 0; i < solv->suggestions.count; i++)
2668 s = pool->solvables + solv->suggestions.elements[i];
2669 printf("- %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2675 printconflicts(Solver *solv, Solvable *s, Id pc)
2677 Pool *pool = solv->pool;
2678 Solvable *sc = pool->solvables + pc;
2679 Id p, *pp, con, *conp, obs, *obsp;
2684 conp = s->repo->idarraydata + s->conflicts;
2685 while ((con = *conp++) != 0)
2687 FOR_PROVIDES(p, pp, con)
2691 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));
2696 if (s->obsoletes && (!solv->installed || s->repo != solv->installed))
2698 obsp = s->repo->idarraydata + s->obsoletes;
2699 while ((obs = *obsp++) != 0)
2701 FOR_PROVIDES(p, pp, obs)
2705 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));
2714 printprobleminfo(Solver *solv, Id p, Id d, Queue *job, Id firstp, Id firstrp)
2716 Pool *pool = solv->pool;
2723 /* learnt rule, ignore for now */
2724 printf("some learnt rule...\n");
2729 /* conflict with system solvable, i.e. could not create rule */
2732 printf("got firstp\n");
2735 what = job->elements[firstrp];
2736 switch (job->elements[firstrp - 1])
2738 case SOLVER_INSTALL_SOLVABLE_NAME:
2739 printf("no solvable exists with name %s\n", dep2str(pool, what));
2741 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
2742 printf("no solvable provides %s\n", dep2str(pool, what));
2745 printf("unknown job\n");
2754 /* conflict with rpm rule, package -d is not installable */
2755 s = pool->solvables + (-d);
2758 reqp = s->repo->idarraydata + s->requires;
2759 while ((req = *reqp++) != 0)
2761 if (req == SOLVABLE_PREREQMARKER)
2763 dp = GET_PROVIDESP(req, p);
2766 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));
2771 printf("package %s-%s.%s is not installable\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2774 if (d >= solv->jobrules)
2776 r = solv->rules + d;
2782 sp = pool->solvables + (-p);
2783 sd = pool->solvables + (-d);
2784 printf("package %s-%s.%s cannot be installed with package %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));
2787 printf("some job rule...\n");
2791 r = solv->rules + d;
2796 if (d == 0 && r->w2 < 0)
2800 sp = pool->solvables + (-p);
2801 sd = pool->solvables + (-d);
2802 if (sp->name == sd->name)
2804 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));
2808 printconflicts(solv, pool->solvables + (-p), -d);
2809 printconflicts(solv, pool->solvables + (-d), -p);
2814 /* find requires of p that corresponds with our rule */
2816 s = pool->solvables + (-p);
2817 reqp = s->repo->idarraydata + s->requires;
2818 while ((req = *reqp++) != 0)
2820 if (req == SOLVABLE_PREREQMARKER)
2822 dp = GET_PROVIDESP(req, p);
2825 if (*dp == r->w2 && dp[1] == 0)
2828 else if (dp - pool->whatprovidesdata == d)
2833 printf("req not found\n");
2836 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));
2841 printsolutions(Solver *solv, Queue *job)
2843 Pool *pool = solv->pool;
2849 printf("Encountered problems! Here are the solutions:\n\n");
2851 for (i = 0; i < solv->problems.count; )
2853 printf("Problem %d:\n", pcnt++);
2854 printf("====================================\n");
2855 p = solv->problems.elements[i++];
2856 d = solv->problems.elements[i++];
2857 printprobleminfo(solv, p, d, job, solv->problems.elements[i], solv->problems.elements[i + 1]);
2861 if (solv->problems.elements[i] == 0 && solv->problems.elements[i + 1] == 0)
2863 /* end of solutions for this problems reached */
2869 p = solv->problems.elements[i];
2870 rp = solv->problems.elements[i + 1];
2872 if (p == 0 && rp == 0)
2874 /* end of this solution reached */
2880 /* job, p is index into job queue */
2881 what = job->elements[rp];
2882 switch (job->elements[rp - 1])
2884 case SOLVER_INSTALL_SOLVABLE:
2885 s = pool->solvables + what;
2886 if (solv->installed && s->repo == solv->installed)
2887 printf("- do not keep %s-%s.%s installed\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2889 printf("- do not install %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2891 case SOLVER_ERASE_SOLVABLE:
2892 s = pool->solvables + what;
2893 if (solv->installed && s->repo == solv->installed)
2894 printf("- do not deinstall %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2896 printf("- do not forbid installation of %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2898 case SOLVER_INSTALL_SOLVABLE_NAME:
2899 printf("- do not install %s\n", id2str(pool, what));
2901 case SOLVER_ERASE_SOLVABLE_NAME:
2902 printf("- do not deinstall %s\n", id2str(pool, what));
2904 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
2905 printf("- do not install a solvable providing %s\n", dep2str(pool, what));
2907 case SOLVER_ERASE_SOLVABLE_PROVIDES:
2908 printf("- do not deinstall all solvables providing %s\n", dep2str(pool, what));
2910 case SOLVER_INSTALL_SOLVABLE_UPDATE:
2911 s = pool->solvables + what;
2912 printf("- do not install most recent version of %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool
2916 printf("- do something different\n");
2922 /* policy, replace p with rp */
2923 s = pool->solvables + p;
2924 sd = rp ? pool->solvables + rp : 0;
2928 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr) > 0)
2930 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));
2933 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(pool, s, sd))
2935 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));
2938 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(pool, s, sd))
2941 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));
2943 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));
2947 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));
2951 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));
2961 /* for each installed solvable find which packages with *different* names
2962 * obsolete the solvable.
2963 * this index is used in policy_findupdatepackages if noupdateprovide is set.
2967 create_obsolete_index(Solver *solv)
2969 Pool *pool = solv->pool;
2971 Repo *installed = solv->installed;
2972 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
2975 if (!installed || !installed->nsolvables)
2977 /* create reverse obsoletes map for installed solvables */
2978 solv->obsoletes = obsoletes = xcalloc(installed->end - installed->start, sizeof(Id));
2979 for (i = 1; i < pool->nsolvables; i++)
2981 s = pool->solvables + i;
2982 if (s->repo == installed)
2986 if (!pool_installable(pool, s))
2988 obsp = s->repo->idarraydata + s->obsoletes;
2989 while ((obs = *obsp++) != 0)
2990 FOR_PROVIDES(p, pp, obs)
2992 if (pool->solvables[p].repo != installed)
2994 if (pool->solvables[p].name == s->name)
2996 obsoletes[p - installed->start]++;
3000 for (i = 0; i < installed->nsolvables; i++)
3003 n += obsoletes[i] + 1;
3006 solv->obsoletes_data = obsoletes_data = xcalloc(n + 1, sizeof(Id));
3007 if (pool->verbose) printf("obsoletes data: %d entries\n", n + 1);
3008 for (i = pool->nsolvables - 1; i > 0; i--)
3010 s = pool->solvables + i;
3013 if (!pool_installable(pool, s))
3015 obsp = s->repo->idarraydata + s->obsoletes;
3016 while ((obs = *obsp++) != 0)
3017 FOR_PROVIDES(p, pp, obs)
3019 if (pool->solvables[p].repo != installed)
3021 if (pool->solvables[p].name == s->name)
3023 p -= installed->start;
3024 if (obsoletes_data[obsoletes[p]] != i)
3025 obsoletes_data[--obsoletes[p]] = i;
3031 /*-----------------------------------------------------------------*/
3041 solve(Solver *solv, Queue *job)
3043 Pool *pool = solv->pool;
3044 Repo *installed = solv->installed;
3046 Map addedmap; /* '1' == have rule for solvable */
3047 Id how, what, p, *pp, d;
3051 /* create obsolete index if needed */
3052 if (solv->noupdateprovide)
3053 create_obsolete_index(solv);
3056 * create basic rule set of all involved packages
3057 * use addedmap bitmap to make sure we don't create rules twice
3061 map_init(&addedmap, pool->nsolvables);
3065 * always install our system solvable
3067 MAPSET(&addedmap, SYSTEMSOLVABLE);
3068 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3069 queue_push(&solv->decisionq_why, 0);
3070 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3073 * create rules for all package that could be involved with the solving
3074 * so called: rpm rules
3079 if (pool->verbose > 3)
3080 printf ("*** create rules for installed solvables ***\n");
3081 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3082 if (s->repo == installed)
3083 addrpmrulesforsolvable(solv, s, &addedmap);
3084 if (pool->verbose > 3)
3085 printf ("*** create rules for updaters of installed solvables ***\n");
3086 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3087 if (s->repo == installed)
3088 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3091 if (solv->pool->verbose > 3)
3092 printf ("*** create rpm rules for packages involved with a job ***\n");
3093 for (i = 0; i < job->count; i += 2)
3095 how = job->elements[i];
3096 what = job->elements[i + 1];
3100 case SOLVER_INSTALL_SOLVABLE:
3101 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3103 case SOLVER_INSTALL_SOLVABLE_NAME:
3104 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3105 FOR_PROVIDES(p, pp, what)
3107 /* if by name, ensure that the name matches */
3108 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3110 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3113 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3114 /* dont allow downgrade */
3115 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3120 if (solv->pool->verbose > 3)
3121 printf ("*** create rpm rules for recommended/suggested packages ***\n");
3122 if (solv->pool->verbose > 3)
3123 printf ("*** Add rules for week dependencies ***\n");
3126 addrpmrulesforweak(solv, &addedmap);
3131 int possible = 0, installable = 0;
3132 for (i = 1; i < pool->nsolvables; i++)
3134 if (pool_installable(pool, pool->solvables + i))
3136 if (MAPTST(&addedmap, i))
3139 printf("%d of %d installable solvables considered for solving\n", possible, installable);
3144 * first pass done, we now have all the rpm rules we need.
3145 * unify existing rules before going over all job rules and
3147 * at this point the system is always solvable,
3148 * as an empty system (remove all packages) is a valid solution
3151 unifyrules(solv); /* remove duplicate rpm rules */
3153 if (pool->verbose) printf("Decisions based on %d rpm rules.\n", solv->decisionq.count);
3156 * now add all job rules
3159 if (solv->pool->verbose > 3)
3160 printf ("*** Add JOB rules ***\n");
3162 solv->jobrules = solv->nrules;
3164 for (i = 0; i < job->count; i += 2)
3166 how = job->elements[i];
3167 what = job->elements[i + 1];
3170 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3171 s = pool->solvables + what;
3172 if (solv->rc_output)
3174 printf(">!> Installing %s from channel %s\n", id2str(pool, s->name), repo_name(s->repo));
3177 printf("job: install solvable %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
3178 addrule(solv, what, 0); /* install by Id */
3179 queue_push(&solv->ruletojob, i);
3181 case SOLVER_ERASE_SOLVABLE:
3182 s = pool->solvables + what;
3184 printf("job: erase solvable %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
3185 addrule(solv, -what, 0); /* remove by Id */
3186 queue_push(&solv->ruletojob, i);
3188 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3189 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3190 if (pool->verbose && how == SOLVER_INSTALL_SOLVABLE_NAME)
3191 printf("job: install name %s\n", id2str(pool, what));
3192 if (pool->verbose && how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3193 printf("job: install provides %s\n", dep2str(pool, what));
3195 FOR_PROVIDES(p, pp, what)
3197 /* if by name, ensure that the name matches */
3198 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3204 /* no provider, make this an impossible rule */
3205 queue_push(&q, -SYSTEMSOLVABLE);
3208 p = queue_shift(&q); /* get first provider */
3210 d = 0; /* single provider ? -> make assertion */
3212 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3213 addrule(solv, p, d); /* add 'requires' rule */
3214 queue_push(&solv->ruletojob, i);
3216 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3217 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3218 if (pool->verbose && how == SOLVER_ERASE_SOLVABLE_NAME)
3219 printf("job: erase name %s\n", id2str(pool, what));
3220 if (pool->verbose && how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3221 printf("job: erase provides %s\n", dep2str(pool, what));
3222 FOR_PROVIDES(p, pp, what)
3224 /* if by name, ensure that the name matches */
3225 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
3227 addrule(solv, -p, 0); /* add 'remove' rule */
3228 queue_push(&solv->ruletojob, i);
3231 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3232 s = pool->solvables + what;
3234 printf("job: update %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
3235 addupdaterule(solv, s, 0);
3236 queue_push(&solv->ruletojob, i);
3241 if (solv->ruletojob.count != solv->nrules - solv->jobrules)
3245 * now add system rules
3249 if (solv->pool->verbose > 3)
3250 printf ("*** Add system rules ***\n");
3253 solv->systemrules = solv->nrules;
3256 * create rules for updating installed solvables
3260 if (installed && !solv->allowuninstall)
3261 { /* loop over all installed solvables */
3262 /* we create all update rules, but disable some later on depending on the job */
3263 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3264 if (s->repo == installed)
3265 addupdaterule(solv, s, 0);
3267 addupdaterule(solv, 0, 0); /* create dummy rule */
3268 /* consistency check: we added a rule for _every_ system solvable */
3269 if (solv->nrules - solv->systemrules != installed->end - installed->start)
3273 /* create special weak system rules */
3274 /* those are used later on to keep a version of the installed packages in
3276 if (installed && installed->nsolvables)
3278 solv->weaksystemrules = xcalloc(installed->end - installed->start, sizeof(Id));
3279 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3280 if (s->repo == installed)
3282 policy_findupdatepackages(solv, s, &q, 1);
3284 solv->weaksystemrules[i - installed->start] = pool_queuetowhatprovides(pool, &q);
3288 /* free unneeded memory */
3289 map_free(&addedmap);
3292 solv->weakrules = solv->nrules;
3294 /* try real hard to keep packages installed */
3297 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3298 if (s->repo == installed)
3300 /* FIXME: can't work with refine_suggestion! */
3301 /* need to always add the rule but disable it */
3302 if (MAPTST(&solv->noupdate, i - installed->start))
3304 d = solv->weaksystemrules[i - installed->start];
3305 addrule(solv, i, d);
3314 disableupdaterules(solv, job, -1);
3315 makeruledecisions(solv);
3317 if (pool->verbose) printf("problems so far: %d\n", solv->problems.count);
3319 run_solver(solv, 1, 1);
3321 /* find suggested packages */
3322 if (!solv->problems.count)
3324 Id sug, *sugp, p, *pp;
3326 /* create map of all suggests that are still open */
3327 solv->recommends_index = -1;
3328 MAPZERO(&solv->suggestsmap);
3329 for (i = 0; i < solv->decisionq.count; i++)
3331 p = solv->decisionq.elements[i];
3334 s = pool->solvables + p;
3337 sugp = s->repo->idarraydata + s->suggests;
3338 while ((sug = *sugp++) != 0)
3340 FOR_PROVIDES(p, pp, sug)
3341 if (solv->decisionmap[p] > 0)
3344 continue; /* already fulfilled */
3345 FOR_PROVIDES(p, pp, sug)
3346 MAPSET(&solv->suggestsmap, p);
3350 for (i = 1; i < pool->nsolvables; i++)
3352 if (solv->decisionmap[i] != 0)
3354 s = pool->solvables + i;
3355 if (!MAPTST(&solv->suggestsmap, i))
3359 if (!pool_installable(pool, s))
3361 if (!solver_is_enhancing(solv, s))
3364 queue_push(&solv->suggestions, i);
3366 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
3369 if (solv->problems.count)
3370 problems_to_solutions(solv, job);