2 * Copyright (c) 2007-2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
20 #include "solver_private.h"
25 #include "solverdebug.h"
28 /**********************************************************************************/
30 /* a problem is an item on the solver's problem list. It can either be >0, in that
31 * case it is a update/infarch/dup rule, or it can be <0, which makes it refer to a job
32 * consisting of multiple job rules.
36 solver_disableproblem(Solver *solv, Id v)
44 if (v >= solv->infarchrules && v < solv->infarchrules_end)
46 Pool *pool = solv->pool;
47 Id name = pool->solvables[-solv->rules[v].p].name;
48 while (v > solv->infarchrules && pool->solvables[-solv->rules[v - 1].p].name == name)
50 for (; v < solv->infarchrules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
51 solver_disablerule(solv, solv->rules + v);
54 if (v >= solv->duprules && v < solv->duprules_end)
56 Pool *pool = solv->pool;
57 Id name = pool->solvables[-solv->rules[v].p].name;
58 while (v > solv->duprules && pool->solvables[-solv->rules[v - 1].p].name == name)
60 for (; v < solv->duprules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
61 solver_disablerule(solv, solv->rules + v);
64 solver_disablerule(solv, solv->rules + v);
66 /* XXX: doesn't work */
67 if (v >= solv->updaterules && v < solv->updaterules_end)
69 /* enable feature rule if we disabled the update rule */
70 r = solv->rules + (v - solv->updaterules + solv->featurerules);
72 solver_enablerule(solv, r);
78 jp = solv->ruletojob.elements;
79 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
81 solver_disablerule(solv, r);
84 /*-------------------------------------------------------------------
89 solver_enableproblem(Solver *solv, Id v)
97 if (v >= solv->infarchrules && v < solv->infarchrules_end)
99 Pool *pool = solv->pool;
100 Id name = pool->solvables[-solv->rules[v].p].name;
101 while (v > solv->infarchrules && pool->solvables[-solv->rules[v - 1].p].name == name)
103 for (; v < solv->infarchrules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
104 solver_enablerule(solv, solv->rules + v);
107 if (v >= solv->duprules && v < solv->duprules_end)
109 Pool *pool = solv->pool;
110 Id name = pool->solvables[-solv->rules[v].p].name;
111 while (v > solv->duprules && pool->solvables[-solv->rules[v - 1].p].name == name)
113 for (; v < solv->duprules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
114 solver_enablerule(solv, solv->rules + v);
117 if (v >= solv->featurerules && v < solv->featurerules_end)
119 /* do not enable feature rule if update rule is enabled */
120 r = solv->rules + (v - solv->featurerules + solv->updaterules);
124 solver_enablerule(solv, solv->rules + v);
125 if (v >= solv->updaterules && v < solv->updaterules_end)
127 /* disable feature rule when enabling update rule */
128 r = solv->rules + (v - solv->updaterules + solv->featurerules);
130 solver_disablerule(solv, r);
135 jp = solv->ruletojob.elements;
136 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
138 solver_enablerule(solv, r);
142 /*-------------------------------------------------------------------
145 * Reenable all disabled weak rules (marked in weakrulemap)
150 enableweakrules(Solver *solv)
155 for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
157 if (r->d >= 0) /* already enabled? */
159 if (!MAPTST(&solv->weakrulemap, i))
161 solver_enablerule(solv, r);
166 /*-------------------------------------------------------------------
170 * at this point, all rules that led to conflicts are disabled.
171 * we re-enable all rules of a problem set but rule "sug", then
172 * continue to disable more rules until there as again a solution.
175 /* FIXME: think about conflicting assertions */
178 refine_suggestion(Solver *solv, Id *problem, Id sug, Queue *refined, int essentialok)
180 Pool *pool = solv->pool;
186 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
188 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "refine_suggestion start\n");
189 for (i = 0; problem[i]; i++)
191 if (problem[i] == sug)
192 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "=> ");
193 solver_printproblem(solv, problem[i]);
196 queue_empty(refined);
197 if (!essentialok && sug < 0 && (solv->job.elements[-sug - 1] & SOLVER_ESSENTIAL) != 0)
199 queue_init(&disabled);
200 queue_push(refined, sug);
202 /* re-enable all problem rules with the exception of "sug"(gestion) */
205 for (i = 0; problem[i]; i++)
206 if (problem[i] != sug)
207 solver_enableproblem(solv, problem[i]);
210 solver_reenablepolicyrules(solv, -sug);
211 else if (sug >= solv->updaterules && sug < solv->updaterules_end)
213 /* enable feature rule */
214 Rule *r = solv->rules + solv->featurerules + (sug - solv->updaterules);
216 solver_enablerule(solv, r);
219 enableweakrules(solv);
223 int njob, nfeature, nupdate, pass;
224 queue_empty(&solv->problems);
227 if (!solv->problems.count)
228 solver_run_sat(solv, 0, 0);
230 if (!solv->problems.count)
232 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "no more problems!\n");
233 break; /* great, no more problems */
235 disabledcnt = disabled.count;
236 /* start with 1 to skip over proof index */
237 njob = nfeature = nupdate = 0;
238 for (pass = 0; pass < 2; pass++)
240 for (i = 1; i < solv->problems.count - 1; i++)
242 /* ignore solutions in refined */
243 v = solv->problems.elements[i];
245 break; /* end of problem reached */
248 /* check if v is in the given problems list
249 * we allow disabling all problem rules *after* sug in
250 * pass 2, to prevent getting the same solution twice */
251 for (j = 0; problem[j]; j++)
252 if (problem[j] == v || (pass && problem[j] == sug))
257 if (v >= solv->featurerules && v < solv->featurerules_end)
263 if (!essentialok && (solv->job.elements[-v -1] & SOLVER_ESSENTIAL) != 0)
264 continue; /* not that one! */
267 queue_push(&disabled, v);
269 if (disabled.count != disabledcnt)
272 if (disabled.count == disabledcnt)
274 /* no solution found, this was an invalid suggestion! */
275 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "no solution found!\n");
279 if (!njob && nupdate && nfeature)
281 /* got only update rules, filter out feature rules */
282 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "throwing away feature rules\n");
283 for (i = j = disabledcnt; i < disabled.count; i++)
285 v = disabled.elements[i];
286 if (v < solv->featurerules || v >= solv->featurerules_end)
287 disabled.elements[j++] = v;
292 if (disabled.count == disabledcnt + 1)
294 /* just one suggestion, add it to refined list */
295 v = disabled.elements[disabledcnt];
296 if (!nfeature && v != sug)
297 queue_push(refined, v); /* do not record feature rules */
298 solver_disableproblem(solv, v);
299 if (v >= solv->updaterules && v < solv->updaterules_end)
301 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
303 solver_enablerule(solv, r); /* enable corresponding feature rule */
306 solver_reenablepolicyrules(solv, -v);
310 /* more than one solution, disable all */
311 /* do not push anything on refine list, as we do not know which solution to choose */
312 /* thus, the user will get another problem if he selects this solution, where he
313 * can choose the right one */
314 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
316 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "more than one solution found:\n");
317 for (i = disabledcnt; i < disabled.count; i++)
318 solver_printproblem(solv, disabled.elements[i]);
320 for (i = disabledcnt; i < disabled.count; i++)
322 v = disabled.elements[i];
323 solver_disableproblem(solv, v);
324 if (v >= solv->updaterules && v < solv->updaterules_end)
326 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
328 solver_enablerule(solv, r);
333 /* all done, get us back into the same state as before */
334 /* enable refined rules again */
335 for (i = 0; i < disabled.count; i++)
336 solver_enableproblem(solv, disabled.elements[i]);
337 queue_free(&disabled);
338 /* reset policy rules */
339 for (i = 0; problem[i]; i++)
340 solver_enableproblem(solv, problem[i]);
341 solver_disablepolicyrules(solv);
342 /* disable problem rules again */
343 for (i = 0; problem[i]; i++)
344 solver_disableproblem(solv, problem[i]);
345 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "refine_suggestion end\n");
349 /*-------------------------------------------------------------------
350 * sorting helper for problems
352 * bring update rules before job rules
353 * make essential job rules last
357 problems_sortcmp(const void *ap, const void *bp, void *dp)
360 Id a = *(Id *)ap, b = *(Id *)bp;
367 int af = job->elements[-a - 1] & SOLVER_ESSENTIAL;
368 int bf = job->elements[-b - 1] & SOLVER_ESSENTIAL;
377 * convert a solution rule into a job modifier
380 convertsolution(Solver *solv, Id why, Queue *solutionq)
382 Pool *pool = solv->pool;
385 queue_push(solutionq, 0);
386 queue_push(solutionq, -why);
389 if (why >= solv->infarchrules && why < solv->infarchrules_end)
392 /* infarch rule, find replacement */
393 assert(solv->rules[why].p < 0);
394 name = pool->solvables[-solv->rules[why].p].name;
395 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
398 for (; why < solv->infarchrules_end && pool->solvables[-solv->rules[why].p].name == name; why++)
399 if (solv->decisionmap[-solv->rules[why].p] > 0)
401 p = -solv->rules[why].p;
405 return; /* false alarm */
406 queue_push(solutionq, SOLVER_SOLUTION_INFARCH);
407 queue_push(solutionq, p);
410 if (why >= solv->duprules && why < solv->duprules_end)
413 /* dist upgrade rule, find replacement */
414 assert(solv->rules[why].p < 0);
415 name = pool->solvables[-solv->rules[why].p].name;
416 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
419 for (; why < solv->duprules_end && pool->solvables[-solv->rules[why].p].name == name; why++)
420 if (solv->decisionmap[-solv->rules[why].p] > 0)
422 p = -solv->rules[why].p;
426 return; /* false alarm */
427 queue_push(solutionq, SOLVER_SOLUTION_DISTUPGRADE);
428 queue_push(solutionq, p);
431 if (why >= solv->updaterules && why < solv->updaterules_end)
433 /* update rule, find replacement package */
437 /* check if this is a false positive, i.e. the update rule is fulfilled */
438 rr = solv->rules + why;
439 FOR_RULELITERALS(p, dp, rr)
440 if (p > 0 && solv->decisionmap[p] > 0)
441 return; /* false alarm */
443 p = solv->installed->start + (why - solv->updaterules);
444 if (solv->dupmap_all && solv->rules[why].p != p && solv->decisionmap[p] > 0)
446 /* distupgrade case, allow to keep old package */
447 queue_push(solutionq, SOLVER_SOLUTION_DISTUPGRADE);
448 queue_push(solutionq, p);
451 if (solv->decisionmap[p] > 0)
452 return; /* false alarm, turned out we can keep the package */
453 rr = solv->rules + solv->featurerules + (why - solv->updaterules);
455 rr = solv->rules + why;
458 int mvrp = 0; /* multi-version replacement */
459 FOR_RULELITERALS(rp, dp, rr)
461 if (rp > 0 && solv->decisionmap[rp] > 0 && pool->solvables[rp].repo != solv->installed)
464 if (!(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, rp)))
470 /* found only multi-version replacements */
471 /* have to split solution into two parts */
472 queue_push(solutionq, p);
473 queue_push(solutionq, mvrp);
476 queue_push(solutionq, p);
477 queue_push(solutionq, rp);
480 if (why >= solv->bestrules && why < solv->bestrules_end)
485 /* check false positive */
486 rr = solv->rules + why;
487 FOR_RULELITERALS(p, dp, rr)
488 if (p > 0 && solv->decisionmap[p] > 0)
489 return; /* false alarm */
490 /* check update/feature rule */
491 p = solv->bestrules_pkg[why - solv->bestrules];
495 queue_push(solutionq, 0);
496 queue_push(solutionq, solv->ruletojob.elements[-p - solv->jobrules] + 1);
499 if (solv->decisionmap[p] > 0)
501 /* disable best rule by keeping the old package */
502 queue_push(solutionq, SOLVER_SOLUTION_BEST);
503 queue_push(solutionq, p);
506 rr = solv->rules + solv->featurerules + (p - solv->installed->start);
508 rr = solv->rules + solv->updaterules + (p - solv->installed->start);
509 mvrp = 0; /* multi-version replacement */
510 FOR_RULELITERALS(rp, dp, rr)
511 if (rp > 0 && solv->decisionmap[rp] > 0 && pool->solvables[rp].repo != solv->installed)
514 if (!(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, rp)))
519 queue_push(solutionq, SOLVER_SOLUTION_BEST); /* split, see above */
520 queue_push(solutionq, mvrp);
521 queue_push(solutionq, p);
522 queue_push(solutionq, 0);
527 queue_push(solutionq, SOLVER_SOLUTION_BEST);
528 queue_push(solutionq, rp);
535 * convert problem data into a form usable for refining.
536 * Returns the number of problems.
539 solver_prepare_solutions(Solver *solv)
543 if (!solv->problems.count)
545 queue_empty(&solv->solutions);
546 queue_push(&solv->solutions, 0); /* dummy so idx is always nonzero */
547 idx = solv->solutions.count;
548 queue_push(&solv->solutions, -1); /* unrefined */
549 /* proofidx stays in position, thus we start with 1 */
550 for (i = 1; i < solv->problems.count; i++)
552 Id p = solv->problems.elements[i];
553 queue_push(&solv->solutions, p);
556 /* end of problem reached */
557 solv->problems.elements[j++] = idx;
558 if (i + 1 >= solv->problems.count)
560 /* start another problem */
561 solv->problems.elements[j++] = solv->problems.elements[++i]; /* copy proofidx */
562 idx = solv->solutions.count;
563 queue_push(&solv->solutions, -1); /* unrefined */
565 solv->problems.count = j;
570 * refine the simple solution rule list provided by
571 * the solver into multiple lists of job modifiers.
574 create_solutions(Solver *solv, int probnr, int solidx)
576 Pool *pool = solv->pool;
578 Queue problem, solution, problems_save;
582 int oldmistakes = solv->cleandeps_mistakes ? solv->cleandeps_mistakes->count : 0;
585 now = solv_timems(0);
587 /* save decisionq, decisionq_why, decisionmap */
588 for (i = 0; i < solv->decisionq.count; i++)
590 Id p = solv->decisionq.elements[i];
591 queue_push(&redoq, p);
592 queue_push(&redoq, solv->decisionq_why.elements[i]);
593 queue_push(&redoq, solv->decisionmap[p > 0 ? p : -p]);
595 /* save problems queue */
596 problems_save = solv->problems;
597 memset(&solv->problems, 0, sizeof(solv->problems));
599 /* extract problem from queue */
600 queue_init(&problem);
601 for (i = solidx + 1; i < solv->solutions.count; i++)
603 Id v = solv->solutions.elements[i];
606 queue_push(&problem, v);
608 extraflags &= solv->job.elements[-v - 1];
610 if (extraflags == -1)
612 if (problem.count > 1)
613 solv_sort(problem.elements, problem.count, sizeof(Id), problems_sortcmp, &solv->job);
614 queue_push(&problem, 0); /* mark end for refine_suggestion */
617 for (i = 0; i < problem.count; i++)
618 printf("PP %d %d\n", i, problem.elements[i]);
621 /* refine each solution element */
624 queue_init(&solution);
625 for (i = 0; i < problem.count; i++)
627 int solstart = solv->solutions.count;
628 refine_suggestion(solv, problem.elements, problem.elements[i], &solution, essentialok);
629 queue_push(&solv->solutions, 0); /* reserve room for number of elements */
630 for (j = 0; j < solution.count; j++)
631 convertsolution(solv, solution.elements[j], &solv->solutions);
632 if (solv->solutions.count == solstart + 1)
634 solv->solutions.count--; /* this one did not work out */
635 if (nsol || i + 1 < problem.count)
636 continue; /* got one or still hope */
639 /* nothing found, start over */
640 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "nothing found, re-run with essentialok = 1\n");
645 /* this is bad, we found no solution */
646 /* for now just offer a rule */
647 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "nothing found, already did essentialok, fake it\n");
648 queue_push(&solv->solutions, 0);
649 for (j = 0; j < problem.count; j++)
651 convertsolution(solv, problem.elements[j], &solv->solutions);
652 if (solv->solutions.count > solstart + 1)
655 if (solv->solutions.count == solstart + 1)
657 solv->solutions.count--;
658 continue; /* sorry */
661 /* patch in number of solution elements */
662 solv->solutions.elements[solstart] = (solv->solutions.count - (solstart + 1)) / 2;
663 queue_push(&solv->solutions, 0); /* add end marker */
664 queue_push(&solv->solutions, 0); /* add end marker */
665 queue_push(&solv->solutions, problem.elements[i]); /* just for bookkeeping */
666 queue_push(&solv->solutions, extraflags & SOLVER_CLEANDEPS); /* our extraflags */
667 solv->solutions.elements[solidx + 1 + nsol++] = solstart;
669 solv->solutions.elements[solidx + 1 + nsol] = 0; /* end marker */
670 solv->solutions.elements[solidx] = nsol;
671 queue_free(&problem);
672 queue_free(&solution);
674 /* restore decisions */
675 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
676 queue_empty(&solv->decisionq);
677 queue_empty(&solv->decisionq_why);
678 for (i = 0; i < redoq.count; i += 3)
680 Id p = redoq.elements[i];
681 queue_push(&solv->decisionq, p);
682 queue_push(&solv->decisionq_why, redoq.elements[i + 1]);
683 solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
686 /* restore problems */
687 queue_free(&solv->problems);
688 solv->problems = problems_save;
690 if (solv->cleandeps_mistakes)
693 queue_truncate(solv->cleandeps_mistakes, oldmistakes);
696 queue_free(solv->cleandeps_mistakes);
697 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
701 POOL_DEBUG(SOLV_DEBUG_STATS, "create_solutions for problem #%d took %d ms\n", probnr, solv_timems(now));
705 /**************************************************************************/
708 solver_problem_count(Solver *solv)
710 return solv->problems.count / 2;
714 solver_next_problem(Solver *solv, Id problem)
717 return solv->problems.count ? 1 : 0;
718 return (problem + 1) * 2 - 1 < solv->problems.count ? problem + 1 : 0;
722 solver_solution_count(Solver *solv, Id problem)
724 Id solidx = solv->problems.elements[problem * 2 - 1];
725 if (solv->solutions.elements[solidx] < 0)
726 create_solutions(solv, problem, solidx);
727 return solv->solutions.elements[solidx];
731 solver_next_solution(Solver *solv, Id problem, Id solution)
733 Id solidx = solv->problems.elements[problem * 2 - 1];
734 if (solv->solutions.elements[solidx] < 0)
735 create_solutions(solv, problem, solidx);
736 return solv->solutions.elements[solidx + solution + 1] ? solution + 1 : 0;
740 solver_solutionelement_count(Solver *solv, Id problem, Id solution)
742 Id solidx = solv->problems.elements[problem * 2 - 1];
743 solidx = solv->solutions.elements[solidx + solution];
744 return solv->solutions.elements[solidx];
748 solver_solutionelement_internalid(Solver *solv, Id problem, Id solution)
750 Id solidx = solv->problems.elements[problem * 2 - 1];
751 solidx = solv->solutions.elements[solidx + solution];
752 return solv->solutions.elements[solidx + 2 * solv->solutions.elements[solidx] + 3];
756 solver_solutionelement_extrajobflags(Solver *solv, Id problem, Id solution)
758 Id solidx = solv->problems.elements[problem * 2 - 1];
759 solidx = solv->solutions.elements[solidx + solution];
760 return solv->solutions.elements[solidx + 2 * solv->solutions.elements[solidx] + 4];
765 * return the next item of the proposed solution
766 * here are the possibilities for p / rp and what
767 * the solver expects the application to do:
769 * -------------------------------------------------------
770 * SOLVER_SOLUTION_INFARCH pkgid
771 * -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
772 * SOLVER_SOLUTION_DISTUPGRADE pkgid
773 * -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
774 * SOLVER_SOLUTION_BEST pkgid
775 * -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
776 * SOLVER_SOLUTION_JOB jobidx
777 * -> remove job (jobidx - 1, jobidx) from job queue
779 * -> add (SOLVER_ERASE|SOLVER_SOLVABLE, p) to the job
780 * pkgid (> 0) pkgid (> 0)
781 * -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
782 * (this will replace package p)
784 * Thus, the solver will either ask the application to remove
785 * a specific job from the job queue, or ask to add an install/erase
791 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
793 Id solidx = solv->problems.elements[problem * 2 - 1];
794 solidx = solv->solutions.elements[solidx + solution];
797 solidx += 1 + element * 2;
798 if (!solv->solutions.elements[solidx] && !solv->solutions.elements[solidx + 1])
800 *p = solv->solutions.elements[solidx];
801 *rp = solv->solutions.elements[solidx + 1];
806 solver_take_solutionelement(Solver *solv, Id p, Id rp, Id extrajobflags, Queue *job)
810 if (p == SOLVER_SOLUTION_JOB)
812 job->elements[rp - 1] = SOLVER_NOOP;
813 job->elements[rp] = 0;
816 if (rp <= 0 && p <= 0)
817 return; /* just in case */
819 p = SOLVER_INSTALL|SOLVER_SOLVABLE|extrajobflags;
823 p = SOLVER_ERASE|SOLVER_SOLVABLE|extrajobflags;
825 for (i = 0; i < job->count; i += 2)
826 if (job->elements[i] == p && job->elements[i + 1] == rp)
828 queue_push2(job, p, rp);
832 solver_take_solution(Solver *solv, Id problem, Id solution, Queue *job)
834 Id p, rp, element = 0;
835 Id extrajobflags = solver_solutionelement_extrajobflags(solv, problem, solution);
836 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
837 solver_take_solutionelement(solv, p, rp, extrajobflags, job);
841 /*-------------------------------------------------------------------
847 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
850 Id lreqr, lconr, lsysr, ljobr;
853 int i, reqset = 0; /* 0: unset, 1: installed, 2: jobassert, 3: assert */
855 /* find us a jobassert rule */
856 for (i = idx; (rid = solv->learnt_pool.elements[i]) != 0; i++)
858 if (rid < solv->jobrules || rid >= solv->jobrules_end)
860 r = solv->rules + rid;
861 d = r->d < 0 ? -r->d - 1 : r->d;
862 if (!d && r->w2 == 0 && r->p > 0)
869 /* the problem rules are somewhat ordered from "near to the problem" to
870 * "near to the job" */
871 lreqr = lconr = lsysr = ljobr = 0;
872 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
875 if (rid >= solv->learntrules)
876 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
877 else if ((rid >= solv->jobrules && rid < solv->jobrules_end) || (rid >= solv->infarchrules && rid < solv->infarchrules_end) || (rid >= solv->duprules && rid < solv->duprules_end) || (rid >= solv->bestrules && rid < solv->bestrules_end))
882 else if (rid >= solv->updaterules && rid < solv->updaterules_end)
889 assert(rid < solv->rpmrules_end);
890 r = solv->rules + rid;
891 d = r->d < 0 ? -r->d - 1 : r->d;
899 if (!d && r->w2 == 0 && reqset < 3)
901 if (*reqrp > 0 && r->p < -1)
903 Id op = -solv->rules[*reqrp].p;
904 if (op > 1 && solv->pool->solvables[op].arch != solv->pool->solvables[-r->p].arch)
905 continue; /* different arch, skip */
907 /* prefer assertions */
911 else if (jobassert && r->p == -jobassert)
913 /* prefer rules of job assertions */
917 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed && reqset <= 1)
919 /* prefer rules of job installed package so that the user doesn't get confused by strange packages */
928 if (!*reqrp && lreqr)
930 if (!*conrp && lconr)
932 if (!*jobrp && ljobr)
934 if (!*sysrp && lsysr)
941 * search for a rule that describes the problem to the
942 * user. Actually a pretty hopeless task that may leave the user
943 * puzzled. To get all of the needed information use
944 * solver_findallproblemrules() instead.
948 solver_findproblemrule(Solver *solv, Id problem)
950 Id reqr, conr, sysr, jobr;
951 Id idx = solv->problems.elements[2 * problem - 2];
952 reqr = conr = sysr = jobr = 0;
953 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
955 return reqr; /* some requires */
957 return conr; /* some conflict */
959 return sysr; /* an update rule */
961 return jobr; /* a user request */
966 /*-------------------------------------------------------------------*/
969 findallproblemrules_internal(Solver *solv, Id idx, Queue *rules)
972 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
974 if (rid >= solv->learntrules)
976 findallproblemrules_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], rules);
979 queue_pushunique(rules, rid);
984 * find all problem rule
986 * return all rules that lead to the problem. This gives the user
987 * all of the information to understand the problem, but the result
988 * can be a large number of rules.
992 solver_findallproblemrules(Solver *solv, Id problem, Queue *rules)
995 findallproblemrules_internal(solv, solv->problems.elements[2 * problem - 2], rules);