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 Rule *rules; /* all rules */
67 Id nrules; /* index of the last rule */
69 Id jobrules; /* user rules */
70 Id updaterules; /* policy rules, e.g. keep packages installed or update. All literals > 0 */
71 Id featurerules; /* feature rules */
72 Id learntrules; /* learnt rules */
74 Map noupdate; /* don't try to update these
75 installed solvables */
79 Id *watches; /* Array of rule offsets
80 * watches has nsolvables*2 entries and is addressed from the middle
81 * middle-solvable : decision to conflict, offset point to linked-list of rules
82 * middle+solvable : decision to install: offset point to linked-list of rules
89 Queue decisionq_why; /* index of rule, Offset into rules */
90 int directdecisions; /* number of decisions with no rule */
92 Id *decisionmap; /* map for all available solvables, > 0: level of decision when installed, < 0 level of decision when conflict */
94 /* learnt rule history */
99 int (*solution_callback)(struct solver *solv, void *data);
100 void *solution_callback_data;
105 Queue recommendations; /* recommended packages */
106 Queue suggestions; /* suggested packages */
108 int stats_learned; /* statistic */
109 int stats_unsolvable; /* statistic */
111 Map recommendsmap; /* recommended packages from decisionmap */
112 Map suggestsmap; /* suggested packages from decisionmap */
113 int recommends_index; /* recommendsmap/suggestsmap is created up to this level */
115 Id *obsoletes; /* obsoletes for each installed solvable */
116 Id *obsoletes_data; /* data area for obsoletes */
118 /*-------------------------------------------------------------------------------------------------------------
119 * Solver configuration
120 *-------------------------------------------------------------------------------------------------------------*/
122 int fixsystem; /* repair errors in rpm dependency graph */
123 int allowdowngrade; /* allow to downgrade installed solvable */
124 int allowarchchange; /* allow to change architecture of installed solvables */
125 int allowvendorchange; /* allow to change vendor of installed solvables */
126 int allowuninstall; /* allow removal of installed solvables */
127 int updatesystem; /* distupgrade */
128 int allowvirtualconflicts; /* false: conflicts on package name, true: conflicts on package provides */
129 int allowselfconflicts; /* true: packages wich conflict with itself are installable */
130 int obsoleteusesprovides; /* true: obsoletes are matched against provides, not names */
131 int implicitobsoleteusesprovides; /* true: implicit obsoletes due to same name are matched against provides, not names */
132 int noupdateprovide; /* true: update packages needs not to provide old package */
133 int dosplitprovides; /* true: consider legacy split provides */
134 int dontinstallrecommended; /* true: do not install recommended packages */
135 int dontshowinstalledrecommended; /* true: do not show recommended packages that are already installed */
137 /* Callbacks for defining the bahaviour of the SAT solver */
139 /* Finding best candidate
141 * Callback definition:
142 * void bestSolvable (Pool *pool, Queue *canditates)
143 * candidates : List of canditates which has to be sorted by the function call
144 * return candidates: Sorted list of the candidates(first is the best).
146 BestSolvableCb bestSolvableCb;
148 /* Checking if two solvables has compatible architectures
150 * Callback definition:
151 * int archCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2);
153 * return 0 it the two solvables has compatible architectures
155 ArchCheckCb archCheckCb;
157 /* Checking if two solvables has compatible vendors
159 * Callback definition:
160 * int vendorCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2);
162 * return 0 it the two solvables has compatible architectures
164 VendorCheckCb vendorCheckCb;
166 /* Evaluate update candidate
168 * Callback definition:
169 * void pdateCandidateCb (Pool *pool, Solvable *solvable, Queue *canditates)
170 * solvable : for which updates should be search
171 * candidates : List of candidates (This list depends on other
172 * restrictions like architecture and vendor policies too)
174 UpdateCandidateCb updateCandidateCb;
177 /* some strange queue that doesn't belong here */
179 Queue covenantq; /* Covenants honored by this solver (generic locks) */
190 SOLVER_INSTALL_SOLVABLE,
191 SOLVER_ERASE_SOLVABLE,
192 SOLVER_INSTALL_SOLVABLE_NAME,
193 SOLVER_ERASE_SOLVABLE_NAME,
194 SOLVER_INSTALL_SOLVABLE_PROVIDES,
195 SOLVER_ERASE_SOLVABLE_PROVIDES,
196 SOLVER_INSTALL_SOLVABLE_UPDATE,
197 SOLVER_INSTALL_SOLVABLE_ONE_OF,
198 SOLVER_WEAKEN_SOLVABLE_DEPS,
203 SOLVER_PROBLEM_UPDATE_RULE,
204 SOLVER_PROBLEM_JOB_RULE,
205 SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP,
206 SOLVER_PROBLEM_NOT_INSTALLABLE,
207 SOLVER_PROBLEM_NOTHING_PROVIDES_DEP,
208 SOLVER_PROBLEM_SAME_NAME,
209 SOLVER_PROBLEM_PACKAGE_CONFLICT,
210 SOLVER_PROBLEM_PACKAGE_OBSOLETES,
211 SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE,
212 SOLVER_PROBLEM_SELF_CONFLICT
216 extern Solver *solver_create(Pool *pool, Repo *installed);
217 extern void solver_free(Solver *solv);
218 extern void solver_solve(Solver *solv, Queue *job);
219 extern int solver_dep_installed(Solver *solv, Id dep);
220 extern int solver_splitprovides(Solver *solv, Id dep);
222 extern Id solver_next_problem(Solver *solv, Id problem);
223 extern Id solver_next_solution(Solver *solv, Id problem, Id solution);
224 extern Id solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp);
225 extern Id solver_findproblemrule(Solver *solv, Id problem);
226 extern SolverProbleminfo solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp);
228 /* XXX: why is this not static? */
229 Id *create_decisions_obsoletesmap(Solver *solv);
232 solver_dep_fulfilled(Solver *solv, Id dep)
234 Pool *pool = solv->pool;
239 Reldep *rd = GETRELDEP(pool, dep);
240 if (rd->flags == REL_AND)
242 if (!solver_dep_fulfilled(solv, rd->name))
244 return solver_dep_fulfilled(solv, rd->evr);
246 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
247 return solver_splitprovides(solv, rd->evr);
248 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
249 return solver_dep_installed(solv, rd->evr);
251 FOR_PROVIDES(p, pp, dep)
253 if (solv->decisionmap[p] > 0)
260 solver_is_supplementing(Solver *solv, Solvable *s)
263 if (!s->supplements && !s->freshens)
267 supp = s->repo->idarraydata + s->supplements;
268 while ((sup = *supp++) != 0)
269 if (solver_dep_fulfilled(solv, sup))
276 supp = s->repo->idarraydata + s->freshens;
277 while ((sup = *supp++) != 0)
278 if (solver_dep_fulfilled(solv, sup))
287 solver_is_enhancing(Solver *solv, Solvable *s)
292 enhp = s->repo->idarraydata + s->enhances;
293 while ((enh = *enhp++) != 0)
294 if (solver_dep_fulfilled(solv, enh))
299 void solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps);
300 int solver_calc_installsizechange(Solver *solv);
303 solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
305 pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
308 #define FOR_RULELITERALS(l, dp, r) \
309 for (l = r->d < 0 ? -r->d - 1 : r->d, \
310 dp = !l ? &r->w2 : pool->whatprovidesdata + l, \
311 l = r->p; l; l = (dp != &r->w2 + 1 ? *dp++ : 0))
317 #endif /* SATSOLVER_SOLVER_H */