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