2 * Copyright (c) 2007-2008, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * SAT based dependency solver
21 #include "solver_private.h"
26 #include "solverdebug.h"
28 #define RULES_BLOCK 63
30 /********************************************************************
32 * dependency check helpers
36 /*-------------------------------------------------------------------
37 * handle split provides
39 * a splitprovides dep looks like
40 * namespace:splitprovides(pkg REL_WITH path)
41 * and is only true if pkg is installed and contains the specified path.
42 * we also make sure that pkg is selected for an update, otherwise the
43 * update would always be forced onto the user.
46 solver_splitprovides(Solver *solv, Id dep)
48 Pool *pool = solv->pool;
53 if (!solv->dosplitprovides || !solv->installed || (!solv->updatemap_all && !solv->updatemap.size))
57 rd = GETRELDEP(pool, dep);
58 if (rd->flags != REL_WITH)
60 FOR_PROVIDES(p, pp, dep)
62 /* here we have packages that provide the correct name and contain the path,
63 * now do extra filtering */
64 s = pool->solvables + p;
65 if (s->repo == solv->installed && s->name == rd->name &&
66 (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, p - solv->installed->start))))
73 /*-------------------------------------------------------------------
74 * solver_dep_installed
78 solver_dep_installed(Solver *solv, Id dep)
81 Pool *pool = solv->pool;
86 Reldep *rd = GETRELDEP(pool, dep);
87 if (rd->flags == REL_AND)
89 if (!solver_dep_installed(solv, rd->name))
91 return solver_dep_installed(solv, rd->evr);
93 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
94 return solver_dep_installed(solv, rd->evr);
96 FOR_PROVIDES(p, pp, dep)
98 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
107 autouninstall(Solver *solv, Id *problem)
109 Pool *pool = solv->pool;
111 int lastfeature = 0, lastupdate = 0;
115 for (i = 0; (v = problem[i]) != 0; i++)
118 extraflags &= solv->job.elements[-v - 1];
119 if (v >= solv->featurerules && v < solv->featurerules_end)
122 if (v >= solv->updaterules && v < solv->updaterules_end)
124 /* check if identical to feature rule */
125 Id p = solv->rules[v].p;
128 Rule *r = solv->rules + solv->featurerules + (p - solv->installed->start);
131 /* update rule == feature rule */
140 if (!lastupdate && !lastfeature)
142 v = lastupdate ? lastupdate : lastfeature;
143 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "allowuninstall disabling ");
144 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + v);
145 solver_disableproblem(solv, v);
146 if (extraflags != -1 && (extraflags & SOLVER_CLEANDEPS) != 0 && solv->cleandepsmap.size)
148 /* add the package to the updatepkgs list, this will automatically turn
149 * on cleandeps mode */
150 Id p = solv->rules[v].p;
151 if (!solv->cleandeps_updatepkgs)
153 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
154 queue_init(solv->cleandeps_updatepkgs);
158 int oldupdatepkgscnt = solv->cleandeps_updatepkgs->count;
159 queue_pushunique(solv->cleandeps_updatepkgs, p);
160 if (solv->cleandeps_updatepkgs->count != oldupdatepkgscnt)
161 solver_disablepolicyrules(solv);
167 /************************************************************************/
170 * enable/disable learnt rules
172 * we have enabled or disabled some of our rules. We now reenable all
173 * of our learnt rules except the ones that were learnt from rules that
177 enabledisablelearntrules(Solver *solv)
179 Pool *pool = solv->pool;
184 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
185 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
187 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
188 while ((why = *whyp++) != 0)
190 assert(why > 0 && why < i);
191 if (solv->rules[why].d < 0)
194 /* why != 0: we found a disabled rule, disable the learnt rule */
195 if (why && r->d >= 0)
197 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
199 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "disabling ");
200 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
202 solver_disablerule(solv, r);
204 else if (!why && r->d < 0)
206 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
208 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "re-enabling ");
209 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
211 solver_enablerule(solv, r);
218 * make assertion rules into decisions
220 * Go through rules and add direct assertions to the decisionqueue.
221 * If we find a conflict, disable rules and add them to problem queue.
225 makeruledecisions(Solver *solv)
227 Pool *pool = solv->pool;
232 int record_proof = 1;
234 int havedisabled = 0;
236 /* The system solvable is always installed first */
237 assert(solv->decisionq.count == 0);
238 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
239 queue_push(&solv->decisionq_why, 0);
240 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
242 decisionstart = solv->decisionq.count;
245 /* if we needed to re-run, back up decisions to decisionstart */
246 while (solv->decisionq.count > decisionstart)
248 v = solv->decisionq.elements[--solv->decisionq.count];
249 --solv->decisionq_why.count;
251 solv->decisionmap[vv] = 0;
254 /* note that the ruleassertions queue is ordered */
255 for (ii = 0; ii < solv->ruleassertions.count; ii++)
257 ri = solv->ruleassertions.elements[ii];
258 r = solv->rules + ri;
260 if (havedisabled && ri >= solv->learntrules)
262 /* just started with learnt rule assertions. If we have disabled
263 * some rules, adapt the learnt rule status */
264 enabledisablelearntrules(solv);
268 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
271 /* do weak rules in phase 2 */
272 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
278 if (!solv->decisionmap[vv]) /* if not yet decided */
280 queue_push(&solv->decisionq, v);
281 queue_push(&solv->decisionq_why, r - solv->rules);
282 solv->decisionmap[vv] = v > 0 ? 1 : -1;
283 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
285 Solvable *s = solv->pool->solvables + vv;
287 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", pool_solvable2str(solv->pool, s));
289 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (assertion)\n", pool_solvable2str(solv->pool, s));
294 /* check against previous decision: is there a conflict? */
295 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
297 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
303 * The rule (r) we're currently processing says something
304 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
308 if (ri >= solv->learntrules)
310 /* conflict with a learnt rule */
311 /* can happen when packages cannot be installed for multiple reasons. */
312 /* we disable the learnt rule in this case */
313 /* (XXX: we should really call analyze_unsolvable_rule here!) */
314 solver_disablerule(solv, r);
319 * find the decision which is the "opposite" of the rule
321 for (i = 0; i < solv->decisionq.count; i++)
322 if (solv->decisionq.elements[i] == -v)
324 assert(i < solv->decisionq.count); /* assert that we found it */
325 oldproblemcount = solv->problems.count;
328 * conflict with system solvable ?
330 if (v == -SYSTEMSOLVABLE)
334 queue_push(&solv->problems, solv->learnt_pool.count);
335 queue_push(&solv->learnt_pool, ri);
336 queue_push(&solv->learnt_pool, 0);
339 queue_push(&solv->problems, 0);
340 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
341 if (ri >= solv->jobrules && ri < solv->jobrules_end)
342 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
345 queue_push(&solv->problems, v);
346 queue_push(&solv->problems, 0);
347 if (solv->allowuninstall && v >= solv->featurerules && v < solv->updaterules_end)
348 solv->problems.count = oldproblemcount;
349 solver_disableproblem(solv, v);
351 break; /* start over */
354 assert(solv->decisionq_why.elements[i] > 0);
357 * conflict with an rpm rule ?
359 if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
363 queue_push(&solv->problems, solv->learnt_pool.count);
364 queue_push(&solv->learnt_pool, ri);
365 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
366 queue_push(&solv->learnt_pool, 0);
369 queue_push(&solv->problems, 0);
370 assert(v > 0 || v == -SYSTEMSOLVABLE);
371 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
372 if (ri >= solv->jobrules && ri < solv->jobrules_end)
373 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
376 queue_push(&solv->problems, v);
377 queue_push(&solv->problems, 0);
378 if (solv->allowuninstall && v >= solv->featurerules && v < solv->updaterules_end)
379 solv->problems.count = oldproblemcount;
380 solver_disableproblem(solv, v);
382 break; /* start over */
386 * conflict with another job or update/feature rule
392 queue_push(&solv->problems, solv->learnt_pool.count);
393 queue_push(&solv->learnt_pool, ri);
394 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
395 queue_push(&solv->learnt_pool, 0);
398 queue_push(&solv->problems, 0);
400 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
403 * push all of our rules (can only be feature or job rules)
404 * asserting this literal on the problem stack
406 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
408 if (rr->d < 0 /* disabled */
409 || rr->w2) /* or no assertion */
411 if (rr->p != vv /* not affecting the literal */
414 if (MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
417 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
418 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + i);
421 if (i >= solv->jobrules && i < solv->jobrules_end)
422 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
423 queue_push(&solv->problems, v);
425 queue_push(&solv->problems, 0);
427 if (solv->allowuninstall && (v = autouninstall(solv, solv->problems.elements + oldproblemcount + 1)) != 0)
428 solv->problems.count = oldproblemcount;
430 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
431 solver_disableproblem(solv, solv->problems.elements[i]);
433 break; /* start over */
435 if (ii < solv->ruleassertions.count)
439 * phase 2: now do the weak assertions
441 for (ii = 0; ii < solv->ruleassertions.count; ii++)
443 ri = solv->ruleassertions.elements[ii];
444 r = solv->rules + ri;
445 if (r->d < 0 || r->w2) /* disabled or no assertion */
447 if (ri >= solv->learntrules || !MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
452 if (!solv->decisionmap[vv]) /* if not yet decided */
454 queue_push(&solv->decisionq, v);
455 queue_push(&solv->decisionq_why, r - solv->rules);
456 solv->decisionmap[vv] = v > 0 ? 1 : -1;
457 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
459 Solvable *s = solv->pool->solvables + vv;
461 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
463 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
467 /* check against previous decision: is there a conflict? */
468 if (v > 0 && solv->decisionmap[vv] > 0)
470 if (v < 0 && solv->decisionmap[vv] < 0)
473 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
474 solver_printrule(solv, SOLV_DEBUG_UNSOLVABLE, r);
476 if (ri >= solv->jobrules && ri < solv->jobrules_end)
477 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
480 solver_disableproblem(solv, v);
482 solver_reenablepolicyrules(solv, -v);
484 break; /* start over */
486 if (ii == solv->ruleassertions.count)
487 break; /* finished! */
492 /********************************************************************/
496 /*-------------------------------------------------------------------
499 * initial setup for all watches
503 makewatches(Solver *solv)
507 int nsolvables = solv->pool->nsolvables;
509 solv_free(solv->watches);
510 /* lower half for removals, upper half for installs */
511 solv->watches = solv_calloc(2 * nsolvables, sizeof(Id));
513 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
514 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
516 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
519 if (!r->w2) /* assertions do not need watches */
522 /* see addwatches_rule(solv, r) */
523 r->n1 = solv->watches[nsolvables + r->w1];
524 solv->watches[nsolvables + r->w1] = r - solv->rules;
526 r->n2 = solv->watches[nsolvables + r->w2];
527 solv->watches[nsolvables + r->w2] = r - solv->rules;
532 /*-------------------------------------------------------------------
534 * add watches (for a new learned rule)
535 * sets up watches for a single rule
537 * see also makewatches() above.
541 addwatches_rule(Solver *solv, Rule *r)
543 int nsolvables = solv->pool->nsolvables;
545 r->n1 = solv->watches[nsolvables + r->w1];
546 solv->watches[nsolvables + r->w1] = r - solv->rules;
548 r->n2 = solv->watches[nsolvables + r->w2];
549 solv->watches[nsolvables + r->w2] = r - solv->rules;
553 /********************************************************************/
559 /* shortcuts to check if a literal (positive or negative) assignment
560 * evaluates to 'true' or 'false'
562 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
563 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
564 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
566 /*-------------------------------------------------------------------
570 * make decision and propagate to all rules
572 * Evaluate each term affected by the decision (linked through watches).
573 * If we find unit rules we make new decisions based on them.
575 * return : 0 = everything is OK
576 * rule = conflict found in this rule
580 propagate(Solver *solv, int level)
582 Pool *pool = solv->pool;
583 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
585 Id p, pkg, other_watch;
587 Id *decisionmap = solv->decisionmap;
589 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
591 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate -----\n");
593 /* foreach non-propagated decision */
594 while (solv->propagate_index < solv->decisionq.count)
597 * 'pkg' was just decided
598 * negate because our watches trigger if literal goes FALSE
600 pkg = -solv->decisionq.elements[solv->propagate_index++];
602 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
604 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
605 solver_printruleelement(solv, SOLV_DEBUG_PROPAGATE, 0, -pkg);
608 /* foreach rule where 'pkg' is now FALSE */
609 for (rp = watches + pkg; *rp; rp = next_rp)
611 r = solv->rules + *rp;
614 /* rule is disabled, goto next */
622 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
624 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," watch triggered ");
625 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
628 /* 'pkg' was just decided (was set to FALSE)
630 * now find other literal watch, check clause
631 * and advance on linked list
645 * This term is already true (through the other literal)
646 * so we have nothing to do
648 if (DECISIONMAP_TRUE(other_watch))
652 * The other literal is FALSE or UNDEF
658 /* Not a binary clause, try to move our watch.
660 * Go over all literals and find one that is
664 * (TRUE is also ok, in that case the rule is fulfilled)
666 if (r->p /* we have a 'p' */
667 && r->p != other_watch /* which is not watched */
668 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
672 else /* go find a 'd' to make 'true' */
675 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
677 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
679 if (p != other_watch /* which is not watched */
680 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
688 * if we found some p that is UNDEF or TRUE, move
691 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
694 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, p));
696 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, -p));
712 watches[p] = r - solv->rules;
715 /* search failed, thus all unwatched literals are FALSE */
720 * unit clause found, set literal other_watch to TRUE
723 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
724 return r; /* eek, a conflict! */
726 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
728 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " unit ");
729 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
733 decisionmap[other_watch] = level; /* install! */
735 decisionmap[-other_watch] = -level; /* remove! */
737 queue_push(&solv->decisionq, other_watch);
738 queue_push(&solv->decisionq_why, r - solv->rules);
740 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
743 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to install %s\n", pool_solvid2str(pool, other_watch));
745 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to conflict %s\n", pool_solvid2str(pool, -other_watch));
748 } /* foreach rule involving 'pkg' */
750 } /* while we have non-decided decisions */
752 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate end-----\n");
754 return 0; /* all is well */
758 /********************************************************************/
761 /*-------------------------------------------------------------------
768 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
770 Pool *pool = solv->pool;
774 Map seen; /* global? */
775 Id d, v, vv, *dp, why;
777 int num = 0, l1num = 0;
778 int learnt_why = solv->learnt_pool.count;
779 Id *decisionmap = solv->decisionmap;
781 queue_init_buffer(&r, r_buf, sizeof(r_buf)/sizeof(*r_buf));
783 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
784 map_init(&seen, pool->nsolvables);
785 idx = solv->decisionq.count;
788 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
789 solver_printruleclass(solv, SOLV_DEBUG_ANALYZE, c);
790 queue_push(&solv->learnt_pool, c - solv->rules);
791 d = c->d < 0 ? -c->d - 1 : c->d;
792 dp = d ? pool->whatprovidesdata + d : 0;
793 /* go through all literals of the rule */
805 if (DECISIONMAP_TRUE(v)) /* the one true literal */
808 if (MAPTST(&seen, vv))
810 l = solv->decisionmap[vv];
813 MAPSET(&seen, vv); /* mark that we also need to look at this literal */
815 l1num++; /* need to do this one in level1 pass */
817 num++; /* need to do this one as well */
820 queue_push(&r, v); /* not level1 or conflict level, add to new rule */
826 if (!num && !--l1num)
827 break; /* all level 1 literals done */
829 /* find the next literal to investigate */
830 /* (as num + l1num > 0, we know that we'll always find one) */
834 v = solv->decisionq.elements[--idx];
836 if (MAPTST(&seen, vv))
841 if (num && --num == 0)
843 *pr = -v; /* so that v doesn't get lost */
846 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
847 /* clear non-l1 bits from seen map */
848 for (i = 0; i < r.count; i++)
851 MAPCLR(&seen, v > 0 ? v : -v);
853 /* only level 1 marks left in seen map */
854 l1num++; /* as l1retry decrements it */
858 why = solv->decisionq_why.elements[idx];
859 if (why <= 0) /* just in case, maybe for SYSTEMSOLVABLE */
861 c = solv->rules + why;
867 else if (r.count == 1 && r.elements[0] < 0)
870 *dr = pool_queuetowhatprovides(pool, &r);
871 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
873 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
874 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, *pr);
875 for (i = 0; i < r.count; i++)
876 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, r.elements[i]);
878 /* push end marker on learnt reasons stack */
879 queue_push(&solv->learnt_pool, 0);
883 solv->stats_learned++;
888 /*-------------------------------------------------------------------
892 * reset all solver decisions
893 * called after rules have been enabled/disabled
897 solver_reset(Solver *solv)
899 Pool *pool = solv->pool;
903 /* rewind all decisions */
904 for (i = solv->decisionq.count - 1; i >= 0; i--)
906 v = solv->decisionq.elements[i];
907 solv->decisionmap[v > 0 ? v : -v] = 0;
909 solv->decisionq_why.count = 0;
910 solv->decisionq.count = 0;
911 solv->recommends_index = -1;
912 solv->propagate_index = 0;
913 solv->branches.count = 0;
915 /* adapt learnt rule status to new set of enabled/disabled rules */
916 enabledisablelearntrules(solv);
918 /* redo all assertion rule decisions */
919 makeruledecisions(solv);
920 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
924 /*-------------------------------------------------------------------
926 * analyze_unsolvable_rule
928 * recursion helper used by analyze_unsolvable
932 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp, Map *rseen)
934 Pool *pool = solv->pool;
936 Id why = r - solv->rules;
938 IF_POOLDEBUG (SOLV_DEBUG_UNSOLVABLE)
939 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, r);
940 if (solv->learntrules && why >= solv->learntrules)
942 if (MAPTST(rseen, why - solv->learntrules))
944 MAPSET(rseen, why - solv->learntrules);
945 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
946 if (solv->learnt_pool.elements[i] > 0)
947 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp, rseen);
950 if (MAPTST(&solv->weakrulemap, why))
951 if (!*lastweakp || why > *lastweakp)
953 /* do not add rpm rules to problem */
954 if (why < solv->rpmrules_end)
956 /* turn rule into problem */
957 if (why >= solv->jobrules && why < solv->jobrules_end)
958 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
959 /* normalize dup/infarch rules */
960 if (why > solv->infarchrules && why < solv->infarchrules_end)
962 Id name = pool->solvables[-solv->rules[why].p].name;
963 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
966 if (why > solv->duprules && why < solv->duprules_end)
968 Id name = pool->solvables[-solv->rules[why].p].name;
969 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
973 /* return if problem already countains our rule */
974 if (solv->problems.count)
976 for (i = solv->problems.count - 1; i >= 0; i--)
977 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
979 else if (solv->problems.elements[i] == why)
982 queue_push(&solv->problems, why);
986 /*-------------------------------------------------------------------
990 * We know that the problem is not solvable. Record all involved
991 * rules (i.e. the "proof") into solv->learnt_pool.
992 * Record the learnt pool index and all non-rpm rules into
993 * solv->problems. (Our solutions to fix the problems are to
994 * disable those rules.)
996 * If the proof contains at least one weak rule, we disable the
999 * Otherwise we return 0 if disablerules is not set or disable
1000 * _all_ of the problem rules and return 1.
1002 * return: 1 - disabled some rules, try again
1007 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1009 Pool *pool = solv->pool;
1011 Map seen; /* global to speed things up? */
1013 Id d, v, vv, *dp, why;
1015 Id *decisionmap = solv->decisionmap;
1016 int oldproblemcount;
1017 int oldlearntpoolcount;
1019 int record_proof = 1;
1021 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1022 solv->stats_unsolvable++;
1023 oldproblemcount = solv->problems.count;
1024 oldlearntpoolcount = solv->learnt_pool.count;
1026 /* make room for proof index */
1027 /* must update it later, as analyze_unsolvable_rule would confuse
1028 * it with a rule index if we put the real value in already */
1029 queue_push(&solv->problems, 0);
1032 map_init(&seen, pool->nsolvables);
1033 map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
1035 queue_push(&solv->learnt_pool, r - solv->rules);
1037 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1038 d = r->d < 0 ? -r->d - 1 : r->d;
1039 dp = d ? pool->whatprovidesdata + d : 0;
1050 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1052 vv = v > 0 ? v : -v;
1053 l = solv->decisionmap[vv];
1058 idx = solv->decisionq.count;
1061 v = solv->decisionq.elements[--idx];
1062 vv = v > 0 ? v : -v;
1063 if (!MAPTST(&seen, vv))
1065 why = solv->decisionq_why.elements[idx];
1068 queue_push(&solv->learnt_pool, why);
1069 r = solv->rules + why;
1070 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1071 d = r->d < 0 ? -r->d - 1 : r->d;
1072 dp = d ? pool->whatprovidesdata + d : 0;
1083 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1085 vv = v > 0 ? v : -v;
1086 l = solv->decisionmap[vv];
1094 queue_push(&solv->problems, 0); /* mark end of this problem */
1098 /* disable last weak rule */
1099 solv->problems.count = oldproblemcount;
1100 solv->learnt_pool.count = oldlearntpoolcount;
1101 if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
1102 v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
1105 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "disabling ");
1106 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + lastweak);
1107 if (lastweak >= solv->choicerules && lastweak < solv->choicerules_end)
1108 solver_disablechoicerules(solv, solv->rules + lastweak);
1109 solver_disableproblem(solv, v);
1111 solver_reenablepolicyrules(solv, -v);
1116 if (solv->allowuninstall && (v = autouninstall(solv, solv->problems.elements + oldproblemcount + 1)) != 0)
1118 solv->problems.count = oldproblemcount;
1119 solv->learnt_pool.count = oldlearntpoolcount;
1127 queue_push(&solv->learnt_pool, 0);
1128 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1131 /* + 2: index + trailing zero */
1132 if (disablerules && oldproblemcount + 2 < solv->problems.count)
1134 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1135 solver_disableproblem(solv, solv->problems.elements[i]);
1136 /* XXX: might want to enable all weak rules again */
1140 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1145 /********************************************************************/
1146 /* Decision revert */
1148 /*-------------------------------------------------------------------
1151 * revert decisionq to a level
1155 revert(Solver *solv, int level)
1157 Pool *pool = solv->pool;
1159 while (solv->decisionq.count)
1161 v = solv->decisionq.elements[solv->decisionq.count - 1];
1162 vv = v > 0 ? v : -v;
1163 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1165 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1166 solv->decisionmap[vv] = 0;
1167 solv->decisionq.count--;
1168 solv->decisionq_why.count--;
1169 solv->propagate_index = solv->decisionq.count;
1171 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1173 solv->branches.count--;
1174 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1175 solv->branches.count--;
1177 solv->recommends_index = -1;
1181 /*-------------------------------------------------------------------
1183 * watch2onhighest - put watch2 on literal with highest level
1187 watch2onhighest(Solver *solv, Rule *r)
1192 d = r->d < 0 ? -r->d - 1 : r->d;
1194 return; /* binary rule, both watches are set */
1195 dp = solv->pool->whatprovidesdata + d;
1196 while ((v = *dp++) != 0)
1198 l = solv->decisionmap[v < 0 ? -v : v];
1210 /*-------------------------------------------------------------------
1214 * add free decision (solvable to install) to decisionq
1215 * increase level and propagate decision
1216 * return if no conflict.
1218 * in conflict case, analyze conflict rule, add resulting
1219 * rule to learnt rule set, make decision from learnt
1220 * rule (always unit) and re-propagate.
1222 * returns the new solver level or 0 if unsolvable
1227 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules, Id ruleid)
1229 Pool *pool = solv->pool;
1234 assert(ruleid >= 0);
1239 solv->decisionmap[decision] = level;
1241 solv->decisionmap[-decision] = -level;
1242 queue_push(&solv->decisionq, decision);
1243 queue_push(&solv->decisionq_why, -ruleid); /* <= 0 -> free decision */
1247 r = propagate(solv, level);
1251 return analyze_unsolvable(solv, r, disablerules);
1252 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1253 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1254 assert(l > 0 && l < level);
1255 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
1257 revert(solv, level);
1258 r = solver_addrule(solv, p, d);
1260 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1261 queue_push(&solv->learnt_why, why);
1264 /* at least 2 literals, needs watches */
1265 watch2onhighest(solv, r);
1266 addwatches_rule(solv, r);
1270 /* learnt rule is an assertion */
1271 queue_push(&solv->ruleassertions, r - solv->rules);
1273 /* the new rule is unit by design */
1274 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1275 queue_push(&solv->decisionq, p);
1276 queue_push(&solv->decisionq_why, r - solv->rules);
1277 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
1279 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "decision: ");
1280 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, p);
1281 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "new rule: ");
1282 solver_printrule(solv, SOLV_DEBUG_ANALYZE, r);
1289 /*-------------------------------------------------------------------
1291 * select and install
1293 * install best package from the queue. We add an extra package, inst, if
1294 * provided. See comment in weak install section.
1296 * returns the new solver level or 0 if unsolvable
1301 selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid)
1303 Pool *pool = solv->pool;
1308 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
1311 /* XXX: didn't we already do that? */
1312 /* XXX: shouldn't we prefer installed packages? */
1313 /* XXX: move to policy.c? */
1314 /* choose the supplemented one */
1315 for (i = 0; i < dq->count; i++)
1316 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1318 dq->elements[0] = dq->elements[i];
1325 /* multiple candidates, open a branch */
1326 for (i = 1; i < dq->count; i++)
1327 queue_push(&solv->branches, dq->elements[i]);
1328 queue_push(&solv->branches, -level);
1330 p = dq->elements[0];
1332 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing %s\n", pool_solvid2str(pool, p));
1334 return setpropagatelearn(solv, level, p, disablerules, ruleid);
1338 /********************************************************************/
1339 /* Main solver interface */
1342 /*-------------------------------------------------------------------
1345 * create solver structure
1347 * pool: all available solvables
1348 * installed: installed Solvables
1351 * Upon solving, rules are created to flag the Solvables
1352 * of the 'installed' Repo as installed.
1356 solver_create(Pool *pool)
1359 solv = (Solver *)solv_calloc(1, sizeof(Solver));
1361 solv->installed = pool->installed;
1363 solv->allownamechange = 1;
1365 solv->dup_allowdowngrade = 1;
1366 solv->dup_allownamechange = 1;
1367 solv->dup_allowarchchange = 1;
1368 solv->dup_allowvendorchange = 1;
1370 queue_init(&solv->ruletojob);
1371 queue_init(&solv->decisionq);
1372 queue_init(&solv->decisionq_why);
1373 queue_init(&solv->problems);
1374 queue_init(&solv->orphaned);
1375 queue_init(&solv->learnt_why);
1376 queue_init(&solv->learnt_pool);
1377 queue_init(&solv->branches);
1378 queue_init(&solv->weakruleq);
1379 queue_init(&solv->ruleassertions);
1381 queue_push(&solv->learnt_pool, 0); /* so that 0 does not describe a proof */
1383 map_init(&solv->recommendsmap, pool->nsolvables);
1384 map_init(&solv->suggestsmap, pool->nsolvables);
1385 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
1386 solv->recommends_index = 0;
1388 solv->decisionmap = (Id *)solv_calloc(pool->nsolvables, sizeof(Id));
1390 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
1391 memset(solv->rules, 0, sizeof(Rule));
1397 /*-------------------------------------------------------------------
1403 solver_free(Solver *solv)
1405 queue_free(&solv->job);
1406 queue_free(&solv->ruletojob);
1407 queue_free(&solv->decisionq);
1408 queue_free(&solv->decisionq_why);
1409 queue_free(&solv->learnt_why);
1410 queue_free(&solv->learnt_pool);
1411 queue_free(&solv->problems);
1412 queue_free(&solv->solutions);
1413 queue_free(&solv->orphaned);
1414 queue_free(&solv->branches);
1415 queue_free(&solv->weakruleq);
1416 queue_free(&solv->ruleassertions);
1417 if (solv->cleandeps_updatepkgs)
1419 queue_free(solv->cleandeps_updatepkgs);
1420 solv->cleandeps_updatepkgs = solv_free(solv->cleandeps_updatepkgs);
1422 if (solv->cleandeps_mistakes)
1424 queue_free(solv->cleandeps_mistakes);
1425 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
1428 map_free(&solv->recommendsmap);
1429 map_free(&solv->suggestsmap);
1430 map_free(&solv->noupdate);
1431 map_free(&solv->weakrulemap);
1432 map_free(&solv->noobsoletes);
1434 map_free(&solv->updatemap);
1435 map_free(&solv->fixmap);
1436 map_free(&solv->dupmap);
1437 map_free(&solv->dupinvolvedmap);
1438 map_free(&solv->droporphanedmap);
1439 map_free(&solv->cleandepsmap);
1441 solv_free(solv->decisionmap);
1442 solv_free(solv->rules);
1443 solv_free(solv->watches);
1444 solv_free(solv->obsoletes);
1445 solv_free(solv->obsoletes_data);
1446 solv_free(solv->multiversionupdaters);
1447 solv_free(solv->choicerules_ref);
1452 solver_get_flag(Solver *solv, int flag)
1456 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1457 return solv->allowdowngrade;
1458 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1459 return solv->allownamechange;
1460 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1461 return solv->allowarchchange;
1462 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1463 return solv->allowvendorchange;
1464 case SOLVER_FLAG_ALLOW_UNINSTALL:
1465 return solv->allowuninstall;
1466 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1467 return solv->noupdateprovide;
1468 case SOLVER_FLAG_SPLITPROVIDES:
1469 return solv->dosplitprovides;
1470 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1471 return solv->dontinstallrecommended;
1472 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1473 return solv->addalreadyrecommended;
1474 case SOLVER_FLAG_NO_INFARCHCHECK:
1475 return solv->noinfarchcheck;
1476 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1477 return solv->keepexplicitobsoletes;
1485 solver_set_flag(Solver *solv, int flag, int value)
1487 int old = solver_get_flag(solv, flag);
1490 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1491 solv->allowdowngrade = value;
1493 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1494 solv->allownamechange = value;
1496 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1497 solv->allowarchchange = value;
1499 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1500 solv->allowvendorchange = value;
1502 case SOLVER_FLAG_ALLOW_UNINSTALL:
1503 solv->allowuninstall = value;
1505 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1506 solv->noupdateprovide = value;
1508 case SOLVER_FLAG_SPLITPROVIDES:
1509 solv->dosplitprovides = value;
1511 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1512 solv->dontinstallrecommended = value;
1514 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1515 solv->addalreadyrecommended = value;
1517 case SOLVER_FLAG_NO_INFARCHCHECK:
1518 solv->noinfarchcheck = value;
1520 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1521 solv->keepexplicitobsoletes = value;
1530 cleandeps_check_mistakes(Solver *solv, int level)
1532 Pool *pool = solv->pool;
1536 int mademistake = 0;
1538 if (!solv->cleandepsmap.size)
1540 /* check for mistakes */
1541 for (i = solv->installed->start; i < solv->installed->end; i++)
1543 if (!MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1545 r = solv->rules + solv->featurerules + (i - solv->installed->start);
1546 /* a mistake is when the featurerule is true but the updaterule is false */
1549 FOR_RULELITERALS(p, dp, r)
1550 if (p > 0 && solv->decisionmap[p] > 0)
1554 r = solv->rules + solv->updaterules + (i - solv->installed->start);
1557 FOR_RULELITERALS(p, dp, r)
1558 if (p > 0 && solv->decisionmap[p] > 0)
1562 POOL_DEBUG(SOLV_DEBUG_SOLVER, "cleandeps mistake: ");
1563 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, r);
1564 POOL_DEBUG(SOLV_DEBUG_SOLVER, "feature rule: ");
1565 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, solv->rules + solv->featurerules + (i - solv->installed->start));
1566 if (!solv->cleandeps_mistakes)
1568 solv->cleandeps_mistakes = solv_calloc(1, sizeof(Queue));
1569 queue_init(solv->cleandeps_mistakes);
1571 queue_push(solv->cleandeps_mistakes, i);
1572 MAPCLR(&solv->cleandepsmap, i - solv->installed->start);
1573 solver_reenablepolicyrules_cleandeps(solv, i);
1584 /*-------------------------------------------------------------------
1588 * all rules have been set up, now actually run the solver
1593 solver_run_sat(Solver *solv, int disablerules, int doweak)
1595 Queue dq; /* local decisionqueue */
1596 Queue dqs; /* local decisionqueue for supplements */
1602 Pool *pool = solv->pool;
1604 int minimizationsteps;
1605 int installedpos = solv->installed ? solv->installed->start : 0;
1607 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
1609 POOL_DEBUG (SOLV_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
1610 for (i = 1; i < solv->nrules; i++)
1611 solver_printruleclass(solv, SOLV_DEBUG_RULE_CREATION, solv->rules + i);
1614 POOL_DEBUG(SOLV_DEBUG_SOLVER, "initial decisions: %d\n", solv->decisionq.count);
1616 /* start SAT algorithm */
1618 systemlevel = level + 1;
1619 POOL_DEBUG(SOLV_DEBUG_SOLVER, "solving...\n");
1625 * here's the main loop:
1626 * 1) propagate new decisions (only needed once)
1628 * 3) try to keep installed packages
1629 * 4) fulfill all unresolved rules
1630 * 5) install recommended packages
1631 * 6) minimalize solution if we had choices
1632 * if we encounter a problem, we rewind to a safe level and restart
1636 minimizationsteps = 0;
1640 * initial propagation of the assertions
1644 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
1645 if ((r = propagate(solv, level)) != 0)
1647 if (analyze_unsolvable(solv, r, disablerules))
1650 break; /* unsolvable */
1655 * resolve jobs first
1657 if (level < systemlevel)
1659 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving job rules\n");
1660 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
1663 if (r->d < 0) /* ignore disabled rules */
1666 FOR_RULELITERALS(l, dp, r)
1670 if (solv->decisionmap[-l] <= 0)
1675 if (solv->decisionmap[l] > 0)
1677 if (solv->decisionmap[l] == 0)
1683 /* prune to installed if not updating */
1684 if (dq.count > 1 && solv->installed && !solv->updatemap_all &&
1685 !(solv->job.elements[solv->ruletojob.elements[i - solv->jobrules]] & SOLVER_ORUPDATE))
1688 for (j = k = 0; j < dq.count; j++)
1690 Solvable *s = pool->solvables + dq.elements[j];
1691 if (s->repo == solv->installed)
1693 dq.elements[k++] = dq.elements[j];
1694 if (solv->updatemap.size && MAPTST(&solv->updatemap, dq.elements[j] - solv->installed->start))
1696 k = 0; /* package wants to be updated, do not prune */
1705 level = selectandinstall(solv, level, &dq, disablerules, i);
1708 if (level <= olevel)
1712 break; /* unsolvable */
1713 systemlevel = level + 1;
1714 if (i < solv->jobrules_end)
1716 solv->decisioncnt_update = solv->decisionq.count;
1717 solv->decisioncnt_keep = solv->decisionq.count;
1721 * installed packages
1723 if (level < systemlevel && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
1725 Repo *installed = solv->installed;
1728 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving installed packages\n");
1729 /* we use two passes if we need to update packages
1730 * to create a better user experience */
1731 for (pass = solv->updatemap.size ? 0 : 1; pass < 2; pass++)
1733 int passlevel = level;
1735 solv->decisioncnt_keep = solv->decisionq.count;
1736 /* start with installedpos, the position that gave us problems last time */
1737 for (i = installedpos, n = installed->start; n < installed->end; i++, n++)
1742 if (i == installed->end)
1743 i = installed->start;
1744 s = pool->solvables + i;
1745 if (s->repo != installed)
1748 if (solv->decisionmap[i] > 0)
1750 if (!pass && solv->updatemap.size && !MAPTST(&solv->updatemap, i - installed->start))
1751 continue; /* updates first */
1752 r = solv->rules + solv->updaterules + (i - installed->start);
1754 if (!rr->p || rr->d < 0) /* disabled -> look at feature rule */
1755 rr -= solv->installed->end - solv->installed->start;
1756 if (!rr->p) /* identical to update rule? */
1759 continue; /* orpaned package */
1761 /* XXX: noupdate check is probably no longer needed, as all jobs should
1762 * already be satisfied */
1763 /* Actually we currently still need it because of erase jobs */
1764 /* if noupdate is set we do not look at update candidates */
1766 if (!MAPTST(&solv->noupdate, i - installed->start) && (solv->decisionmap[i] < 0 || solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, i - installed->start)) || rr->p != i))
1768 if (solv->noobsoletes.size && solv->multiversionupdaters
1769 && (d = solv->multiversionupdaters[i - installed->start]) != 0)
1771 /* special multiversion handling, make sure best version is chosen */
1773 while ((p = pool->whatprovidesdata[d++]) != 0)
1774 if (solv->decisionmap[p] >= 0)
1776 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
1778 if (p != i && solv->decisionmap[p] == 0)
1780 rr = solv->rules + solv->featurerules + (i - solv->installed->start);
1781 if (!rr->p) /* update rule == feature rule? */
1782 rr = rr - solv->featurerules + solv->updaterules;
1790 /* update to best package */
1791 FOR_RULELITERALS(p, dp, rr)
1793 if (solv->decisionmap[p] > 0)
1795 dq.count = 0; /* already fulfilled */
1798 if (!solv->decisionmap[p])
1803 /* install best version */
1807 level = selectandinstall(solv, level, &dq, disablerules, rr - solv->rules);
1814 if (level <= olevel)
1816 if (level == 1 || level < passlevel)
1817 break; /* trouble */
1819 n = installed->start; /* redo all */
1825 /* if still undecided keep package */
1826 if (solv->decisionmap[i] == 0)
1829 if (solv->cleandepsmap.size && MAPTST(&solv->cleandepsmap, i - installed->start))
1831 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, i));
1832 level = setpropagatelearn(solv, level, -i, disablerules, 0);
1836 POOL_DEBUG(SOLV_DEBUG_POLICY, "keeping %s\n", pool_solvid2str(pool, i));
1837 level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules);
1841 if (level <= olevel)
1843 if (level == 1 || level < passlevel)
1844 break; /* trouble */
1846 n = installed->start; /* redo all */
1849 continue; /* retry with learnt rule */
1853 if (n < installed->end)
1855 installedpos = i; /* retry problem solvable next time */
1856 break; /* ran into trouble */
1858 installedpos = installed->start; /* reset installedpos */
1861 break; /* unsolvable */
1862 systemlevel = level + 1;
1864 continue; /* had trouble, retry */
1867 if (level < systemlevel)
1868 systemlevel = level;
1873 solv->decisioncnt_resolve = solv->decisionq.count;
1874 POOL_DEBUG(SOLV_DEBUG_POLICY, "deciding unresolved rules\n");
1875 for (i = 1, n = 1; n < solv->nrules; i++, n++)
1877 if (i == solv->nrules)
1879 r = solv->rules + i;
1880 if (r->d < 0) /* ignore disabled rules */
1885 /* binary or unary rule */
1886 /* need two positive undecided literals */
1887 if (r->p < 0 || r->w2 <= 0)
1889 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
1891 queue_push(&dq, r->p);
1892 queue_push(&dq, r->w2);
1897 * all negative literals are installed
1898 * no positive literal is installed
1899 * i.e. the rule is not fulfilled and we
1900 * just need to decide on the positive literals
1904 if (solv->decisionmap[-r->p] <= 0)
1909 if (solv->decisionmap[r->p] > 0)
1911 if (solv->decisionmap[r->p] == 0)
1912 queue_push(&dq, r->p);
1914 dp = pool->whatprovidesdata + r->d;
1915 while ((p = *dp++) != 0)
1919 if (solv->decisionmap[-p] <= 0)
1924 if (solv->decisionmap[p] > 0)
1926 if (solv->decisionmap[p] == 0)
1933 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
1935 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "unfulfilled ");
1936 solver_printruleclass(solv, SOLV_DEBUG_PROPAGATE, r);
1938 /* dq.count < 2 cannot happen as this means that
1939 * the rule is unit */
1940 assert(dq.count > 1);
1943 level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
1945 break; /* unsolvable */
1946 if (level < systemlevel || level == 1)
1947 break; /* trouble */
1948 /* something changed, so look at all rules again */
1952 if (n != solv->nrules) /* ran into trouble? */
1955 break; /* unsolvable */
1956 continue; /* start over */
1959 /* at this point we have a consistent system. now do the extras... */
1961 solv->decisioncnt_weak = solv->decisionq.count;
1966 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended packages\n");
1967 queue_empty(&dq); /* recommended packages */
1968 queue_empty(&dqs); /* supplemented packages */
1969 for (i = 1; i < pool->nsolvables; i++)
1971 if (solv->decisionmap[i] < 0)
1973 if (solv->decisionmap[i] > 0)
1975 /* installed, check for recommends */
1976 Id *recp, rec, pp, p;
1977 s = pool->solvables + i;
1978 if (!solv->addalreadyrecommended && s->repo == solv->installed)
1980 /* XXX need to special case AND ? */
1983 recp = s->repo->idarraydata + s->recommends;
1984 while ((rec = *recp++) != 0)
1987 FOR_PROVIDES(p, pp, rec)
1989 if (solv->decisionmap[p] > 0)
1994 else if (solv->decisionmap[p] == 0)
1996 if (solv->dupmap_all && solv->installed && pool->solvables[p].repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))))
1998 queue_pushunique(&dq, p);
2006 s = pool->solvables + i;
2007 if (!s->supplements)
2009 if (!pool_installable(pool, s))
2011 if (!solver_is_supplementing(solv, s))
2013 if (solv->dupmap_all && solv->installed && s->repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, i - solv->installed->start))))
2015 queue_push(&dqs, i);
2019 /* filter out all packages obsoleted by installed packages */
2020 /* this is no longer needed if we have reverse obsoletes */
2021 if ((dqs.count || dq.count) && solv->installed)
2024 Id obs, *obsp, po, ppo;
2026 map_init(&obsmap, pool->nsolvables);
2027 for (p = solv->installed->start; p < solv->installed->end; p++)
2029 s = pool->solvables + p;
2030 if (s->repo != solv->installed || !s->obsoletes)
2032 if (solv->decisionmap[p] <= 0)
2034 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p))
2036 obsp = s->repo->idarraydata + s->obsoletes;
2037 /* foreach obsoletes */
2038 while ((obs = *obsp++) != 0)
2039 FOR_PROVIDES(po, ppo, obs)
2040 MAPSET(&obsmap, po);
2042 for (i = j = 0; i < dqs.count; i++)
2043 if (!MAPTST(&obsmap, dqs.elements[i]))
2044 dqs.elements[j++] = dqs.elements[i];
2046 for (i = j = 0; i < dq.count; i++)
2047 if (!MAPTST(&obsmap, dq.elements[i]))
2048 dq.elements[j++] = dq.elements[i];
2053 /* filter out all already supplemented packages if requested */
2054 if (!solv->addalreadyrecommended && dqs.count)
2056 /* turn off all new packages */
2057 for (i = 0; i < solv->decisionq.count; i++)
2059 p = solv->decisionq.elements[i];
2062 s = pool->solvables + p;
2063 if (s->repo && s->repo != solv->installed)
2064 solv->decisionmap[p] = -solv->decisionmap[p];
2066 /* filter out old supplements */
2067 for (i = j = 0; i < dqs.count; i++)
2069 p = dqs.elements[i];
2070 s = pool->solvables + p;
2071 if (!s->supplements)
2073 if (!solver_is_supplementing(solv, s))
2074 dqs.elements[j++] = p;
2077 /* undo turning off */
2078 for (i = 0; i < solv->decisionq.count; i++)
2080 p = solv->decisionq.elements[i];
2083 s = pool->solvables + p;
2084 if (s->repo && s->repo != solv->installed)
2085 solv->decisionmap[p] = -solv->decisionmap[p];
2089 /* multiversion doesn't mix well with supplements.
2090 * filter supplemented packages where we already decided
2091 * to install a different version (see bnc#501088) */
2092 if (dqs.count && solv->noobsoletes.size)
2094 for (i = j = 0; i < dqs.count; i++)
2096 p = dqs.elements[i];
2097 if (MAPTST(&solv->noobsoletes, p))
2100 s = pool->solvables + p;
2101 FOR_PROVIDES(p2, pp2, s->name)
2102 if (solv->decisionmap[p2] > 0 && pool->solvables[p2].name == s->name)
2105 continue; /* ignore this package */
2107 dqs.elements[j++] = p;
2112 /* make dq contain both recommended and supplemented pkgs */
2115 for (i = 0; i < dqs.count; i++)
2116 queue_pushunique(&dq, dqs.elements[i]);
2122 int decisioncount = solv->decisionq.count;
2126 /* simple case, just one package. no need to choose to best version */
2129 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2131 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2132 level = setpropagatelearn(solv, level, p, 0, 0);
2135 continue; /* back to main loop */
2138 /* filter packages, this gives us the best versions */
2139 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
2141 /* create map of result */
2142 map_init(&dqmap, pool->nsolvables);
2143 for (i = 0; i < dq.count; i++)
2144 MAPSET(&dqmap, dq.elements[i]);
2146 /* install all supplemented packages */
2147 for (i = 0; i < dqs.count; i++)
2149 p = dqs.elements[i];
2150 if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
2152 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2154 level = setpropagatelearn(solv, level, p, 0, 0);
2155 if (level <= olevel)
2158 if (i < dqs.count || solv->decisionq.count < decisioncount)
2166 /* install all recommended packages */
2167 /* more work as we want to created branches if multiple
2168 * choices are valid */
2169 for (i = 0; i < decisioncount; i++)
2172 p = solv->decisionq.elements[i];
2175 s = pool->solvables + p;
2176 if (!s->repo || (!solv->addalreadyrecommended && s->repo == solv->installed))
2180 recp = s->repo->idarraydata + s->recommends;
2181 while ((rec = *recp++) != 0)
2184 FOR_PROVIDES(p, pp, rec)
2186 if (solv->decisionmap[p] > 0)
2191 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
2192 queue_pushunique(&dq, p);
2198 /* multiple candidates, open a branch */
2199 for (i = 1; i < dq.count; i++)
2200 queue_push(&solv->branches, dq.elements[i]);
2201 queue_push(&solv->branches, -level);
2204 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2206 level = setpropagatelearn(solv, level, p, 0, 0);
2207 if (level <= olevel || solv->decisionq.count < decisioncount)
2208 break; /* we had to revert some decisions */
2211 break; /* had a problem above, quit loop */
2216 continue; /* back to main loop so that all deps are checked */
2220 solv->decisioncnt_orphan = solv->decisionq.count;
2221 if (solv->dupmap_all && solv->installed)
2223 int installedone = 0;
2225 /* let's see if we can install some unsupported package */
2226 POOL_DEBUG(SOLV_DEBUG_SOLVER, "deciding orphaned packages\n");
2227 for (i = 0; i < solv->orphaned.count; i++)
2229 p = solv->orphaned.elements[i];
2230 if (solv->decisionmap[p])
2231 continue; /* already decided */
2232 if (solv->droporphanedmap_all)
2234 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))
2236 POOL_DEBUG(SOLV_DEBUG_SOLVER, "keeping orphaned %s\n", pool_solvid2str(pool, p));
2238 level = setpropagatelearn(solv, level, p, 0, 0);
2243 if (installedone || i < solv->orphaned.count)
2247 continue; /* back to main loop */
2249 for (i = 0; i < solv->orphaned.count; i++)
2251 p = solv->orphaned.elements[i];
2252 if (solv->decisionmap[p])
2253 continue; /* already decided */
2254 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing orphaned %s\n", pool_solvid2str(pool, p));
2256 level = setpropagatelearn(solv, level, -p, 0, 0);
2260 if (i < solv->orphaned.count)
2264 continue; /* back to main loop */
2268 if (solv->installed && solv->cleandepsmap.size)
2270 if (cleandeps_check_mistakes(solv, level))
2272 level = 1; /* restart from scratch */
2277 if (solv->solution_callback)
2279 solv->solution_callback(solv, solv->solution_callback_data);
2280 if (solv->branches.count)
2282 int i = solv->branches.count - 1;
2283 int l = -solv->branches.elements[i];
2287 if (solv->branches.elements[i - 1] < 0)
2289 p = solv->branches.elements[i];
2290 POOL_DEBUG(SOLV_DEBUG_SOLVER, "branching with %s\n", pool_solvid2str(pool, p));
2292 for (j = i + 1; j < solv->branches.count; j++)
2293 queue_push(&dq, solv->branches.elements[j]);
2294 solv->branches.count = i;
2296 revert(solv, level);
2298 for (j = 0; j < dq.count; j++)
2299 queue_push(&solv->branches, dq.elements[j]);
2301 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
2303 level = setpropagatelearn(solv, level, p, disablerules, why);
2308 /* all branches done, we're finally finished */
2312 /* auto-minimization step */
2313 if (solv->branches.count)
2315 int l = 0, lasti = -1, lastl = -1;
2319 for (i = solv->branches.count - 1; i >= 0; i--)
2321 p = solv->branches.elements[i];
2324 else if (p > 0 && solv->decisionmap[p] > l + 1)
2332 /* kill old solvable so that we do not loop */
2333 p = solv->branches.elements[lasti];
2334 solv->branches.elements[lasti] = 0;
2335 POOL_DEBUG(SOLV_DEBUG_SOLVER, "minimizing %d -> %d with %s\n", solv->decisionmap[p], lastl, pool_solvid2str(pool, p));
2336 minimizationsteps++;
2339 revert(solv, level);
2340 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
2343 level = setpropagatelearn(solv, level, p, disablerules, why);
2346 continue; /* back to main loop */
2349 /* no minimization found, we're finally finished! */
2353 POOL_DEBUG(SOLV_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
2355 POOL_DEBUG(SOLV_DEBUG_STATS, "done solving.\n\n");
2361 solv->decisioncnt_update = solv->decisionq.count;
2362 solv->decisioncnt_keep = solv->decisionq.count;
2363 solv->decisioncnt_resolve = solv->decisionq.count;
2364 solv->decisioncnt_weak = solv->decisionq.count;
2365 solv->decisioncnt_orphan = solv->decisionq.count;
2368 solver_printdecisionq(solv, SOLV_DEBUG_RESULT);
2373 /*-------------------------------------------------------------------
2375 * remove disabled conflicts
2377 * purpose: update the decisionmap after some rules were disabled.
2378 * this is used to calculate the suggested/recommended package list.
2379 * Also returns a "removed" list to undo the discisionmap changes.
2383 removedisabledconflicts(Solver *solv, Queue *removed)
2385 Pool *pool = solv->pool;
2390 Id *decisionmap = solv->decisionmap;
2392 queue_empty(removed);
2393 for (i = 0; i < solv->decisionq.count; i++)
2395 p = solv->decisionq.elements[i];
2397 continue; /* conflicts only, please */
2398 why = solv->decisionq_why.elements[i];
2401 /* no rule involved, must be a orphan package drop */
2404 /* we never do conflicts on free decisions, so there
2405 * must have been an unit rule */
2407 r = solv->rules + why;
2408 if (r->d < 0 && decisionmap[-p])
2410 /* rule is now disabled, remove from decisionmap */
2411 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing conflict for package %s[%d]\n", pool_solvid2str(pool, -p), -p);
2412 queue_push(removed, -p);
2413 queue_push(removed, decisionmap[-p]);
2414 decisionmap[-p] = 0;
2417 if (!removed->count)
2419 /* we removed some confliced packages. some of them might still
2420 * be in conflict, so search for unit rules and re-conflict */
2422 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
2424 if (i == solv->nrules)
2427 r = solv->rules + i;
2433 if (r->p < 0 && !decisionmap[-r->p])
2439 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
2441 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
2446 if (r->p < 0 && decisionmap[-r->p] == 0)
2448 if (new || DECISIONMAP_FALSE(r->p))
2450 dp = pool->whatprovidesdata + r->d;
2451 while ((p = *dp++) != 0)
2453 if (new && p == new)
2455 if (p < 0 && decisionmap[-p] == 0)
2464 else if (!DECISIONMAP_FALSE(p))
2474 POOL_DEBUG(SOLV_DEBUG_SOLVER, "re-conflicting package %s[%d]\n", pool_solvid2str(pool, -new), -new);
2475 decisionmap[-new] = -1;
2477 n = 0; /* redo all rules */
2483 undo_removedisabledconflicts(Solver *solv, Queue *removed)
2486 for (i = 0; i < removed->count; i += 2)
2487 solv->decisionmap[removed->elements[i]] = removed->elements[i + 1];
2491 /*-------------------------------------------------------------------
2493 * weaken solvable dependencies
2497 weaken_solvable_deps(Solver *solv, Id p)
2502 for (i = 1, r = solv->rules + i; i < solv->rpmrules_end; i++, r++)
2506 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
2507 continue; /* conflict */
2508 queue_push(&solv->weakruleq, i);
2513 /********************************************************************/
2518 solver_calculate_noobsmap(Pool *pool, Queue *job, Map *noobsmap)
2521 Id how, what, select;
2523 for (i = 0; i < job->count; i += 2)
2525 how = job->elements[i];
2526 if ((how & SOLVER_JOBMASK) != SOLVER_NOOBSOLETES)
2528 what = job->elements[i + 1];
2529 select = how & SOLVER_SELECTMASK;
2530 if (!noobsmap->size)
2531 map_grow(noobsmap, pool->nsolvables);
2532 if (select == SOLVER_SOLVABLE_ALL)
2534 FOR_POOL_SOLVABLES(p)
2535 MAPSET(noobsmap, p);
2537 else if (select == SOLVER_SOLVABLE_REPO)
2540 Repo *repo = pool_id2repo(pool, what);
2542 FOR_REPO_SOLVABLES(repo, p, s)
2543 MAPSET(noobsmap, p);
2545 FOR_JOB_SELECT(p, pp, select, what)
2546 MAPSET(noobsmap, p);
2551 * add a rule created by a job, record job number and weak flag
2554 solver_addjobrule(Solver *solv, Id p, Id d, Id job, int weak)
2556 solver_addrule(solv, p, d);
2557 queue_push(&solv->ruletojob, job);
2559 queue_push(&solv->weakruleq, solv->nrules - 1);
2569 solver_solve(Solver *solv, Queue *job)
2571 Pool *pool = solv->pool;
2572 Repo *installed = solv->installed;
2575 Map addedmap; /* '1' == have rpm-rules for solvable */
2576 Map installcandidatemap;
2577 Id how, what, select, name, weak, p, pp, d;
2581 int now, solve_start;
2584 solve_start = solv_timems(0);
2586 /* log solver options */
2587 POOL_DEBUG(SOLV_DEBUG_STATS, "solver started\n");
2588 POOL_DEBUG(SOLV_DEBUG_STATS, "dosplitprovides=%d, noupdateprovide=%d, noinfarchcheck=%d\n", solv->dosplitprovides, solv->noupdateprovide, solv->noinfarchcheck);
2589 POOL_DEBUG(SOLV_DEBUG_STATS, "allowuninstall=%d, allowdowngrade=%d, allownamechange=%d, allowarchchange=%d, allowvendorchange=%d\n", solv->allowuninstall, solv->allowdowngrade, solv->allownamechange, solv->allowarchchange, solv->allowvendorchange);
2590 POOL_DEBUG(SOLV_DEBUG_STATS, "promoteepoch=%d, forbidselfconflicts=%d\n", pool->promoteepoch, pool->forbidselfconflicts);
2591 POOL_DEBUG(SOLV_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d, obsoleteusescolors=%d\n", pool->obsoleteusesprovides, pool->implicitobsoleteusesprovides, pool->obsoleteusescolors);
2592 POOL_DEBUG(SOLV_DEBUG_STATS, "dontinstallrecommended=%d, addalreadyrecommended=%d\n", solv->dontinstallrecommended, solv->addalreadyrecommended);
2594 /* create whatprovides if not already there */
2595 if (!pool->whatprovides)
2596 pool_createwhatprovides(pool);
2598 /* create obsolete index */
2599 policy_create_obsolete_index(solv);
2602 queue_free(&solv->job);
2603 queue_init_clone(&solv->job, job);
2606 * create basic rule set of all involved packages
2607 * use addedmap bitmap to make sure we don't create rules twice
2610 /* create noobsolete map if needed */
2611 solver_calculate_noobsmap(pool, job, &solv->noobsoletes);
2613 map_init(&addedmap, pool->nsolvables);
2614 MAPSET(&addedmap, SYSTEMSOLVABLE);
2616 map_init(&installcandidatemap, pool->nsolvables);
2619 now = solv_timems(0);
2621 * create rules for all package that could be involved with the solving
2622 * so called: rpm rules
2627 /* check for update/verify jobs as they need to be known early */
2628 for (i = 0; i < job->count; i += 2)
2630 how = job->elements[i];
2631 what = job->elements[i + 1];
2632 select = how & SOLVER_SELECTMASK;
2633 switch (how & SOLVER_JOBMASK)
2636 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && solv->installed && what == solv->installed->repoid))
2637 solv->fixmap_all = 1;
2638 FOR_JOB_SELECT(p, pp, select, what)
2640 s = pool->solvables + p;
2641 if (!solv->installed || s->repo != solv->installed)
2643 if (!solv->fixmap.size)
2644 map_grow(&solv->fixmap, solv->installed->end - solv->installed->start);
2645 MAPSET(&solv->fixmap, p - solv->installed->start);
2649 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && solv->installed && what == solv->installed->repoid))
2650 solv->updatemap_all = 1;
2651 FOR_JOB_SELECT(p, pp, select, what)
2653 s = pool->solvables + p;
2654 if (!solv->installed || s->repo != solv->installed)
2656 if (!solv->updatemap.size)
2657 map_grow(&solv->updatemap, solv->installed->end - solv->installed->start);
2658 MAPSET(&solv->updatemap, p - solv->installed->start);
2666 oldnrules = solv->nrules;
2667 FOR_REPO_SOLVABLES(installed, p, s)
2668 solver_addrpmrulesforsolvable(solv, s, &addedmap);
2669 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
2670 oldnrules = solv->nrules;
2671 FOR_REPO_SOLVABLES(installed, p, s)
2672 solver_addrpmrulesforupdaters(solv, s, &addedmap, 1);
2673 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
2677 * create rules for all packages involved in the job
2678 * (to be installed or removed)
2681 oldnrules = solv->nrules;
2682 for (i = 0; i < job->count; i += 2)
2684 how = job->elements[i];
2685 what = job->elements[i + 1];
2686 select = how & SOLVER_SELECTMASK;
2688 switch (how & SOLVER_JOBMASK)
2690 case SOLVER_INSTALL:
2691 FOR_JOB_SELECT(p, pp, select, what)
2693 MAPSET(&installcandidatemap, p);
2694 solver_addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
2697 case SOLVER_DISTUPGRADE:
2698 if (select == SOLVER_SOLVABLE_ALL)
2700 solv->dupmap_all = 1;
2701 solv->updatemap_all = 1;
2703 if (!solv->dupmap_all)
2710 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
2714 * add rules for suggests, enhances
2716 oldnrules = solv->nrules;
2717 solver_addrpmrulesforweak(solv, &addedmap);
2718 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
2721 * first pass done, we now have all the rpm rules we need.
2722 * unify existing rules before going over all job rules and
2724 * at this point the system is always solvable,
2725 * as an empty system (remove all packages) is a valid solution
2728 IF_POOLDEBUG (SOLV_DEBUG_STATS)
2730 int possible = 0, installable = 0;
2731 for (i = 1; i < pool->nsolvables; i++)
2733 if (pool_installable(pool, pool->solvables + i))
2735 if (MAPTST(&addedmap, i))
2738 POOL_DEBUG(SOLV_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
2741 solver_unifyrules(solv); /* remove duplicate rpm rules */
2742 solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
2744 POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
2745 POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule creation took %d ms\n", solv_timems(now));
2747 /* create dup maps if needed. We need the maps early to create our
2750 solver_createdupmaps(solv);
2753 * create feature rules
2755 * foreach installed:
2756 * create assertion (keep installed, if no update available)
2758 * create update rule (A|update1(A)|update2(A)|...)
2760 * those are used later on to keep a version of the installed packages in
2764 solv->featurerules = solv->nrules; /* mark start of feature rules */
2767 /* foreach possibly installed solvable */
2768 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
2770 if (s->repo != installed)
2772 solver_addrule(solv, 0, 0); /* create dummy rule */
2775 solver_addupdaterule(solv, s, 1); /* allow s to be updated */
2777 /* make sure we accounted for all rules */
2778 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
2780 solv->featurerules_end = solv->nrules;
2783 * Add update rules for installed solvables
2785 * almost identical to feature rules
2786 * except that downgrades/archchanges/vendorchanges are not allowed
2789 solv->updaterules = solv->nrules;
2792 { /* foreach installed solvables */
2793 /* we create all update rules, but disable some later on depending on the job */
2794 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
2798 if (s->repo != installed)
2800 solver_addrule(solv, 0, 0); /* create dummy rule */
2803 solver_addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
2805 * check for and remove duplicate
2807 r = solv->rules + solv->nrules - 1; /* r: update rule */
2808 sr = r - (installed->end - installed->start); /* sr: feature rule */
2809 /* it's orphaned if there is no feature rule or the feature rule
2810 * consists just of the installed package */
2811 if (!sr->p || (sr->p == i && !sr->d && !sr->w2))
2812 queue_push(&solv->orphaned, i);
2815 assert(solv->dupmap_all && !sr->p);
2818 if (!solver_samerule(solv, r, sr))
2819 memset(sr, 0, sizeof(*sr)); /* delete unneeded feature rule */
2821 solver_disablerule(solv, sr); /* disable feature rule */
2823 /* consistency check: we added a rule for _every_ installed solvable */
2824 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
2826 solv->updaterules_end = solv->nrules;
2830 * now add all job rules
2833 solv->jobrules = solv->nrules;
2834 if (solv->cleandeps_updatepkgs)
2836 queue_free(solv->cleandeps_updatepkgs);
2837 solv->cleandeps_updatepkgs = solv_free(solv->cleandeps_updatepkgs);
2839 for (i = 0; i < job->count; i += 2)
2841 oldnrules = solv->nrules;
2843 how = job->elements[i];
2844 what = job->elements[i + 1];
2845 weak = how & SOLVER_WEAK;
2846 select = how & SOLVER_SELECTMASK;
2847 switch (how & SOLVER_JOBMASK)
2849 case SOLVER_INSTALL:
2850 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
2851 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
2852 map_grow(&solv->cleandepsmap, installed->end - installed->start);
2853 if (select == SOLVER_SOLVABLE)
2861 FOR_JOB_SELECT(p, pp, select, what)
2865 /* no candidate found, make this an impossible rule */
2866 queue_push(&q, -SYSTEMSOLVABLE);
2868 p = queue_shift(&q); /* get first candidate */
2869 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
2871 solver_addjobrule(solv, p, d, i, weak);
2874 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %s%serase %s\n", weak ? "weak " : "", how & SOLVER_CLEANDEPS ? "clean deps " : "", solver_select2str(pool, select, what));
2875 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
2876 map_grow(&solv->cleandepsmap, installed->end - installed->start);
2877 /* specific solvable: by id or by nevra */
2878 name = (select == SOLVER_SOLVABLE || (select == SOLVER_SOLVABLE_NAME && ISRELDEP(what))) ? 0 : -1;
2879 if (select == SOLVER_SOLVABLE_ALL) /* hmmm ;) */
2881 FOR_POOL_SOLVABLES(p)
2882 solver_addjobrule(solv, -p, 0, i, weak);
2884 else if (select == SOLVER_SOLVABLE_REPO)
2886 Repo *repo = pool_id2repo(pool, what);
2888 FOR_REPO_SOLVABLES(repo, p, s)
2889 solver_addjobrule(solv, -p, 0, i, weak);
2891 FOR_JOB_SELECT(p, pp, select, what)
2893 s = pool->solvables + p;
2894 if (installed && s->repo == installed)
2895 name = !name ? s->name : -1;
2896 solver_addjobrule(solv, -p, 0, i, weak);
2898 /* special case for "erase a specific solvable": we also
2899 * erase all other solvables with that name, so that they
2900 * don't get picked up as replacement.
2901 * name is > 0 if exactly one installed solvable matched.
2903 /* XXX: look also at packages that obsolete this package? */
2908 FOR_PROVIDES(p, pp, name)
2910 s = pool->solvables + p;
2911 if (s->name != name)
2913 /* keep other versions installed */
2914 if (s->repo == installed)
2916 /* keep installcandidates of other jobs */
2917 if (MAPTST(&installcandidatemap, p))
2919 /* don't add the same rule twice */
2920 for (j = oldnrules; j < k; j++)
2921 if (solv->rules[j].p == -p)
2924 solver_addjobrule(solv, -p, 0, i, weak); /* remove by id */
2930 if ((how & SOLVER_CLEANDEPS) != 0 && installed)
2932 if (how == SOLVER_SOLVABLE_ALL || (how == SOLVER_SOLVABLE_REPO && what == installed->repoid))
2934 FOR_REPO_SOLVABLES(installed, p, s)
2936 if (!solv->cleandeps_updatepkgs)
2938 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
2939 queue_init(solv->cleandeps_updatepkgs);
2941 queue_pushunique(solv->cleandeps_updatepkgs, p);
2942 if (!solv->cleandepsmap.size)
2943 map_grow(&solv->cleandepsmap, installed->end - installed->start);
2946 FOR_JOB_SELECT(p, pp, select, what)
2948 s = pool->solvables + p;
2949 if (s->repo != installed)
2951 if (!solv->cleandeps_updatepkgs)
2953 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
2954 queue_init(solv->cleandeps_updatepkgs);
2956 queue_pushunique(solv->cleandeps_updatepkgs, p);
2957 if (!solv->cleandepsmap.size)
2958 map_grow(&solv->cleandepsmap, installed->end - installed->start);
2961 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
2964 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sverify %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
2966 case SOLVER_WEAKENDEPS:
2967 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
2968 if (select != SOLVER_SOLVABLE)
2970 s = pool->solvables + what;
2971 weaken_solvable_deps(solv, what);
2973 case SOLVER_NOOBSOLETES:
2974 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sno obsolete %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
2977 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
2978 if (select == SOLVER_SOLVABLE_ALL)
2980 FOR_POOL_SOLVABLES(p)
2981 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
2983 else if (select == SOLVER_SOLVABLE_REPO)
2985 Repo *repo = pool_id2repo(pool, what);
2987 FOR_REPO_SOLVABLES(repo, p, s)
2988 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
2990 FOR_JOB_SELECT(p, pp, select, what)
2991 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
2993 case SOLVER_DISTUPGRADE:
2994 POOL_DEBUG(SOLV_DEBUG_JOB, "job: distupgrade %s\n", solver_select2str(pool, select, what));
2996 case SOLVER_DROP_ORPHANED:
2997 POOL_DEBUG(SOLV_DEBUG_JOB, "job: drop orphaned %s\n", solver_select2str(pool, select, what));
2998 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
2999 solv->droporphanedmap_all = 1;
3000 FOR_JOB_SELECT(p, pp, select, what)
3002 s = pool->solvables + p;
3003 if (!installed || s->repo != installed)
3005 if (!solv->droporphanedmap.size)
3006 map_grow(&solv->droporphanedmap, installed->end - installed->start);
3007 MAPSET(&solv->droporphanedmap, p - installed->start);
3010 case SOLVER_USERINSTALLED:
3011 POOL_DEBUG(SOLV_DEBUG_JOB, "job: user installed %s\n", solver_select2str(pool, select, what));
3014 POOL_DEBUG(SOLV_DEBUG_JOB, "job: unknown job\n");
3022 IF_POOLDEBUG (SOLV_DEBUG_JOB)
3025 if (solv->nrules == oldnrules)
3026 POOL_DEBUG(SOLV_DEBUG_JOB, " - no rule created\n");
3027 for (j = oldnrules; j < solv->nrules; j++)
3029 POOL_DEBUG(SOLV_DEBUG_JOB, " - job ");
3030 solver_printrule(solv, SOLV_DEBUG_JOB, solv->rules + j);
3034 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3035 solv->jobrules_end = solv->nrules;
3037 /* now create infarch and dup rules */
3038 if (!solv->noinfarchcheck)
3040 solver_addinfarchrules(solv, &addedmap);
3041 if (pool->obsoleteusescolors)
3043 /* currently doesn't work well with infarch rules, so make
3045 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
3046 queue_push(&solv->weakruleq, i);
3050 solv->infarchrules = solv->infarchrules_end = solv->nrules;
3054 solver_addduprules(solv, &addedmap);
3055 solver_freedupmaps(solv); /* no longer needed */
3058 solv->duprules = solv->duprules_end = solv->nrules;
3061 solver_addchoicerules(solv);
3063 solv->choicerules = solv->choicerules_end = solv->nrules;
3065 /* all rules created
3066 * --------------------------------------------------------------
3067 * prepare for solving
3070 /* free unneeded memory */
3071 map_free(&addedmap);
3072 map_free(&installcandidatemap);
3075 POOL_DEBUG(SOLV_DEBUG_STATS, "%d rpm rules, 2 * %d update rules, %d job rules, %d infarch rules, %d dup rules, %d choice rules\n", solv->rpmrules_end - 1, solv->updaterules_end - solv->updaterules, solv->jobrules_end - solv->jobrules, solv->infarchrules_end - solv->infarchrules, solv->duprules_end - solv->duprules, solv->choicerules_end - solv->choicerules);
3076 POOL_DEBUG(SOLV_DEBUG_STATS, "overall rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3078 /* create weak map */
3079 map_init(&solv->weakrulemap, solv->nrules);
3080 for (i = 0; i < solv->weakruleq.count; i++)
3082 p = solv->weakruleq.elements[i];
3083 MAPSET(&solv->weakrulemap, p);
3086 /* all new rules are learnt after this point */
3087 solv->learntrules = solv->nrules;
3089 /* create watches chains */
3092 /* create assertion index. it is only used to speed up
3093 * makeruledecsions() a bit */
3094 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
3095 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
3096 queue_push(&solv->ruleassertions, i);
3098 /* disable update rules that conflict with our job */
3099 solver_disablepolicyrules(solv);
3101 /* make initial decisions based on assertion rules */
3102 makeruledecisions(solv);
3103 POOL_DEBUG(SOLV_DEBUG_SOLVER, "problems so far: %d\n", solv->problems.count);
3106 if (solv->cleandeps_mistakes)
3108 queue_free(solv->cleandeps_mistakes);
3109 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
3113 * ********************************************
3115 * ********************************************
3118 now = solv_timems(0);
3119 solver_run_sat(solv, 1, solv->dontinstallrecommended ? 0 : 1);
3120 POOL_DEBUG(SOLV_DEBUG_STATS, "solver took %d ms\n", solv_timems(now));
3123 * prepare solution queue if there were problems
3125 solver_prepare_solutions(solv);
3127 POOL_DEBUG(SOLV_DEBUG_STATS, "final solver statistics: %d problems, %d learned rules, %d unsolvable\n", solv->problems.count / 2, solv->stats_learned, solv->stats_unsolvable);
3128 POOL_DEBUG(SOLV_DEBUG_STATS, "solver_solve took %d ms\n", solv_timems(solve_start));
3130 /* return number of problems */
3131 return solv->problems.count ? solv->problems.count / 2 : 0;
3135 solver_create_transaction(Solver *solv)
3137 return transaction_create_decisionq(solv->pool, &solv->decisionq, &solv->noobsoletes);
3140 void solver_get_orphaned(Solver *solv, Queue *orphanedq)
3142 queue_free(orphanedq);
3143 queue_init_clone(orphanedq, &solv->orphaned);
3146 void solver_get_recommendations(Solver *solv, Queue *recommendationsq, Queue *suggestionsq, int noselected)
3148 Pool *pool = solv->pool;
3149 Queue redoq, disabledq;
3155 if (!recommendationsq && !suggestionsq)
3158 map_init(&obsmap, pool->nsolvables);
3159 if (solv->installed)
3161 Id obs, *obsp, p, po, ppo;
3162 for (p = solv->installed->start; p < solv->installed->end; p++)
3164 s = pool->solvables + p;
3165 if (s->repo != solv->installed || !s->obsoletes)
3167 if (solv->decisionmap[p] <= 0)
3169 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p))
3171 obsp = s->repo->idarraydata + s->obsoletes;
3172 /* foreach obsoletes */
3173 while ((obs = *obsp++) != 0)
3174 FOR_PROVIDES(po, ppo, obs)
3175 MAPSET(&obsmap, po);
3180 queue_init(&disabledq);
3182 /* disable all erase jobs (including weak "keep uninstalled" rules) */
3183 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
3185 if (r->d < 0) /* disabled ? */
3187 if (r->p >= 0) /* install job? */
3189 queue_push(&disabledq, i);
3190 solver_disablerule(solv, r);
3196 enabledisablelearntrules(solv);
3197 removedisabledconflicts(solv, &redoq);
3201 * find recommended packages
3203 if (recommendationsq)
3205 Id rec, *recp, p, pp;
3207 queue_empty(recommendationsq);
3208 /* create map of all recommened packages */
3209 solv->recommends_index = -1;
3210 MAPZERO(&solv->recommendsmap);
3212 /* put all packages the solver already chose in the map */
3213 if (solv->decisioncnt_weak)
3215 for (i = solv->decisioncnt_weak; i < solv->decisioncnt_orphan; i++)
3218 why = solv->decisionq_why.elements[i];
3220 continue; /* forced by unit rule */
3221 p = solv->decisionq.elements[i];
3224 MAPSET(&solv->recommendsmap, p);
3228 for (i = 0; i < solv->decisionq.count; i++)
3230 p = solv->decisionq.elements[i];
3233 s = pool->solvables + p;
3236 recp = s->repo->idarraydata + s->recommends;
3237 while ((rec = *recp++) != 0)
3239 FOR_PROVIDES(p, pp, rec)
3240 if (solv->decisionmap[p] > 0)
3246 FOR_PROVIDES(p, pp, rec)
3247 if (solv->decisionmap[p] > 0)
3248 MAPSET(&solv->recommendsmap, p);
3250 continue; /* p != 0: already fulfilled */
3252 FOR_PROVIDES(p, pp, rec)
3253 MAPSET(&solv->recommendsmap, p);
3257 for (i = 1; i < pool->nsolvables; i++)
3259 if (solv->decisionmap[i] < 0)
3261 if (solv->decisionmap[i] > 0 && noselected)
3263 if (MAPTST(&obsmap, i))
3265 s = pool->solvables + i;
3266 if (!MAPTST(&solv->recommendsmap, i))
3268 if (!s->supplements)
3270 if (!pool_installable(pool, s))
3272 if (!solver_is_supplementing(solv, s))
3275 queue_push(recommendationsq, i);
3277 /* we use MODE_SUGGEST here so that repo prio is ignored */
3278 policy_filter_unwanted(solv, recommendationsq, POLICY_MODE_SUGGEST);
3282 * find suggested packages
3287 Id sug, *sugp, p, pp;
3289 queue_empty(suggestionsq);
3290 /* create map of all suggests that are still open */
3291 solv->recommends_index = -1;
3292 MAPZERO(&solv->suggestsmap);
3293 for (i = 0; i < solv->decisionq.count; i++)
3295 p = solv->decisionq.elements[i];
3298 s = pool->solvables + p;
3301 sugp = s->repo->idarraydata + s->suggests;
3302 while ((sug = *sugp++) != 0)
3304 FOR_PROVIDES(p, pp, sug)
3305 if (solv->decisionmap[p] > 0)
3311 FOR_PROVIDES(p, pp, sug)
3312 if (solv->decisionmap[p] > 0)
3313 MAPSET(&solv->suggestsmap, p);
3315 continue; /* already fulfilled */
3317 FOR_PROVIDES(p, pp, sug)
3318 MAPSET(&solv->suggestsmap, p);
3322 for (i = 1; i < pool->nsolvables; i++)
3324 if (solv->decisionmap[i] < 0)
3326 if (solv->decisionmap[i] > 0 && noselected)
3328 if (MAPTST(&obsmap, i))
3330 s = pool->solvables + i;
3331 if (!MAPTST(&solv->suggestsmap, i))
3335 if (!pool_installable(pool, s))
3337 if (!solver_is_enhancing(solv, s))
3340 queue_push(suggestionsq, i);
3342 policy_filter_unwanted(solv, suggestionsq, POLICY_MODE_SUGGEST);
3345 /* undo removedisabledconflicts */
3347 undo_removedisabledconflicts(solv, &redoq);
3350 /* undo job rule disabling */
3351 for (i = 0; i < disabledq.count; i++)
3352 solver_enablerule(solv, solv->rules + disabledq.elements[i]);
3353 queue_free(&disabledq);
3358 /***********************************************************************/
3359 /* disk usage computations */
3361 /*-------------------------------------------------------------------
3363 * calculate DU changes
3367 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
3371 solver_create_state_maps(solv, &installedmap, 0);
3372 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
3373 map_free(&installedmap);
3377 /*-------------------------------------------------------------------
3379 * calculate changes in install size
3383 solver_calc_installsizechange(Solver *solv)
3388 solver_create_state_maps(solv, &installedmap, 0);
3389 change = pool_calc_installsizechange(solv->pool, &installedmap);
3390 map_free(&installedmap);
3395 solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
3397 pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
3401 solver_trivial_installable(Solver *solv, Queue *pkgs, Queue *res)
3404 pool_create_state_maps(solv->pool, &solv->decisionq, &installedmap, 0);
3405 pool_trivial_installable_noobsoletesmap(solv->pool, &installedmap, pkgs, res, solv->noobsoletes.size ? &solv->noobsoletes : 0);
3406 map_free(&installedmap);
3409 /*-------------------------------------------------------------------
3411 * decision introspection
3415 solver_get_decisionlevel(Solver *solv, Id p)
3417 return solv->decisionmap[p];
3421 solver_get_decisionqueue(Solver *solv, Queue *decisionq)
3423 queue_free(decisionq);
3424 queue_init_clone(decisionq, &solv->decisionq);
3428 solver_get_lastdecisionblocklevel(Solver *solv)
3431 if (solv->decisionq.count == 0)
3433 p = solv->decisionq.elements[solv->decisionq.count - 1];
3436 return solv->decisionmap[p] < 0 ? -solv->decisionmap[p] : solv->decisionmap[p];
3440 solver_get_decisionblock(Solver *solv, int level, Queue *decisionq)
3445 queue_empty(decisionq);
3446 for (i = 0; i < solv->decisionq.count; i++)
3448 p = solv->decisionq.elements[i];
3451 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
3454 if (i == solv->decisionq.count)
3456 for (i = 0; i < solv->decisionq.count; i++)
3458 p = solv->decisionq.elements[i];
3461 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
3462 queue_push(decisionq, p);
3469 solver_describe_decision(Solver *solv, Id p, Id *infop)
3476 if (!solv->decisionmap[p])
3477 return SOLVER_REASON_UNRELATED;
3478 pp = solv->decisionmap[p] < 0 ? -p : p;
3479 for (i = 0; i < solv->decisionq.count; i++)
3480 if (solv->decisionq.elements[i] == pp)
3482 if (i == solv->decisionq.count) /* just in case... */
3483 return SOLVER_REASON_UNRELATED;
3484 why = solv->decisionq_why.elements[i];
3489 return SOLVER_REASON_UNIT_RULE;
3492 if (i < solv->decisioncnt_update)
3497 *infop = SYSTEMSOLVABLE;
3498 return SOLVER_REASON_KEEP_INSTALLED;
3502 return SOLVER_REASON_RESOLVE_JOB;
3504 if (i < solv->decisioncnt_keep)
3506 if (why == 0 && pp < 0)
3507 return SOLVER_REASON_CLEANDEPS_ERASE;
3510 if (why >= solv->updaterules && why < solv->updaterules_end)
3511 *infop = why - solv->updaterules;
3512 else if (why >= solv->featurerules && why < solv->featurerules_end)
3513 *infop = why - solv->featurerules;
3515 return SOLVER_REASON_UPDATE_INSTALLED;
3517 if (i < solv->decisioncnt_resolve)
3519 if (why == 0 && pp < 0)
3520 return SOLVER_REASON_CLEANDEPS_ERASE;
3523 if (why >= solv->updaterules && why < solv->updaterules_end)
3524 *infop = why - solv->updaterules;
3525 else if (why >= solv->featurerules && why < solv->featurerules_end)
3526 *infop = why - solv->featurerules;
3528 return SOLVER_REASON_KEEP_INSTALLED;
3530 if (i < solv->decisioncnt_weak)
3534 return SOLVER_REASON_RESOLVE;
3536 if (solv->decisionq.count < solv->decisioncnt_orphan)
3537 return SOLVER_REASON_WEAKDEP;
3538 return SOLVER_REASON_RESOLVE_ORPHAN;
3543 solver_describe_weakdep_decision(Solver *solv, Id p, Queue *whyq)
3545 Pool *pool = solv->pool;
3547 int level = solv->decisionmap[p];
3554 for (decisionno = 0; decisionno < solv->decisionq.count; decisionno++)
3555 if (solv->decisionq.elements[decisionno] == p)
3557 if (decisionno == solv->decisionq.count)
3559 if (decisionno < solv->decisioncnt_weak || decisionno >= solv->decisioncnt_orphan)
3562 /* 1) list all packages that recommend us */
3563 for (i = 1; i < pool->nsolvables; i++)
3565 Id *recp, rec, pp2, p2;
3566 if (solv->decisionmap[i] < 0 || solv->decisionmap[i] >= level)
3568 s = pool->solvables + i;
3571 if (!solv->addalreadyrecommended && s->repo == solv->installed)
3573 recp = s->repo->idarraydata + s->recommends;
3574 while ((rec = *recp++) != 0)
3577 FOR_PROVIDES(p2, pp2, rec)
3583 /* if p2 is already installed, this recommends is ignored */
3584 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
3590 queue_push(whyq, SOLVER_REASON_RECOMMENDED);
3591 queue_push2(whyq, p2, rec);
3595 /* 2) list all supplements */
3596 s = pool->solvables + p;
3597 if (s->supplements && level > 0)
3599 Id *supp, sup, pp2, p2;
3600 /* this is a hack. to use solver_dep_fulfilled we temporarily clear
3601 * everything above our level in the decisionmap */
3602 for (i = decisionno; i < solv->decisionq.count; i++ )
3604 p2 = solv->decisionq.elements[i];
3606 solv->decisionmap[p2] = -solv->decisionmap[p2];
3608 supp = s->repo->idarraydata + s->supplements;
3609 while ((sup = *supp++) != 0)
3610 if (solver_dep_fulfilled(solv, sup))
3613 /* let's see if this is an easy supp */
3614 FOR_PROVIDES(p2, pp2, sup)
3616 if (!solv->addalreadyrecommended && solv->installed)
3618 if (pool->solvables[p2].repo == solv->installed)
3621 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
3623 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
3624 queue_push2(whyq, p2, sup);
3630 /* hard case, just note dependency with no package */
3631 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
3632 queue_push2(whyq, 0, sup);
3635 for (i = decisionno; i < solv->decisionq.count; i++)
3637 p2 = solv->decisionq.elements[i];
3639 solv->decisionmap[p2] = -solv->decisionmap[p2];
3645 pool_job2solvables(Pool *pool, Queue *pkgs, Id how, Id what)
3648 how &= SOLVER_SELECTMASK;
3650 if (how == SOLVER_SOLVABLE_ALL)
3652 FOR_POOL_SOLVABLES(p)
3653 queue_push(pkgs, p);
3655 else if (how == SOLVER_SOLVABLE_REPO)
3657 Repo *repo = pool_id2repo(pool, what);
3660 FOR_REPO_SOLVABLES(repo, p, s)
3661 queue_push(pkgs, p);
3665 FOR_JOB_SELECT(p, pp, how, what)
3666 queue_push(pkgs, p);