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 /* ----------------------------------------------
25 * providerN(B) == Package Id of package providing tag B
26 * N = 1, 2, 3, in case of multiple providers
28 * A requires B : !A | provider1(B) | provider2(B)
30 * A conflicts B : (!A | !provider1(B)) & (!A | !provider2(B)) ...
32 * 'not' is encoded as a negative Id
34 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
38 Id p; /* first literal in rule */
39 Id d; /* Id offset into 'list of providers terminated by 0' as used by whatprovides; pool->whatprovides + d */
40 /* in case of binary rules, d == 0, w1 == p, w2 == other literal */
41 Id w1, w2; /* watches, literals not-yet-decided */
42 /* if !w1, disabled */
43 /* if !w2, assertion, not rule */
44 Id n1, n2; /* next rules in linked list, corresponding to w1,w2 */
49 typedef struct solver {
53 int fixsystem; /* repair errors in rpm dependency graph */
54 int allowdowngrade; /* allow to downgrade installed solvable */
55 int allowarchchange; /* allow to change architecture of installed solvables */
56 int allowvendorchange; /* allow to change vendor of installed solvables */
57 int allowuninstall; /* allow removal of installed solvables */
58 int updatesystem; /* distupgrade */
59 int allowvirtualconflicts; /* false: conflicts on package name, true: conflicts on package provides */
60 int noupdateprovide; /* true: update packages needs not to provide old package */
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 */
117 SOLVER_INSTALL_SOLVABLE,
118 SOLVER_ERASE_SOLVABLE,
119 SOLVER_INSTALL_SOLVABLE_NAME,
120 SOLVER_ERASE_SOLVABLE_NAME,
121 SOLVER_INSTALL_SOLVABLE_PROVIDES,
122 SOLVER_ERASE_SOLVABLE_PROVIDES,
123 SOLVER_INSTALL_SOLVABLE_UPDATE
127 SOLVER_PROBLEM_UPDATE_RULE,
128 SOLVER_PROBLEM_JOB_RULE,
129 SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP,
130 SOLVER_PROBLEM_NOT_INSTALLABLE,
131 SOLVER_PROBLEM_NOTHING_PROVIDES_DEP,
132 SOLVER_PROBLEM_SAME_NAME,
133 SOLVER_PROBLEM_PACKAGE_CONFLICT,
134 SOLVER_PROBLEM_PACKAGE_OBSOLETES,
135 SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE
139 extern Solver *solver_create(Pool *pool, Repo *installed);
140 extern void solver_free(Solver *solv);
141 extern void solver_solve(Solver *solv, Queue *job);
142 extern int solver_dep_installed(Solver *solv, Id dep);
144 extern Id solver_next_problem(Solver *solv, Id problem);
145 extern Id solver_next_solution(Solver *solv, Id problem, Id solution);
146 extern Id solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp);
147 extern Id solver_findproblemrule(Solver *solv, Id problem);
148 extern SolverProbleminfo solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp);
150 Id *create_obsoletesmap(Solver *solv);
152 /* debug functions, do not use */
153 void printdecisions(Solver *solv);
154 void printsolutions(Solver *solv, Queue *job);
158 solver_dep_fulfilled(Solver *solv, Id dep)
160 Pool *pool = solv->pool;
165 Reldep *rd = GETRELDEP(pool, dep);
166 if (rd->flags == REL_AND)
168 if (!solver_dep_fulfilled(solv, rd->name))
170 return solver_dep_fulfilled(solv, rd->evr);
172 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
173 return solver_dep_installed(solv, rd->evr);
175 FOR_PROVIDES(p, pp, dep)
177 if (solv->decisionmap[p] > 0)
184 solver_is_supplementing(Solver *solv, Solvable *s)
187 if (!s->supplements && !s->freshens)
191 supp = s->repo->idarraydata + s->supplements;
192 while ((sup = *supp++) != 0)
193 if (solver_dep_fulfilled(solv, sup))
200 supp = s->repo->idarraydata + s->freshens;
201 while ((sup = *supp++) != 0)
202 if (solver_dep_fulfilled(solv, sup))
211 solver_is_enhancing(Solver *solv, Solvable *s)
216 enhp = s->repo->idarraydata + s->enhances;
217 while ((enh = *enhp++) != 0)
218 if (solver_dep_fulfilled(solv, enh))
223 #endif /* SATSOLVER_SOLVER_H */