refine_suggestion
[platform/upstream/libsolv.git] / src / solver.h
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * solver.h
10  *
11  */
12
13 #ifndef SOLVER_H
14 #define SOLVER_H
15
16 #include "pooltypes.h"
17 #include "pool.h"
18 #include "repo.h"
19 #include "queue.h"
20 #include "bitmap.h"
21
22 /* ----------------------------------------------
23  * Rule
24  *
25  *   providerN(B) == Package Id of package providing tag B
26  *   N = 1, 2, 3, in case of multiple providers
27  *
28  * A requires B : !A | provider1(B) | provider2(B)
29  *
30  * A conflicts B : (!A | !provider1(B)) & (!A | !provider2(B)) ...
31  *
32  * 'not' is encoded as a negative Id
33  * 
34  * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
35  */
36
37 typedef struct rule {
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 */
45 } Rule;
46
47 struct solver;
48
49 typedef struct solver {
50   Pool *pool;
51   Repo *installed;
52
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 */
61   
62   Rule *rules;                          /* all rules */
63   Id nrules;                            /* rpm rules */
64
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 */
69
70   Id *weaksystemrules;                  /* please try to install (r->d) */
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;
79
80   /* our decisions: */
81   Queue decisionq;
82   Queue decisionq_why;                  /* index of rule, Offset into rules */
83   Id *decisionmap;                      /* map for all available solvables, > 0: level of decision when installed, < 0 level of decision when conflict */
84
85   /* learnt rule history */
86   Queue learnt_why;
87   Queue learnt_pool;
88
89   Queue branches;
90   int (*solution_callback)(struct solver *solv, void *data);
91   void *solution_callback_data;
92
93   int propagate_index;
94
95   Queue problems;
96   Queue suggestions;                    /* suggested packages */
97
98   Map recommendsmap;                    /* recommended packages from decisionmap */
99   Map suggestsmap;                      /* suggested packages from decisionmap */
100   int recommends_index;                 /* recommended level */
101
102   Id *obsoletes;                        /* obsoletes for each installed solvable */
103   Id *obsoletes_data;                   /* data area for obsoletes */
104
105   int rc_output;                        /* output result compatible to redcarpet/zypp testsuite, set == 2 for pure rc (will suppress architecture) */
106 } Solver;
107
108 /*
109  * queue commands
110  */
111
112 enum solvcmds {
113   SOLVCMD_NULL=0,
114   SOLVER_INSTALL_SOLVABLE,
115   SOLVER_ERASE_SOLVABLE,
116   SOLVER_INSTALL_SOLVABLE_NAME,
117   SOLVER_ERASE_SOLVABLE_NAME,
118   SOLVER_INSTALL_SOLVABLE_PROVIDES,
119   SOLVER_ERASE_SOLVABLE_PROVIDES,
120   SOLVER_INSTALL_SOLVABLE_UPDATE
121 } SolverCmd;
122
123 extern Solver *solver_create(Pool *pool, Repo *installed);
124 extern void solver_free(Solver *solv);
125 extern void solve(Solver *solv, Queue *job);
126
127 extern void prune_best_version_arch(Pool *pool, Queue *plist);
128
129 void printdecisions(Solver *solv);
130
131 void refine_suggestion(Solver *solv, Id *problem, Id sug, Queue *refined);
132 int archchanges(Pool *pool, Solvable *s1, Solvable *s2);
133
134 #endif /* SOLVER_H */