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
91 installed solvables */
92 Map noobsoletes; /* ignore obsoletes for these
95 Queue weakruleq; /* index into 'rules' for weak ones */
96 Map weakrulemap; /* map rule# to '1' for weak rules, 1..learntrules */
98 Id *watches; /* Array of rule offsets
99 * watches has nsolvables*2 entries and is addressed from the middle
100 * middle-solvable : decision to conflict, offset point to linked-list of rules
101 * middle+solvable : decision to install: offset point to linked-list of rules
104 Queue ruletojob; /* index into job queue: jobs for which a rule exits */
107 Queue decisionq; /* >0:install, <0:remove/conflict */
108 Queue decisionq_why; /* index of rule, Offset into rules */
109 int directdecisions; /* number of decisions with no rule */
111 Id *decisionmap; /* map for all available solvables,
113 * > 0: level of decision when installed,
114 * < 0: level of decision when conflict */
116 /* learnt rule history */
121 int (*solution_callback)(struct solver *solv, void *data);
122 void *solution_callback_data;
124 int propagate_index; /* index into decisionq for non-propagated decisions */
126 Queue problems; /* index of conflicting rules, < 0 for job rules */
127 Queue recommendations; /* recommended packages */
128 Queue suggestions; /* suggested packages */
129 Queue orphaned; /* orphaned packages */
131 int stats_learned; /* statistic */
132 int stats_unsolvable; /* statistic */
134 Map recommendsmap; /* recommended packages from decisionmap */
135 Map suggestsmap; /* suggested packages from decisionmap */
136 int recommends_index; /* recommendsmap/suggestsmap is created up to this level */
138 Id *obsoletes; /* obsoletes for each installed solvable */
139 Id *obsoletes_data; /* data area for obsoletes */
141 /*-------------------------------------------------------------------------------------------------------------
142 * Solver configuration
143 *-------------------------------------------------------------------------------------------------------------*/
145 int fixsystem; /* repair errors in rpm dependency graph */
146 int allowdowngrade; /* allow to downgrade installed solvable */
147 int allowarchchange; /* allow to change architecture of installed solvables */
148 int allowvendorchange; /* allow to change vendor of installed solvables */
149 int allowuninstall; /* allow removal of installed solvables */
150 int updatesystem; /* distupgrade */
151 int allowvirtualconflicts; /* false: conflicts on package name, true: conflicts on package provides */
152 int allowselfconflicts; /* true: packages wich conflict with itself are installable */
153 int obsoleteusesprovides; /* true: obsoletes are matched against provides, not names */
154 int implicitobsoleteusesprovides; /* true: implicit obsoletes due to same name are matched against provides, not names */
155 int noupdateprovide; /* true: update packages needs not to provide old package */
156 int dosplitprovides; /* true: consider legacy split provides */
157 int dontinstallrecommended; /* true: do not install recommended packages */
158 int ignorealreadyrecommended; /* true: ignore recommended packages that were already recommended by the installed packages */
159 int dontshowinstalledrecommended; /* true: do not show recommended packages that are already installed */
161 /* distupgrade also needs updatesystem and dosplitprovides */
163 int distupgrade_removeunsupported;
165 /* Callbacks for defining the bahaviour of the SAT solver */
167 /* Finding best candidate
169 * Callback definition:
170 * void bestSolvable (Pool *pool, Queue *canditates)
171 * candidates : List of canditates which has to be sorted by the function call
172 * return candidates: Sorted list of the candidates(first is the best).
174 BestSolvableCb bestSolvableCb;
176 /* Checking if two solvables has compatible architectures
178 * Callback definition:
179 * int archCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2);
181 * return 0 it the two solvables has compatible architectures
183 ArchCheckCb archCheckCb;
185 /* Checking if two solvables has compatible vendors
187 * Callback definition:
188 * int vendorCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2);
190 * return 0 it the two solvables has compatible architectures
192 VendorCheckCb vendorCheckCb;
194 /* Evaluate update candidate
196 * Callback definition:
197 * void pdateCandidateCb (Pool *pool, Solvable *solvable, Queue *canditates)
198 * solvable : for which updates should be search
199 * candidates : List of candidates (This list depends on other
200 * restrictions like architecture and vendor policies too)
202 UpdateCandidateCb updateCandidateCb;
205 /* some strange queue that doesn't belong here */
207 Queue covenantq; /* Covenants honored by this solver (generic locks) */
216 #define SOLVER_SOLVABLE 0x01
217 #define SOLVER_SOLVABLE_NAME 0x02
218 #define SOLVER_SOLVABLE_PROVIDES 0x03
219 #define SOLVER_SOLVABLE_ONE_OF 0x04
221 #define SOLVER_SELECTMASK 0xff
223 #define SOLVER_INSTALL 0x0100
224 #define SOLVER_ERASE 0x0200
225 #define SOLVER_UPDATE 0x0300
226 #define SOLVER_WEAKENDEPS 0x0400
227 #define SOLVER_NOOBSOLETES 0x0500
228 #define SOLVER_LOCK 0x0600
230 #define SOLVER_JOBMASK 0xff00
232 #define SOLVER_WEAK 0x010000
233 #define SOLVER_ESSENTIAL 0x020000
235 /* old API compatibility, do not use in new code */
237 #define SOLVER_INSTALL_SOLVABLE (SOLVER_INSTALL|SOLVER_SOLVABLE)
238 #define SOLVER_ERASE_SOLVABLE (SOLVER_ERASE|SOLVER_SOLVABLE)
239 #define SOLVER_INSTALL_SOLVABLE_NAME (SOLVER_INSTALL|SOLVER_SOLVABLE_NAME)
240 #define SOLVER_ERASE_SOLVABLE_NAME (SOLVER_ERASE|SOLVER_SOLVABLE_NAME)
241 #define SOLVER_INSTALL_SOLVABLE_PROVIDES (SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES)
242 #define SOLVER_ERASE_SOLVABLE_PROVIDES (SOLVER_ERASE|SOLVER_SOLVABLE_PROVIDES)
243 #define SOLVER_INSTALL_SOLVABLE_UPDATE (SOLVER_UPDATE|SOLVER_SOLVABLE)
244 #define SOLVER_INSTALL_SOLVABLE_ONE_OF (SOLVER_INSTALL|SOLVER_SOLVABLE_ONE_OF)
245 #define SOLVER_WEAKEN_SOLVABLE_DEPS (SOLVER_WEAKENDEPS|SOLVER_SOLVABLE)
246 #define SOLVER_NOOBSOLETES_SOLVABLE (SOLVER_NOOBSOLETES|SOLVER_SOLVABLE)
247 #define SOLVER_NOOBSOLETES_SOLVABLE_NAME (SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME)
248 #define SOLVER_NOOBSOLETES_SOLVABLE_PROVIDES (SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_PROVIDES)
252 SOLVER_PROBLEM_UPDATE_RULE,
253 SOLVER_PROBLEM_JOB_RULE,
254 SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP,
255 SOLVER_PROBLEM_NOT_INSTALLABLE,
256 SOLVER_PROBLEM_NOTHING_PROVIDES_DEP,
257 SOLVER_PROBLEM_SAME_NAME,
258 SOLVER_PROBLEM_PACKAGE_CONFLICT,
259 SOLVER_PROBLEM_PACKAGE_OBSOLETES,
260 SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE,
261 SOLVER_PROBLEM_SELF_CONFLICT,
262 SOLVER_PROBLEM_RPM_RULE
266 extern Solver *solver_create(Pool *pool);
267 extern void solver_free(Solver *solv);
268 extern void solver_solve(Solver *solv, Queue *job);
269 extern int solver_dep_installed(Solver *solv, Id dep);
270 extern int solver_splitprovides(Solver *solv, Id dep);
272 extern Id solver_next_problem(Solver *solv, Id problem);
273 extern Id solver_next_solution(Solver *solv, Id problem, Id solution);
274 extern Id solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp);
275 extern Id solver_findproblemrule(Solver *solv, Id problem);
276 extern SolverProbleminfo solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp);
278 /* XXX: why is this not static? */
279 Id *solver_create_decisions_obsoletesmap(Solver *solv);
282 solver_dep_fulfilled(Solver *solv, Id dep)
284 Pool *pool = solv->pool;
289 Reldep *rd = GETRELDEP(pool, dep);
290 if (rd->flags == REL_AND)
292 if (!solver_dep_fulfilled(solv, rd->name))
294 return solver_dep_fulfilled(solv, rd->evr);
296 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
297 return solver_splitprovides(solv, rd->evr);
298 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
299 return solver_dep_installed(solv, rd->evr);
301 FOR_PROVIDES(p, pp, dep)
303 if (solv->decisionmap[p] > 0)
310 solver_is_supplementing(Solver *solv, Solvable *s)
315 supp = s->repo->idarraydata + s->supplements;
316 while ((sup = *supp++) != 0)
317 if (solver_dep_fulfilled(solv, sup))
323 solver_is_enhancing(Solver *solv, Solvable *s)
328 enhp = s->repo->idarraydata + s->enhances;
329 while ((enh = *enhp++) != 0)
330 if (solver_dep_fulfilled(solv, enh))
335 void solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps);
336 int solver_calc_installsizechange(Solver *solv);
338 void solver_find_involved(Solver *solv, Queue *installedq, Solvable *s, Queue *q);
341 solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
343 pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
346 /* iterate over all literals of a rule */
347 /* WARNING: loop body must not relocate whatprovidesdata, e.g. by
348 * looking up the providers of a dependency */
349 #define FOR_RULELITERALS(l, dp, r) \
350 for (l = r->d < 0 ? -r->d - 1 : r->d, \
351 dp = !l ? &r->w2 : pool->whatprovidesdata + l, \
352 l = r->p; l; l = (dp != &r->w2 + 1 ? *dp++ : 0))
354 /* iterate over all packages selected by a job */
355 #define FOR_JOB_SELECT(p, pp, select, what) \
356 for (pp = (select == SOLVER_SOLVABLE ? 0 : \
357 select == SOLVER_SOLVABLE_ONE_OF ? what : \
358 pool_whatprovides(pool, what)), \
359 p = (select == SOLVER_SOLVABLE ? what : pool->whatprovidesdata[pp++]) ; p ; p = pool->whatprovidesdata[pp++]) \
360 if (select != SOLVER_SOLVABLE_NAME || pool_match_nevr(pool, pool->solvables + p, what))
366 #endif /* SATSOLVER_SOLVER_H */