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->dup_allowdowngrade = 1;
1364 solv->dup_allowarchchange = 1;
1365 solv->dup_allowvendorchange = 1;
1367 queue_init(&solv->ruletojob);
1368 queue_init(&solv->decisionq);
1369 queue_init(&solv->decisionq_why);
1370 queue_init(&solv->problems);
1371 queue_init(&solv->orphaned);
1372 queue_init(&solv->learnt_why);
1373 queue_init(&solv->learnt_pool);
1374 queue_init(&solv->branches);
1375 queue_init(&solv->weakruleq);
1376 queue_init(&solv->ruleassertions);
1378 queue_push(&solv->learnt_pool, 0); /* so that 0 does not describe a proof */
1380 map_init(&solv->recommendsmap, pool->nsolvables);
1381 map_init(&solv->suggestsmap, pool->nsolvables);
1382 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
1383 solv->recommends_index = 0;
1385 solv->decisionmap = (Id *)solv_calloc(pool->nsolvables, sizeof(Id));
1387 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
1388 memset(solv->rules, 0, sizeof(Rule));
1394 /*-------------------------------------------------------------------
1400 solver_free(Solver *solv)
1402 queue_free(&solv->job);
1403 queue_free(&solv->ruletojob);
1404 queue_free(&solv->decisionq);
1405 queue_free(&solv->decisionq_why);
1406 queue_free(&solv->learnt_why);
1407 queue_free(&solv->learnt_pool);
1408 queue_free(&solv->problems);
1409 queue_free(&solv->solutions);
1410 queue_free(&solv->orphaned);
1411 queue_free(&solv->branches);
1412 queue_free(&solv->weakruleq);
1413 queue_free(&solv->ruleassertions);
1414 if (solv->cleandeps_updatepkgs)
1416 queue_free(solv->cleandeps_updatepkgs);
1417 solv->cleandeps_updatepkgs = solv_free(solv->cleandeps_updatepkgs);
1419 if (solv->cleandeps_mistakes)
1421 queue_free(solv->cleandeps_mistakes);
1422 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
1425 map_free(&solv->recommendsmap);
1426 map_free(&solv->suggestsmap);
1427 map_free(&solv->noupdate);
1428 map_free(&solv->weakrulemap);
1429 map_free(&solv->noobsoletes);
1431 map_free(&solv->updatemap);
1432 map_free(&solv->fixmap);
1433 map_free(&solv->dupmap);
1434 map_free(&solv->dupinvolvedmap);
1435 map_free(&solv->droporphanedmap);
1436 map_free(&solv->cleandepsmap);
1438 solv_free(solv->decisionmap);
1439 solv_free(solv->rules);
1440 solv_free(solv->watches);
1441 solv_free(solv->obsoletes);
1442 solv_free(solv->obsoletes_data);
1443 solv_free(solv->multiversionupdaters);
1444 solv_free(solv->choicerules_ref);
1449 solver_get_flag(Solver *solv, int flag)
1453 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1454 return solv->allowdowngrade;
1455 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1456 return solv->allowarchchange;
1457 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1458 return solv->allowvendorchange;
1459 case SOLVER_FLAG_ALLOW_UNINSTALL:
1460 return solv->allowuninstall;
1461 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1462 return solv->noupdateprovide;
1463 case SOLVER_FLAG_SPLITPROVIDES:
1464 return solv->dosplitprovides;
1465 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1466 return solv->dontinstallrecommended;
1467 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1468 return solv->addalreadyrecommended;
1469 case SOLVER_FLAG_NO_INFARCHCHECK:
1470 return solv->noinfarchcheck;
1478 solver_set_flag(Solver *solv, int flag, int value)
1480 int old = solver_get_flag(solv, flag);
1483 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1484 solv->allowdowngrade = value;
1486 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1487 solv->allowarchchange = value;
1489 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1490 solv->allowvendorchange = value;
1492 case SOLVER_FLAG_ALLOW_UNINSTALL:
1493 solv->allowuninstall = value;
1495 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1496 solv->noupdateprovide = value;
1498 case SOLVER_FLAG_SPLITPROVIDES:
1499 solv->dosplitprovides = value;
1501 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1502 solv->dontinstallrecommended = value;
1504 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1505 solv->addalreadyrecommended = value;
1507 case SOLVER_FLAG_NO_INFARCHCHECK:
1508 solv->noinfarchcheck = value;
1517 cleandeps_check_mistakes(Solver *solv, int level)
1519 Pool *pool = solv->pool;
1523 int mademistake = 0;
1525 if (!solv->cleandepsmap.size)
1527 /* check for mistakes */
1528 for (i = solv->installed->start; i < solv->installed->end; i++)
1530 if (!MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1532 r = solv->rules + solv->featurerules + (i - solv->installed->start);
1533 /* a mistake is when the featurerule is true but the updaterule is false */
1536 FOR_RULELITERALS(p, dp, r)
1537 if (p > 0 && solv->decisionmap[p] > 0)
1541 r = solv->rules + solv->updaterules + (i - solv->installed->start);
1544 FOR_RULELITERALS(p, dp, r)
1545 if (p > 0 && solv->decisionmap[p] > 0)
1549 POOL_DEBUG(SOLV_DEBUG_SOLVER, "cleandeps mistake: ");
1550 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, r);
1551 POOL_DEBUG(SOLV_DEBUG_SOLVER, "feature rule: ");
1552 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, solv->rules + solv->featurerules + (i - solv->installed->start));
1553 if (!solv->cleandeps_mistakes)
1555 solv->cleandeps_mistakes = solv_calloc(1, sizeof(Queue));
1556 queue_init(solv->cleandeps_mistakes);
1558 queue_push(solv->cleandeps_mistakes, i);
1559 MAPCLR(&solv->cleandepsmap, i - solv->installed->start);
1560 solver_reenablepolicyrules_cleandeps(solv, i);
1571 /*-------------------------------------------------------------------
1575 * all rules have been set up, now actually run the solver
1580 solver_run_sat(Solver *solv, int disablerules, int doweak)
1582 Queue dq; /* local decisionqueue */
1583 Queue dqs; /* local decisionqueue for supplements */
1589 Pool *pool = solv->pool;
1591 int minimizationsteps;
1592 int installedpos = solv->installed ? solv->installed->start : 0;
1594 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
1596 POOL_DEBUG (SOLV_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
1597 for (i = 1; i < solv->nrules; i++)
1598 solver_printruleclass(solv, SOLV_DEBUG_RULE_CREATION, solv->rules + i);
1601 POOL_DEBUG(SOLV_DEBUG_SOLVER, "initial decisions: %d\n", solv->decisionq.count);
1603 /* start SAT algorithm */
1605 systemlevel = level + 1;
1606 POOL_DEBUG(SOLV_DEBUG_SOLVER, "solving...\n");
1612 * here's the main loop:
1613 * 1) propagate new decisions (only needed once)
1615 * 3) try to keep installed packages
1616 * 4) fulfill all unresolved rules
1617 * 5) install recommended packages
1618 * 6) minimalize solution if we had choices
1619 * if we encounter a problem, we rewind to a safe level and restart
1623 minimizationsteps = 0;
1627 * initial propagation of the assertions
1631 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
1632 if ((r = propagate(solv, level)) != 0)
1634 if (analyze_unsolvable(solv, r, disablerules))
1637 break; /* unsolvable */
1642 * resolve jobs first
1644 if (level < systemlevel)
1646 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving job rules\n");
1647 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
1650 if (r->d < 0) /* ignore disabled rules */
1653 FOR_RULELITERALS(l, dp, r)
1657 if (solv->decisionmap[-l] <= 0)
1662 if (solv->decisionmap[l] > 0)
1664 if (solv->decisionmap[l] == 0)
1670 /* prune to installed if not updating */
1671 if (dq.count > 1 && solv->installed && !solv->updatemap_all)
1674 for (j = k = 0; j < dq.count; j++)
1676 Solvable *s = pool->solvables + dq.elements[j];
1677 if (s->repo == solv->installed)
1679 dq.elements[k++] = dq.elements[j];
1680 if (solv->updatemap.size && MAPTST(&solv->updatemap, dq.elements[j] - solv->installed->start))
1682 k = 0; /* package wants to be updated, do not prune */
1691 level = selectandinstall(solv, level, &dq, disablerules, i);
1694 if (level <= olevel)
1698 break; /* unsolvable */
1699 systemlevel = level + 1;
1700 if (i < solv->jobrules_end)
1702 solv->decisioncnt_update = solv->decisionq.count;
1703 solv->decisioncnt_keep = solv->decisionq.count;
1707 * installed packages
1709 if (level < systemlevel && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
1711 Repo *installed = solv->installed;
1714 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving installed packages\n");
1715 /* we use two passes if we need to update packages
1716 * to create a better user experience */
1717 for (pass = solv->updatemap.size ? 0 : 1; pass < 2; pass++)
1719 int passlevel = level;
1721 solv->decisioncnt_keep = solv->decisionq.count;
1722 /* start with installedpos, the position that gave us problems last time */
1723 for (i = installedpos, n = installed->start; n < installed->end; i++, n++)
1728 if (i == installed->end)
1729 i = installed->start;
1730 s = pool->solvables + i;
1731 if (s->repo != installed)
1734 if (solv->decisionmap[i] > 0)
1736 if (!pass && solv->updatemap.size && !MAPTST(&solv->updatemap, i - installed->start))
1737 continue; /* updates first */
1738 r = solv->rules + solv->updaterules + (i - installed->start);
1740 if (!rr->p || rr->d < 0) /* disabled -> look at feature rule */
1741 rr -= solv->installed->end - solv->installed->start;
1742 if (!rr->p) /* identical to update rule? */
1745 continue; /* orpaned package */
1747 /* XXX: noupdate check is probably no longer needed, as all jobs should
1748 * already be satisfied */
1749 /* Actually we currently still need it because of erase jobs */
1750 /* if noupdate is set we do not look at update candidates */
1752 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))
1754 if (solv->noobsoletes.size && solv->multiversionupdaters
1755 && (d = solv->multiversionupdaters[i - installed->start]) != 0)
1757 /* special multiversion handling, make sure best version is chosen */
1759 while ((p = pool->whatprovidesdata[d++]) != 0)
1760 if (solv->decisionmap[p] >= 0)
1762 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
1764 if (p != i && solv->decisionmap[p] == 0)
1766 rr = solv->rules + solv->featurerules + (i - solv->installed->start);
1767 if (!rr->p) /* update rule == feature rule? */
1768 rr = rr - solv->featurerules + solv->updaterules;
1776 /* update to best package */
1777 FOR_RULELITERALS(p, dp, rr)
1779 if (solv->decisionmap[p] > 0)
1781 dq.count = 0; /* already fulfilled */
1784 if (!solv->decisionmap[p])
1789 /* install best version */
1793 level = selectandinstall(solv, level, &dq, disablerules, rr - solv->rules);
1800 if (level <= olevel)
1802 if (level == 1 || level < passlevel)
1803 break; /* trouble */
1805 n = installed->start; /* redo all */
1811 /* if still undecided keep package */
1812 if (solv->decisionmap[i] == 0)
1815 if (solv->cleandepsmap.size && MAPTST(&solv->cleandepsmap, i - installed->start))
1817 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, i));
1818 level = setpropagatelearn(solv, level, -i, disablerules, 0);
1822 POOL_DEBUG(SOLV_DEBUG_POLICY, "keeping %s\n", pool_solvid2str(pool, i));
1823 level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules);
1827 if (level <= olevel)
1829 if (level == 1 || level < passlevel)
1830 break; /* trouble */
1832 n = installed->start; /* redo all */
1835 continue; /* retry with learnt rule */
1839 if (n < installed->end)
1841 installedpos = i; /* retry problem solvable next time */
1842 break; /* ran into trouble */
1844 installedpos = installed->start; /* reset installedpos */
1847 break; /* unsolvable */
1848 systemlevel = level + 1;
1850 continue; /* had trouble, retry */
1853 if (level < systemlevel)
1854 systemlevel = level;
1859 solv->decisioncnt_resolve = solv->decisionq.count;
1860 POOL_DEBUG(SOLV_DEBUG_POLICY, "deciding unresolved rules\n");
1861 for (i = 1, n = 1; n < solv->nrules; i++, n++)
1863 if (i == solv->nrules)
1865 r = solv->rules + i;
1866 if (r->d < 0) /* ignore disabled rules */
1871 /* binary or unary rule */
1872 /* need two positive undecided literals */
1873 if (r->p < 0 || r->w2 <= 0)
1875 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
1877 queue_push(&dq, r->p);
1878 queue_push(&dq, r->w2);
1883 * all negative literals are installed
1884 * no positive literal is installed
1885 * i.e. the rule is not fulfilled and we
1886 * just need to decide on the positive literals
1890 if (solv->decisionmap[-r->p] <= 0)
1895 if (solv->decisionmap[r->p] > 0)
1897 if (solv->decisionmap[r->p] == 0)
1898 queue_push(&dq, r->p);
1900 dp = pool->whatprovidesdata + r->d;
1901 while ((p = *dp++) != 0)
1905 if (solv->decisionmap[-p] <= 0)
1910 if (solv->decisionmap[p] > 0)
1912 if (solv->decisionmap[p] == 0)
1919 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
1921 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "unfulfilled ");
1922 solver_printruleclass(solv, SOLV_DEBUG_PROPAGATE, r);
1924 /* dq.count < 2 cannot happen as this means that
1925 * the rule is unit */
1926 assert(dq.count > 1);
1929 level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
1931 break; /* unsolvable */
1932 if (level < systemlevel || level == 1)
1933 break; /* trouble */
1934 /* something changed, so look at all rules again */
1938 if (n != solv->nrules) /* ran into trouble? */
1941 break; /* unsolvable */
1942 continue; /* start over */
1945 /* at this point we have a consistent system. now do the extras... */
1947 solv->decisioncnt_weak = solv->decisionq.count;
1952 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended packages\n");
1953 queue_empty(&dq); /* recommended packages */
1954 queue_empty(&dqs); /* supplemented packages */
1955 for (i = 1; i < pool->nsolvables; i++)
1957 if (solv->decisionmap[i] < 0)
1959 if (solv->decisionmap[i] > 0)
1961 /* installed, check for recommends */
1962 Id *recp, rec, pp, p;
1963 s = pool->solvables + i;
1964 if (!solv->addalreadyrecommended && s->repo == solv->installed)
1966 /* XXX need to special case AND ? */
1969 recp = s->repo->idarraydata + s->recommends;
1970 while ((rec = *recp++) != 0)
1973 FOR_PROVIDES(p, pp, rec)
1975 if (solv->decisionmap[p] > 0)
1980 else if (solv->decisionmap[p] == 0)
1982 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))))
1984 queue_pushunique(&dq, p);
1992 s = pool->solvables + i;
1993 if (!s->supplements)
1995 if (!pool_installable(pool, s))
1997 if (!solver_is_supplementing(solv, s))
1999 if (solv->dupmap_all && solv->installed && s->repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, i - solv->installed->start))))
2001 queue_push(&dqs, i);
2005 /* filter out all packages obsoleted by installed packages */
2006 /* this is no longer needed if we have reverse obsoletes */
2007 if ((dqs.count || dq.count) && solv->installed)
2010 Id obs, *obsp, po, ppo;
2012 map_init(&obsmap, pool->nsolvables);
2013 for (p = solv->installed->start; p < solv->installed->end; p++)
2015 s = pool->solvables + p;
2016 if (s->repo != solv->installed || !s->obsoletes)
2018 if (solv->decisionmap[p] <= 0)
2020 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p))
2022 obsp = s->repo->idarraydata + s->obsoletes;
2023 /* foreach obsoletes */
2024 while ((obs = *obsp++) != 0)
2025 FOR_PROVIDES(po, ppo, obs)
2026 MAPSET(&obsmap, po);
2028 for (i = j = 0; i < dqs.count; i++)
2029 if (!MAPTST(&obsmap, dqs.elements[i]))
2030 dqs.elements[j++] = dqs.elements[i];
2032 for (i = j = 0; i < dq.count; i++)
2033 if (!MAPTST(&obsmap, dq.elements[i]))
2034 dq.elements[j++] = dq.elements[i];
2039 /* filter out all already supplemented packages if requested */
2040 if (!solv->addalreadyrecommended && dqs.count)
2042 /* turn off all new packages */
2043 for (i = 0; i < solv->decisionq.count; i++)
2045 p = solv->decisionq.elements[i];
2048 s = pool->solvables + p;
2049 if (s->repo && s->repo != solv->installed)
2050 solv->decisionmap[p] = -solv->decisionmap[p];
2052 /* filter out old supplements */
2053 for (i = j = 0; i < dqs.count; i++)
2055 p = dqs.elements[i];
2056 s = pool->solvables + p;
2057 if (!s->supplements)
2059 if (!solver_is_supplementing(solv, s))
2060 dqs.elements[j++] = p;
2063 /* undo turning off */
2064 for (i = 0; i < solv->decisionq.count; i++)
2066 p = solv->decisionq.elements[i];
2069 s = pool->solvables + p;
2070 if (s->repo && s->repo != solv->installed)
2071 solv->decisionmap[p] = -solv->decisionmap[p];
2075 /* multiversion doesn't mix well with supplements.
2076 * filter supplemented packages where we already decided
2077 * to install a different version (see bnc#501088) */
2078 if (dqs.count && solv->noobsoletes.size)
2080 for (i = j = 0; i < dqs.count; i++)
2082 p = dqs.elements[i];
2083 if (MAPTST(&solv->noobsoletes, p))
2086 s = pool->solvables + p;
2087 FOR_PROVIDES(p2, pp2, s->name)
2088 if (solv->decisionmap[p2] > 0 && pool->solvables[p2].name == s->name)
2091 continue; /* ignore this package */
2093 dqs.elements[j++] = p;
2098 /* make dq contain both recommended and supplemented pkgs */
2101 for (i = 0; i < dqs.count; i++)
2102 queue_pushunique(&dq, dqs.elements[i]);
2108 int decisioncount = solv->decisionq.count;
2112 /* simple case, just one package. no need to choose to best version */
2115 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2117 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2118 level = setpropagatelearn(solv, level, p, 0, 0);
2121 continue; /* back to main loop */
2124 /* filter packages, this gives us the best versions */
2125 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
2127 /* create map of result */
2128 map_init(&dqmap, pool->nsolvables);
2129 for (i = 0; i < dq.count; i++)
2130 MAPSET(&dqmap, dq.elements[i]);
2132 /* install all supplemented packages */
2133 for (i = 0; i < dqs.count; i++)
2135 p = dqs.elements[i];
2136 if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
2138 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2140 level = setpropagatelearn(solv, level, p, 0, 0);
2141 if (level <= olevel)
2144 if (i < dqs.count || solv->decisionq.count < decisioncount)
2152 /* install all recommended packages */
2153 /* more work as we want to created branches if multiple
2154 * choices are valid */
2155 for (i = 0; i < decisioncount; i++)
2158 p = solv->decisionq.elements[i];
2161 s = pool->solvables + p;
2162 if (!s->repo || (!solv->addalreadyrecommended && s->repo == solv->installed))
2166 recp = s->repo->idarraydata + s->recommends;
2167 while ((rec = *recp++) != 0)
2170 FOR_PROVIDES(p, pp, rec)
2172 if (solv->decisionmap[p] > 0)
2177 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
2178 queue_pushunique(&dq, p);
2184 /* multiple candidates, open a branch */
2185 for (i = 1; i < dq.count; i++)
2186 queue_push(&solv->branches, dq.elements[i]);
2187 queue_push(&solv->branches, -level);
2190 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2192 level = setpropagatelearn(solv, level, p, 0, 0);
2193 if (level <= olevel || solv->decisionq.count < decisioncount)
2194 break; /* we had to revert some decisions */
2197 break; /* had a problem above, quit loop */
2202 continue; /* back to main loop so that all deps are checked */
2206 solv->decisioncnt_orphan = solv->decisionq.count;
2207 if (solv->dupmap_all && solv->installed)
2209 int installedone = 0;
2211 /* let's see if we can install some unsupported package */
2212 POOL_DEBUG(SOLV_DEBUG_SOLVER, "deciding orphaned packages\n");
2213 for (i = 0; i < solv->orphaned.count; i++)
2215 p = solv->orphaned.elements[i];
2216 if (solv->decisionmap[p])
2217 continue; /* already decided */
2218 if (solv->droporphanedmap_all)
2220 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))
2222 POOL_DEBUG(SOLV_DEBUG_SOLVER, "keeping orphaned %s\n", pool_solvid2str(pool, p));
2224 level = setpropagatelearn(solv, level, p, 0, 0);
2229 if (installedone || i < solv->orphaned.count)
2233 continue; /* back to main loop */
2235 for (i = 0; i < solv->orphaned.count; i++)
2237 p = solv->orphaned.elements[i];
2238 if (solv->decisionmap[p])
2239 continue; /* already decided */
2240 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing orphaned %s\n", pool_solvid2str(pool, p));
2242 level = setpropagatelearn(solv, level, -p, 0, 0);
2246 if (i < solv->orphaned.count)
2250 continue; /* back to main loop */
2254 if (solv->installed && solv->cleandepsmap.size)
2256 if (cleandeps_check_mistakes(solv, level))
2258 level = 1; /* restart from scratch */
2263 if (solv->solution_callback)
2265 solv->solution_callback(solv, solv->solution_callback_data);
2266 if (solv->branches.count)
2268 int i = solv->branches.count - 1;
2269 int l = -solv->branches.elements[i];
2273 if (solv->branches.elements[i - 1] < 0)
2275 p = solv->branches.elements[i];
2276 POOL_DEBUG(SOLV_DEBUG_SOLVER, "branching with %s\n", pool_solvid2str(pool, p));
2278 for (j = i + 1; j < solv->branches.count; j++)
2279 queue_push(&dq, solv->branches.elements[j]);
2280 solv->branches.count = i;
2282 revert(solv, level);
2284 for (j = 0; j < dq.count; j++)
2285 queue_push(&solv->branches, dq.elements[j]);
2287 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
2289 level = setpropagatelearn(solv, level, p, disablerules, why);
2294 /* all branches done, we're finally finished */
2298 /* auto-minimization step */
2299 if (solv->branches.count)
2301 int l = 0, lasti = -1, lastl = -1;
2305 for (i = solv->branches.count - 1; i >= 0; i--)
2307 p = solv->branches.elements[i];
2310 else if (p > 0 && solv->decisionmap[p] > l + 1)
2318 /* kill old solvable so that we do not loop */
2319 p = solv->branches.elements[lasti];
2320 solv->branches.elements[lasti] = 0;
2321 POOL_DEBUG(SOLV_DEBUG_SOLVER, "minimizing %d -> %d with %s\n", solv->decisionmap[p], lastl, pool_solvid2str(pool, p));
2322 minimizationsteps++;
2325 revert(solv, level);
2326 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
2329 level = setpropagatelearn(solv, level, p, disablerules, why);
2332 continue; /* back to main loop */
2335 /* no minimization found, we're finally finished! */
2339 POOL_DEBUG(SOLV_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
2341 POOL_DEBUG(SOLV_DEBUG_STATS, "done solving.\n\n");
2347 solv->decisioncnt_update = solv->decisionq.count;
2348 solv->decisioncnt_keep = solv->decisionq.count;
2349 solv->decisioncnt_resolve = solv->decisionq.count;
2350 solv->decisioncnt_weak = solv->decisionq.count;
2351 solv->decisioncnt_orphan = solv->decisionq.count;
2354 solver_printdecisionq(solv, SOLV_DEBUG_RESULT);
2359 /*-------------------------------------------------------------------
2361 * remove disabled conflicts
2363 * purpose: update the decisionmap after some rules were disabled.
2364 * this is used to calculate the suggested/recommended package list.
2365 * Also returns a "removed" list to undo the discisionmap changes.
2369 removedisabledconflicts(Solver *solv, Queue *removed)
2371 Pool *pool = solv->pool;
2376 Id *decisionmap = solv->decisionmap;
2378 queue_empty(removed);
2379 for (i = 0; i < solv->decisionq.count; i++)
2381 p = solv->decisionq.elements[i];
2383 continue; /* conflicts only, please */
2384 why = solv->decisionq_why.elements[i];
2387 /* no rule involved, must be a orphan package drop */
2390 /* we never do conflicts on free decisions, so there
2391 * must have been an unit rule */
2393 r = solv->rules + why;
2394 if (r->d < 0 && decisionmap[-p])
2396 /* rule is now disabled, remove from decisionmap */
2397 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing conflict for package %s[%d]\n", pool_solvid2str(pool, -p), -p);
2398 queue_push(removed, -p);
2399 queue_push(removed, decisionmap[-p]);
2400 decisionmap[-p] = 0;
2403 if (!removed->count)
2405 /* we removed some confliced packages. some of them might still
2406 * be in conflict, so search for unit rules and re-conflict */
2408 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
2410 if (i == solv->nrules)
2413 r = solv->rules + i;
2419 if (r->p < 0 && !decisionmap[-r->p])
2425 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
2427 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
2432 if (r->p < 0 && decisionmap[-r->p] == 0)
2434 if (new || DECISIONMAP_FALSE(r->p))
2436 dp = pool->whatprovidesdata + r->d;
2437 while ((p = *dp++) != 0)
2439 if (new && p == new)
2441 if (p < 0 && decisionmap[-p] == 0)
2450 else if (!DECISIONMAP_FALSE(p))
2460 POOL_DEBUG(SOLV_DEBUG_SOLVER, "re-conflicting package %s[%d]\n", pool_solvid2str(pool, -new), -new);
2461 decisionmap[-new] = -1;
2463 n = 0; /* redo all rules */
2469 undo_removedisabledconflicts(Solver *solv, Queue *removed)
2472 for (i = 0; i < removed->count; i += 2)
2473 solv->decisionmap[removed->elements[i]] = removed->elements[i + 1];
2477 /*-------------------------------------------------------------------
2479 * weaken solvable dependencies
2483 weaken_solvable_deps(Solver *solv, Id p)
2488 for (i = 1, r = solv->rules + i; i < solv->rpmrules_end; i++, r++)
2492 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
2493 continue; /* conflict */
2494 queue_push(&solv->weakruleq, i);
2499 /********************************************************************/
2504 solver_calculate_noobsmap(Pool *pool, Queue *job, Map *noobsmap)
2507 Id how, what, select;
2509 for (i = 0; i < job->count; i += 2)
2511 how = job->elements[i];
2512 if ((how & SOLVER_JOBMASK) != SOLVER_NOOBSOLETES)
2514 what = job->elements[i + 1];
2515 select = how & SOLVER_SELECTMASK;
2516 if (!noobsmap->size)
2517 map_grow(noobsmap, pool->nsolvables);
2518 FOR_JOB_SELECT(p, pp, select, what)
2519 MAPSET(noobsmap, p);
2524 * add a rule created by a job, record job number and weak flag
2527 solver_addjobrule(Solver *solv, Id p, Id d, Id job, int weak)
2529 solver_addrule(solv, p, d);
2530 queue_push(&solv->ruletojob, job);
2532 queue_push(&solv->weakruleq, solv->nrules - 1);
2542 solver_solve(Solver *solv, Queue *job)
2544 Pool *pool = solv->pool;
2545 Repo *installed = solv->installed;
2548 Map addedmap; /* '1' == have rpm-rules for solvable */
2549 Map installcandidatemap;
2550 Id how, what, select, name, weak, p, pp, d;
2554 int now, solve_start;
2557 solve_start = solv_timems(0);
2559 /* log solver options */
2560 POOL_DEBUG(SOLV_DEBUG_STATS, "solver started\n");
2561 POOL_DEBUG(SOLV_DEBUG_STATS, "dosplitprovides=%d, noupdateprovide=%d noinfarchcheck=%d\n", solv->dosplitprovides, solv->noupdateprovide, solv->noinfarchcheck);
2562 POOL_DEBUG(SOLV_DEBUG_STATS, "allowuninstall=%d, allowdowngrade=%d, allowarchchange=%d, allowvendorchange=%d\n", solv->allowuninstall, solv->allowdowngrade, solv->allowarchchange, solv->allowvendorchange);
2563 POOL_DEBUG(SOLV_DEBUG_STATS, "promoteepoch=%d, forbidselfconflicts=%d\n", pool->promoteepoch, pool->forbidselfconflicts);
2564 POOL_DEBUG(SOLV_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d, obsoleteusescolors=%d\n", pool->obsoleteusesprovides, pool->implicitobsoleteusesprovides, pool->obsoleteusescolors);
2565 POOL_DEBUG(SOLV_DEBUG_STATS, "dontinstallrecommended=%d, addalreadyrecommended=%d\n", solv->dontinstallrecommended, solv->addalreadyrecommended);
2567 /* create whatprovides if not already there */
2568 if (!pool->whatprovides)
2569 pool_createwhatprovides(pool);
2571 /* create obsolete index */
2572 policy_create_obsolete_index(solv);
2575 queue_free(&solv->job);
2576 queue_init_clone(&solv->job, job);
2579 * create basic rule set of all involved packages
2580 * use addedmap bitmap to make sure we don't create rules twice
2583 /* create noobsolete map if needed */
2584 solver_calculate_noobsmap(pool, job, &solv->noobsoletes);
2586 map_init(&addedmap, pool->nsolvables);
2587 MAPSET(&addedmap, SYSTEMSOLVABLE);
2589 map_init(&installcandidatemap, pool->nsolvables);
2592 now = solv_timems(0);
2594 * create rules for all package that could be involved with the solving
2595 * so called: rpm rules
2600 /* check for update/verify jobs as they need to be known early */
2601 for (i = 0; i < job->count; i += 2)
2603 how = job->elements[i];
2604 what = job->elements[i + 1];
2605 select = how & SOLVER_SELECTMASK;
2606 switch (how & SOLVER_JOBMASK)
2609 if (select == SOLVER_SOLVABLE_ALL)
2610 solv->fixmap_all = 1;
2611 FOR_JOB_SELECT(p, pp, select, what)
2613 s = pool->solvables + p;
2614 if (!solv->installed || s->repo != solv->installed)
2616 if (!solv->fixmap.size)
2617 map_grow(&solv->fixmap, solv->installed->end - solv->installed->start);
2618 MAPSET(&solv->fixmap, p - solv->installed->start);
2622 if (select == SOLVER_SOLVABLE_ALL)
2623 solv->updatemap_all = 1;
2624 FOR_JOB_SELECT(p, pp, select, what)
2626 s = pool->solvables + p;
2627 if (!solv->installed || s->repo != solv->installed)
2629 if (!solv->updatemap.size)
2630 map_grow(&solv->updatemap, solv->installed->end - solv->installed->start);
2631 MAPSET(&solv->updatemap, p - solv->installed->start);
2639 oldnrules = solv->nrules;
2640 FOR_REPO_SOLVABLES(installed, p, s)
2641 solver_addrpmrulesforsolvable(solv, s, &addedmap);
2642 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
2643 oldnrules = solv->nrules;
2644 FOR_REPO_SOLVABLES(installed, p, s)
2645 solver_addrpmrulesforupdaters(solv, s, &addedmap, 1);
2646 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
2650 * create rules for all packages involved in the job
2651 * (to be installed or removed)
2654 oldnrules = solv->nrules;
2655 for (i = 0; i < job->count; i += 2)
2657 how = job->elements[i];
2658 what = job->elements[i + 1];
2659 select = how & SOLVER_SELECTMASK;
2661 switch (how & SOLVER_JOBMASK)
2663 case SOLVER_INSTALL:
2664 FOR_JOB_SELECT(p, pp, select, what)
2666 MAPSET(&installcandidatemap, p);
2667 solver_addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
2670 case SOLVER_DISTUPGRADE:
2671 if (select == SOLVER_SOLVABLE_ALL)
2673 solv->dupmap_all = 1;
2674 solv->updatemap_all = 1;
2676 if (!solv->dupmap_all)
2683 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
2687 * add rules for suggests, enhances
2689 oldnrules = solv->nrules;
2690 solver_addrpmrulesforweak(solv, &addedmap);
2691 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
2694 * first pass done, we now have all the rpm rules we need.
2695 * unify existing rules before going over all job rules and
2697 * at this point the system is always solvable,
2698 * as an empty system (remove all packages) is a valid solution
2701 IF_POOLDEBUG (SOLV_DEBUG_STATS)
2703 int possible = 0, installable = 0;
2704 for (i = 1; i < pool->nsolvables; i++)
2706 if (pool_installable(pool, pool->solvables + i))
2708 if (MAPTST(&addedmap, i))
2711 POOL_DEBUG(SOLV_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
2714 solver_unifyrules(solv); /* remove duplicate rpm rules */
2715 solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
2717 POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
2718 POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule creation took %d ms\n", solv_timems(now));
2720 /* create dup maps if needed. We need the maps early to create our
2723 solver_createdupmaps(solv);
2726 * create feature rules
2728 * foreach installed:
2729 * create assertion (keep installed, if no update available)
2731 * create update rule (A|update1(A)|update2(A)|...)
2733 * those are used later on to keep a version of the installed packages in
2737 solv->featurerules = solv->nrules; /* mark start of feature rules */
2740 /* foreach possibly installed solvable */
2741 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
2743 if (s->repo != installed)
2745 solver_addrule(solv, 0, 0); /* create dummy rule */
2748 solver_addupdaterule(solv, s, 1); /* allow s to be updated */
2750 /* make sure we accounted for all rules */
2751 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
2753 solv->featurerules_end = solv->nrules;
2756 * Add update rules for installed solvables
2758 * almost identical to feature rules
2759 * except that downgrades/archchanges/vendorchanges are not allowed
2762 solv->updaterules = solv->nrules;
2765 { /* foreach installed solvables */
2766 /* we create all update rules, but disable some later on depending on the job */
2767 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
2771 if (s->repo != installed)
2773 solver_addrule(solv, 0, 0); /* create dummy rule */
2776 solver_addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
2778 * check for and remove duplicate
2780 r = solv->rules + solv->nrules - 1; /* r: update rule */
2781 sr = r - (installed->end - installed->start); /* sr: feature rule */
2782 /* it's orphaned if there is no feature rule or the feature rule
2783 * consists just of the installed package */
2784 if (!sr->p || (sr->p == i && !sr->d && !sr->w2))
2785 queue_push(&solv->orphaned, i);
2788 assert(solv->dupmap_all && !sr->p);
2791 if (!solver_samerule(solv, r, sr))
2792 memset(sr, 0, sizeof(*sr)); /* delete unneeded feature rule */
2794 solver_disablerule(solv, sr); /* disable feature rule */
2796 /* consistency check: we added a rule for _every_ installed solvable */
2797 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
2799 solv->updaterules_end = solv->nrules;
2803 * now add all job rules
2806 solv->jobrules = solv->nrules;
2807 if (solv->cleandeps_updatepkgs)
2809 queue_free(solv->cleandeps_updatepkgs);
2810 solv->cleandeps_updatepkgs = solv_free(solv->cleandeps_updatepkgs);
2812 for (i = 0; i < job->count; i += 2)
2814 oldnrules = solv->nrules;
2816 how = job->elements[i];
2817 what = job->elements[i + 1];
2818 weak = how & SOLVER_WEAK;
2819 select = how & SOLVER_SELECTMASK;
2820 switch (how & SOLVER_JOBMASK)
2822 case SOLVER_INSTALL:
2823 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
2824 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
2825 map_grow(&solv->cleandepsmap, installed->end - installed->start);
2826 if (select == SOLVER_SOLVABLE)
2834 FOR_JOB_SELECT(p, pp, select, what)
2838 /* no candidate found, make this an impossible rule */
2839 queue_push(&q, -SYSTEMSOLVABLE);
2841 p = queue_shift(&q); /* get first candidate */
2842 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
2844 solver_addjobrule(solv, p, d, i, weak);
2847 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %s%serase %s\n", weak ? "weak " : "", how & SOLVER_CLEANDEPS ? "clean deps " : "", solver_select2str(pool, select, what));
2848 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
2849 map_grow(&solv->cleandepsmap, installed->end - installed->start);
2850 name = (select == SOLVER_SOLVABLE || (select == SOLVER_SOLVABLE_NAME && ISRELDEP(what))) ? 0 : -1;
2851 FOR_JOB_SELECT(p, pp, select, what)
2853 s = pool->solvables + p;
2854 if (installed && s->repo == installed)
2855 name = !name ? s->name : -1;
2856 solver_addjobrule(solv, -p, 0, i, weak);
2858 /* special case for "erase a specific solvable": we also
2859 * erase all other solvables with that name, so that they
2860 * don't get picked up as replacement.
2861 * name is > 0 if exactly one installed solvable matched.
2863 /* XXX: look also at packages that obsolete this package? */
2868 FOR_PROVIDES(p, pp, name)
2870 s = pool->solvables + p;
2871 if (s->name != name)
2873 /* keep other versions installed */
2874 if (s->repo == installed)
2876 /* keep installcandidates of other jobs */
2877 if (MAPTST(&installcandidatemap, p))
2879 /* don't add the same rule twice */
2880 for (j = oldnrules; j < k; j++)
2881 if (solv->rules[j].p == -p)
2884 solver_addjobrule(solv, -p, 0, i, weak); /* remove by id */
2890 if ((how & SOLVER_CLEANDEPS) != 0 && installed)
2892 FOR_JOB_SELECT(p, pp, select, what)
2894 s = pool->solvables + p;
2895 if (s->repo != installed)
2897 if (!solv->cleandeps_updatepkgs)
2899 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
2900 queue_init(solv->cleandeps_updatepkgs);
2902 queue_pushunique(solv->cleandeps_updatepkgs, p);
2903 if (!solv->cleandepsmap.size)
2904 map_grow(&solv->cleandepsmap, installed->end - installed->start);
2907 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
2910 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sverify %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
2912 case SOLVER_WEAKENDEPS:
2913 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
2914 if (select != SOLVER_SOLVABLE)
2916 s = pool->solvables + what;
2917 weaken_solvable_deps(solv, what);
2919 case SOLVER_NOOBSOLETES:
2920 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sno obsolete %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
2923 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
2924 FOR_JOB_SELECT(p, pp, select, what)
2926 s = pool->solvables + p;
2927 solver_addjobrule(solv, installed && s->repo == installed ? p : -p, 0, i, weak);
2930 case SOLVER_DISTUPGRADE:
2931 POOL_DEBUG(SOLV_DEBUG_JOB, "job: distupgrade %s\n", solver_select2str(pool, select, what));
2933 case SOLVER_DROP_ORPHANED:
2934 POOL_DEBUG(SOLV_DEBUG_JOB, "job: drop orphaned %s\n", solver_select2str(pool, select, what));
2935 if (select == SOLVER_SOLVABLE_ALL)
2936 solv->droporphanedmap_all = 1;
2937 FOR_JOB_SELECT(p, pp, select, what)
2939 s = pool->solvables + p;
2940 if (!installed || s->repo != installed)
2942 if (!solv->droporphanedmap.size)
2943 map_grow(&solv->droporphanedmap, installed->end - installed->start);
2944 MAPSET(&solv->droporphanedmap, p - installed->start);
2947 case SOLVER_USERINSTALLED:
2948 POOL_DEBUG(SOLV_DEBUG_JOB, "job: user installed %s\n", solver_select2str(pool, select, what));
2951 POOL_DEBUG(SOLV_DEBUG_JOB, "job: unknown job\n");
2959 IF_POOLDEBUG (SOLV_DEBUG_JOB)
2962 if (solv->nrules == oldnrules)
2963 POOL_DEBUG(SOLV_DEBUG_JOB, " - no rule created\n");
2964 for (j = oldnrules; j < solv->nrules; j++)
2966 POOL_DEBUG(SOLV_DEBUG_JOB, " - job ");
2967 solver_printrule(solv, SOLV_DEBUG_JOB, solv->rules + j);
2971 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
2972 solv->jobrules_end = solv->nrules;
2974 /* now create infarch and dup rules */
2975 if (!solv->noinfarchcheck)
2977 solver_addinfarchrules(solv, &addedmap);
2978 if (pool->obsoleteusescolors)
2980 /* currently doesn't work well with infarch rules, so make
2982 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
2983 queue_push(&solv->weakruleq, i);
2987 solv->infarchrules = solv->infarchrules_end = solv->nrules;
2991 solver_addduprules(solv, &addedmap);
2992 solver_freedupmaps(solv); /* no longer needed */
2995 solv->duprules = solv->duprules_end = solv->nrules;
2998 solver_addchoicerules(solv);
3000 solv->choicerules = solv->choicerules_end = solv->nrules;
3002 /* all rules created
3003 * --------------------------------------------------------------
3004 * prepare for solving
3007 /* free unneeded memory */
3008 map_free(&addedmap);
3009 map_free(&installcandidatemap);
3012 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);
3013 POOL_DEBUG(SOLV_DEBUG_STATS, "overall rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3015 /* create weak map */
3016 map_init(&solv->weakrulemap, solv->nrules);
3017 for (i = 0; i < solv->weakruleq.count; i++)
3019 p = solv->weakruleq.elements[i];
3020 MAPSET(&solv->weakrulemap, p);
3023 /* all new rules are learnt after this point */
3024 solv->learntrules = solv->nrules;
3026 /* create watches chains */
3029 /* create assertion index. it is only used to speed up
3030 * makeruledecsions() a bit */
3031 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
3032 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
3033 queue_push(&solv->ruleassertions, i);
3035 /* disable update rules that conflict with our job */
3036 solver_disablepolicyrules(solv);
3038 /* make initial decisions based on assertion rules */
3039 makeruledecisions(solv);
3040 POOL_DEBUG(SOLV_DEBUG_SOLVER, "problems so far: %d\n", solv->problems.count);
3043 if (solv->cleandeps_mistakes)
3045 queue_free(solv->cleandeps_mistakes);
3046 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
3050 * ********************************************
3052 * ********************************************
3055 now = solv_timems(0);
3056 solver_run_sat(solv, 1, solv->dontinstallrecommended ? 0 : 1);
3057 POOL_DEBUG(SOLV_DEBUG_STATS, "solver took %d ms\n", solv_timems(now));
3060 * prepare solution queue if there were problems
3062 solver_prepare_solutions(solv);
3064 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);
3065 POOL_DEBUG(SOLV_DEBUG_STATS, "solver_solve took %d ms\n", solv_timems(solve_start));
3067 /* return number of problems */
3068 return solv->problems.count ? solv->problems.count / 2 : 0;
3072 solver_create_transaction(Solver *solv)
3074 return transaction_create_decisionq(solv->pool, &solv->decisionq, &solv->noobsoletes);
3077 void solver_get_orphaned(Solver *solv, Queue *orphanedq)
3079 queue_free(orphanedq);
3080 queue_init_clone(orphanedq, &solv->orphaned);
3083 void solver_get_recommendations(Solver *solv, Queue *recommendationsq, Queue *suggestionsq, int noselected)
3085 Pool *pool = solv->pool;
3086 Queue redoq, disabledq;
3092 if (!recommendationsq && !suggestionsq)
3095 map_init(&obsmap, pool->nsolvables);
3096 if (solv->installed)
3098 Id obs, *obsp, p, po, ppo;
3099 for (p = solv->installed->start; p < solv->installed->end; p++)
3101 s = pool->solvables + p;
3102 if (s->repo != solv->installed || !s->obsoletes)
3104 if (solv->decisionmap[p] <= 0)
3106 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p))
3108 obsp = s->repo->idarraydata + s->obsoletes;
3109 /* foreach obsoletes */
3110 while ((obs = *obsp++) != 0)
3111 FOR_PROVIDES(po, ppo, obs)
3112 MAPSET(&obsmap, po);
3117 queue_init(&disabledq);
3119 /* disable all erase jobs (including weak "keep uninstalled" rules) */
3120 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
3122 if (r->d < 0) /* disabled ? */
3124 if (r->p >= 0) /* install job? */
3126 queue_push(&disabledq, i);
3127 solver_disablerule(solv, r);
3133 enabledisablelearntrules(solv);
3134 removedisabledconflicts(solv, &redoq);
3138 * find recommended packages
3140 if (recommendationsq)
3142 Id rec, *recp, p, pp;
3144 queue_empty(recommendationsq);
3145 /* create map of all recommened packages */
3146 solv->recommends_index = -1;
3147 MAPZERO(&solv->recommendsmap);
3149 /* put all packages the solver already chose in the map */
3150 if (solv->decisioncnt_weak)
3152 for (i = solv->decisioncnt_weak; i < solv->decisioncnt_orphan; i++)
3155 why = solv->decisionq_why.elements[i];
3157 continue; /* forced by unit rule */
3158 p = solv->decisionq.elements[i];
3161 MAPSET(&solv->recommendsmap, p);
3165 for (i = 0; i < solv->decisionq.count; i++)
3167 p = solv->decisionq.elements[i];
3170 s = pool->solvables + p;
3173 recp = s->repo->idarraydata + s->recommends;
3174 while ((rec = *recp++) != 0)
3176 FOR_PROVIDES(p, pp, rec)
3177 if (solv->decisionmap[p] > 0)
3183 FOR_PROVIDES(p, pp, rec)
3184 if (solv->decisionmap[p] > 0)
3185 MAPSET(&solv->recommendsmap, p);
3187 continue; /* p != 0: already fulfilled */
3189 FOR_PROVIDES(p, pp, rec)
3190 MAPSET(&solv->recommendsmap, p);
3194 for (i = 1; i < pool->nsolvables; i++)
3196 if (solv->decisionmap[i] < 0)
3198 if (solv->decisionmap[i] > 0 && noselected)
3200 if (MAPTST(&obsmap, i))
3202 s = pool->solvables + i;
3203 if (!MAPTST(&solv->recommendsmap, i))
3205 if (!s->supplements)
3207 if (!pool_installable(pool, s))
3209 if (!solver_is_supplementing(solv, s))
3212 queue_push(recommendationsq, i);
3214 /* we use MODE_SUGGEST here so that repo prio is ignored */
3215 policy_filter_unwanted(solv, recommendationsq, POLICY_MODE_SUGGEST);
3219 * find suggested packages
3224 Id sug, *sugp, p, pp;
3226 queue_empty(suggestionsq);
3227 /* create map of all suggests that are still open */
3228 solv->recommends_index = -1;
3229 MAPZERO(&solv->suggestsmap);
3230 for (i = 0; i < solv->decisionq.count; i++)
3232 p = solv->decisionq.elements[i];
3235 s = pool->solvables + p;
3238 sugp = s->repo->idarraydata + s->suggests;
3239 while ((sug = *sugp++) != 0)
3241 FOR_PROVIDES(p, pp, sug)
3242 if (solv->decisionmap[p] > 0)
3248 FOR_PROVIDES(p, pp, sug)
3249 if (solv->decisionmap[p] > 0)
3250 MAPSET(&solv->suggestsmap, p);
3252 continue; /* already fulfilled */
3254 FOR_PROVIDES(p, pp, sug)
3255 MAPSET(&solv->suggestsmap, p);
3259 for (i = 1; i < pool->nsolvables; i++)
3261 if (solv->decisionmap[i] < 0)
3263 if (solv->decisionmap[i] > 0 && noselected)
3265 if (MAPTST(&obsmap, i))
3267 s = pool->solvables + i;
3268 if (!MAPTST(&solv->suggestsmap, i))
3272 if (!pool_installable(pool, s))
3274 if (!solver_is_enhancing(solv, s))
3277 queue_push(suggestionsq, i);
3279 policy_filter_unwanted(solv, suggestionsq, POLICY_MODE_SUGGEST);
3282 /* undo removedisabledconflicts */
3284 undo_removedisabledconflicts(solv, &redoq);
3287 /* undo job rule disabling */
3288 for (i = 0; i < disabledq.count; i++)
3289 solver_enablerule(solv, solv->rules + disabledq.elements[i]);
3290 queue_free(&disabledq);
3295 /***********************************************************************/
3296 /* disk usage computations */
3298 /*-------------------------------------------------------------------
3300 * calculate DU changes
3304 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
3308 solver_create_state_maps(solv, &installedmap, 0);
3309 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
3310 map_free(&installedmap);
3314 /*-------------------------------------------------------------------
3316 * calculate changes in install size
3320 solver_calc_installsizechange(Solver *solv)
3325 solver_create_state_maps(solv, &installedmap, 0);
3326 change = pool_calc_installsizechange(solv->pool, &installedmap);
3327 map_free(&installedmap);
3332 solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
3334 pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
3338 solver_trivial_installable(Solver *solv, Queue *pkgs, Queue *res)
3341 pool_create_state_maps(solv->pool, &solv->decisionq, &installedmap, 0);
3342 pool_trivial_installable_noobsoletesmap(solv->pool, &installedmap, pkgs, res, solv->noobsoletes.size ? &solv->noobsoletes : 0);
3343 map_free(&installedmap);
3346 /*-------------------------------------------------------------------
3348 * decision introspection
3352 solver_get_decisionlevel(Solver *solv, Id p)
3354 return solv->decisionmap[p];
3358 solver_get_decisionqueue(Solver *solv, Queue *decisionq)
3360 queue_free(decisionq);
3361 queue_init_clone(decisionq, &solv->decisionq);
3365 solver_get_lastdecisionblocklevel(Solver *solv)
3368 if (solv->decisionq.count == 0)
3370 p = solv->decisionq.elements[solv->decisionq.count - 1];
3373 return solv->decisionmap[p] < 0 ? -solv->decisionmap[p] : solv->decisionmap[p];
3377 solver_get_decisionblock(Solver *solv, int level, Queue *decisionq)
3382 queue_empty(decisionq);
3383 for (i = 0; i < solv->decisionq.count; i++)
3385 p = solv->decisionq.elements[i];
3388 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
3391 if (i == solv->decisionq.count)
3393 for (i = 0; i < solv->decisionq.count; i++)
3395 p = solv->decisionq.elements[i];
3398 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
3399 queue_push(decisionq, p);
3406 solver_describe_decision(Solver *solv, Id p, Id *infop)
3413 if (!solv->decisionmap[p])
3414 return SOLVER_REASON_UNRELATED;
3415 pp = solv->decisionmap[p] < 0 ? -p : p;
3416 for (i = 0; i < solv->decisionq.count; i++)
3417 if (solv->decisionq.elements[i] == pp)
3419 if (i == solv->decisionq.count) /* just in case... */
3420 return SOLVER_REASON_UNRELATED;
3421 why = solv->decisionq_why.elements[i];
3426 return SOLVER_REASON_UNIT_RULE;
3429 if (i < solv->decisioncnt_update)
3434 *infop = SYSTEMSOLVABLE;
3435 return SOLVER_REASON_KEEP_INSTALLED;
3439 return SOLVER_REASON_RESOLVE_JOB;
3441 if (i < solv->decisioncnt_keep)
3443 if (why == 0 && pp < 0)
3444 return SOLVER_REASON_CLEANDEPS_ERASE;
3447 if (why >= solv->updaterules && why < solv->updaterules_end)
3448 *infop = why - solv->updaterules;
3449 else if (why >= solv->featurerules && why < solv->featurerules_end)
3450 *infop = why - solv->featurerules;
3452 return SOLVER_REASON_UPDATE_INSTALLED;
3454 if (i < solv->decisioncnt_resolve)
3456 if (why == 0 && pp < 0)
3457 return SOLVER_REASON_CLEANDEPS_ERASE;
3460 if (why >= solv->updaterules && why < solv->updaterules_end)
3461 *infop = why - solv->updaterules;
3462 else if (why >= solv->featurerules && why < solv->featurerules_end)
3463 *infop = why - solv->featurerules;
3465 return SOLVER_REASON_KEEP_INSTALLED;
3467 if (i < solv->decisioncnt_weak)
3471 return SOLVER_REASON_RESOLVE;
3473 if (solv->decisionq.count < solv->decisioncnt_orphan)
3474 return SOLVER_REASON_WEAKDEP;
3475 return SOLVER_REASON_RESOLVE_ORPHAN;
3480 solver_describe_weakdep_decision(Solver *solv, Id p, Queue *whyq)
3482 Pool *pool = solv->pool;
3484 int level = solv->decisionmap[p];
3491 for (decisionno = 0; decisionno < solv->decisionq.count; decisionno++)
3492 if (solv->decisionq.elements[decisionno] == p)
3494 if (decisionno == solv->decisionq.count)
3496 if (decisionno < solv->decisioncnt_weak || decisionno >= solv->decisioncnt_orphan)
3499 /* 1) list all packages that recommend us */
3500 for (i = 1; i < pool->nsolvables; i++)
3502 Id *recp, rec, pp2, p2;
3503 if (solv->decisionmap[i] < 0 || solv->decisionmap[i] >= level)
3505 s = pool->solvables + i;
3508 if (!solv->addalreadyrecommended && s->repo == solv->installed)
3510 recp = s->repo->idarraydata + s->recommends;
3511 while ((rec = *recp++) != 0)
3514 FOR_PROVIDES(p2, pp2, rec)
3520 /* if p2 is already installed, this recommends is ignored */
3521 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
3527 queue_push(whyq, SOLVER_REASON_RECOMMENDED);
3528 queue_push2(whyq, p2, rec);
3532 /* 2) list all supplements */
3533 s = pool->solvables + p;
3534 if (s->supplements && level > 0)
3536 Id *supp, sup, pp2, p2;
3537 /* this is a hack. to use solver_dep_fulfilled we temporarily clear
3538 * everything above our level in the decisionmap */
3539 for (i = decisionno; i < solv->decisionq.count; i++ )
3541 p2 = solv->decisionq.elements[i];
3543 solv->decisionmap[p2] = -solv->decisionmap[p2];
3545 supp = s->repo->idarraydata + s->supplements;
3546 while ((sup = *supp++) != 0)
3547 if (solver_dep_fulfilled(solv, sup))
3550 /* let's see if this is an easy supp */
3551 FOR_PROVIDES(p2, pp2, sup)
3553 if (!solv->addalreadyrecommended && solv->installed)
3555 if (pool->solvables[p2].repo == solv->installed)
3558 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
3560 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
3561 queue_push2(whyq, p2, sup);
3567 /* hard case, just note dependency with no package */
3568 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
3569 queue_push2(whyq, 0, sup);
3572 for (i = decisionno; i < solv->decisionq.count; i++)
3574 p2 = solv->decisionq.elements[i];
3576 solv->decisionmap[p2] = -solv->decisionmap[p2];