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
16 #include "pooltypes.h"
22 * Callback definitions in order to "overwrite" the policies by an external application.
25 typedef void (*BestSolvableCb) (Pool *pool, Queue *canditates);
26 typedef int (*ArchCheckCb) (Pool *pool, Solvable *solvable1, Solvable *solvable2);
27 typedef int (*VendorCheckCb) (Pool *pool, Solvable *solvable1, Solvable *solvable2);
28 typedef void (*UpdateCandidateCb) (Pool *pool, Solvable *solvable, Queue *canditates);
31 /* ----------------------------------------------
34 * providerN(B) == Package Id of package providing tag B
35 * N = 1, 2, 3, in case of multiple providers
37 * A requires B : !A | provider1(B) | provider2(B)
39 * A conflicts B : (!A | !provider1(B)) & (!A | !provider2(B)) ...
41 * 'not' is encoded as a negative Id
43 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
47 Id p; /* first literal in rule */
48 Id d; /* Id offset into 'list of providers terminated by 0' as used by whatprovides; pool->whatprovides + d */
49 /* in case of binary rules, d == 0, w1 == p, w2 == other literal */
50 Id w1, w2; /* watches, literals not-yet-decided */
51 /* if !w1, disabled */
52 /* if !w2, assertion, not rule */
53 Id n1, n2; /* next rules in linked list, corresponding to w1,w2 */
58 typedef struct solver {
62 Rule *rules; /* all rules */
63 Id nrules; /* index of the last rule */
65 Id jobrules; /* user rules */
66 Id systemrules; /* policy rules, e.g. keep packages installed or update. All literals > 0 */
67 Id weakrules; /* rules that can be autodisabled */
68 Id learntrules; /* learnt rules */
70 Id *weaksystemrules; /* please try to install (r->d) */
71 Map noupdate; /* don't try to update these
72 installed solvables */
74 Id *watches; /* Array of rule offsets
75 * watches has nsolvables*2 entries and is addressed from the middle
76 * middle-solvable : decision to conflict, offset point to linked-list of rules
77 * middle+solvable : decision to install: offset point to linked-list of rules
84 Queue decisionq_why; /* index of rule, Offset into rules */
85 int directdecisions; /* number of decisions with no rule */
87 Id *decisionmap; /* map for all available solvables, > 0: level of decision when installed, < 0 level of decision when conflict */
89 /* learnt rule history */
94 int (*solution_callback)(struct solver *solv, void *data);
95 void *solution_callback_data;
100 Queue suggestions; /* suggested packages */
102 Map recommendsmap; /* recommended packages from decisionmap */
103 Map suggestsmap; /* suggested packages from decisionmap */
104 int recommends_index; /* recommended level */
106 Id *obsoletes; /* obsoletes for each installed solvable */
107 Id *obsoletes_data; /* data area for obsoletes */
109 Queue covenantq; /* Covenants honored by this solver (generic locks) */
111 /*-------------------------------------------------------------------------------------------------------------
112 * Solver configuration
113 *-------------------------------------------------------------------------------------------------------------*/
115 int fixsystem; /* repair errors in rpm dependency graph */
116 int allowdowngrade; /* allow to downgrade installed solvable */
117 int allowarchchange; /* allow to change architecture of installed solvables */
118 int allowvendorchange; /* allow to change vendor of installed solvables */
119 int allowuninstall; /* allow removal of installed solvables */
120 int updatesystem; /* distupgrade */
121 int allowvirtualconflicts; /* false: conflicts on package name, true: conflicts on package provides */
122 int noupdateprovide; /* true: update packages needs not to provide old package */
123 int dosplitprovides; /* true: consider legacy split provides */
125 /* Callbacks for defining the bahaviour of the SAT solver */
127 /* Finding best candidate
129 * Callback definition:
130 * void bestSolvable (Pool *pool, Queue *canditates)
131 * candidates : List of canditates which has to be sorted by the function call
132 * return candidates: Sorted list of the candidates(first is the best).
134 BestSolvableCb bestSolvableCb;
136 /* Checking if two solvables has compatible architectures
138 * Callback definition:
139 * int archCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2);
141 * return 0 it the two solvables has compatible architectures
143 ArchCheckCb archCheckCb;
145 /* Checking if two solvables has compatible vendors
147 * Callback definition:
148 * int vendorCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2);
150 * return 0 it the two solvables has compatible architectures
152 VendorCheckCb vendorCheckCb;
154 /* Evaluate update candidate
156 * Callback definition:
157 * void pdateCandidateCb (Pool *pool, Solvable *solvable, Queue *canditates)
158 * solvable : for which updates should be search
159 * candidates : List of candidates (This list depends on other
160 * restrictions like architecture and vendor policies too)
162 UpdateCandidateCb updateCandidateCb;
173 SOLVER_INSTALL_SOLVABLE,
174 SOLVER_ERASE_SOLVABLE,
175 SOLVER_INSTALL_SOLVABLE_NAME,
176 SOLVER_ERASE_SOLVABLE_NAME,
177 SOLVER_INSTALL_SOLVABLE_PROVIDES,
178 SOLVER_ERASE_SOLVABLE_PROVIDES,
179 SOLVER_INSTALL_SOLVABLE_UPDATE
183 SOLVER_PROBLEM_UPDATE_RULE,
184 SOLVER_PROBLEM_JOB_RULE,
185 SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP,
186 SOLVER_PROBLEM_NOT_INSTALLABLE,
187 SOLVER_PROBLEM_NOTHING_PROVIDES_DEP,
188 SOLVER_PROBLEM_SAME_NAME,
189 SOLVER_PROBLEM_PACKAGE_CONFLICT,
190 SOLVER_PROBLEM_PACKAGE_OBSOLETES,
191 SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE
195 extern Solver *solver_create(Pool *pool, Repo *installed);
196 extern void solver_free(Solver *solv);
197 extern void solver_solve(Solver *solv, Queue *job);
198 extern int solver_dep_installed(Solver *solv, Id dep);
199 extern int solver_splitprovides(Solver *solv, Id dep);
201 extern Id solver_next_problem(Solver *solv, Id problem);
202 extern Id solver_next_solution(Solver *solv, Id problem, Id solution);
203 extern Id solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp);
204 extern Id solver_findproblemrule(Solver *solv, Id problem);
205 extern SolverProbleminfo solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp);
207 Id *create_obsoletesmap(Solver *solv);
209 /* debug functions, do not use */
210 void printdecisions(Solver *solv);
211 void printsolutions(Solver *solv, Queue *job);
215 solver_dep_fulfilled(Solver *solv, Id dep)
217 Pool *pool = solv->pool;
222 Reldep *rd = GETRELDEP(pool, dep);
223 if (rd->flags == REL_AND)
225 if (!solver_dep_fulfilled(solv, rd->name))
227 return solver_dep_fulfilled(solv, rd->evr);
229 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
230 return solver_splitprovides(solv, rd->evr);
231 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
232 return solver_dep_installed(solv, rd->evr);
234 FOR_PROVIDES(p, pp, dep)
236 if (solv->decisionmap[p] > 0)
243 solver_is_supplementing(Solver *solv, Solvable *s)
246 if (!s->supplements && !s->freshens)
250 supp = s->repo->idarraydata + s->supplements;
251 while ((sup = *supp++) != 0)
252 if (solver_dep_fulfilled(solv, sup))
259 supp = s->repo->idarraydata + s->freshens;
260 while ((sup = *supp++) != 0)
261 if (solver_dep_fulfilled(solv, sup))
270 solver_is_enhancing(Solver *solv, Solvable *s)
275 enhp = s->repo->idarraydata + s->enhances;
276 while ((enh = *enhp++) != 0)
277 if (solver_dep_fulfilled(solv, enh))
282 #endif /* SATSOLVER_SOLVER_H */