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;
386 if (why < solv->pooljobcnt)
388 queue_push(solutionq, SOLVER_SOLUTION_POOLJOB);
389 queue_push(solutionq, why);
393 queue_push(solutionq, SOLVER_SOLUTION_JOB);
394 queue_push(solutionq, why - solv->pooljobcnt);
398 if (why >= solv->infarchrules && why < solv->infarchrules_end)
401 /* infarch rule, find replacement */
402 assert(solv->rules[why].p < 0);
403 name = pool->solvables[-solv->rules[why].p].name;
404 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
407 for (; why < solv->infarchrules_end && pool->solvables[-solv->rules[why].p].name == name; why++)
408 if (solv->decisionmap[-solv->rules[why].p] > 0)
410 p = -solv->rules[why].p;
414 return; /* false alarm */
415 queue_push(solutionq, SOLVER_SOLUTION_INFARCH);
416 queue_push(solutionq, p);
419 if (why >= solv->duprules && why < solv->duprules_end)
422 /* dist upgrade rule, find replacement */
423 assert(solv->rules[why].p < 0);
424 name = pool->solvables[-solv->rules[why].p].name;
425 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
428 for (; why < solv->duprules_end && pool->solvables[-solv->rules[why].p].name == name; why++)
429 if (solv->decisionmap[-solv->rules[why].p] > 0)
431 p = -solv->rules[why].p;
435 return; /* false alarm */
436 queue_push(solutionq, SOLVER_SOLUTION_DISTUPGRADE);
437 queue_push(solutionq, p);
440 if (why >= solv->updaterules && why < solv->updaterules_end)
442 /* update rule, find replacement package */
446 /* check if this is a false positive, i.e. the update rule is fulfilled */
447 rr = solv->rules + why;
448 FOR_RULELITERALS(p, pp, rr)
449 if (p > 0 && solv->decisionmap[p] > 0)
450 return; /* false alarm */
452 p = solv->installed->start + (why - solv->updaterules);
453 if (solv->dupmap_all && solv->rules[why].p != p && solv->decisionmap[p] > 0)
455 /* distupgrade case, allow to keep old package */
456 queue_push(solutionq, SOLVER_SOLUTION_DISTUPGRADE);
457 queue_push(solutionq, p);
460 if (solv->decisionmap[p] > 0)
461 return; /* false alarm, turned out we can keep the package */
462 rr = solv->rules + solv->featurerules + (why - solv->updaterules);
464 rr = solv->rules + why;
467 int mvrp = 0; /* multi-version replacement */
468 FOR_RULELITERALS(rp, pp, rr)
470 if (rp > 0 && solv->decisionmap[rp] > 0 && pool->solvables[rp].repo != solv->installed)
473 if (!(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, rp)))
479 /* found only multi-version replacements */
480 /* have to split solution into two parts */
481 queue_push(solutionq, p);
482 queue_push(solutionq, mvrp);
485 queue_push(solutionq, p);
486 queue_push(solutionq, rp);
489 if (why >= solv->bestrules && why < solv->bestrules_end)
494 /* check false positive */
495 rr = solv->rules + why;
496 FOR_RULELITERALS(p, pp, rr)
497 if (p > 0 && solv->decisionmap[p] > 0)
498 return; /* false alarm */
499 /* check update/feature rule */
500 p = solv->bestrules_pkg[why - solv->bestrules];
504 queue_push(solutionq, 0);
505 queue_push(solutionq, solv->ruletojob.elements[-p - solv->jobrules] + 1);
508 if (solv->decisionmap[p] > 0)
510 /* disable best rule by keeping the old package */
511 queue_push(solutionq, SOLVER_SOLUTION_BEST);
512 queue_push(solutionq, p);
515 rr = solv->rules + solv->featurerules + (p - solv->installed->start);
517 rr = solv->rules + solv->updaterules + (p - solv->installed->start);
518 mvrp = 0; /* multi-version replacement */
519 FOR_RULELITERALS(rp, pp, rr)
520 if (rp > 0 && solv->decisionmap[rp] > 0 && pool->solvables[rp].repo != solv->installed)
523 if (!(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, rp)))
528 queue_push(solutionq, SOLVER_SOLUTION_BEST); /* split, see above */
529 queue_push(solutionq, mvrp);
530 queue_push(solutionq, p);
531 queue_push(solutionq, 0);
536 queue_push(solutionq, SOLVER_SOLUTION_BEST);
537 queue_push(solutionq, rp);
544 * convert problem data into a form usable for refining.
545 * Returns the number of problems.
548 solver_prepare_solutions(Solver *solv)
552 if (!solv->problems.count)
554 queue_empty(&solv->solutions);
555 queue_push(&solv->solutions, 0); /* dummy so idx is always nonzero */
556 idx = solv->solutions.count;
557 queue_push(&solv->solutions, -1); /* unrefined */
558 /* proofidx stays in position, thus we start with 1 */
559 for (i = 1; i < solv->problems.count; i++)
561 Id p = solv->problems.elements[i];
562 queue_push(&solv->solutions, p);
565 /* end of problem reached */
566 solv->problems.elements[j++] = idx;
567 if (i + 1 >= solv->problems.count)
569 /* start another problem */
570 solv->problems.elements[j++] = solv->problems.elements[++i]; /* copy proofidx */
571 idx = solv->solutions.count;
572 queue_push(&solv->solutions, -1); /* unrefined */
574 solv->problems.count = j;
579 * refine the simple solution rule list provided by
580 * the solver into multiple lists of job modifiers.
583 create_solutions(Solver *solv, int probnr, int solidx)
585 Pool *pool = solv->pool;
587 Queue problem, solution, problems_save;
591 int oldmistakes = solv->cleandeps_mistakes ? solv->cleandeps_mistakes->count : 0;
594 now = solv_timems(0);
596 /* save decisionq, decisionq_why, decisionmap */
597 for (i = 0; i < solv->decisionq.count; i++)
599 Id p = solv->decisionq.elements[i];
600 queue_push(&redoq, p);
601 queue_push(&redoq, solv->decisionq_why.elements[i]);
602 queue_push(&redoq, solv->decisionmap[p > 0 ? p : -p]);
604 /* save problems queue */
605 problems_save = solv->problems;
606 memset(&solv->problems, 0, sizeof(solv->problems));
608 /* extract problem from queue */
609 queue_init(&problem);
610 for (i = solidx + 1; i < solv->solutions.count; i++)
612 Id v = solv->solutions.elements[i];
615 queue_push(&problem, v);
617 extraflags &= solv->job.elements[-v - 1];
619 if (extraflags == -1)
621 if (problem.count > 1)
622 solv_sort(problem.elements, problem.count, sizeof(Id), problems_sortcmp, &solv->job);
623 queue_push(&problem, 0); /* mark end for refine_suggestion */
626 for (i = 0; i < problem.count; i++)
627 printf("PP %d %d\n", i, problem.elements[i]);
630 /* refine each solution element */
633 queue_init(&solution);
634 for (i = 0; i < problem.count; i++)
636 int solstart = solv->solutions.count;
637 refine_suggestion(solv, problem.elements, problem.elements[i], &solution, essentialok);
638 queue_push(&solv->solutions, 0); /* reserve room for number of elements */
639 for (j = 0; j < solution.count; j++)
640 convertsolution(solv, solution.elements[j], &solv->solutions);
641 if (solv->solutions.count == solstart + 1)
643 solv->solutions.count--; /* this one did not work out */
644 if (nsol || i + 1 < problem.count)
645 continue; /* got one or still hope */
648 /* nothing found, start over */
649 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "nothing found, re-run with essentialok = 1\n");
654 /* this is bad, we found no solution */
655 /* for now just offer a rule */
656 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "nothing found, already did essentialok, fake it\n");
657 queue_push(&solv->solutions, 0);
658 for (j = 0; j < problem.count; j++)
660 convertsolution(solv, problem.elements[j], &solv->solutions);
661 if (solv->solutions.count > solstart + 1)
664 if (solv->solutions.count == solstart + 1)
666 solv->solutions.count--;
667 continue; /* sorry */
670 /* patch in number of solution elements */
671 solv->solutions.elements[solstart] = (solv->solutions.count - (solstart + 1)) / 2;
672 queue_push(&solv->solutions, 0); /* add end marker */
673 queue_push(&solv->solutions, 0); /* add end marker */
674 queue_push(&solv->solutions, problem.elements[i]); /* just for bookkeeping */
675 queue_push(&solv->solutions, extraflags & SOLVER_CLEANDEPS); /* our extraflags */
676 solv->solutions.elements[solidx + 1 + nsol++] = solstart;
678 solv->solutions.elements[solidx + 1 + nsol] = 0; /* end marker */
679 solv->solutions.elements[solidx] = nsol;
680 queue_free(&problem);
681 queue_free(&solution);
683 /* restore decisions */
684 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
685 queue_empty(&solv->decisionq);
686 queue_empty(&solv->decisionq_why);
687 for (i = 0; i < redoq.count; i += 3)
689 Id p = redoq.elements[i];
690 queue_push(&solv->decisionq, p);
691 queue_push(&solv->decisionq_why, redoq.elements[i + 1]);
692 solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
695 /* restore problems */
696 queue_free(&solv->problems);
697 solv->problems = problems_save;
699 if (solv->cleandeps_mistakes)
702 queue_truncate(solv->cleandeps_mistakes, oldmistakes);
705 queue_free(solv->cleandeps_mistakes);
706 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
710 POOL_DEBUG(SOLV_DEBUG_STATS, "create_solutions for problem #%d took %d ms\n", probnr, solv_timems(now));
714 /**************************************************************************/
717 solver_problem_count(Solver *solv)
719 return solv->problems.count / 2;
723 solver_next_problem(Solver *solv, Id problem)
726 return solv->problems.count ? 1 : 0;
727 return (problem + 1) * 2 - 1 < solv->problems.count ? problem + 1 : 0;
731 solver_solution_count(Solver *solv, Id problem)
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];
740 solver_next_solution(Solver *solv, Id problem, Id solution)
742 Id solidx = solv->problems.elements[problem * 2 - 1];
743 if (solv->solutions.elements[solidx] < 0)
744 create_solutions(solv, problem, solidx);
745 return solv->solutions.elements[solidx + solution + 1] ? solution + 1 : 0;
749 solver_solutionelement_count(Solver *solv, Id problem, Id solution)
751 Id solidx = solv->problems.elements[problem * 2 - 1];
752 solidx = solv->solutions.elements[solidx + solution];
753 return solv->solutions.elements[solidx];
757 solver_solutionelement_internalid(Solver *solv, Id problem, Id solution)
759 Id solidx = solv->problems.elements[problem * 2 - 1];
760 solidx = solv->solutions.elements[solidx + solution];
761 return solv->solutions.elements[solidx + 2 * solv->solutions.elements[solidx] + 3];
765 solver_solutionelement_extrajobflags(Solver *solv, Id problem, Id solution)
767 Id solidx = solv->problems.elements[problem * 2 - 1];
768 solidx = solv->solutions.elements[solidx + solution];
769 return solv->solutions.elements[solidx + 2 * solv->solutions.elements[solidx] + 4];
774 * return the next item of the proposed solution
775 * here are the possibilities for p / rp and what
776 * the solver expects the application to do:
778 * -------------------------------------------------------
779 * SOLVER_SOLUTION_INFARCH pkgid
780 * -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
781 * SOLVER_SOLUTION_DISTUPGRADE pkgid
782 * -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
783 * SOLVER_SOLUTION_BEST pkgid
784 * -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
785 * SOLVER_SOLUTION_JOB jobidx
786 * -> remove job (jobidx - 1, jobidx) from job queue
787 * SOLVER_SOLUTION_POOLJOB jobidx
788 * -> remove job (jobidx - 1, jobidx) from pool job queue
790 * -> add (SOLVER_ERASE|SOLVER_SOLVABLE, p) to the job
791 * pkgid (> 0) pkgid (> 0)
792 * -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
793 * (this will replace package p)
795 * Thus, the solver will either ask the application to remove
796 * a specific job from the job queue, or ask to add an install/erase
802 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
804 Id solidx = solv->problems.elements[problem * 2 - 1];
805 solidx = solv->solutions.elements[solidx + solution];
808 solidx += 1 + element * 2;
809 if (!solv->solutions.elements[solidx] && !solv->solutions.elements[solidx + 1])
811 *p = solv->solutions.elements[solidx];
812 *rp = solv->solutions.elements[solidx + 1];
817 solver_take_solutionelement(Solver *solv, Id p, Id rp, Id extrajobflags, Queue *job)
821 if (p == SOLVER_SOLUTION_POOLJOB)
823 solv->pool->pooljobs.elements[rp - 1] = SOLVER_NOOP;
824 solv->pool->pooljobs.elements[rp] = 0;
827 if (p == SOLVER_SOLUTION_JOB)
829 job->elements[rp - 1] = SOLVER_NOOP;
830 job->elements[rp] = 0;
833 if (rp <= 0 && p <= 0)
834 return; /* just in case */
836 p = SOLVER_INSTALL|SOLVER_SOLVABLE|extrajobflags;
840 p = SOLVER_ERASE|SOLVER_SOLVABLE|extrajobflags;
842 for (i = 0; i < job->count; i += 2)
843 if (job->elements[i] == p && job->elements[i + 1] == rp)
845 queue_push2(job, p, rp);
849 solver_take_solution(Solver *solv, Id problem, Id solution, Queue *job)
851 Id p, rp, element = 0;
852 Id extrajobflags = solver_solutionelement_extrajobflags(solv, problem, solution);
853 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
854 solver_take_solutionelement(solv, p, rp, extrajobflags, job);
858 /*-------------------------------------------------------------------
864 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp, Map *rseen)
867 Id lreqr, lconr, lsysr, ljobr;
870 int i, reqset = 0; /* 0: unset, 1: installed, 2: jobassert, 3: assert */
872 /* find us a jobassert rule */
873 for (i = idx; (rid = solv->learnt_pool.elements[i]) != 0; i++)
875 if (rid < solv->jobrules || rid >= solv->jobrules_end)
877 r = solv->rules + rid;
878 d = r->d < 0 ? -r->d - 1 : r->d;
879 if (!d && r->w2 == 0 && r->p > 0)
886 /* the problem rules are somewhat ordered from "near to the problem" to
887 * "near to the job" */
888 lreqr = lconr = lsysr = ljobr = 0;
889 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
892 if (rid >= solv->learntrules)
894 if (MAPTST(rseen, rid - solv->learntrules))
896 MAPSET(rseen, rid - solv->learntrules);
897 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr, rseen);
899 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))
904 else if (rid >= solv->updaterules && rid < solv->updaterules_end)
911 assert(rid < solv->rpmrules_end);
912 r = solv->rules + rid;
913 d = r->d < 0 ? -r->d - 1 : r->d;
921 if (!d && r->w2 == 0 && reqset < 3)
923 if (*reqrp > 0 && r->p < -1)
925 Id op = -solv->rules[*reqrp].p;
926 if (op > 1 && solv->pool->solvables[op].arch != solv->pool->solvables[-r->p].arch)
927 continue; /* different arch, skip */
929 /* prefer assertions */
933 else if (jobassert && r->p == -jobassert)
935 /* prefer rules of job assertions */
939 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed && reqset <= 1)
941 /* prefer rules of job installed package so that the user doesn't get confused by strange packages */
950 if (!*reqrp && lreqr)
952 if (!*conrp && lconr)
954 if (!*jobrp && ljobr)
956 if (!*sysrp && lsysr)
963 * search for a rule that describes the problem to the
964 * user. Actually a pretty hopeless task that may leave the user
965 * puzzled. To get all of the needed information use
966 * solver_findallproblemrules() instead.
970 solver_findproblemrule(Solver *solv, Id problem)
972 Id reqr, conr, sysr, jobr;
973 Id idx = solv->problems.elements[2 * problem - 2];
975 reqr = conr = sysr = jobr = 0;
976 map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
977 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr, &rseen);
980 return reqr; /* some requires */
982 return conr; /* some conflict */
984 return sysr; /* an update rule */
986 return jobr; /* a user request */
991 /*-------------------------------------------------------------------*/
994 findallproblemrules_internal(Solver *solv, Id idx, Queue *rules, Map *rseen)
997 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
999 if (rid >= solv->learntrules)
1001 if (MAPTST(rseen, rid - solv->learntrules))
1003 MAPSET(rseen, rid - solv->learntrules);
1004 findallproblemrules_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], rules, rseen);
1007 queue_pushunique(rules, rid);
1012 * find all problem rule
1014 * return all rules that lead to the problem. This gives the user
1015 * all of the information to understand the problem, but the result
1016 * can be a large number of rules.
1020 solver_findallproblemrules(Solver *solv, Id problem, Queue *rules)
1024 map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
1025 findallproblemrules_internal(solv, solv->problems.elements[2 * problem - 2], rules, &rseen);