- remove obsolete interface, add decisioncnt_{weak,orphan}
[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_weak;
90   int decisioncnt_orphan;
91
92   /* learnt rule history */
93   Queue learnt_why;
94   Queue learnt_pool;
95
96   Queue branches;
97   int (*solution_callback)(struct _Solver *solv, void *data);
98   void *solution_callback_data;
99
100   int propagate_index;                  /* index into decisionq for non-propagated decisions */
101
102   Queue problems;                       /* list of lists of conflicting rules, < 0 for job rules */
103   Queue solutions;                      /* refined problem storage space */
104
105   Queue recommendations;                /* recommended packages */
106   Queue suggestions;                    /* suggested packages */
107   Queue orphaned;                       /* orphaned packages */
108
109   int stats_learned;                    /* statistic */
110   int stats_unsolvable;                 /* statistic */
111
112   Map recommendsmap;                    /* recommended packages from decisionmap */
113   Map suggestsmap;                      /* suggested packages from decisionmap */
114   int recommends_index;                 /* recommendsmap/suggestsmap is created up to this level */
115
116   Id *obsoletes;                        /* obsoletes for each installed solvable */
117   Id *obsoletes_data;                   /* data area for obsoletes */
118   Id *multiversionupdaters;             /* updaters for multiversion packages in updatesystem mode */
119
120   /*-------------------------------------------------------------------------------------------------------------
121    * Solver configuration
122    *-------------------------------------------------------------------------------------------------------------*/
123
124   int fixsystem;                        /* repair errors in rpm dependency graph */
125   int allowdowngrade;                   /* allow to downgrade installed solvable */
126   int allowarchchange;                  /* allow to change architecture of installed solvables */
127   int allowvendorchange;                /* allow to change vendor of installed solvables */
128   int allowuninstall;                   /* allow removal of installed solvables */
129   int updatesystem;                     /* update all packages to the newest version */
130   int noupdateprovide;                  /* true: update packages needs not to provide old package */
131   int dosplitprovides;                  /* true: consider legacy split provides */
132   int dontinstallrecommended;           /* true: do not install recommended packages */
133   int ignorealreadyrecommended;         /* true: ignore recommended packages that were already recommended by the installed packages */
134   int dontshowinstalledrecommended;     /* true: do not show recommended packages that are already installed */
135   
136   /* distupgrade also needs updatesystem and dosplitprovides */
137   int distupgrade;
138   int distupgrade_removeunsupported;
139
140   int noinfarchcheck;                   /* true: do not forbid inferior architectures */
141
142   /* Callbacks for defining the bahaviour of the SAT solver */
143
144   /* Finding best candidate
145    *
146    * Callback definition:
147    * void  bestSolvable (Pool *pool, Queue *canditates)
148    *     candidates       : List of canditates which has to be sorted by the function call
149    *     return candidates: Sorted list of the candidates(first is the best).
150    */
151   BestSolvableCb bestSolvableCb;
152
153   /* Checking if two solvables has compatible architectures
154    *
155    * Callback definition:
156    *     int  archCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2);
157    *     
158    *     return 0 it the two solvables has compatible architectures
159    */
160   ArchCheckCb archCheckCb;
161
162   /* Checking if two solvables has compatible vendors
163    *
164    * Callback definition:
165    *     int  vendorCheck (Pool *pool, Solvable *solvable1, Solvable *solvable2);
166    *     
167    *     return 0 it the two solvables has compatible architectures
168    */
169   VendorCheckCb vendorCheckCb;
170     
171   /* Evaluate update candidate
172    *
173    * Callback definition:
174    * void pdateCandidateCb (Pool *pool, Solvable *solvable, Queue *canditates)
175    *     solvable   : for which updates should be search
176    *     candidates : List of candidates (This list depends on other
177    *                  restrictions like architecture and vendor policies too)
178    */
179   UpdateCandidateCb   updateCandidateCb;
180     
181   Map dupmap;                           /* dup these packages*/
182   int dupmap_all;                       /* dup all packages */
183   Map dupinvolvedmap;                   /* packages involved in dup process */
184
185   Map droporphanedmap;                  /* packages to drop in dup mode */
186   int droporphanedmap_all;
187
188   Map cleandepsmap;                     /* try to drop these packages as of cleandeps erases */
189
190   Queue *ruleinfoq;                     /* tmp space for solver_ruleinfo() */
191 };
192 #endif
193
194 extern void solver_run_sat(Solver *solv, int disablerules, int doweak);
195 extern void solver_reset(Solver *solv);
196
197 extern int solver_dep_installed(Solver *solv, Id dep);
198 extern int solver_splitprovides(Solver *solv, Id dep);
199
200 static inline int
201 solver_dep_fulfilled(Solver *solv, Id dep)
202 {
203   Pool *pool = solv->pool;
204   Id p, pp;
205
206   if (ISRELDEP(dep))
207     {
208       Reldep *rd = GETRELDEP(pool, dep);
209       if (rd->flags == REL_AND)
210         {
211           if (!solver_dep_fulfilled(solv, rd->name))
212             return 0;
213           return solver_dep_fulfilled(solv, rd->evr);
214         }
215       if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
216         return solver_splitprovides(solv, rd->evr);
217       if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
218         return solver_dep_installed(solv, rd->evr);
219     }
220   FOR_PROVIDES(p, pp, dep)
221     {
222       if (solv->decisionmap[p] > 0)
223         return 1;
224     }
225   return 0;
226 }
227
228 static inline int
229 solver_is_supplementing(Solver *solv, Solvable *s)
230 {
231   Id sup, *supp;
232   if (!s->supplements)
233     return 0;
234   supp = s->repo->idarraydata + s->supplements;
235   while ((sup = *supp++) != 0)
236     if (solver_dep_fulfilled(solv, sup))
237       return 1;
238   return 0;
239 }
240
241 static inline int
242 solver_is_enhancing(Solver *solv, Solvable *s)
243 {
244   Id enh, *enhp;
245   if (!s->enhances)
246     return 0;
247   enhp = s->repo->idarraydata + s->enhances;
248   while ((enh = *enhp++) != 0)
249     if (solver_dep_fulfilled(solv, enh))
250       return 1;
251   return 0;
252 }
253
254 #endif /* LIBSOLV_SOLVER_P_H */