cc37e118cd640dced09084bdd67b929b4b2c44e2
[platform/upstream/libsolv.git] / src / solver_private.h
1 /*
2  * Copyright (c) 2011, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * solver_p.h - private functions
10  *
11  */
12
13 #ifndef LIBSOLV_SOLVER_P_H
14 #define LIBSOLV_SOLVER_P_H
15
16 #if 0
17 struct _Solver {
18   Pool *pool;                           /* back pointer to pool */
19   Queue job;                            /* copy of the job we're solving */
20
21   Transaction trans;                    /* calculated transaction */
22
23   Repo *installed;                      /* copy of pool->installed */
24   
25   /* list of rules, ordered
26    * rpm rules first, then features, updates, jobs, learnt
27    * see start/end offsets below
28    */
29   Rule *rules;                          /* all rules */
30   Id nrules;                            /* [Offset] index of the last rule */
31
32   Queue ruleassertions;                 /* Queue of all assertion rules */
33
34   /* start/end offset for rule 'areas' */
35     
36   Id rpmrules_end;                      /* [Offset] rpm rules end */
37     
38   Id featurerules;                      /* feature rules start/end */
39   Id featurerules_end;
40     
41   Id updaterules;                       /* policy rules, e.g. keep packages installed or update. All literals > 0 */
42   Id updaterules_end;
43     
44   Id jobrules;                          /* user rules */
45   Id jobrules_end;
46
47   Id infarchrules;                      /* inferior arch rules */
48   Id infarchrules_end;
49
50   Id duprules;                          /* dist upgrade rules */
51   Id duprules_end;
52     
53   Id choicerules;                       /* choice rules (always weak) */
54   Id choicerules_end;
55   Id *choicerules_ref;
56
57   Id learntrules;                       /* learnt rules, (end == nrules) */
58
59   Map noupdate;                         /* don't try to update these
60                                            installed solvables */
61   Map noobsoletes;                      /* ignore obsoletes for these (multiinstall) */
62
63   Map updatemap;                        /* bring these installed packages to the newest version */
64   int updatemap_all;                    /* bring all packages to the newest version */
65
66   Map fixmap;                           /* fix these packages */
67   int fixmap_all;                       /* fix all packages */
68
69   Queue weakruleq;                      /* index into 'rules' for weak ones */
70   Map weakrulemap;                      /* map rule# to '1' for weak rules, 1..learntrules */
71
72   Id *watches;                          /* Array of rule offsets
73                                          * watches has nsolvables*2 entries and is addressed from the middle
74                                          * middle-solvable : decision to conflict, offset point to linked-list of rules
75                                          * middle+solvable : decision to install: offset point to linked-list of rules
76                                          */
77
78   Queue ruletojob;                      /* index into job queue: jobs for which a rule exits */
79
80   /* our decisions: */
81   Queue decisionq;                      /* >0:install, <0:remove/conflict */
82   Queue decisionq_why;                  /* index of rule, Offset into rules */
83
84   Id *decisionmap;                      /* map for all available solvables,
85                                          * = 0: undecided
86                                          * > 0: level of decision when installed,
87                                          * < 0: level of decision when conflict */
88
89   int decisioncnt_update;
90   int decisioncnt_keep;
91   int decisioncnt_resolve;
92   int decisioncnt_weak;
93   int decisioncnt_orphan;
94
95   /* learnt rule history */
96   Queue learnt_why;
97   Queue learnt_pool;
98
99   Queue branches;
100   int (*solution_callback)(struct _Solver *solv, void *data);
101   void *solution_callback_data;
102
103   int propagate_index;                  /* index into decisionq for non-propagated decisions */
104
105   Queue problems;                       /* list of lists of conflicting rules, < 0 for job rules */
106   Queue solutions;                      /* refined problem storage space */
107
108   Queue recommendations;                /* recommended packages */
109   Queue suggestions;                    /* suggested packages */
110   Queue orphaned;                       /* orphaned packages */
111
112   int stats_learned;                    /* statistic */
113   int stats_unsolvable;                 /* statistic */
114
115   Map recommendsmap;                    /* recommended packages from decisionmap */
116   Map suggestsmap;                      /* suggested packages from decisionmap */
117   int recommends_index;                 /* recommendsmap/suggestsmap is created up to this level */
118
119   Id *obsoletes;                        /* obsoletes for each installed solvable */
120   Id *obsoletes_data;                   /* data area for obsoletes */
121   Id *multiversionupdaters;             /* updaters for multiversion packages in updatesystem mode */
122
123   /*-------------------------------------------------------------------------------------------------------------
124    * Solver configuration
125    *-------------------------------------------------------------------------------------------------------------*/
126
127   int fixsystem;                        /* repair errors in rpm dependency graph */
128   int allowdowngrade;                   /* allow to downgrade installed solvable */
129   int allowarchchange;                  /* allow to change architecture of installed solvables */
130   int allowvendorchange;                /* allow to change vendor of installed solvables */
131   int allowuninstall;                   /* allow removal of installed solvables */
132   int updatesystem;                     /* update all packages to the newest version */
133   int noupdateprovide;                  /* true: update packages needs not to provide old package */
134   int dosplitprovides;                  /* true: consider legacy split provides */
135   int dontinstallrecommended;           /* true: do not install recommended packages */
136   int ignorealreadyrecommended;         /* true: ignore recommended packages that were already recommended by the installed packages */
137   int dontshowinstalledrecommended;     /* true: do not show recommended packages that are already installed */
138   
139   /* distupgrade also needs updatesystem and dosplitprovides */
140   int distupgrade;
141   int distupgrade_removeunsupported;
142
143   int noinfarchcheck;                   /* true: do not forbid inferior architectures */
144
145   /* Callbacks for defining the bahaviour of the SAT solver */
146
147   /* Finding best candidate
148    *
149    * Callback definition:
150    * void  bestSolvable (Pool *pool, Queue *canditates)
151    *     candidates       : List of canditates which has to be sorted by the function call
152    *     return candidates: Sorted list of the candidates(first is the best).
153    */
154   BestSolvableCb bestSolvableCb;
155
156   /* Checking if two solvables has compatible architectures
157    *
158    * Callback definition:
159    *     int  archCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2);
160    *     
161    *     return 0 it the two solvables has compatible architectures
162    */
163   ArchCheckCb archCheckCb;
164
165   /* Checking if two solvables has compatible vendors
166    *
167    * Callback definition:
168    *     int  vendorCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2);
169    *     
170    *     return 0 it the two solvables has compatible architectures
171    */
172   VendorCheckCb vendorCheckCb;
173     
174   /* Evaluate update candidate
175    *
176    * Callback definition:
177    * void pdateCandidateCb (Pool *pool, Solvable *solvable, Queue *canditates)
178    *     solvable   : for which updates should be search
179    *     candidates : List of candidates (This list depends on other
180    *                  restrictions like architecture and vendor policies too)
181    */
182   UpdateCandidateCb   updateCandidateCb;
183     
184   Map dupmap;                           /* dup these packages*/
185   int dupmap_all;                       /* dup all packages */
186   Map dupinvolvedmap;                   /* packages involved in dup process */
187
188   Map droporphanedmap;                  /* packages to drop in dup mode */
189   int droporphanedmap_all;
190
191   Map cleandepsmap;                     /* try to drop these packages as of cleandeps erases */
192
193   Queue *ruleinfoq;                     /* tmp space for solver_ruleinfo() */
194 };
195 #endif
196
197 extern void solver_run_sat(Solver *solv, int disablerules, int doweak);
198 extern void solver_reset(Solver *solv);
199
200 extern int solver_dep_installed(Solver *solv, Id dep);
201 extern int solver_splitprovides(Solver *solv, Id dep);
202
203 static inline int
204 solver_dep_fulfilled(Solver *solv, Id dep)
205 {
206   Pool *pool = solv->pool;
207   Id p, pp;
208
209   if (ISRELDEP(dep))
210     {
211       Reldep *rd = GETRELDEP(pool, dep);
212       if (rd->flags == REL_AND)
213         {
214           if (!solver_dep_fulfilled(solv, rd->name))
215             return 0;
216           return solver_dep_fulfilled(solv, rd->evr);
217         }
218       if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
219         return solver_splitprovides(solv, rd->evr);
220       if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
221         return solver_dep_installed(solv, rd->evr);
222     }
223   FOR_PROVIDES(p, pp, dep)
224     {
225       if (solv->decisionmap[p] > 0)
226         return 1;
227     }
228   return 0;
229 }
230
231 static inline int
232 solver_is_supplementing(Solver *solv, Solvable *s)
233 {
234   Id sup, *supp;
235   if (!s->supplements)
236     return 0;
237   supp = s->repo->idarraydata + s->supplements;
238   while ((sup = *supp++) != 0)
239     if (solver_dep_fulfilled(solv, sup))
240       return 1;
241   return 0;
242 }
243
244 static inline int
245 solver_is_enhancing(Solver *solv, Solvable *s)
246 {
247   Id enh, *enhp;
248   if (!s->enhances)
249     return 0;
250   enhp = s->repo->idarraydata + s->enhances;
251   while ((enh = *enhp++) != 0)
252     if (solver_dep_fulfilled(solv, enh))
253       return 1;
254   return 0;
255 }
256
257 #endif /* LIBSOLV_SOLVER_P_H */