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
27 #define REGARD_RECOMMENDS_OF_INSTALLED_ITEMS 0
31 solver_dep_installed(Solver *solv, Id dep)
33 /* disable for now, splitprovides don't work anyway and it breaks
36 Pool *pool = solv->pool;
41 Reldep *rd = GETRELDEP(pool, dep);
42 if (rd->flags == REL_AND)
44 if (!solver_dep_installed(solv, rd->name))
46 return solver_dep_installed(solv, rd->evr);
48 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
49 return solver_dep_installed(solv, rd->evr);
51 FOR_PROVIDES(p, pp, dep)
53 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
61 /* this mirrors solver_dep_fulfilled but uses map m instead of the decisionmap */
63 dep_possible(Solver *solv, Id dep, Map *m)
65 Pool *pool = solv->pool;
70 Reldep *rd = GETRELDEP(pool, dep);
71 if (rd->flags == REL_AND)
73 if (!dep_possible(solv, rd->name, m))
75 return dep_possible(solv, rd->evr, m);
77 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
78 return solver_dep_installed(solv, rd->evr);
80 FOR_PROVIDES(p, pp, dep)
88 /*-----------------------------------------------------------------*/
95 printruleelement(Solver *solv, int type, Rule *r, Id v)
97 Pool *pool = solv->pool;
101 s = pool->solvables + -v;
102 POOL_DEBUG(type, " !%s [%d]", solvable2str(pool, s), -v);
106 s = pool->solvables + v;
107 POOL_DEBUG(type, " %s [%d]", solvable2str(pool, s), v);
112 POOL_DEBUG(type, " (w1)");
114 POOL_DEBUG(type, " (w2)");
116 if (solv->decisionmap[s - pool->solvables] > 0)
117 POOL_DEBUG(type, " Install.level%d", solv->decisionmap[s - pool->solvables]);
118 if (solv->decisionmap[s - pool->solvables] < 0)
119 POOL_DEBUG(type, " Conflict.level%d", -solv->decisionmap[s - pool->solvables]);
120 POOL_DEBUG(type, "\n");
129 printrule(Solver *solv, int type, Rule *r)
131 Pool *pool = solv->pool;
135 if (r >= solv->rules && r < solv->rules + solv->nrules) /* r is a solver rule */
136 POOL_DEBUG(type, "Rule #%d:", (int)(r - solv->rules));
138 POOL_DEBUG(type, "Rule:"); /* r is any rule */
140 POOL_DEBUG(type, " (disabled)");
141 POOL_DEBUG(type, "\n");
145 /* print direct literal */
147 else if (r->d == ID_NULL)
151 /* binary rule --> print w2 as second literal */
155 /* every other which is in d */
156 v = solv->pool->whatprovidesdata[r->d + i - 1];
159 printruleelement(solv, type, r, v);
161 POOL_DEBUG(type, " next rules: %d %d\n", r->n1, r->n2);
165 printruleclass(Solver *solv, int type, Rule *r)
167 Pool *pool = solv->pool;
168 if (r - solv->rules >= solv->learntrules)
169 POOL_DEBUG(type, "LEARNT ");
170 else if (r - solv->rules >= solv->weakrules)
171 POOL_DEBUG(type, "WEAK ");
172 else if (r - solv->rules >= solv->systemrules)
173 POOL_DEBUG(type, "SYSTEM ");
174 else if (r - solv->rules >= solv->jobrules)
175 POOL_DEBUG(type, "JOB ");
176 printrule(solv, type, r);
180 /*-----------------------------------------------------------------*/
186 static Pool *unifyrules_sortcmp_data;
189 * compare rules for unification sort
193 unifyrules_sortcmp(const void *ap, const void *bp)
195 Pool *pool = unifyrules_sortcmp_data;
196 Rule *a = (Rule *)ap;
197 Rule *b = (Rule *)bp;
203 return x; /* p differs */
206 if (a->d == 0 && b->d == 0)
207 return a->w2 - b->w2; /* assertion: return w2 diff */
209 if (a->d == 0) /* a is assertion, b not */
211 x = a->w2 - pool->whatprovidesdata[b->d];
215 if (b->d == 0) /* b is assertion, a not */
217 x = pool->whatprovidesdata[a->d] - b->w2;
221 /* compare whatprovidesdata */
222 ad = pool->whatprovidesdata + a->d;
223 bd = pool->whatprovidesdata + b->d;
225 if ((x = *ad++ - *bd++) != 0)
236 unifyrules(Solver *solv)
238 Pool *pool = solv->pool;
242 if (solv->nrules <= 1) /* nothing to unify */
245 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
247 /* sort rules first */
248 unifyrules_sortcmp_data = solv->pool;
249 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
256 for (i = j = 1, ir = solv->rules + 1; i < solv->nrules; i++, ir++)
258 if (jr && !unifyrules_sortcmp(ir, jr))
259 continue; /* prune! */
260 jr = solv->rules + j++; /* keep! */
265 /* reduced count from nrules to j rules */
266 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
268 /* adapt rule buffer */
270 solv->rules = (Rule *)xrealloc(solv->rules, ((solv->nrules + RULES_BLOCK) & ~RULES_BLOCK) * sizeof(Rule));
271 IF_POOLDEBUG (SAT_DEBUG_STATS)
278 for (i = 1; i < solv->nrules; i++)
285 dp = solv->pool->whatprovidesdata + r->d;
290 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
291 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
293 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
303 hashrule(Solver *solv, Id p, Id d, int n)
305 unsigned int x = (unsigned int)p;
309 return (x * 37) ^ (unsigned int)d;
310 dp = solv->pool->whatprovidesdata + d;
312 x = (x * 37) ^ (unsigned int)*dp++;
320 * p = direct literal; always < 0 for installed rpm rules
321 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
324 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
326 * p < 0 : pkg id of A
327 * d > 0 : Offset in whatprovidesdata (list of providers of b)
329 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
330 * p < 0 : pkg id of A
331 * d < 0 : Id of solvable (e.g. B1)
333 * d == 0: unary rule, assertion => (A) or (-A)
335 * Install: p > 0, d = 0 (A) user requested install
336 * Remove: p < 0, d = 0 (-A) user requested remove
337 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
338 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
339 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
340 * ? p > 0, d < 0 (A|-B)
341 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
345 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
346 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
347 * every other : w1 = p, w2 = whatprovidesdata[d];
348 * Disabled rule: w1 = 0
350 * always returns a rule for non-rpm rules
354 addrule(Solver *solv, Id p, Id d)
356 Pool *pool = solv->pool;
360 int n = 0; /* number of literals in rule - 1
361 0 = direct assertion (single literal)
365 /* it often happenes that requires lead to adding the same rpm rule
366 * multiple times, so we prune those duplicates right away to make
367 * the work for unifyrules a bit easier */
369 if (solv->nrules && !solv->jobrules)
371 r = solv->rules + solv->nrules - 1; /* get the last added rule */
372 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
378 /* always a binary rule */
380 return 0; /* ignore self conflict */
385 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
387 return 0; /* rule is self-fulfilling */
389 d = dp[-1]; /* take single literal */
392 if (n == 0 && !solv->jobrules)
394 /* this is a rpm rule assertion, we do not have to allocate it */
395 /* it can be identified by a level of 1 and a zero reason */
396 /* we must not drop those rules from the decisionq when rewinding! */
398 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
401 if (solv->decisionmap[-p] > 0 || solv->decisionmap[-p] < -1) {
402 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
405 if (solv->decisionmap[-p])
406 return 0; /* already got that one */
407 queue_push(&solv->decisionq, p);
408 queue_push(&solv->decisionq_why, 0);
409 solv->decisionmap[-p] = -1;
414 /* smallest literal first so we can find dups */
418 n = 1; /* re-set n, was used as temp var */
421 /* check if the last added rule is exactly the same as what we're looking for. */
422 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
423 return r; /* binary rule */
425 if (r && n > 1 && r->d && r->p == p)
427 /* Rule where d is an offset in whatprovidesdata */
431 dp2 = pool->whatprovidesdata + r->d;
432 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
443 /* check and extend rule buffer */
444 if ((solv->nrules & RULES_BLOCK) == 0)
446 solv->rules = (Rule *)xrealloc(solv->rules, (solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
449 r = solv->rules + solv->nrules++; /* point to rule space */
454 /* direct assertion, no watch needed */
470 r->w2 = pool->whatprovidesdata[d];
475 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
477 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
478 printrule(solv, SAT_DEBUG_RULE_CREATION, r);
485 disablerule(Solver *solv, Rule *r)
491 enablerule(Solver *solv, Rule *r)
493 if (r->d == 0 || r->w2 != r->p)
496 r->w1 = solv->pool->whatprovidesdata[r->d];
500 /**********************************************************************************/
502 /* a problem is an item on the solver's problem list. It can either be >0, in that
503 * case it is a system (upgrade) rule, or it can be <0, which makes it refer to a job
504 * consisting of multiple job rules.
508 disableproblem(Solver *solv, Id v)
516 disablerule(solv, solv->rules + v);
520 jp = solv->ruletojob.elements;
521 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
523 disablerule(solv, r);
527 enableproblem(Solver *solv, Id v)
535 enablerule(solv, solv->rules + v);
539 jp = solv->ruletojob.elements;
540 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
546 printproblem(Solver *solv, Id v)
548 Pool *pool = solv->pool;
554 printrule(solv, SAT_DEBUG_SOLUTIONS, solv->rules + v);
558 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "JOB %d\n", v);
559 jp = solv->ruletojob.elements;
560 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
563 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "- ");
564 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
566 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "ENDJOB\n");
572 /************************************************************************/
574 /* go through system and job rules and add direct assertions
575 * to the decisionqueue. If we find a conflict, disable rules and
576 * add them to problem queue.
577 * (disablerules is always true for the cases when we get called)
580 makeruledecisions(Solver *solv)
582 Pool *pool = solv->pool;
588 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
590 decisionstart = solv->decisionq.count;
591 /* rpm rules don't have assertions, so we can start with the job
593 for (ri = solv->jobrules, r = solv->rules + ri; ri < solv->nrules; ri++, r++)
595 if (!r->w1 || r->w2) /* disabled or no assertion */
599 if (solv->decisionmap[vv] == 0)
601 queue_push(&solv->decisionq, v);
602 queue_push(&solv->decisionq_why, r - solv->rules);
603 solv->decisionmap[vv] = v > 0 ? 1 : -1;
604 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
606 Solvable *s = solv->pool->solvables + vv;
608 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
610 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
614 if (v > 0 && solv->decisionmap[vv] > 0)
616 if (v < 0 && solv->decisionmap[vv] < 0)
618 /* found a conflict! */
619 if (ri >= solv->learntrules)
621 /* cannot happen, as this would mean that the problem
622 * was not solvable, so we wouldn't have created the
623 * learnt rule at all */
624 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
627 /* if we are weak, just disable ourself */
628 if (ri >= solv->weakrules)
630 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
631 printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
632 disablerule(solv, r);
636 /* only job and system rules left in the decisionq*/
637 /* find the decision which is the "opposite" of the jobrule */
638 for (i = 0; i < solv->decisionq.count; i++)
639 if (solv->decisionq.elements[i] == -v)
641 if (i == solv->decisionq.count) {
642 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
645 if (solv->decisionq_why.elements[i] == 0)
647 /* conflict with rpm rule, need only disable our rule */
648 if (v < 0 && v != -SYSTEMSOLVABLE) {
649 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
653 queue_push(&solv->problems, solv->learnt_pool.count);
654 queue_push(&solv->learnt_pool, ri);
655 queue_push(&solv->learnt_pool, v != -SYSTEMSOLVABLE ? -v : v);
656 queue_push(&solv->learnt_pool, 0);
657 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
658 if (ri < solv->systemrules)
659 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
662 queue_push(&solv->problems, v);
663 disableproblem(solv, v);
664 queue_push(&solv->problems, 0);
668 queue_push(&solv->problems, solv->learnt_pool.count);
669 queue_push(&solv->learnt_pool, ri);
670 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
671 queue_push(&solv->learnt_pool, 0);
673 /* conflict with another job or system rule */
674 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting system/job assertions over literal %d\n", vv);
675 /* push all of our rules asserting this literal on the problem stack */
676 for (i = solv->jobrules, rr = solv->rules + i; i < solv->nrules; i++, rr++)
678 if (!rr->w1 || rr->w2)
680 if (rr->p != vv && rr->p != -vv)
682 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
684 if (i < solv->systemrules)
685 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
686 queue_push(&solv->problems, v);
687 disableproblem(solv, v);
689 queue_push(&solv->problems, 0);
692 while (solv->decisionq.count > decisionstart)
694 v = solv->decisionq.elements[--solv->decisionq.count];
695 --solv->decisionq_why.count;
697 solv->decisionmap[vv] = 0;
699 ri = solv->jobrules - 1;
700 r = solv->rules + ri;
703 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
707 * we have enabled or disabled some of our rules. We now reenable all
708 * of our learnt rules but the ones that were learnt from rules that
712 enabledisablelearntrules(Solver *solv)
714 Pool *pool = solv->pool;
719 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
720 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
722 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
723 while ((why = *whyp++) != 0)
725 if (why < 0 || why >= i) {
726 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
727 abort(); /* cannot reference newer learnt rules */
729 if (!solv->rules[why].w1)
732 /* why != 0: we found a disabled rule, disable the learnt rule */
735 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
737 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling learnt ");
738 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
740 disablerule(solv, r);
742 else if (!why && !r->w1)
744 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
746 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling learnt ");
747 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
755 /* FIXME: bad code ahead, replace as soon as possible */
757 disableupdaterules(Solver *solv, Queue *job, int jobidx)
759 Pool *pool = solv->pool;
761 Id how, what, p, *pp;
767 installed = solv->installed;
773 how = job->elements[jobidx];
776 case SOLVER_INSTALL_SOLVABLE:
777 case SOLVER_ERASE_SOLVABLE:
778 case SOLVER_ERASE_SOLVABLE_NAME:
779 case SOLVER_ERASE_SOLVABLE_PROVIDES:
785 /* go through all enabled job rules */
786 MAPZERO(&solv->noupdate);
787 for (i = solv->jobrules; i < solv->systemrules; i++)
790 if (!r->w1) /* disabled? */
792 j = solv->ruletojob.elements[i - solv->jobrules];
796 how = job->elements[j];
797 what = job->elements[j + 1];
800 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
801 s = pool->solvables + what;
802 FOR_PROVIDES(p, pp, s->name)
804 if (pool->solvables[p].name != s->name)
806 if (pool->solvables[p].repo == installed)
807 MAPSET(&solv->noupdate, p - installed->start);
810 case SOLVER_ERASE_SOLVABLE:
811 s = pool->solvables + what;
812 if (s->repo == installed)
813 MAPSET(&solv->noupdate, what - installed->start);
815 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
816 case SOLVER_ERASE_SOLVABLE_PROVIDES:
817 FOR_PROVIDES(p, pp, what)
819 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
821 if (pool->solvables[p].repo == installed)
822 MAPSET(&solv->noupdate, p - installed->start);
830 /* fixup update rule status */
831 if (solv->allowuninstall)
832 return; /* no update rules at all */
836 /* we just disabled job #jobidx. enable all update rules
837 * that aren't disabled by the remaining job rules */
838 how = job->elements[jobidx];
839 what = job->elements[jobidx + 1];
842 case SOLVER_INSTALL_SOLVABLE:
843 s = pool->solvables + what;
844 FOR_PROVIDES(p, pp, s->name)
846 if (pool->solvables[p].name != s->name)
848 if (pool->solvables[p].repo != installed)
850 if (MAPTST(&solv->noupdate, p - installed->start))
852 r = solv->rules + solv->systemrules + (p - installed->start);
856 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
858 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
859 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
863 case SOLVER_ERASE_SOLVABLE:
864 s = pool->solvables + what;
865 if (s->repo != installed)
867 if (MAPTST(&solv->noupdate, what - installed->start))
869 r = solv->rules + solv->systemrules + (what - installed->start);
873 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
875 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
876 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
879 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
880 case SOLVER_ERASE_SOLVABLE_PROVIDES:
881 FOR_PROVIDES(p, pp, what)
883 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
885 if (pool->solvables[p].repo != installed)
887 if (MAPTST(&solv->noupdate, p - installed->start))
889 r = solv->rules + solv->systemrules + (p - installed->start);
893 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
895 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
896 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
906 for (i = 0; i < installed->nsolvables; i++)
908 r = solv->rules + solv->systemrules + i;
909 if (r->w1 && MAPTST(&solv->noupdate, i))
910 disablerule(solv, r); /* was enabled, need to disable */
916 * add (install) rules for solvable
917 * for unfulfilled requirements, conflicts, obsoletes,....
918 * add a negative assertion for solvables that are not installable
922 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
924 Pool *pool = solv->pool;
925 Repo *installed = solv->installed;
939 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
941 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
942 queue_push(&q, s - pool->solvables); /* push solvable Id */
948 * s: Pointer to solvable
952 if (MAPTST(m, n)) /* continue if already done */
956 s = pool->solvables + n; /* s = Solvable in question */
959 if (installed /* Installed system available */
960 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
961 && s->repo == installed) /* solvable is installed? */
963 dontfix = 1; /* dont care about broken rpm deps */
966 if (!dontfix && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
968 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
969 addrule(solv, -n, 0); /* uninstallable */
972 /*-----------------------------------------
973 * check requires of s
978 reqp = s->repo->idarraydata + s->requires;
979 while ((req = *reqp++) != 0) /* go throw all requires */
981 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
984 dp = pool_whatprovides(pool, req);
986 if (*dp == SYSTEMSOLVABLE) /* always installed */
991 /* the strategy here is to not insist on dependencies
992 * that are already broken. so if we find one provider
993 * that was already installed, we know that the
994 * dependency was not broken before so we enforce it */
995 for (i = 0; (p = dp[i]) != 0; i++) /* for all providers */
997 if (pool->solvables[p].repo == installed)
998 break; /* provider was installed */
1000 if (!p) /* previously broken dependency */
1002 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
1009 /* nothing provides req! */
1010 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
1011 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1015 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
1017 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1018 for (i = 0; dp[i]; i++)
1019 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1022 /* add 'requires' dependency */
1023 /* rule: (-requestor|provider1|provider2|...|providerN) */
1024 addrule(solv, -n, dp - pool->whatprovidesdata);
1026 /* descend the dependency tree */
1027 for (; *dp; dp++) /* loop through all providers */
1029 if (!MAPTST(m, *dp))
1030 queue_push(&q, *dp);
1033 } /* while, requirements of n */
1035 } /* if, requirements */
1037 /* that's all we check for src packages */
1038 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1041 /*-----------------------------------------
1042 * check conflicts of s
1047 conp = s->repo->idarraydata + s->conflicts;
1048 while ((con = *conp++) != 0)
1050 FOR_PROVIDES(p, pp, con)
1052 /* dontfix: dont care about conflicts with already installed packs */
1053 if (dontfix && pool->solvables[p].repo == installed)
1055 /* rule: -n|-p: either solvable _or_ provider of conflict */
1056 addrule(solv, -n, -p);
1061 /*-----------------------------------------
1062 * check obsoletes if not installed
1064 if (!installed || pool->solvables[n].repo != installed)
1065 { /* not installed */
1068 obsp = s->repo->idarraydata + s->obsoletes;
1069 while ((obs = *obsp++) != 0)
1071 FOR_PROVIDES(p, pp, obs)
1072 addrule(solv, -n, -p);
1075 FOR_PROVIDES(p, pp, s->name)
1077 if (s->name == pool->solvables[p].name)
1078 addrule(solv, -n, -p);
1082 /*-----------------------------------------
1083 * add recommends to the rule list
1087 recp = s->repo->idarraydata + s->recommends;
1088 while ((rec = *recp++) != 0)
1090 FOR_PROVIDES(p, pp, rec)
1097 sugp = s->repo->idarraydata + s->suggests;
1098 while ((sug = *sugp++) != 0)
1100 FOR_PROVIDES(p, pp, sug)
1107 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
1111 addrpmrulesforweak(Solver *solv, Map *m)
1113 Pool *pool = solv->pool;
1118 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
1119 for (i = n = 1; n < pool->nsolvables; i++, n++)
1121 if (i == pool->nsolvables)
1125 s = pool->solvables + i;
1126 if (!pool_installable(pool, s))
1131 supp = s->repo->idarraydata + s->supplements;
1132 while ((sup = *supp++) != ID_NULL)
1133 if (dep_possible(solv, sup, m))
1136 if (!sup && s->freshens)
1138 supp = s->repo->idarraydata + s->freshens;
1139 while ((sup = *supp++) != ID_NULL)
1140 if (dep_possible(solv, sup, m))
1143 if (!sup && s->enhances)
1145 supp = s->repo->idarraydata + s->enhances;
1146 while ((sup = *supp++) != ID_NULL)
1147 if (dep_possible(solv, sup, m))
1152 addrpmrulesforsolvable(solv, s, m);
1155 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
1159 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
1161 Pool *pool = solv->pool;
1166 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1168 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1169 policy_findupdatepackages(solv, s, &qs, allowall);
1170 if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
1171 addrpmrulesforsolvable(solv, s, m);
1172 for (i = 0; i < qs.count; i++)
1173 if (!MAPTST(m, qs.elements[i]))
1174 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1177 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
1181 * add rule for update
1182 * (A|A1|A2|A3...) An = update candidates for A
1184 * s = (installed) solvable
1188 addupdaterule(Solver *solv, Solvable *s, int allowall)
1190 /* installed packages get a special upgrade allowed rule */
1191 Pool *pool = solv->pool;
1196 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
1198 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1199 policy_findupdatepackages(solv, s, &qs, allowall);
1200 if (qs.count == 0) /* no updaters found */
1203 d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
1205 addrule(solv, s - pool->solvables, d); /* allow update of s */
1206 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
1210 /*-----------------------------------------------------------------*/
1219 printWatches(Solver *solv, int type)
1221 Pool *pool = solv->pool;
1224 POOL_DEBUG(type, "Watches: \n");
1226 for (counter = -(pool->nsolvables); counter <= pool->nsolvables; counter ++)
1228 POOL_DEBUG(type, " solvable [%d] -- rule [%d]\n", counter, solv->watches[counter+pool->nsolvables]);
1235 * initial setup for all watches
1239 makewatches(Solver *solv)
1243 int nsolvables = solv->pool->nsolvables;
1245 xfree(solv->watches);
1246 /* lower half for removals, upper half for installs */
1247 solv->watches = (Id *)xcalloc(2 * nsolvables, sizeof(Id));
1249 /* do it reverse so rpm rules get triggered first */
1250 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1252 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1255 if (!r->w1 /* rule is disabled */
1256 || !r->w2) /* rule is assertion */
1259 /* see addwatches(solv, r) */
1260 r->n1 = solv->watches[nsolvables + r->w1];
1261 solv->watches[nsolvables + r->w1] = r - solv->rules;
1263 r->n2 = solv->watches[nsolvables + r->w2];
1264 solv->watches[nsolvables + r->w2] = r - solv->rules;
1270 * add watches (for rule)
1274 addwatches(Solver *solv, Rule *r)
1276 int nsolvables = solv->pool->nsolvables;
1278 r->n1 = solv->watches[nsolvables + r->w1];
1279 solv->watches[nsolvables + r->w1] = r - solv->rules;
1281 r->n2 = solv->watches[nsolvables + r->w2];
1282 solv->watches[nsolvables + r->w2] = r - solv->rules;
1286 /*-----------------------------------------------------------------*/
1287 /* rule propagation */
1289 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1294 * propagate decision to all rules
1295 * return : 0 = everything is OK
1296 * watched rule = there is a conflict
1300 propagate(Solver *solv, int level)
1302 Pool *pool = solv->pool;
1307 Id *decisionmap = solv->decisionmap;
1308 Id *watches = solv->watches + pool->nsolvables;
1310 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
1312 while (solv->propagate_index < solv->decisionq.count)
1314 /* negate because our watches trigger if literal goes FALSE */
1315 pkg = -solv->decisionq.elements[solv->propagate_index++];
1316 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1318 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "popagate for decision %d level %d\n", -pkg, level);
1319 printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
1320 printWatches(solv, SAT_DEBUG_SCHUBI);
1323 for (rp = watches + pkg; *rp; rp = nrp)
1325 r = solv->rules + *rp;
1327 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1329 POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
1330 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1335 ow = r->w2; /* regard the second watchpoint to come to a solution */
1340 ow = r->w1; /* regard the first watchpoint to come to a solution */
1343 /* if clause is TRUE, nothing to do */
1344 if (DECISIONMAP_TRUE(ow))
1349 /* not a binary clause, check if we need to move our watch */
1350 /* search for a literal that is not ow and not false */
1351 /* (true is also ok, in that case the rule is fulfilled) */
1352 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1355 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1356 if (p != ow && !DECISIONMAP_TRUE(-p))
1360 /* p is free to watch, move watch to p */
1361 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1364 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1366 POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1380 watches[p] = r - solv->rules;
1384 /* unit clause found, set other watch to TRUE */
1385 if (DECISIONMAP_TRUE(-ow))
1386 return r; /* eek, a conflict! */
1387 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1389 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
1390 printrule(solv, SAT_DEBUG_PROPAGATE, r);
1393 decisionmap[ow] = level;
1395 decisionmap[-ow] = -level;
1396 queue_push(&solv->decisionq, ow);
1397 queue_push(&solv->decisionq_why, r - solv->rules);
1398 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
1400 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1402 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
1404 POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
1408 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
1410 return 0; /* all is well */
1414 /*-----------------------------------------------------------------*/
1423 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *why)
1425 Pool *pool = solv->pool;
1428 Map seen; /* global? */
1431 int num = 0, l1num = 0;
1432 int learnt_why = solv->learnt_pool.count;
1433 Id *decisionmap = solv->decisionmap;
1437 POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
1438 map_init(&seen, pool->nsolvables);
1439 idx = solv->decisionq.count;
1442 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1443 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1444 queue_push(&solv->learnt_pool, c - solv->rules);
1445 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1446 /* go through all literals of the rule */
1458 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1460 vv = v > 0 ? v : -v;
1461 if (MAPTST(&seen, vv))
1463 l = solv->decisionmap[vv];
1468 /* a level 1 literal, mark it for later */
1471 for (j = 0; j < solv->decisionq.count; j++)
1472 if (solv->decisionq.elements[j] == v)
1474 if (j == solv->decisionq.count)
1476 queue_push(&rulq, -(j + 1));
1478 MAPSET(&seen, vv); /* mark for scanning in level 1 phase */
1484 num++; /* need to do this one as well */
1493 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
1498 v = solv->decisionq.elements[--idx];
1499 vv = v > 0 ? v : -v;
1500 if (MAPTST(&seen, vv))
1503 c = solv->rules + solv->decisionq_why.elements[idx];
1508 *pr = -v; /* so that v doesn't get lost */
1510 /* add involved level 1 rules */
1513 POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1517 v = solv->decisionq.elements[--idx];
1518 vv = v > 0 ? v : -v;
1519 if (!MAPTST(&seen, vv))
1521 if (!solv->decisionq_why.elements[idx])
1523 c = solv->rules + solv->decisionq_why.elements[idx];
1524 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1525 printruleclass(solv, SAT_DEBUG_ANALYZE, c);
1526 queue_push(&solv->learnt_pool, c - solv->rules);
1537 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1539 vv = v > 0 ? v : -v;
1540 l = solv->decisionmap[vv];
1541 if (l != 1 && l != -1)
1550 else if (r.count == 1 && r.elements[0] < 0)
1551 *dr = r.elements[0];
1553 *dr = pool_queuetowhatprovides(pool, &r);
1554 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1556 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1557 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
1558 for (i = 0; i < r.count; i++)
1559 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
1562 /* push end marker on learnt reasons stack */
1563 queue_push(&solv->learnt_pool, 0);
1564 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1566 for (i = learnt_why; solv->learnt_pool.elements[i]; i++)
1568 POOL_DEBUG(SAT_DEBUG_ANALYZE, "learnt_why ");
1569 printrule(solv, SAT_DEBUG_ANALYZE, solv->rules + solv->learnt_pool.elements[i]);
1580 * reset the solver decisions to right after the rpm rules.
1581 * called after rules have been enabled/disabled
1585 reset_solver(Solver *solv)
1587 Pool *pool = solv->pool;
1591 enabledisablelearntrules(solv);
1593 /* redo all direct rpm rule decisions */
1594 /* we break at the first decision with a why attached, this is
1595 * either a job/system rule assertion or a propagated decision */
1596 for (i = 0; i < solv->decisionq.count; i++)
1598 v = solv->decisionq.elements[i];
1599 solv->decisionmap[v > 0 ? v : -v] = 0;
1601 for (i = 0; i < solv->decisionq_why.count; i++)
1602 if (solv->decisionq_why.elements[i])
1606 v = solv->decisionq.elements[i];
1607 solv->decisionmap[v > 0 ? v : -v] = v > 0 ? 1 : -1;
1610 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, i);
1612 solv->decisionq_why.count = i;
1613 solv->decisionq.count = i;
1614 solv->recommends_index = -1;
1615 solv->propagate_index = 0;
1617 /* redo all job/system decisions */
1618 makeruledecisions(solv);
1619 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
1620 /* recreate watch chains */
1626 * analyze_unsolvable_rule
1630 analyze_unsolvable_rule(Solver *solv, Rule *r)
1632 Pool *pool = solv->pool;
1634 Id why = r - solv->rules;
1635 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1636 printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
1637 if (solv->learntrules && why >= solv->learntrules)
1639 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1640 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i]);
1643 /* do not add rpm rules to problem */
1644 if (why < solv->jobrules)
1646 /* turn rule into problem */
1647 if (why >= solv->jobrules && why < solv->systemrules)
1648 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1649 /* return if problem already countains our rule */
1650 if (solv->problems.count)
1652 for (i = solv->problems.count - 1; i >= 0; i--)
1653 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1655 else if (solv->problems.elements[i] == why)
1658 queue_push(&solv->problems, why);
1663 * analyze_unsolvable
1665 * return: 1 - disabled some rules, try again
1670 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1672 Pool *pool = solv->pool;
1674 Map seen; /* global to speed things up? */
1677 Id *decisionmap = solv->decisionmap;
1678 int oldproblemcount;
1679 int oldlearntpoolcount;
1682 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1683 oldproblemcount = solv->problems.count;
1684 oldlearntpoolcount = solv->learnt_pool.count;
1686 /* make room for proof index */
1687 /* must update it later, as analyze_unsolvable_rule would confuse
1688 * it with a rule index if we put the real value in already */
1689 queue_push(&solv->problems, 0);
1692 map_init(&seen, pool->nsolvables);
1693 queue_push(&solv->learnt_pool, r - solv->rules);
1694 analyze_unsolvable_rule(solv, r);
1695 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1706 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1708 vv = v > 0 ? v : -v;
1709 l = solv->decisionmap[vv];
1714 idx = solv->decisionq.count;
1717 v = solv->decisionq.elements[--idx];
1718 vv = v > 0 ? v : -v;
1719 if (!MAPTST(&seen, vv))
1721 why = solv->decisionq_why.elements[idx];
1724 /* level 1 and no why, must be an rpm assertion */
1725 IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
1727 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "RPM ");
1728 printruleelement(solv, SAT_DEBUG_UNSOLVABLE, 0, v);
1730 /* this is the only positive rpm assertion */
1731 if (v == SYSTEMSOLVABLE)
1734 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
1737 queue_push(&solv->learnt_pool, v);
1740 r = solv->rules + why;
1741 queue_push(&solv->learnt_pool, why);
1742 analyze_unsolvable_rule(solv, r);
1743 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1754 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1756 vv = v > 0 ? v : -v;
1757 l = solv->decisionmap[vv];
1764 queue_push(&solv->problems, 0); /* mark end of this problem */
1767 if (solv->weakrules != solv->learntrules)
1769 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1771 why = solv->problems.elements[i];
1772 if (why < solv->weakrules || why >= solv->learntrules)
1774 if (!lastweak || lastweak < why)
1780 /* disable last weak rule */
1781 solv->problems.count = oldproblemcount;
1782 solv->learnt_pool.count = oldlearntpoolcount;
1783 r = solv->rules + lastweak;
1784 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling weak ");
1785 printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
1786 disablerule(solv, r);
1792 queue_push(&solv->learnt_pool, 0);
1793 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1797 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1798 disableproblem(solv, solv->problems.elements[i]);
1802 POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1807 /*-----------------------------------------------------------------*/
1808 /* Decision revert */
1812 * revert decision at level
1816 revert(Solver *solv, int level)
1818 Pool *pool = solv->pool;
1820 while (solv->decisionq.count)
1822 v = solv->decisionq.elements[solv->decisionq.count - 1];
1823 vv = v > 0 ? v : -v;
1824 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1826 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1827 solv->decisionmap[vv] = 0;
1828 solv->decisionq.count--;
1829 solv->decisionq_why.count--;
1830 solv->propagate_index = solv->decisionq.count;
1832 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1834 solv->branches.count--;
1835 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1836 solv->branches.count--;
1838 solv->recommends_index = -1;
1843 * watch2onhighest - put watch2 on literal with highest level
1847 watch2onhighest(Solver *solv, Rule *r)
1853 return; /* binary rule, both watches are set */
1854 dp = solv->pool->whatprovidesdata + r->d;
1855 while ((v = *dp++) != 0)
1857 l = solv->decisionmap[v < 0 ? -v : v];
1872 * add free decision to decision q, increase level
1873 * propagate decision, return if no conflict.
1874 * in conflict case, analyze conflict rule, add resulting
1875 * rule to learnt rule set, make decision from learnt
1876 * rule (always unit) and re-propagate.
1880 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1882 Pool *pool = solv->pool;
1891 solv->decisionmap[decision] = level;
1893 solv->decisionmap[-decision] = -level;
1894 queue_push(&solv->decisionq, decision);
1895 queue_push(&solv->decisionq_why, 0);
1899 r = propagate(solv, level);
1903 return analyze_unsolvable(solv, r, disablerules);
1904 POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1905 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1906 if (l >= level || l <= 0) {
1907 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
1910 POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
1912 revert(solv, level);
1913 r = addrule(solv, p, d); /* p requires d */
1915 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
1918 if (solv->learnt_why.count != (r - solv->rules) - solv->learntrules) {
1919 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
1922 queue_push(&solv->learnt_why, why);
1925 /* at least 2 literals, needs watches */
1926 watch2onhighest(solv, r);
1927 addwatches(solv, r);
1929 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1930 queue_push(&solv->decisionq, p);
1931 queue_push(&solv->decisionq_why, r - solv->rules);
1932 IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
1934 POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
1935 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
1936 POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
1937 printrule(solv, SAT_DEBUG_ANALYZE, r);
1945 * install best package from the queue. We add an extra package, inst, if
1946 * provided. See comment in weak install section.
1949 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
1951 Pool *pool = solv->pool;
1955 if (dq->count > 1 || inst)
1956 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
1961 /* choose the supplemented one */
1962 for (i = 0; i < dq->count; i++)
1963 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1967 for (i = 1; i < dq->count; i++)
1968 queue_push(&solv->branches, dq->elements[i]);
1969 queue_push(&solv->branches, -level);
1973 p = dq->elements[i];
1975 POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
1977 return setpropagatelearn(solv, level, p, disablerules);
1981 /*-----------------------------------------------------------------*/
1982 /* Main solver interface */
1987 * create solver structure
1989 * pool: all available solvables
1990 * installed: installed Solvables
1993 * Upon solving, rules are created to flag the Solvables
1994 * of the 'installed' Repo as installed.
1998 solver_create(Pool *pool, Repo *installed)
2001 solv = (Solver *)xcalloc(1, sizeof(Solver));
2003 solv->installed = installed;
2005 queue_init(&solv->ruletojob);
2006 queue_init(&solv->decisionq);
2007 queue_init(&solv->decisionq_why);
2008 queue_init(&solv->problems);
2009 queue_init(&solv->suggestions);
2010 queue_init(&solv->learnt_why);
2011 queue_init(&solv->learnt_pool);
2012 queue_init(&solv->branches);
2014 map_init(&solv->recommendsmap, pool->nsolvables);
2015 map_init(&solv->suggestsmap, pool->nsolvables);
2016 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
2017 solv->recommends_index = 0;
2019 solv->decisionmap = (Id *)xcalloc(pool->nsolvables, sizeof(Id));
2020 solv->rules = (Rule *)xmalloc((solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
2021 memset(solv->rules, 0, sizeof(Rule));
2033 solver_free(Solver *solv)
2035 queue_free(&solv->ruletojob);
2036 queue_free(&solv->decisionq);
2037 queue_free(&solv->decisionq_why);
2038 queue_free(&solv->learnt_why);
2039 queue_free(&solv->learnt_pool);
2040 queue_free(&solv->problems);
2041 queue_free(&solv->suggestions);
2042 queue_free(&solv->branches);
2044 map_free(&solv->recommendsmap);
2045 map_free(&solv->suggestsmap);
2046 map_free(&solv->noupdate);
2047 xfree(solv->decisionmap);
2049 xfree(solv->watches);
2050 xfree(solv->weaksystemrules);
2051 xfree(solv->obsoletes);
2052 xfree(solv->obsoletes_data);
2057 /*-------------------------------------------------------*/
2062 * all rules have been set up, now actually run the solver
2067 run_solver(Solver *solv, int disablerules, int doweak)
2075 Pool *pool = solv->pool;
2078 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
2080 POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2081 for (i = 0; i < solv->nrules; i++)
2082 printrule(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
2085 /* create watches chains */
2088 POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
2090 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2091 printdecisions(solv);
2093 /* start SAT algorithm */
2095 systemlevel = level + 1;
2096 POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
2107 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2108 if ((r = propagate(solv, level)) != 0)
2110 if (analyze_unsolvable(solv, r, disablerules))
2118 * installed packages
2121 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2123 if (!solv->updatesystem)
2125 /* try to keep as many packages as possible */
2126 POOL_DEBUG(SAT_DEBUG_STATS, "installing system packages\n");
2127 for (i = solv->installed->start, n = 0; ; i++)
2129 if (n == solv->installed->nsolvables)
2131 if (i == solv->installed->end)
2132 i = solv->installed->start;
2133 s = pool->solvables + i;
2134 if (s->repo != solv->installed)
2137 if (solv->decisionmap[i] != 0)
2139 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
2141 level = setpropagatelearn(solv, level, i, disablerules);
2147 if (level <= olevel)
2151 if (solv->weaksystemrules)
2153 POOL_DEBUG(SAT_DEBUG_STATS, "installing weak system packages\n");
2154 for (i = solv->installed->start; i < solv->installed->end; i++)
2156 if (pool->solvables[i].repo != solv->installed)
2158 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
2160 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2161 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2164 if (solv->weaksystemrules[i - solv->installed->start])
2166 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
2167 while ((p = *dp++) != 0)
2169 if (solv->decisionmap[p] > 0)
2171 if (solv->decisionmap[p] == 0)
2175 continue; /* update package already installed */
2177 if (!dq.count && solv->decisionmap[i] != 0)
2180 /* FIXME: i is handled a bit different because we do not want
2181 * to have it pruned just because it is not recommened.
2182 * we should not prune installed packages instead */
2183 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2189 if (level <= olevel)
2192 if (i < solv->installed->end)
2195 systemlevel = level;
2202 POOL_DEBUG(SAT_DEBUG_STATS, "deciding unresolved rules\n");
2203 for (i = 1, n = 1; ; i++, n++)
2205 if (n == solv->nrules)
2207 if (i == solv->nrules)
2209 r = solv->rules + i;
2215 /* binary or unary rule */
2216 /* need two positive undecided literals */
2217 if (r->p < 0 || r->w2 <= 0)
2219 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2221 queue_push(&dq, r->p);
2222 queue_push(&dq, r->w2);
2227 * all negative literals are installed
2228 * no positive literal is installed
2229 * i.e. the rule is not fulfilled and we
2230 * just need to decide on the positive literals
2234 if (solv->decisionmap[-r->p] <= 0)
2239 if (solv->decisionmap[r->p] > 0)
2241 if (solv->decisionmap[r->p] == 0)
2242 queue_push(&dq, r->p);
2244 dp = pool->whatprovidesdata + r->d;
2245 while ((p = *dp++) != 0)
2249 if (solv->decisionmap[-p] <= 0)
2254 if (solv->decisionmap[p] > 0)
2256 if (solv->decisionmap[p] == 0)
2265 /* cannot happen as this means that
2266 * the rule is unit */
2267 printrule(solv, SAT_FATAL, r);
2268 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
2271 IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
2273 POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
2274 printrule(solv, SAT_DEBUG_PROPAGATE, r);
2278 level = selectandinstall(solv, level, &dq, 0, disablerules);
2284 if (level < systemlevel)
2287 } /* for(), decide */
2289 if (n != solv->nrules) /* continue if level < systemlevel */
2292 if (doweak && !solv->problems.count)
2296 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
2297 if (!REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2299 for (i = 0; i < solv->decisionq.count; i++)
2301 p = solv->decisionq.elements[i];
2302 if (p > 0 && pool->solvables[p].repo == solv->installed)
2303 solv->decisionmap[p] = -solv->decisionmap[p];
2307 for (i = 1; i < pool->nsolvables; i++)
2309 if (solv->decisionmap[i] < 0)
2311 if (solv->decisionmap[i] > 0)
2313 Id *recp, rec, *pp, p;
2314 s = pool->solvables + i;
2315 /* installed, check for recommends */
2316 /* XXX need to special case AND ? */
2319 recp = s->repo->idarraydata + s->recommends;
2320 while ((rec = *recp++) != 0)
2323 FOR_PROVIDES(p, pp, rec)
2325 if (solv->decisionmap[p] > 0)
2330 else if (solv->decisionmap[p] == 0)
2332 queue_pushunique(&dq, p);
2340 s = pool->solvables + i;
2341 if (!s->supplements && !s->freshens)
2343 if (!pool_installable(pool, s))
2345 if (solver_is_supplementing(solv, s))
2346 queue_pushunique(&dq, i);
2349 if (!REGARD_RECOMMENDS_OF_INSTALLED_ITEMS)
2351 for (i = 0; i < solv->decisionq.count; i++)
2353 p = solv->decisionq.elements[i];
2354 if (p > 0 && pool->solvables[p].repo == solv->installed)
2355 solv->decisionmap[p] = -solv->decisionmap[p];
2361 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2363 POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2364 level = setpropagatelearn(solv, level, p, 0);
2369 if (solv->solution_callback)
2371 solv->solution_callback(solv, solv->solution_callback_data);
2372 if (solv->branches.count)
2374 int i = solv->branches.count - 1;
2375 int l = -solv->branches.elements[i];
2377 if (solv->branches.elements[i - 1] < 0)
2379 p = solv->branches.elements[i];
2380 POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
2382 for (j = i + 1; j < solv->branches.count; j++)
2383 queue_push(&dq, solv->branches.elements[j]);
2384 solv->branches.count = i;
2386 revert(solv, level);
2388 for (j = 0; j < dq.count; j++)
2389 queue_push(&solv->branches, dq.elements[j]);
2391 level = setpropagatelearn(solv, level, p, disablerules);
2399 /* all branches done, we're finally finished */
2403 /* minimization step */
2404 if (solv->branches.count)
2406 int l = 0, lasti = -1, lastl = -1;
2408 for (i = solv->branches.count - 1; i >= 0; i--)
2410 p = solv->branches.elements[i];
2413 else if (p > 0 && solv->decisionmap[p] > l + 1)
2421 /* kill old solvable so that we do not loop */
2422 p = solv->branches.elements[lasti];
2423 solv->branches.elements[lasti] = 0;
2424 POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
2427 revert(solv, level);
2429 level = setpropagatelearn(solv, level, p, disablerules);
2446 * at this point, all rules that led to conflicts are disabled.
2447 * we re-enable all rules of a problem set but rule "sug", then
2448 * continue to disable more rules until there as again a solution.
2451 /* FIXME: think about conflicting assertions */
2454 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2456 Pool *pool = solv->pool;
2463 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2465 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
2466 for (i = 0; problem[i]; i++)
2468 if (problem[i] == sug)
2469 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
2470 printproblem(solv, problem[i]);
2473 queue_init(&disabled);
2474 queue_empty(refined);
2475 queue_push(refined, sug);
2477 /* re-enable all problem rules with the exception of "sug" */
2481 for (i = 0; problem[i]; i++)
2482 if (problem[i] != sug)
2483 enableproblem(solv, problem[i]);
2486 disableupdaterules(solv, job, -(sug + 1));
2490 /* re-enable as many weak rules as possible */
2491 for (i = solv->weakrules; i < solv->learntrules; i++)
2493 r = solv->rules + i;
2495 enablerule(solv, r);
2498 queue_empty(&solv->problems);
2499 revert(solv, 1); /* XXX move to reset_solver? */
2502 run_solver(solv, 0, 0);
2503 if (!solv->problems.count)
2505 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
2506 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2507 printdecisions(solv);
2508 break; /* great, no more problems */
2510 disabledcnt = disabled.count;
2511 /* skip over proof index */
2512 for (i = 1; i < solv->problems.count - 1; i++)
2514 /* ignore solutions in refined */
2515 v = solv->problems.elements[i];
2517 break; /* end of problem reached */
2518 for (j = 0; problem[j]; j++)
2519 if (problem[j] != sug && problem[j] == v)
2523 queue_push(&disabled, v);
2525 if (disabled.count == disabledcnt)
2527 /* no solution found, this was an invalid suggestion! */
2528 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
2532 if (disabled.count == disabledcnt + 1)
2534 /* just one suggestion, add it to refined list */
2535 v = disabled.elements[disabledcnt];
2536 queue_push(refined, v);
2537 disableproblem(solv, v);
2539 disableupdaterules(solv, job, -(v + 1));
2543 /* more than one solution, disable all */
2544 /* do not push anything on refine list */
2545 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
2547 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
2548 for (i = disabledcnt; i < disabled.count; i++)
2549 printproblem(solv, disabled.elements[i]);
2551 for (i = disabledcnt; i < disabled.count; i++)
2552 disableproblem(solv, disabled.elements[i]);
2555 /* all done, get us back into the same state as before */
2556 /* enable refined rules again */
2557 for (i = 0; i < disabled.count; i++)
2558 enableproblem(solv, disabled.elements[i]);
2559 /* disable problem rules again */
2560 for (i = 0; problem[i]; i++)
2561 disableproblem(solv, problem[i]);
2562 disableupdaterules(solv, job, -1);
2563 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
2567 problems_to_solutions(Solver *solv, Queue *job)
2569 Pool *pool = solv->pool;
2577 if (!solv->problems.count)
2579 queue_clone(&problems, &solv->problems);
2580 queue_init(&solution);
2581 queue_init(&solutions);
2582 /* copy over proof index */
2583 queue_push(&solutions, problems.elements[0]);
2584 problem = problems.elements + 1;
2585 for (i = 1; i < problems.count; i++)
2587 Id v = problems.elements[i];
2590 /* mark end of this problem */
2591 queue_push(&solutions, 0);
2592 queue_push(&solutions, 0);
2593 if (i + 1 == problems.count)
2595 /* copy over proof of next problem */
2596 queue_push(&solutions, problems.elements[i + 1]);
2598 problem = problems.elements + i + 1;
2601 refine_suggestion(solv, job, problem, v, &solution);
2602 if (!solution.count)
2603 continue; /* this solution didn't work out */
2605 for (j = 0; j < solution.count; j++)
2607 why = solution.elements[j];
2609 printproblem(solv, why);
2613 queue_push(&solutions, 0);
2614 queue_push(&solutions, -why);
2616 else if (why >= solv->systemrules && why < solv->weakrules)
2619 p = solv->installed->start + (why - solv->systemrules);
2620 if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
2622 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
2625 if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
2627 if (solv->decisionmap[*dp] > 0)
2634 queue_push(&solutions, p);
2635 queue_push(&solutions, rp);
2638 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
2642 /* mark end of this solution */
2643 queue_push(&solutions, 0);
2644 queue_push(&solutions, 0);
2646 queue_free(&solution);
2647 queue_free(&problems);
2648 /* copy queue over to solutions */
2649 queue_free(&solv->problems);
2650 queue_clone(&solv->problems, &solutions);
2652 /* bring solver back into problem state */
2653 revert(solv, 1); /* XXX move to reset_solver? */
2656 if (solv->problems.count != solutions.count) {
2657 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
2660 queue_free(&solutions);
2664 solver_next_problem(Solver *solv, Id problem)
2668 return solv->problems.count ? 1 : 0;
2669 pp = solv->problems.elements + problem;
2670 while (pp[0] || pp[1])
2674 while (pp[0] || pp[1])
2679 problem = pp - solv->problems.elements;
2680 if (problem >= solv->problems.count)
2686 solver_next_solution(Solver *solv, Id problem, Id solution)
2692 pp = solv->problems.elements + solution;
2693 return pp[0] || pp[1] ? solution : 0;
2695 pp = solv->problems.elements + solution;
2696 while (pp[0] || pp[1])
2699 solution = pp - solv->problems.elements;
2700 return pp[0] || pp[1] ? solution : 0;
2704 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
2707 element = element ? element + 2 : solution;
2708 pp = solv->problems.elements + element;
2709 if (!(pp[0] || pp[1]))
2718 * create obsoletesmap from solver decisions
2719 * required for decision handling
2723 create_obsoletesmap(Solver *solv)
2725 Pool *pool = solv->pool;
2726 Repo *installed = solv->installed;
2727 Id p, *obsoletesmap = NULL;
2731 obsoletesmap = (Id *)xcalloc(pool->nsolvables, sizeof(Id));
2734 for (i = 0; i < solv->decisionq.count; i++)
2738 n = solv->decisionq.elements[i];
2741 if (n == SYSTEMSOLVABLE)
2743 s = pool->solvables + n;
2744 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2746 FOR_PROVIDES(p, pp, s->name)
2747 if (s->name == pool->solvables[p].name)
2749 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2751 obsoletesmap[p] = n;
2756 for (i = 0; i < solv->decisionq.count; i++)
2761 n = solv->decisionq.elements[i];
2764 if (n == SYSTEMSOLVABLE)
2766 s = pool->solvables + n;
2767 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2771 obsp = s->repo->idarraydata + s->obsoletes;
2772 while ((obs = *obsp++) != 0)
2773 FOR_PROVIDES(p, pp, obs)
2775 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2777 obsoletesmap[p] = n;
2783 return obsoletesmap;
2792 printdecisions(Solver *solv)
2794 Pool *pool = solv->pool;
2795 Repo *installed = solv->installed;
2796 Id p, *obsoletesmap = create_obsoletesmap( solv );
2800 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
2802 /* print solvables to be erased */
2806 FOR_REPO_SOLVABLES(installed, p, s)
2808 if (solv->decisionmap[p] >= 0)
2810 if (obsoletesmap[p])
2812 POOL_DEBUG(SAT_DEBUG_RESULT, "erase %s\n", solvable2str(pool, s));
2816 /* print solvables to be installed */
2818 for (i = 0; i < solv->decisionq.count; i++)
2821 p = solv->decisionq.elements[i];
2824 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
2827 s = pool->solvables + p;
2828 POOL_DEBUG(SAT_DEBUG_SCHUBI, "level of %s is %d\n", solvable2str(pool, s), p);
2832 if (p == SYSTEMSOLVABLE)
2834 POOL_DEBUG(SAT_DEBUG_SCHUBI, "SYSTEMSOLVABLE\n");
2837 s = pool->solvables + p;
2838 if (installed && s->repo == installed)
2841 if (!obsoletesmap[p])
2843 POOL_DEBUG(SAT_DEBUG_RESULT, "install %s", solvable2str(pool, s));
2847 POOL_DEBUG(SAT_DEBUG_RESULT, "update %s", solvable2str(pool, s));
2848 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
2849 for (j = installed->start; j < installed->end; j++)
2850 if (obsoletesmap[j] == p)
2851 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
2852 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
2854 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
2857 xfree(obsoletesmap);
2859 if (solv->suggestions.count)
2861 POOL_DEBUG(SAT_DEBUG_RESULT, "\nsuggested packages:\n");
2862 for (i = 0; i < solv->suggestions.count; i++)
2864 s = pool->solvables + solv->suggestions.elements[i];
2865 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
2868 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
2871 /* this is basically the reverse of addrpmrulesforsolvable */
2873 solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
2875 Pool *pool = solv->pool;
2876 Repo *installed = solv->installed;
2880 Id p, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
2882 if (rid >= solv->weakrules) {
2883 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
2886 if (rid >= solv->systemrules)
2889 *sourcep = solv->installed->start + (rid - solv->systemrules);
2891 return SOLVER_PROBLEM_UPDATE_RULE;
2893 if (rid >= solv->jobrules)
2896 r = solv->rules + rid;
2897 p = solv->ruletojob.elements[rid - solv->jobrules];
2898 *depp = job->elements[p + 1];
2900 *targetp = job->elements[p];
2901 if (r->d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE)
2902 return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
2903 return SOLVER_PROBLEM_JOB_RULE;
2907 /* a rpm rule assertion */
2908 if (rid == -SYSTEMSOLVABLE) {
2909 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
2910 abort(); /* can happen only for job rules */
2912 s = pool->solvables - rid;
2913 if (installed && !solv->fixsystem && s->repo == installed)
2915 if (dontfix) { /* dontfix packages never have a neg assertion */
2916 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
2919 /* see why the package is not installable */
2920 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
2921 return SOLVER_PROBLEM_NOT_INSTALLABLE;
2922 /* check requires */
2924 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
2927 reqp = s->repo->idarraydata + s->requires;
2928 while ((req = *reqp++) != 0)
2930 if (req == SOLVABLE_PREREQMARKER)
2932 dp = pool_whatprovides(pool, req);
2938 return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
2941 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
2944 r = solv->rules + rid;
2946 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
2947 abort(); /* not a rpm rule */
2949 if (r->d == 0 && r->w2 == 0)
2951 /* an assertion. we don't store them as rpm rules, so
2953 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
2956 s = pool->solvables - r->p;
2957 if (installed && !solv->fixsystem && s->repo == installed)
2959 if (r->d == 0 && r->w2 < 0)
2961 /* a package conflict */
2962 Solvable *s2 = pool->solvables - r->w2;
2965 if (installed && !solv->fixsystem && s2->repo == installed)
2968 /* if both packages have the same name and at least one of them
2969 * is not installed, they conflict */
2970 if (s->name == s2->name && (!installed || (s->repo != installed || s2->repo != installed)))
2975 return SOLVER_PROBLEM_SAME_NAME;
2978 /* check conflicts in both directions */
2981 conp = s->repo->idarraydata + s->conflicts;
2982 while ((con = *conp++) != 0)
2984 FOR_PROVIDES(p, pp, con)
2986 if (dontfix && pool->solvables[p].repo == installed)
2993 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
2999 conp = s2->repo->idarraydata + s2->conflicts;
3000 while ((con = *conp++) != 0)
3002 FOR_PROVIDES(p, pp, con)
3004 if (dontfix2 && pool->solvables[p].repo == installed)
3011 return SOLVER_PROBLEM_PACKAGE_CONFLICT;
3015 /* check obsoletes in both directions */
3016 if ((!installed || s->repo != installed) && s->obsoletes)
3018 obsp = s->repo->idarraydata + s->obsoletes;
3019 while ((obs = *obsp++) != 0)
3021 FOR_PROVIDES(p, pp, obs)
3028 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3032 if ((!installed || s2->repo != installed) && s2->obsoletes)
3034 obsp = s2->repo->idarraydata + s2->obsoletes;
3035 while ((obs = *obsp++) != 0)
3037 FOR_PROVIDES(p, pp, obs)
3044 return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
3048 /* all cases checked, can't happen */
3049 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
3052 /* simple requires */
3054 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
3057 reqp = s->repo->idarraydata + s->requires;
3058 while ((req = *reqp++) != 0)
3060 if (req == SOLVABLE_PREREQMARKER)
3062 dp = pool_whatprovides(pool, req);
3065 if (*dp == r->w2 && dp[1] == 0)
3068 else if (dp - pool->whatprovidesdata == r->d)
3072 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
3078 return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
3082 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
3085 Id lreqr, lconr, lsysr, ljobr;
3089 lreqr = lconr = lsysr = ljobr = 0;
3090 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
3092 if (rid >= solv->learntrules)
3093 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
3094 else if (rid >= solv->systemrules)
3099 else if (rid >= solv->jobrules)
3106 r = solv->rules + rid;
3107 if (!r->d && r->w2 < 0)
3120 /* assertion, counts as require rule */
3121 /* ignore system solvable as we need useful info */
3122 if (rid == -SYSTEMSOLVABLE)
3124 if (!*reqrp || !reqassert)
3131 if (!*reqrp && lreqr)
3133 if (!*conrp && lconr)
3135 if (!*jobrp && ljobr)
3137 if (!*sysrp && lsysr)
3142 solver_findproblemrule(Solver *solv, Id problem)
3144 Id reqr, conr, sysr, jobr;
3145 Id idx = solv->problems.elements[problem - 1];
3146 reqr = conr = sysr = jobr = 0;
3147 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
3156 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
3161 printprobleminfo(Solver *solv, Queue *job, Id problem)
3163 Pool *pool = solv->pool;
3165 Id dep, source, target;
3168 probr = solver_findproblemrule(solv, problem);
3169 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
3171 case SOLVER_PROBLEM_UPDATE_RULE:
3172 s = pool_id2solvable(pool, source);
3173 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
3175 case SOLVER_PROBLEM_JOB_RULE:
3176 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
3178 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
3179 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
3181 case SOLVER_PROBLEM_NOT_INSTALLABLE:
3182 s = pool_id2solvable(pool, source);
3183 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
3185 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
3186 s = pool_id2solvable(pool, source);
3187 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
3189 case SOLVER_PROBLEM_SAME_NAME:
3190 s = pool_id2solvable(pool, source);
3191 s2 = pool_id2solvable(pool, target);
3192 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
3194 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
3195 s = pool_id2solvable(pool, source);
3196 s2 = pool_id2solvable(pool, target);
3197 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3199 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
3200 s = pool_id2solvable(pool, source);
3201 s2 = pool_id2solvable(pool, target);
3202 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
3204 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
3205 s = pool_id2solvable(pool, source);
3206 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
3212 printsolutions(Solver *solv, Queue *job)
3214 Pool *pool = solv->pool;
3217 Id problem, solution, element;
3220 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
3223 while ((problem = solver_next_problem(solv, problem)) != 0)
3225 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
3226 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
3227 printprobleminfo(solv, job, problem);
3228 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3230 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
3233 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
3237 /* job, rp is index into job queue */
3238 what = job->elements[rp];
3239 switch (job->elements[rp - 1])
3241 case SOLVER_INSTALL_SOLVABLE:
3242 s = pool->solvables + what;
3243 if (solv->installed && s->repo == solv->installed)
3244 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, s));
3246 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solvable2str(pool, s));
3248 case SOLVER_ERASE_SOLVABLE:
3249 s = pool->solvables + what;
3250 if (solv->installed && s->repo == solv->installed)
3251 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solvable2str(pool, s));
3253 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, s));
3255 case SOLVER_INSTALL_SOLVABLE_NAME:
3256 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", id2str(pool, what));
3258 case SOLVER_ERASE_SOLVABLE_NAME:
3259 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", id2str(pool, what));
3261 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3262 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable providing %s\n", dep2str(pool, what));
3264 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3265 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables providing %s\n", dep2str(pool, what));
3267 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3268 s = pool->solvables + what;
3269 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solvable2str(pool, s));
3272 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
3278 /* policy, replace p with rp */
3279 s = pool->solvables + p;
3280 sd = rp ? pool->solvables + rp : 0;
3284 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
3286 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3289 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(pool, s, sd))
3291 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3294 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(pool, s, sd))
3297 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change from '%s' (%s) to '%s' (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), id2str(pool, sd->vendor), solvable2str(pool, sd));
3299 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change from '%s' (%s) to no vendor (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), solvable2str(pool, sd));
3303 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3307 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
3312 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
3318 /* for each installed solvable find which packages with *different* names
3319 * obsolete the solvable.
3320 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3324 create_obsolete_index(Solver *solv)
3326 Pool *pool = solv->pool;
3328 Repo *installed = solv->installed;
3329 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3332 if (!installed || !installed->nsolvables)
3334 /* create reverse obsoletes map for installed solvables */
3335 solv->obsoletes = obsoletes = xcalloc(installed->end - installed->start, sizeof(Id));
3336 for (i = 1; i < pool->nsolvables; i++)
3338 s = pool->solvables + i;
3339 if (s->repo == installed)
3343 if (!pool_installable(pool, s))
3345 obsp = s->repo->idarraydata + s->obsoletes;
3346 while ((obs = *obsp++) != 0)
3347 FOR_PROVIDES(p, pp, obs)
3349 if (pool->solvables[p].repo != installed)
3351 if (pool->solvables[p].name == s->name)
3353 obsoletes[p - installed->start]++;
3357 for (i = 0; i < installed->nsolvables; i++)
3360 n += obsoletes[i] + 1;
3363 solv->obsoletes_data = obsoletes_data = xcalloc(n + 1, sizeof(Id));
3364 POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
3365 for (i = pool->nsolvables - 1; i > 0; i--)
3367 s = pool->solvables + i;
3368 if (s->repo == installed)
3372 if (!pool_installable(pool, s))
3374 obsp = s->repo->idarraydata + s->obsoletes;
3375 while ((obs = *obsp++) != 0)
3376 FOR_PROVIDES(p, pp, obs)
3378 if (pool->solvables[p].repo != installed)
3380 if (pool->solvables[p].name == s->name)
3382 p -= installed->start;
3383 if (obsoletes_data[obsoletes[p]] != i)
3384 obsoletes_data[--obsoletes[p]] = i;
3390 /*-----------------------------------------------------------------*/
3400 solver_solve(Solver *solv, Queue *job)
3402 Pool *pool = solv->pool;
3403 Repo *installed = solv->installed;
3406 Map addedmap; /* '1' == have rpm-rules for solvable */
3407 Id how, what, p, *pp, d;
3411 /* create whatprovides if not already there */
3412 if (!pool->whatprovides)
3413 pool_createwhatprovides(pool);
3415 /* create obsolete index if needed */
3416 if (solv->noupdateprovide)
3417 create_obsolete_index(solv);
3420 * create basic rule set of all involved packages
3421 * use addedmap bitmap to make sure we don't create rules twice
3425 map_init(&addedmap, pool->nsolvables);
3429 * always install our system solvable
3431 MAPSET(&addedmap, SYSTEMSOLVABLE);
3432 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3433 queue_push(&solv->decisionq_why, 0);
3434 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3437 * create rules for all package that could be involved with the solving
3438 * so called: rpm rules
3443 oldnrules = solv->nrules;
3444 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
3445 FOR_REPO_SOLVABLES(installed, p, s)
3446 addrpmrulesforsolvable(solv, s, &addedmap);
3447 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3448 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
3449 oldnrules = solv->nrules;
3450 FOR_REPO_SOLVABLES(installed, p, s)
3451 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3452 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3455 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
3456 oldnrules = solv->nrules;
3457 for (i = 0; i < job->count; i += 2)
3459 how = job->elements[i];
3460 what = job->elements[i + 1];
3464 case SOLVER_INSTALL_SOLVABLE:
3465 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3467 case SOLVER_INSTALL_SOLVABLE_NAME:
3468 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3469 FOR_PROVIDES(p, pp, what)
3471 /* if by name, ensure that the name matches */
3472 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3474 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3477 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3478 /* dont allow downgrade */
3479 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3483 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3485 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
3487 oldnrules = solv->nrules;
3488 addrpmrulesforweak(solv, &addedmap);
3489 POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3491 IF_POOLDEBUG (SAT_DEBUG_STATS)
3493 int possible = 0, installable = 0;
3494 for (i = 1; i < pool->nsolvables; i++)
3496 if (pool_installable(pool, pool->solvables + i))
3498 if (MAPTST(&addedmap, i))
3501 POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving (rules has been generated for)\n", possible, installable);
3505 * first pass done, we now have all the rpm rules we need.
3506 * unify existing rules before going over all job rules and
3508 * at this point the system is always solvable,
3509 * as an empty system (remove all packages) is a valid solution
3512 unifyrules(solv); /* remove duplicate rpm rules */
3514 POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
3515 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
3516 printdecisions (solv);
3519 * now add all job rules
3522 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
3524 solv->jobrules = solv->nrules;
3526 for (i = 0; i < job->count; i += 2)
3528 oldnrules = solv->nrules;
3530 how = job->elements[i];
3531 what = job->elements[i + 1];
3534 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3535 s = pool->solvables + what;
3536 POOL_DEBUG(SAT_DEBUG_JOB, "job: install solvable %s\n", solvable2str(pool, s));
3537 addrule(solv, what, 0); /* install by Id */
3538 queue_push(&solv->ruletojob, i);
3540 case SOLVER_ERASE_SOLVABLE:
3541 s = pool->solvables + what;
3542 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase solvable %s\n", solvable2str(pool, s));
3543 addrule(solv, -what, 0); /* remove by Id */
3544 queue_push(&solv->ruletojob, i);
3546 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3547 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3548 if (how == SOLVER_INSTALL_SOLVABLE_NAME)
3549 POOL_DEBUG(SAT_DEBUG_JOB, "job: install name %s\n", id2str(pool, what));
3550 if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3551 POOL_DEBUG(SAT_DEBUG_JOB, "job: install provides %s\n", dep2str(pool, what));
3553 FOR_PROVIDES(p, pp, what)
3555 /* if by name, ensure that the name matches */
3556 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3562 /* no provider, make this an impossible rule */
3563 queue_push(&q, -SYSTEMSOLVABLE);
3566 p = queue_shift(&q); /* get first provider */
3568 d = 0; /* single provider ? -> make assertion */
3570 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3571 addrule(solv, p, d); /* add 'requires' rule */
3572 queue_push(&solv->ruletojob, i);
3574 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3575 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3576 if (how == SOLVER_ERASE_SOLVABLE_NAME)
3577 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase name %s\n", id2str(pool, what));
3578 if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3579 POOL_DEBUG(SAT_DEBUG_JOB, "job: erase provides %s\n", dep2str(pool, what));
3580 FOR_PROVIDES(p, pp, what)
3582 /* if by name, ensure that the name matches */
3583 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
3585 addrule(solv, -p, 0); /* add 'remove' rule */
3586 queue_push(&solv->ruletojob, i);
3589 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3590 s = pool->solvables + what;
3591 POOL_DEBUG(SAT_DEBUG_JOB, "job: update %s\n", solvable2str(pool, s));
3592 addupdaterule(solv, s, 0);
3593 queue_push(&solv->ruletojob, i);
3596 IF_POOLDEBUG (SAT_DEBUG_JOB)
3599 if (solv->nrules == oldnrules)
3600 POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created");
3601 for (j = oldnrules; j < solv->nrules; j++)
3603 POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
3604 printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
3609 if (solv->ruletojob.count != solv->nrules - solv->jobrules) {
3610 fprintf( stderr, "ruletojob.count %d != nrules %d - jobrules %d\n", solv->ruletojob.count, solv->nrules, solv->jobrules );
3611 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
3615 * now add system rules
3619 POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add system rules ***\n");
3622 solv->systemrules = solv->nrules;
3625 * create rules for updating installed solvables
3629 if (installed && !solv->allowuninstall)
3630 { /* loop over all installed solvables */
3631 /* we create all update rules, but disable some later on depending on the job */
3632 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3633 if (s->repo == installed)
3634 addupdaterule(solv, s, 0); /* allowall = 0 */
3636 addupdaterule(solv, 0, 0); /* create dummy rule; allowall = 0 */
3637 /* consistency check: we added a rule for _every_ system solvable */
3638 if (solv->nrules - solv->systemrules != installed->end - installed->start) {
3639 fprintf( stderr, "abort at solver.c:%d\n", __LINE__ );
3644 /* create special weak system rules */
3645 /* those are used later on to keep a version of the installed packages in
3647 if (installed && installed->nsolvables)
3649 solv->weaksystemrules = xcalloc(installed->end - installed->start, sizeof(Id));
3650 FOR_REPO_SOLVABLES(installed, p, s)
3652 policy_findupdatepackages(solv, s, &q, 1);
3654 solv->weaksystemrules[p - installed->start] = pool_queuetowhatprovides(pool, &q);
3658 /* free unneeded memory */
3659 map_free(&addedmap);
3662 solv->weakrules = solv->nrules;
3664 /* try real hard to keep packages installed */
3667 FOR_REPO_SOLVABLES(installed, p, s)
3669 /* FIXME: can't work with refine_suggestion! */
3670 /* need to always add the rule but disable it */
3671 if (MAPTST(&solv->noupdate, p - installed->start))
3673 d = solv->weaksystemrules[p - installed->start];
3674 addrule(solv, p, d);
3678 /* all new rules are learnt after this point */
3679 solv->learntrules = solv->nrules;
3686 disableupdaterules(solv, job, -1);
3687 makeruledecisions(solv);
3689 POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
3691 run_solver(solv, 1, 1);
3693 /* find suggested packages */
3694 if (!solv->problems.count)
3696 Id sug, *sugp, p, *pp;
3698 /* create map of all suggests that are still open */
3699 solv->recommends_index = -1;
3700 MAPZERO(&solv->suggestsmap);
3701 for (i = 0; i < solv->decisionq.count; i++)
3703 p = solv->decisionq.elements[i];
3706 s = pool->solvables + p;
3709 sugp = s->repo->idarraydata + s->suggests;
3710 while ((sug = *sugp++) != 0)
3712 FOR_PROVIDES(p, pp, sug)
3713 if (solv->decisionmap[p] > 0)
3716 continue; /* already fulfilled */
3717 FOR_PROVIDES(p, pp, sug)
3718 MAPSET(&solv->suggestsmap, p);
3722 for (i = 1; i < pool->nsolvables; i++)
3724 if (solv->decisionmap[i] != 0)
3726 s = pool->solvables + i;
3727 if (!MAPTST(&solv->suggestsmap, i))
3731 if (!pool_installable(pool, s))
3733 if (!solver_is_enhancing(solv, s))
3736 queue_push(&solv->suggestions, i);
3738 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
3741 if (solv->problems.count)
3742 problems_to_solutions(solv, job);