2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
13 #ifndef SATSOLVER_SOLVER_H
14 #define SATSOLVER_SOLVER_H
20 #include "pooltypes.h"
26 * Callback definitions in order to "overwrite" the policies by an external application.
29 typedef void (*BestSolvableCb) (Pool *pool, Queue *canditates);
30 typedef int (*ArchCheckCb) (Pool *pool, Solvable *solvable1, Solvable *solvable2);
31 typedef int (*VendorCheckCb) (Pool *pool, Solvable *solvable1, Solvable *solvable2);
32 typedef void (*UpdateCandidateCb) (Pool *pool, Solvable *solvable, Queue *canditates);
35 /* ----------------------------------------------
38 * providerN(B) == Package Id of package providing tag B
39 * N = 1, 2, 3, in case of multiple providers
41 * A requires B : !A | provider1(B) | provider2(B)
43 * A conflicts B : (!A | !provider1(B)) & (!A | !provider2(B)) ...
45 * 'not' is encoded as a negative Id
47 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
51 Id p; /* first literal in rule */
52 Id d; /* Id offset into 'list of providers terminated by 0' as used by whatprovides; pool->whatprovides + d */
53 /* in case of binary rules, d == 0, w1 == p, w2 == other literal */
54 /* in case of disabled rules: ~d, aka -d - 1 */
55 Id w1, w2; /* watches, literals not-yet-decided */
56 /* if !w2, assertion, not rule */
57 Id n1, n2; /* next rules in linked list, corresponding to w1,w2 */
62 typedef struct solver {
66 /* list of rules, ordered
67 * rpm rules first, then features, updates, jobs, learnt
68 * see start/end offsets below
70 Rule *rules; /* all rules */
71 Id nrules; /* [Offset] index of the last rule */
73 Queue ruleassertions; /* Queue of all assertion rules */
75 /* start/end offset for rule 'areas' */
77 Id rpmrules_end; /* [Offset] rpm rules end */
79 Id featurerules; /* feature rules start/end */
82 Id updaterules; /* policy rules, e.g. keep packages installed or update. All literals > 0 */
85 Id jobrules; /* user rules */
88 Id learntrules; /* learnt rules, (end == nrules) */
90 Map noupdate; /* don't try to update these installed solvables */
91 /* aka 'obsoletesmap' */
93 Queue weakruleq; /* index into 'rules' for weak ones */
95 Map weakrulemap; /* map rule# to '1' for weak rules, 1..learntrules */
97 Id *watches; /* Array of rule offsets
98 * watches has nsolvables*2 entries and is addressed from the middle
99 * middle-solvable : decision to conflict, offset point to linked-list of rules
100 * middle+solvable : decision to install: offset point to linked-list of rules
103 Queue ruletojob; /* index into job queue: jobs for which a rule exits */
106 Queue decisionq; /* >0:install, <0:remove/conflict */
107 Queue decisionq_why; /* index of rule, Offset into rules */
108 int directdecisions; /* number of decisions with no rule */
110 Id *decisionmap; /* map for all available solvables,
111 > 0: level of decision when installed,
112 < 0: level of decision when conflict */
114 /* learnt rule history */
119 int (*solution_callback)(struct solver *solv, void *data);
120 void *solution_callback_data;
122 int propagate_index; /* index into decisionq for non-propagated decisions */
124 Queue problems; /* index of conflicting rules, < 0 for job rules */
125 Queue recommendations; /* recommended packages */
126 Queue suggestions; /* suggested packages */
128 int stats_learned; /* statistic */
129 int stats_unsolvable; /* statistic */
131 Map recommendsmap; /* recommended packages from decisionmap */
132 Map suggestsmap; /* suggested packages from decisionmap */
133 int recommends_index; /* recommendsmap/suggestsmap is created up to this level */
135 Id *obsoletes; /* obsoletes for each installed solvable */
136 Id *obsoletes_data; /* data area for obsoletes */
138 /*-------------------------------------------------------------------------------------------------------------
139 * Solver configuration
140 *-------------------------------------------------------------------------------------------------------------*/
142 int fixsystem; /* repair errors in rpm dependency graph */
143 int allowdowngrade; /* allow to downgrade installed solvable */
144 int allowarchchange; /* allow to change architecture of installed solvables */
145 int allowvendorchange; /* allow to change vendor of installed solvables */
146 int allowuninstall; /* allow removal of installed solvables */
147 int updatesystem; /* distupgrade */
148 int allowvirtualconflicts; /* false: conflicts on package name, true: conflicts on package provides */
149 int allowselfconflicts; /* true: packages wich conflict with itself are installable */
150 int obsoleteusesprovides; /* true: obsoletes are matched against provides, not names */
151 int implicitobsoleteusesprovides; /* true: implicit obsoletes due to same name are matched against provides, not names */
152 int noupdateprovide; /* true: update packages needs not to provide old package */
153 int dosplitprovides; /* true: consider legacy split provides */
154 int dontinstallrecommended; /* true: do not install recommended packages */
155 int dontshowinstalledrecommended; /* true: do not show recommended packages that are already installed */
157 /* Callbacks for defining the bahaviour of the SAT solver */
159 /* Finding best candidate
161 * Callback definition:
162 * void bestSolvable (Pool *pool, Queue *canditates)
163 * candidates : List of canditates which has to be sorted by the function call
164 * return candidates: Sorted list of the candidates(first is the best).
166 BestSolvableCb bestSolvableCb;
168 /* Checking if two solvables has compatible architectures
170 * Callback definition:
171 * int archCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2);
173 * return 0 it the two solvables has compatible architectures
175 ArchCheckCb archCheckCb;
177 /* Checking if two solvables has compatible vendors
179 * Callback definition:
180 * int vendorCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2);
182 * return 0 it the two solvables has compatible architectures
184 VendorCheckCb vendorCheckCb;
186 /* Evaluate update candidate
188 * Callback definition:
189 * void pdateCandidateCb (Pool *pool, Solvable *solvable, Queue *canditates)
190 * solvable : for which updates should be search
191 * candidates : List of candidates (This list depends on other
192 * restrictions like architecture and vendor policies too)
194 UpdateCandidateCb updateCandidateCb;
197 /* some strange queue that doesn't belong here */
199 Queue covenantq; /* Covenants honored by this solver (generic locks) */
210 SOLVER_INSTALL_SOLVABLE,
211 SOLVER_ERASE_SOLVABLE,
212 SOLVER_INSTALL_SOLVABLE_NAME,
213 SOLVER_ERASE_SOLVABLE_NAME,
214 SOLVER_INSTALL_SOLVABLE_PROVIDES,
215 SOLVER_ERASE_SOLVABLE_PROVIDES,
216 SOLVER_INSTALL_SOLVABLE_UPDATE,
217 SOLVER_INSTALL_SOLVABLE_ONE_OF,
218 SOLVER_WEAKEN_SOLVABLE_DEPS,
223 SOLVER_PROBLEM_UPDATE_RULE,
224 SOLVER_PROBLEM_JOB_RULE,
225 SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP,
226 SOLVER_PROBLEM_NOT_INSTALLABLE,
227 SOLVER_PROBLEM_NOTHING_PROVIDES_DEP,
228 SOLVER_PROBLEM_SAME_NAME,
229 SOLVER_PROBLEM_PACKAGE_CONFLICT,
230 SOLVER_PROBLEM_PACKAGE_OBSOLETES,
231 SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE,
232 SOLVER_PROBLEM_SELF_CONFLICT
236 extern Solver *solver_create(Pool *pool, Repo *installed);
237 extern void solver_free(Solver *solv);
238 extern void solver_solve(Solver *solv, Queue *job);
239 extern int solver_dep_installed(Solver *solv, Id dep);
240 extern int solver_splitprovides(Solver *solv, Id dep);
242 extern Id solver_next_problem(Solver *solv, Id problem);
243 extern Id solver_next_solution(Solver *solv, Id problem, Id solution);
244 extern Id solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp);
245 extern Id solver_findproblemrule(Solver *solv, Id problem);
246 extern SolverProbleminfo solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp);
248 /* XXX: why is this not static? */
249 Id *create_decisions_obsoletesmap(Solver *solv);
252 solver_dep_fulfilled(Solver *solv, Id dep)
254 Pool *pool = solv->pool;
259 Reldep *rd = GETRELDEP(pool, dep);
260 if (rd->flags == REL_AND)
262 if (!solver_dep_fulfilled(solv, rd->name))
264 return solver_dep_fulfilled(solv, rd->evr);
266 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
267 return solver_splitprovides(solv, rd->evr);
268 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
269 return solver_dep_installed(solv, rd->evr);
271 FOR_PROVIDES(p, pp, dep)
273 if (solv->decisionmap[p] > 0)
280 solver_is_supplementing(Solver *solv, Solvable *s)
283 if (!s->supplements && !s->freshens)
287 supp = s->repo->idarraydata + s->supplements;
288 while ((sup = *supp++) != 0)
289 if (solver_dep_fulfilled(solv, sup))
296 supp = s->repo->idarraydata + s->freshens;
297 while ((sup = *supp++) != 0)
298 if (solver_dep_fulfilled(solv, sup))
307 solver_is_enhancing(Solver *solv, Solvable *s)
312 enhp = s->repo->idarraydata + s->enhances;
313 while ((enh = *enhp++) != 0)
314 if (solver_dep_fulfilled(solv, enh))
319 void solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps);
320 int solver_calc_installsizechange(Solver *solv);
323 solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
325 pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
328 #define FOR_RULELITERALS(l, dp, r) \
329 for (l = r->d < 0 ? -r->d - 1 : r->d, \
330 dp = !l ? &r->w2 : pool->whatprovidesdata + l, \
331 l = r->p; l; l = (dp != &r->w2 + 1 ? *dp++ : 0))
337 #endif /* SATSOLVER_SOLVER_H */