4 * SAT based dependency solver
18 #define RULES_BLOCK 63
20 static Pool *prune_best_version_arch_sortcmp_data;
22 /*-----------------------------------------------------------------*/
25 * prep for prune_best_version_arch
30 prune_best_version_arch_sortcmp(const void *ap, const void *bp)
32 Pool *pool = prune_best_version_arch_sortcmp_data;
35 return pool->solvables[a].name - pool->solvables[b].name;
41 replaces_system(Solver *solv, Id id)
43 Pool *pool = solv->pool;
44 Source *system = solv->system;
45 Id *name = pool->solvables[id].name;
47 FOR_PROVIDES(p, pp, id)
49 s = pool->solvables + p;
52 if (p >= system->start && p < system->start + system->nsolvables)
59 dep_is_installed(Solver *solv, Id dep)
61 Pool *pool = solv->pool;
66 Reldep *rd = GETRELDEP(pool, dep);
67 if (rd->flags == REL_AND)
69 if (!dep_is_installed(solv, rd->name))
71 return dep_is_installed(solv, rd->evr);
74 FOR_PROVIDES(p, pp, dep)
76 if (solv->decisionmap[p] > 0)
83 * prune_to_recommended
87 prune_to_recommended(Solver *solv, Queue *plist)
89 Pool *pool = solv->pool;
94 for (i = j = 0; i < plist->count; i++)
96 s = pool->solvables + plist->elements[i];
97 if (!s->supplements && !s->freshens)
99 if ((supp = s->supplements) != 0)
101 while ((sup = *supp++) != 0)
102 if (dep_is_installed(solv, sup))
107 if ((supp = s->freshens) != 0)
109 while ((sup = *supp++) != 0)
110 if (dep_is_installed(solv, sup))
115 plist->elements[j++] = s - pool->solvables;
122 * prune_best_version_arch
124 * sort list of packages (given through plist) by name and evr
125 * return result through plist
129 /* FIXME: must also look at update packages */
132 prune_best_version_arch(Pool *pool, Queue *plist)
139 if (plist->count < 2) /* no need to prune for a single entry */
141 if (pool->verbose) printf("prune_best_version_arch %d\n", plist->count);
143 /* prune to best architecture */
147 for (i = 0; i < plist->count; i++)
149 s = pool->solvables + plist->elements[i];
151 if (a > pool->lastarch)
153 a = pool->id2arch[a];
154 if ((a & 0xffff0000) > bestscore)
155 bestscore = a & 0xffff0000;
157 for (i = j = 0; i < plist->count; i++)
159 s = pool->solvables + plist->elements[i];
161 if (a > pool->lastarch)
163 a = pool->id2arch[a];
164 /* a == 1 -> noarch */
165 if (a != 1 && (a & 0xffff0000) != bestscore)
167 plist->elements[j++] = plist->elements[i];
174 prune_best_version_arch_sortcmp_data = pool;
175 /* sort by name first */
176 qsort(plist->elements, plist->count, sizeof(Id), prune_best_version_arch_sortcmp);
178 /* now find best 'per name' */
179 for (i = j = 0; i < plist->count; i++)
181 s = pool->solvables + plist->elements[i];
182 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
185 if (pool->verbose) printf("- %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
187 if (!best) /* if no best yet, the current is best */
189 best = plist->elements[i];
193 /* name switch: re-init */
194 if (pool->solvables[best].name != s->name) /* new name */
196 if (pool->verbose) printf("BEST: %s-%s.%s\n", id2str(pool, pool->solvables[best].name), id2str(pool, pool->solvables[best].evr), id2str(pool, pool->solvables[best].arch));
197 plist->elements[j++] = best; /* move old best to front */
198 best = plist->elements[i]; /* take current as new best */
202 if (pool->solvables[best].evr != s->evr) /* compare evr */
204 if (evrcmp(pool, pool->solvables[best].evr, s->evr) < 0)
205 best = plist->elements[i];
210 best = plist->elements[0];
212 /* XXX also check obsoletes! */
213 if (pool->verbose) printf("BEST: %s-%s.%s\n", id2str(pool, pool->solvables[best].name), id2str(pool, pool->solvables[best].evr), id2str(pool, pool->solvables[best].arch));
215 plist->elements[j++] = best;
220 /*-----------------------------------------------------------------*/
227 printruleelement(Solver *solv, Rule *r, Id v)
229 Pool *pool = solv->pool;
233 s = pool->solvables + -v;
234 printf(" !%s-%s.%s [%d]", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), -v);
238 s = pool->solvables + v;
239 printf(" %s-%s.%s [%d]", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), v);
248 if (solv->decisionmap[s - pool->solvables] > 0)
249 printf(" I.%d", solv->decisionmap[s - pool->solvables]);
250 if (solv->decisionmap[s - pool->solvables] < 0)
251 printf(" C.%d", -solv->decisionmap[s - pool->solvables]);
261 printrule(Solver *solv, Rule *r)
266 if (r >= solv->rules && r < solv->rules + solv->nrules) /* r is a solver rule */
267 printf("Rule #%d:\n", (int)(r - solv->rules));
269 printf("Rule:\n"); /* r is any rule */
274 else if (r->d == ID_NULL)
281 v = solv->pool->whatprovidesdata[r->d + i - 1];
284 printruleelement(solv, r, v);
286 printf(" next: %d %d\n", r->n1, r->n2);
290 /*-----------------------------------------------------------------*/
296 static Pool *unifyrules_sortcmp_data;
299 * compare rules for unification sort
303 unifyrules_sortcmp(const void *ap, const void *bp)
305 Pool *pool = unifyrules_sortcmp_data;
306 Rule *a = (Rule *)ap;
307 Rule *b = (Rule *)bp;
313 return x; /* p differs */
316 if (a->d == 0 && b->d == 0)
317 return a->w2 - b->w2; /* assertion: return w2 diff */
319 if (a->d == 0) /* a is assertion, b not */
321 x = a->w2 - pool->whatprovidesdata[b->d];
325 if (b->d == 0) /* b is assertion, a not */
327 x = pool->whatprovidesdata[a->d] - b->w2;
331 /* compare whatprovidesdata */
332 ad = pool->whatprovidesdata + a->d;
333 bd = pool->whatprovidesdata + b->d;
334 for (; *ad && *ad == *bd; ad++, bd++)
345 unifyrules(Solver *solv)
350 if (solv->nrules <= 1) /* nothing to unify */
353 /* sort rules first */
354 unifyrules_sortcmp_data = solv->pool;
355 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
362 for (i = j = 1, ir = solv->rules + 1; i < solv->nrules; i++, ir++)
364 if (jr && !unifyrules_sortcmp(ir, jr))
365 continue; /* prune! */
366 jr = solv->rules + j++; /* keep! */
371 /* reduced count from nrules to j rules */
372 if (solv->pool->verbose) printf("pruned rules from %d to %d\n", solv->nrules, j);
374 /* adapt rule buffer */
375 solv->rules = (Rule *)xrealloc(solv->rules, ((solv->nrules + RULES_BLOCK) & ~RULES_BLOCK) * sizeof(Rule));
384 for (i = 1; i < solv->nrules; i++)
387 if (r->d == 0) /* assertion */
392 dp = solv->pool->whatprovidesdata + r->d;
396 if (solv->pool->verbose)
398 printf(" binary: %d\n", binr);
399 printf(" normal: %d\n", solv->nrules - 1 - binr);
400 printf(" normal lits: %d\n", dc);
413 hashrule(Solver *solv, Id p, Id d, int n)
415 unsigned int x = (unsigned int)p;
419 return (x * 37) ^ (unsigned int)d;
420 dp = solv->pool->whatprovidesdata + d;
422 x = (x * 37) ^ (unsigned int)*dp++;
430 * p = direct literal; > 0 for learnt, < 0 for installed pkg (rpm)
431 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
434 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
436 * p < 0 : rule from rpm (installed pkg)
437 * d > 0 : Offset in whatprovidesdata (list of providers)
439 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
440 * d < 0: Id of solvable (e.g. B1)
442 * d == 0: unary rule, assertion => (A) or (-A)
444 * Install: p > 0, d = 0 (A) user requested install
445 * Remove: p < 0, d = 0 (-A) user requested remove
446 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
447 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
448 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider)
449 * ? p > 0, d < 0 (A|-B)
450 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
454 addrule(Solver *solv, Id p, Id d)
459 int n = 0; /* number of literals in rule - 1
460 0 = direct assertion (single literal)
464 /* it often happenes that requires lead to adding the same rpm rule
465 * multiple times, so we prune those duplicates right away to make
466 * the work for unifyrules a bit easier */
468 if (solv->nrules && !solv->jobrules)
470 r = solv->rules + solv->nrules - 1; /* get the last added rule */
471 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
478 return NULL; /* ignore self conflict */
481 else if (d == 0) /* user requested */
485 for (dp = solv->pool->whatprovidesdata + d; *dp; dp++, n++)
487 return NULL; /* rule is self-fulfilling */
492 if (n == 0) /* direct assertion */
496 /* this is a rpm rule assertion, we do not have to allocate it */
497 /* we can identify it by looking at the decision level, it will be 1 */
500 if (solv->decisionmap[-p] > 0) /* */
502 if (solv->decisionmap[-p]) /* */
504 queuepush(&solv->decisionq, p);
505 queuepush(&solv->decisionq_why, 0);
506 solv->decisionmap[-p] = -1;
511 else if (n == 1 && p > d)
513 /* smallest literal first so we can find dups */
517 n = 1; /* re-set n, was used as temp var */
533 Id *dp2 = solv->pool->whatprovidesdata + r->d;
534 for (dp = solv->pool->whatprovidesdata + d; *dp; dp++, dp2++)
547 /* check and extend rule buffer */
548 if ((solv->nrules & RULES_BLOCK) == 0)
550 solv->rules = (Rule *)xrealloc(solv->rules, (solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
553 r = solv->rules + solv->nrules++; /* point to rule space */
558 /* direct assertion, no watch needed */
574 r->w2 = solv->pool->whatprovidesdata[d];
579 /* we don't add the decision for learnt rules, as the code does that
580 * right after calling addrule anyway */
583 && !solv->learntrules)
585 /* must be system or job rule, as there are only negative unary rpm rules */
586 Id vv = p > 0 ? p : -p;
587 if (solv->decisionmap[vv])
590 if (solv->decisionmap[vv] > 0 && p > 0)
592 if (solv->decisionmap[vv] < 0 && p < 0)
594 /* direct conflict! */
595 for (i = 0; i < solv->decisionq.count; i++)
597 if (solv->decisionq.elements[i] == -p)
600 if (i == solv->decisionq.count)
602 if (solv->decisionq_why.elements[i] == 0)
604 /* conflict with rpm rule */
605 queuepush(&solv->problems, r - solv->rules);
606 queuepush(&solv->problems, 0);
607 r->w1 = 0; /* disable */
610 /* conflict with other job or system rule */
611 queuepush(&solv->problems, solv->decisionq_why.elements[i]);
612 queuepush(&solv->problems, r - solv->rules);
613 queuepush(&solv->problems, 0);
614 r->w1 = 0; /* disable */
615 /* also disable conflicting rule */
616 solv->rules[solv->decisionq_why.elements[i]].w1 = 0;
617 /* XXX: remove from decisionq! */
618 printf("XXX remove from decisionq\n");
621 queuepush(&solv->decisionq, p);
622 queuepush(&solv->decisionq_why, r - solv->rules);
623 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? 1 : -1;
630 * add (install) rules for solvable
635 addrulesforsolvable(Solver *solv, Solvable *s, Map *m)
637 Pool *pool = solv->pool;
638 Source *system = solv->system;
651 queuepush(&q, s - pool->solvables);/* push solvable Id */
657 * s: Pointer to solvable
661 if (MAPTST(m, n)) /* continue if already set in map */
665 s = pool->solvables + n; /* s = Solvable in question */
668 if (system /* have rpm */
670 && n >= system->start /* its an rpm rule */
671 && n < system->start + system->nsolvables)
673 dontfix = 1; /* dont care about broken rpm deps */
676 /*-----------------------------------------
677 * check requires of s
680 if ((reqp = s->requires) != ID_NULL)
682 while ((req = *reqp++) != ID_NULL)
684 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
687 dp = GET_PROVIDESP(req, p); /* get providers of req */
689 if (!*dp /* dont care if noone provides rpmlib() */
690 && !strncmp(id2str(pool, req), "rpmlib(", 7))
695 if (dontfix) /* rpm rule, dont care about breakage */
697 for (i = 0; dp[i]; i++)/* for all providers */
699 if (dp[i] >= system->start && dp[i] < system->start + system->nsolvables)
700 break; /* provider is installed */
702 if (!dp[i]) /* no provider found */
704 if (pool->verbose) printf("ignoring broken requires %s of system package %s-%s.%s\n", dep2str(pool, req), id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
711 /* nothing provides req! */
713 if (pool->verbose) printf("package %s-%s.%s is not installable (%s)\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), dep2str(pool, req));
715 addrule(solv, -n, 0); /* mark requestor as uninstallable */
717 printf(">!> !unflag %s-%s.%s[%s]\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), source_name(pool_source(pool, s)));
721 printf("addrule %s-%s.%s %s %d %d\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), dep2str(pool, req), -n, dp - pool->whatprovidesdata);
722 for (i = 0; dp[i]; i++)
723 printf(" %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));
725 /* add 'requires' dependency */
726 addrule(solv, -n, dp - pool->whatprovidesdata); /* rule: (-requestor|provider1|provider2|...|providerN) */
728 /* descend the dependency tree */
729 for (; *dp != ID_NULL; dp++) /* loop through all providers */
735 } /* while, requirements of n */
737 } /* if, requirements */
740 /*-----------------------------------------
741 * check conflicts of s
744 if ((conp = s->conflicts) != ID_NULL)
746 while ((con = *conp++) != ID_NULL)
748 FOR_PROVIDES(p, pp, con) /* loop through all providers of this conflict */
750 /* dontfix: dont care about conflicts with already installed packs */
751 if (dontfix && p >= system->start && p < system->start + system->nsolvables)
753 addrule(solv, -n, -p); /* rule: -n|-p: either solvable _or_ provider of conflict */
758 /*-----------------------------------------
759 * check obsoletes if not installed
761 if (!system || n < system->start || n >= (system->start + system->nsolvables))
762 { /* not installed */
763 if ((obsp = s->obsoletes) != ID_NULL)
765 while ((obs = *obsp++) != ID_NULL)
767 FOR_PROVIDES(p, pp, obs)
768 addrule(solv, -n, -p);
771 FOR_PROVIDES(p, pp, s->name)
773 if (s->name == pool->solvables[p].name)
774 addrule(solv, -n, -p);
778 /*-----------------------------------------
779 * add recommends to the rule list
781 if ((recp = s->recommends) != ID_NULL)
782 while ((rec = *recp++) != ID_NULL)
784 FOR_PROVIDES(p, pp, rec)
793 addrulesforsupplements(Solver *solv, Map *m)
795 Pool *pool = solv->pool;
801 if (pool->verbose) printf("addrulesforsupplements... (%d)\n", solv->nrules);
802 for (i = n = 1; n < pool->nsolvables; i++, n++)
804 if (i == pool->nsolvables)
808 s = pool->solvables + i;
810 if ((supp = s->supplements) != 0)
812 while ((sup = *supp++) != ID_NULL)
814 FOR_PROVIDES(p, pp, sup)
821 if (!sup && (supp = s->freshens) != 0)
823 while ((sup = *supp++) != ID_NULL)
825 FOR_PROVIDES(p, pp, sup)
834 addrulesforsolvable(solv, s, m);
837 if (pool->verbose) printf("done. (%d)\n", solv->nrules);
842 archchanges(Pool *pool, Solvable *s1, Solvable *s2)
844 Id a1 = s1->arch, a2 = s2->arch;
846 /* we allow changes to/from noarch */
847 if (a1 == a2 || a1 == ARCH_NOARCH || a2 == ARCH_NOARCH)
851 a1 = a1 <= pool->lastarch ? pool->id2arch[a1] : 0;
852 a2 = a2 <= pool->lastarch ? pool->id2arch[a2] : 0;
853 if (((a1 ^ a2) & 0xffff0000) != 0)
860 findupdatepackages(Solver *solv, Solvable *s, Queue *qs, Map *m, int allowdowngrade, int allowarchchange)
862 /* system packages get a special upgrade allowed rule */
863 Pool *pool = solv->pool;
864 Id p, *pp, n, p2, *pp2;
872 n = s - pool->solvables;
873 if (m && !MAPTST(m, n)) /* add rule for s if not already done */
874 addrulesforsolvable(solv, s, m);
877 * look for updates for s
879 FOR_PROVIDES(p, pp, s->name) /* every provider of s' name */
881 if (p == n) /* skip itself */
884 if (s->name == pool->solvables[p].name) /* name match */
886 if (!allowdowngrade /* consider downgrades ? */
887 && evrcmp(pool, s->evr, pool->solvables[p].evr) > 0)
890 if (!allowarchchange && archchanges(pool, s, pool->solvables + p))
893 else if ((obsp = pool->solvables[p].obsoletes) != 0) /* provides/obsoletes combination ? */
895 while ((obs = *obsp++) != 0) /* for all obsoletes */
897 FOR_PROVIDES(p2, pp2, obs) /* and all matching providers of the obsoletes */
899 if (p2 == n) /* match ! */
905 if (!obs) /* continue if no match */
907 /* here we have 'p' with a matching provides/obsoletes combination
908 * thus flagging p as a valid update candidate for s
913 if (m && !MAPTST(m, p)) /* mark p for install if not already done */
914 addrulesforsolvable(solv, pool->solvables + p, m);
919 * add rule for update
920 * (A|A1|A2|A3...) An = update candidates for A
922 * s = (installed) solvable
923 * m = 'addedmap', bit set if 'install' rule for solvable exists
927 addupdaterule(Solver *solv, Solvable *s, Map *m, int allowdowngrade, int allowarchchange, int dontaddrule)
929 /* system packages get a special upgrade allowed rule */
930 Pool *pool = solv->pool;
936 findupdatepackages(solv, s, &qs, m, allowdowngrade, allowarchchange);
937 n = s - pool->solvables;
938 if (dontaddrule) /* we consider update candidates but dont force them */
944 if (qs.count == 0) /* no updates found */
947 printf("new update rule: must keep %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
949 addrule(solv, n, 0); /* request 'install' of s */
954 d = pool_queuetowhatprovides(pool, &qs); /* intern computed provider queue */
956 r = addrule(solv, n, d); /* allow update of s */
958 printf("new update rule ");
965 /*-----------------------------------------------------------------*/
972 * initial setup for all watches
976 makewatches(Solver *solv)
980 int nsolvables = solv->pool->nsolvables;
982 xfree(solv->watches);
983 /* lower half for removals, upper half for installs */
984 solv->watches = (Id *)xcalloc(2 * nsolvables, sizeof(Id));
986 /* do it reverse so rpm rules get triggered first */
987 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
989 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
992 if (!r->w1 /* rule is disabled */
993 || !r->w2) /* rule is assertion */
996 /* see addwatches(solv, r) */
997 r->n1 = solv->watches[nsolvables + r->w1];
998 solv->watches[nsolvables + r->w1] = r - solv->rules;
1000 r->n2 = solv->watches[nsolvables + r->w2];
1001 solv->watches[nsolvables + r->w2] = r - solv->rules;
1007 * add watches (for rule)
1011 addwatches(Solver *solv, Rule *r)
1013 int nsolvables = solv->pool->nsolvables;
1015 r->n1 = solv->watches[nsolvables + r->w1];
1016 solv->watches[nsolvables + r->w1] = r - solv->rules;
1018 r->n2 = solv->watches[nsolvables + r->w2];
1019 solv->watches[nsolvables + r->w2] = r - solv->rules;
1023 /*-----------------------------------------------------------------*/
1024 /* rule propagation */
1026 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1031 * propagate decision to all rules
1035 propagate(Solver *solv, int level)
1037 Pool *pool = solv->pool;
1042 Id *decisionmap = solv->decisionmap;
1043 Id *watches = solv->watches + pool->nsolvables;
1045 while (solv->propagate_index < solv->decisionq.count)
1047 /* negative because our watches trigger if literal goes FALSE */
1048 pkg = -solv->decisionq.elements[solv->propagate_index++];
1050 printf("popagate for decision %d level %d\n", -pkg, level);
1051 printruleelement(solv, 0, -pkg);
1053 for (rp = watches + pkg; *rp; rp = nrp)
1055 r = solv->rules + *rp;
1057 printf(" watch triggered ");
1070 /* if clause is TRUE, nothing to do */
1071 if (DECISIONMAP_TRUE(ow))
1076 /* not a binary clause, check if we need to move our watch */
1077 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1080 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1081 if (p != ow && !DECISIONMAP_TRUE(-p))
1085 /* p is free to watch, move watch to p */
1088 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));
1090 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));
1104 watches[p] = r - solv->rules;
1108 /* unit clause found, set other watch to TRUE */
1109 if (DECISIONMAP_TRUE(-ow))
1110 return r; /* eek, a conflict! */
1116 decisionmap[ow] = level;
1118 decisionmap[-ow] = -level;
1119 queuepush(&solv->decisionq, ow);
1120 queuepush(&solv->decisionq_why, r - solv->rules);
1123 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1125 printf(" -> decided to install %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1127 printf(" -> decided to conflict %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1132 return 0; /* all is well */
1136 /*-----------------------------------------------------------------*/
1145 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *why)
1147 Pool *pool = solv->pool;
1150 Map seen; /* global? */
1154 int learnt_why = solv->learnt_pool.count;
1155 Id *decisionmap = solv->decisionmap;
1159 if (pool->verbose) printf("ANALYZE at %d ----------------------\n", level);
1160 mapinit(&seen, pool->nsolvables);
1161 idx = solv->decisionq.count;
1165 queuepush(&solv->learnt_pool, c - solv->rules);
1166 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1177 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1179 vv = v > 0 ? v : -v;
1180 if (MAPTST(&seen, vv))
1182 l = solv->decisionmap[vv];
1189 for (j = 0; j < solv->decisionq.count; j++)
1190 if (solv->decisionq.elements[j] == v)
1192 if (j == solv->decisionq.count)
1194 queuepush(&rulq, -(j + 1));
1196 continue; /* initial setting */
1200 num++; /* need to do this one as well */
1205 printf("PUSH %d ", v);
1206 printruleelement(solv, 0, v);
1213 printf("num = %d\n", num);
1219 v = solv->decisionq.elements[--idx];
1220 vv = v > 0 ? v : -v;
1221 if (MAPTST(&seen, vv))
1224 c = solv->rules + solv->decisionq_why.elements[idx];
1232 else if (r.count == 1 && r.elements[0] < 0)
1233 *dr = r.elements[0];
1235 *dr = pool_queuetowhatprovides(pool, &r);
1238 printf("learned rule for level %d (am %d)\n", rlevel, level);
1239 printruleelement(solv, 0, -v);
1240 for (i = 0; i < r.count; i++)
1243 printruleelement(solv, 0, v);
1247 queuepush(&solv->learnt_pool, 0);
1249 for (i = learnt_why; solv->learnt_pool.elements[i]; i++)
1251 printf("learnt_why ");
1252 printrule(solv, solv->rules + solv->learnt_pool.elements[i]);
1263 * reset the solver decisions to right after the rpm rules
1267 reset_solver(Solver *solv)
1273 /* delete all learnt rules */
1274 solv->nrules = solv->learntrules;
1275 QUEUEEMPTY(&solv->learnt_why);
1276 QUEUEEMPTY(&solv->learnt_pool);
1278 /* redo all direct decision without the disabled rules */
1279 for (i = 0; i < solv->decisionq.count; i++)
1281 v = solv->decisionq.elements[i];
1282 solv->decisionmap[v > 0 ? v : -v] = 0;
1284 for (i = 0; i < solv->decisionq_why.count; i++)
1285 if (solv->decisionq_why.elements[i])
1289 v = solv->decisionq.elements[i];
1290 solv->decisionmap[v > 0 ? v : -v] = v > 0 ? 1 : -1;
1293 if (solv->pool->verbose)
1294 printf("decisions done reduced from %d to %d\n", solv->decisionq.count, i);
1296 solv->decisionq_why.count = i;
1297 solv->decisionq.count = i;
1298 if (i < solv->propagate_index)
1299 solv->propagate_index = i;
1300 /* make direct decisions from enabled unary rules */
1301 for (i = solv->jobrules, r = solv->rules + solv->jobrules; i < solv->nrules; i++, r++)
1303 if (!r->w1 || r->w2)
1309 queuepush(&solv->decisionq, v);
1310 queuepush(&solv->decisionq_why, r - solv->rules);
1311 solv->decisionmap[v > 0 ? v : -v] = v > 0 ? 1 : -1;
1313 if (solv->pool->verbose)
1314 printf("decisions after adding job and system rules: %d\n", solv->decisionq.count);
1315 /* recreate watches */
1321 * analyze_unsolvable_rule
1325 analyze_unsolvable_rule(Solver *solv, Rule *c, int disablerules)
1330 why = c - solv->rules;
1332 if (why >= solv->jobrules && why < solv->systemrules)
1334 if (why >= solv->systemrules && why < solv->learntrules)
1335 printf("SYSTEM %d ", why - solv->systemrules);
1336 if (solv->learntrules && why >= solv->learntrules)
1340 if (solv->learntrules && why >= solv->learntrules)
1342 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1343 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], disablerules);
1346 if (why >= solv->jobrules && why < solv->learntrules)
1350 /* turn off rule for further analysis */
1354 if (solv->problems.count)
1356 for (i = solv->problems.count - 1; i >= 0; i--)
1357 if (solv->problems.elements[i] == 0)
1359 else if (solv->problems.elements[i] == why)
1362 queuepush(&solv->problems, why);
1368 * analyze_unsolvable
1372 analyze_unsolvable(Solver *solv, Rule *c, int disablerules)
1374 Pool *pool = solv->pool;
1375 Map seen; /* global? */
1378 Id *decisionmap = solv->decisionmap;
1381 printf("ANALYZE UNSOLVABLE ----------------------\n");
1383 mapinit(&seen, pool->nsolvables);
1384 analyze_unsolvable_rule(solv, c, disablerules);
1385 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1396 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1398 vv = v > 0 ? v : -v;
1399 l = solv->decisionmap[vv];
1404 idx = solv->decisionq.count;
1407 v = solv->decisionq.elements[--idx];
1408 vv = v > 0 ? v : -v;
1409 if (!MAPTST(&seen, vv))
1411 why = solv->decisionq_why.elements[idx];
1416 printruleelement(solv, 0, v);
1420 c = solv->rules + why;
1421 analyze_unsolvable_rule(solv, c, disablerules);
1422 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1433 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1435 vv = v > 0 ? v : -v;
1436 l = solv->decisionmap[vv];
1443 queuepush(&solv->problems, 0); /* mark end of this problem */
1447 printf("analyze_unsolvables done\n");
1452 /*-----------------------------------------------------------------*/
1453 /* Decision revert */
1457 * revert decision at level
1461 revert(Solver *solv, int level)
1464 while (solv->decisionq.count)
1466 v = solv->decisionq.elements[solv->decisionq.count - 1];
1467 vv = v > 0 ? v : -v;
1468 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1471 printf("reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1473 solv->decisionmap[vv] = 0;
1474 solv->decisionq.count--;
1475 solv->decisionq_why.count--;
1476 solv->propagate_index = solv->decisionq.count;
1486 watch2onhighest(Solver *solv, Rule *r)
1492 return; /* binary rule, both watches are set */
1493 dp = solv->pool->whatprovidesdata + r->d;
1494 while ((v = *dp++) != 0)
1496 l = solv->decisionmap[v < 0 ? -v : v];
1513 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1523 solv->decisionmap[decision] = level;
1525 solv->decisionmap[-decision] = -level;
1526 queuepush(&solv->decisionq, decision);
1527 queuepush(&solv->decisionq_why, 0);
1531 r = propagate(solv, level);
1536 analyze_unsolvable(solv, r, disablerules);
1541 printf("conflict with rule #%d\n", (int)(r - solv->rules));
1542 l = analyze(solv, level, r, &p, &d, &why);
1543 if (l >= level || l <= 0)
1545 printf("reverting decisions (level %d -> %d)\n", level, l);
1547 revert(solv, level);
1548 r = addrule(solv, p, d); /* p requires d */
1551 if (solv->learnt_why.count != (r - solv->rules) - solv->learntrules)
1553 printf("%d %d\n", solv->learnt_why.count, (int)(r - solv->rules) - solv->learntrules);
1556 queuepush(&solv->learnt_why, why);
1559 /* at least 2 literals, needs watches */
1560 watch2onhighest(solv, r);
1561 addwatches(solv, r);
1563 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1564 queuepush(&solv->decisionq, p);
1565 queuepush(&solv->decisionq_why, r - solv->rules);
1566 printf("decision: ");
1567 printruleelement(solv, 0, p);
1568 printf("new rule: ");
1574 /*-----------------------------------------------------------------*/
1575 /* Main solver interface */
1580 * create solver structure
1582 * pool: all available solvables
1583 * system: installed Solvables
1586 * Upon solving, rules are created to flag the Solvables
1587 * of the 'system' Source as installed.
1591 solver_create(Pool *pool, Source *system)
1594 solv = (Solver *)xcalloc(1, sizeof(Solver));
1596 solv->system = system;
1599 queueinit(&solv->decisionq);
1600 queueinit(&solv->decisionq_why);
1601 queueinit(&solv->problems);
1602 queueinit(&solv->learnt_why);
1603 queueinit(&solv->learnt_pool);
1605 solv->decisionmap = (Id *)xcalloc(pool->nsolvables, sizeof(Id));
1606 solv->rules = (Rule *)xmalloc((solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
1607 memset(solv->rules, 0, sizeof(Rule));
1620 solver_free(Solver *solv)
1622 queuefree(&solv->decisionq);
1623 queuefree(&solv->decisionq_why);
1624 queuefree(&solv->learnt_why);
1625 queuefree(&solv->learnt_pool);
1626 xfree(solv->decisionmap);
1628 xfree(solv->watches);
1629 xfree(solv->weaksystemrules);
1637 * r->w1 was set to 0, now find proper value for w1
1641 reenablerule(Solver *solv, Rule *r)
1646 if (!r->w2) /* not a rule, but an assertion */
1656 r->w2 = r->d; /* mls: shouldn't this be r->w1 ? */
1660 /* put it on the first not-false literal */
1666 v = solv->pool->whatprovidesdata[r->d + i];
1674 l = solv->decisionmap[v > 0 ? v : -v];
1675 if (!l || (v < 0 && l < 0) || (v > 0 && l > 0))
1682 /*-------------------------------------------------------*/
1687 * all rules have been set up, not actually run the solver
1692 run_solver(Solver *solv, int disablerules, int doweak)
1700 Pool *pool = solv->pool;
1704 printf("number of rules: %d\n", solv->nrules);
1707 for (i = 0; i < solv->nrules; i++)
1709 printrule(solv, solv->rules + i);
1714 /* all new rules are learnt after this point */
1715 solv->learntrules = solv->nrules;
1716 /* crate watches lists */
1719 if (pool->verbose) printf("initial decisions: %d\n", solv->decisionq.count);
1721 /* start SAT algorithm */
1723 systemlevel = level + 1;
1724 if (pool->verbose) printf("solving...\n");
1735 if (pool->verbose) printf("propagating (%d %d)...\n", solv->propagate_index, solv->decisionq.count);
1736 if ((r = propagate(solv, level)) != 0)
1738 analyze_unsolvable(solv, r, disablerules);
1741 printf("UNSOLVABLE\n");
1751 if (level < systemlevel && solv->system->nsolvables)
1753 if (!solv->updatesystem)
1755 /* try to keep as many packages as possible */
1756 if (pool->verbose) printf("installing system packages\n");
1757 for (i = solv->system->start, n = 0; ; i++, n++)
1759 if (n == solv->system->nsolvables)
1761 if (i == solv->system->start + solv->system->nsolvables)
1762 i = solv->system->start;
1763 s = pool->solvables + i;
1764 if (solv->decisionmap[i] != 0)
1767 printf("system installing %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1770 level = setpropagatelearn(solv, level, i, disablerules);
1773 printf("UNSOLVABLE\n");
1777 if (level <= olevel)
1781 if (solv->weaksystemrules)
1783 if (pool->verbose) printf("installing weak system packages\n");
1784 for (i = solv->system->start, n = 0; ; i++, n++)
1786 if (n == solv->system->nsolvables)
1788 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->system->start] == 0))
1791 if (solv->decisionmap[i] == 0)
1793 if (solv->weaksystemrules[i - solv->system->start])
1795 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->system->start];
1796 while ((p = *dp++) != 0)
1798 if (solv->decisionmap[p] > 0)
1800 if (solv->decisionmap[p] == 0)
1804 continue; /* rule is already true */
1810 prune_best_version_arch(pool, &dq);
1812 s = pool->solvables + dq.elements[0];
1813 printf("weak system installing %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1816 level = setpropagatelearn(solv, level, dq.elements[0], disablerules);
1819 printf("UNSOLVABLE\n");
1823 if (level <= olevel)
1829 if (n != solv->system->nsolvables)
1832 systemlevel = level;
1839 if (pool->verbose) printf("deciding unresolved rules\n");
1840 for (i = 1, n = 1; ; i++, n++)
1842 if (n == solv->nrules)
1844 if (i == solv->nrules)
1846 r = solv->rules + i;
1852 /* binary or unary rule */
1853 /* need two positive undecided literals */
1854 if (r->p < 0 || r->w2 <= 0)
1856 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
1858 queuepush(&dq, r->p);
1859 queuepush(&dq, r->w2);
1864 * all negative literals are installed
1865 * no positive literal is installed
1866 * i.e. the rule is not fulfilled and we
1867 * just need to decide on the positive literals
1871 if (solv->decisionmap[-r->p] <= 0)
1876 if (solv->decisionmap[r->p] > 0)
1878 if (solv->decisionmap[r->p] == 0)
1879 queuepush(&dq, r->p);
1881 dp = pool->whatprovidesdata + r->d;
1882 while ((p = *dp++) != 0)
1886 if (solv->decisionmap[-p] <= 0)
1891 if (solv->decisionmap[p] > 0)
1893 if (solv->decisionmap[p] == 0)
1902 /* cannot happen as this means that
1903 * the rule is unit */
1907 prune_to_recommended(solv, &dq);
1909 prune_best_version_arch(pool, &dq);
1910 p = dq.elements[dq.count - 1];
1911 s = pool->solvables + p;
1913 printf("installing %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1916 level = setpropagatelearn(solv, level, p, disablerules);
1919 printf("UNSOLVABLE\n");
1923 if (level < systemlevel)
1925 if (level <= olevel)
1927 } /* for(), decide */
1929 if (n != solv->nrules) /* continue if level < systemlevel */
1932 if (doweak && !solv->problems.count)
1936 if (pool->verbose) printf("installing recommended packages\n");
1938 for (i = 1; i < pool->nsolvables; i++)
1940 if (solv->decisionmap[i] < 0)
1942 if (solv->decisionmap[i] > 0)
1944 Id *recp, rec, *pp, p;
1945 s = pool->solvables + i;
1946 /* installed, check for recommends */
1947 /* XXX need to special case AND ? */
1948 if ((recp = s->recommends) != 0)
1950 while ((rec = *recp++) != 0)
1953 FOR_PROVIDES(p, pp, rec)
1955 if (solv->decisionmap[p] > 0)
1960 else if (solv->decisionmap[p] == 0)
1961 queuepushunique(&dq, p);
1969 s = pool->solvables + i;
1970 if (!s->supplements && !s->freshens)
1972 if ((supp = s->supplements) != 0)
1974 while ((sup = *supp++) != 0)
1975 if (dep_is_installed(solv, sup))
1980 if ((supp = s->freshens) != 0)
1982 while ((sup = *supp++) != 0)
1983 if (dep_is_installed(solv, sup))
1988 queuepushunique(&dq, i);
1993 prune_best_version_arch(pool, &dq);
1994 p = dq.elements[dq.count - 1];
1995 s = pool->solvables + p;
1997 printf("installing recommended %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1999 level = setpropagatelearn(solv, level, p, 0);
2014 refine_suggestion(Solver *solv, Id *problem, Id sug, Queue *refined)
2022 printf("refine_suggestion start\n");
2023 queueinit(&disabled);
2024 QUEUEEMPTY(refined);
2025 queuepush(refined, sug);
2027 /* re-enable all rules but rule "sug" of the problem */
2028 for (i = 0; problem[i]; i++)
2030 if (problem[i] == sug)
2032 r = solv->rules + problem[i];
2037 reenablerule(solv, r);
2043 QUEUEEMPTY(&solv->problems);
2044 run_solver(solv, 0, 0);
2045 if (!solv->problems.count)
2047 printf("no more problems!\n");
2049 printdecisions(solv);
2051 break; /* great, no more problems */
2053 disabledcnt = disabled.count;
2054 for (i = 0; i < solv->problems.elements[i]; i++)
2056 /* ignore solutions in refined */
2057 v = solv->problems.elements[i];
2058 for (j = 0; problem[j]; j++)
2059 if (problem[j] != sug && problem[j] == v)
2063 queuepush(&disabled, v);
2065 if (disabled.count == disabledcnt)
2067 /* no solution found, this was an invalid suggestion! */
2068 printf("no solution found!\n");
2069 for (i = 0; i < refined->count; i++)
2070 reenablerule(solv, solv->rules + refined->elements[i]);
2074 if (disabled.count == disabledcnt + 1)
2076 /* just one solution, add it to refined list */
2077 queuepush(refined, disabled.elements[disabledcnt]);
2081 printf("############################################## more than one solution found.\n");
2083 for (i = 0; i < solv->problems.elements[i]; i++)
2085 printrule(solv, solv->rules + solv->problems.elements[i]);
2087 printf("##############################################\n");
2089 /* more than one solution */
2090 /* for now return */
2092 for (i = disabledcnt; i < disabled.count; i++)
2094 r = solv->rules + disabled.elements[i];;
2103 /* enable refined rules again */
2105 for (i = 0; i < disabled.count; i++)
2106 reenablerule(solv, solv->rules + disabled.elements[i]);
2107 /* disable problem rules again so that we are in the same state as before */
2108 for (i = 0; problem[i]; i++)
2110 r = solv->rules + problem[i];
2113 printf("refine_suggestion end\n");
2122 id2rc(Solver *solv, Id id)
2125 if (solv->rc_output != 2)
2127 evr = id2str(solv->pool, id);
2128 if (*evr < '0' || *evr > '9')
2130 while (*evr >= '0' && *evr <= '9')
2138 printdecisions(Solver *solv)
2140 Pool *pool = solv->pool;
2141 Id p, *obsoletesmap;
2145 obsoletesmap = (Id *)xcalloc(pool->nsolvables, sizeof(Id));
2146 for (i = 0; i < solv->decisionq.count; i++)
2151 n = solv->decisionq.elements[i];
2154 if (n >= solv->system->start && n < solv->system->start + solv->system->nsolvables)
2156 s = pool->solvables + n;
2157 if ((obsp = s->obsoletes) != 0)
2158 while ((obs = *obsp++) != 0)
2159 FOR_PROVIDES(p, pp, obs)
2161 if (p >= solv->system->start && p < solv->system->start + solv->system->nsolvables)
2163 obsoletesmap[p] = n;
2167 FOR_PROVIDES(p, pp, s->name)
2168 if (s->name == pool->solvables[p].name)
2170 if (p >= solv->system->start && p < solv->system->start + solv->system->nsolvables)
2172 obsoletesmap[p] = n;
2178 if (solv->rc_output)
2179 printf(">!> Solution #1:\n");
2181 int installs = 0, uninstalls = 0, upgrades = 0;
2183 /* print solvables to be erased */
2185 for (i = solv->system->start; i < solv->system->start + solv->system->nsolvables; i++)
2187 if (solv->decisionmap[i] > 0)
2189 if (obsoletesmap[i])
2191 s = pool->solvables + i;
2192 if (solv->rc_output)
2195 if (solv->rc_output == 2)
2198 printf(" %s-%s%s", id2str(pool, s->name), id2rc(solv, s->evr), id2str(pool, s->evr));
2202 printf("remove %s-%s.%s", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2207 printf("erase %s-%s.%s", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2213 /* print solvables to be installed */
2215 for (i = 0; i < solv->decisionq.count; i++)
2217 p = solv->decisionq.elements[i];
2220 if (p >= solv->system->start && p < solv->system->start + solv->system->nsolvables)
2222 s = pool->solvables + p;
2224 if (solv->rc_output)
2227 if (!obsoletesmap[p])
2229 printf("install %s-%s%s", id2str(pool, s->name), id2rc(solv, s->evr), id2str(pool, s->evr));
2230 if (solv->rc_output != 2)
2231 printf(".%s", id2str(pool, s->arch));
2237 Solvable *from = NULL, *to = NULL;
2238 if (solv->rc_output)
2241 printf("update %s-%s.%s (obsoletes", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2243 for (j = solv->system->start; j < solv->system->start + solv->system->nsolvables; j++)
2245 if (obsoletesmap[j] == p)
2247 s = pool->solvables + j;
2248 if (solv->rc_output)
2251 printf(" %s-%s.%s", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2254 if (solv->rc_output)
2256 if (solv->rc_output == 2)
2257 printf("upgrade %s-%s => %s-%s%s", id2str(pool, from->name), id2str(pool, from->evr), id2str(pool, to->name), id2rc(solv, to->evr), id2str(pool, to->evr));
2259 printf("upgrade %s-%s.%s => %s-%s.%s", id2str(pool, from->name), id2str(pool, from->evr), id2str(pool, from->arch), id2str(pool, to->name), id2str(pool, to->evr), id2str(pool, to->arch));
2260 s = to; /* for final source name */
2265 if (solv->rc_output)
2267 Source *source = pool_source(pool, s);
2269 printf("[%s]", source_name(source));
2274 if (solv->rc_output)
2275 printf(">!> installs=%d, upgrades=%d, uninstalls=%d\n", installs, upgrades, uninstalls);
2277 xfree(obsoletesmap);
2281 /*-----------------------------------------------------------------*/
2291 solve(Solver *solv, Queue *job)
2293 Pool *pool = solv->pool;
2295 Map addedmap; /* '1' == have rule for solvable */
2296 Map noupdaterule; /* '1' == don't update (scheduled for removal) */
2297 Id how, what, p, *pp, d;
2303 * create basic rule set of all involved packages
2308 mapinit(&addedmap, pool->nsolvables);
2309 mapinit(&noupdaterule, pool->nsolvables);
2314 * create rules for installed solvables -> keep them installed
2315 * so called: rpm rules
2319 for (i = solv->system->start; i < solv->system->start + solv->system->nsolvables; i++)
2320 addrulesforsolvable(solv, pool->solvables + i, &addedmap);
2323 * create install rules
2325 * two passes, as we want to keep the rpm rules distinct from the job rules
2331 * process job rules for solvables
2334 for (i = 0; i < job->count; i += 2)
2336 how = job->elements[i];
2337 what = job->elements[i + 1];
2341 case SOLVER_INSTALL_SOLVABLE:
2342 addrulesforsolvable(solv, pool->solvables + what, &addedmap);
2344 case SOLVER_INSTALL_SOLVABLE_NAME:
2345 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
2347 FOR_PROVIDES(p, pp, what)
2349 /* if by name, ensure that the name matches */
2350 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
2352 addrulesforsolvable(solv, pool->solvables + p, &addedmap);
2355 case SOLVER_INSTALL_SOLVABLE_UPDATE:
2356 /* dont allow downgrade */
2357 addupdaterule(solv, pool->solvables + what, &addedmap, 0, 0, 1);
2363 * if unstalls are disallowed, add update rules for every
2364 * installed solvables in the hope to circumvent uninstall
2370 if (!solv->allowuninstall)
2372 /* add update rule for every installed package */
2373 for (i = solv->system->start; i < solv->system->start + solv->system->nsolvables; i++)
2374 addupdaterule(solv, pool->solvables + i, &addedmap, solv->allowdowngrade, solv->allowarchchange, 1);
2376 #else /* this is just to add the needed rpm rules to our set */
2377 for (i = solv->system->start; i < solv->system->start + solv->system->nsolvables; i++)
2378 addupdaterule(solv, pool->solvables + i, &addedmap, 1, 1, 1);
2381 addrulesforsupplements(solv, &addedmap);
2386 * unify existing rules before going over all job rules
2390 unifyrules(solv); /* remove duplicate rpm rules */
2393 * at this point the system is always solvable,
2394 * as an empty system (remove all packages) is a valid solution
2396 if (pool->verbose) printf("decisions based on rpms: %d\n", solv->decisionq.count);
2399 * now add all job rules
2402 solv->jobrules = solv->nrules;
2404 for (i = 0; i < job->count; i += 2)
2406 how = job->elements[i];
2407 what = job->elements[i + 1];
2410 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
2411 if (solv->rc_output) {
2412 Solvable *s = pool->solvables + what;
2413 printf(">!> Installing %s from channel %s\n", id2str(pool, s->name), source_name(pool_source(pool, s)));
2415 addrule(solv, what, 0); /* install by Id */
2417 case SOLVER_ERASE_SOLVABLE:
2418 addrule(solv, -what, 0); /* remove by Id */
2419 MAPSET(&noupdaterule, what);
2421 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
2422 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
2424 FOR_PROVIDES(p, pp, what) /* check all providers */
2426 /* if by name, ensure that the name matches */
2427 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
2431 if (!q.count) { /* no provider found -> abort */
2432 fprintf(stderr, "Nothing provides '%s'\n", id2str(pool, what));
2433 /* XXX make this a problem! */
2438 p = queueshift(&q); /* get first provider */
2440 d = 0; /* single provider ? -> make assertion */
2442 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
2443 addrule(solv, p, d); /* add 'requires' rule */
2445 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
2446 case SOLVER_ERASE_SOLVABLE_PROVIDES:
2447 FOR_PROVIDES(p, pp, what)
2449 /* if by name, ensure that the name matches */
2450 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
2453 addrule(solv, -p, 0); /* add 'remove' rule */
2454 MAPSET(&noupdaterule, p);
2457 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
2458 addupdaterule(solv, pool->solvables + what, &addedmap, 0, 0, 0);
2463 if (pool->verbose) printf("problems so far: %d\n", solv->problems.count);
2466 * now add policy rules
2470 solv->systemrules = solv->nrules;
2473 * create rules for updating installed solvables
2479 if (!solv->allowuninstall)
2480 { /* loop over all installed solvables */
2481 for (i = solv->system->start; i < solv->system->start + solv->system->nsolvables; i++)
2483 if (!MAPTST(&noupdaterule, i)) /* if not marked as 'noupdate' */
2484 addupdaterule(solv, pool->solvables + i, &addedmap, solv->allowdowngrade, solv->allowarchchange, 0);
2486 addrule(solv, 0, 0); /* place holder */
2488 /* consistency check: we added a rule for _every_ system solvable */
2489 if (solv->nrules - solv->systemrules != solv->system->nsolvables)
2493 if (pool->verbose) printf("problems so far: %d\n", solv->problems.count);
2495 /* create special weak system rules */
2496 if (solv->system->nsolvables)
2498 solv->weaksystemrules = xcalloc(solv->system->nsolvables, sizeof(Id));
2499 for (i = 0; i < solv->system->nsolvables; i++)
2501 findupdatepackages(solv, pool->solvables + solv->system->start + i, &q, (Map *)0, 1, 1);
2503 solv->weaksystemrules[i] = pool_queuetowhatprovides(pool, &q);
2507 /* free unneeded memory */
2509 mapfree(&noupdaterule);
2517 run_solver(solv, 1, 1);
2521 * print solver result
2525 if (pool->verbose) printf("-------------------------------------------------------------\n");
2527 if (solv->problems.count)
2537 clonequeue(&problems, &solv->problems);
2538 queueinit(&solution);
2539 printf("Encountered problems! Here are the solutions:\n");
2540 problem = problems.elements;
2541 for (i = 0; i < problems.count; i++)
2543 Id v = problems.elements[i];
2546 printf("====================================\n");
2547 problem = problems.elements + i + 1;
2550 refine_suggestion(solv, problem, v, &solution);
2551 for (j = 0; j < solution.count; j++)
2553 r = solv->rules + solution.elements[j];
2554 why = solution.elements[j];
2558 if (why >= solv->jobrules && why < solv->systemrules)
2560 /* do a sloppy job of analyzing the job rule */
2563 s = pool->solvables + r->p;
2564 printf("- do not install %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2568 s = pool->solvables - r->p;
2569 printf("- do not erase %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2572 else if (why >= solv->systemrules && why < solv->learntrules)
2574 s = pool->solvables + solv->system->start + (why - solv->systemrules);
2575 printf("- allow deinstallation/downgrade of %s-%s.%s [%d]\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), why);
2582 printf("------------------------------------\n");
2587 printdecisions(solv);