- do a better job at presenting a solution
[platform/upstream/libsolv.git] / src / solver.h
1 /*
2  * solver.h
3  *
4  */
5
6 #ifndef SOLVER_H
7 #define SOLVER_H
8
9 #include "pooltypes.h"
10 #include "pool.h"
11 #include "source.h"
12 #include "queue.h"
13 #include "bitmap.h"
14
15 /* ----------------------------------------------
16  * Rule
17  *
18  *   providerN(B) == Package Id of package providing tag B
19  *   N = 1, 2, 3, in case of multiple providers
20  *
21  * A requires B : !A | provider1(B) | provider2(B)
22  *
23  * A conflicts B : (!A | !provider1(B)) & (!A | !provider2(B)) ...
24  *
25  * 'not' is encoded as a negative Id
26  * 
27  * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
28  */
29
30 typedef struct rule {
31   Id p;                 /* first literal in rule */
32   Id d;                 /* Id offset into 'list of providers terminated by 0' as used by whatprovides; pool->whatprovides + d */
33                         /* in case of binary rules, d == 0, w1 == p, w2 == other literal */
34   Id w1, w2;            /* watches, literals not-yet-decided */
35                                        /* if !w1, disabled */
36                                        /* if !w2, assertion, not rule */
37   Id n1, n2;            /* next rules in linked list, corresponding to w1,w2 */
38 } Rule;
39
40 typedef struct solver {
41   Pool *pool;
42   Source *system;
43
44   int fixsystem;                        /* repair errors in rpm dependency graph */
45   int allowdowngrade;                   /* allow to downgrade installed solvable */
46   int allowarchchange;                  /* allow to change architecture of installed solvables */
47   int allowuninstall;                   /* allow removal of system solvables, else keep all installed solvables */
48   int updatesystem;                     /* distupgrade */
49   int allowvirtualconflicts;            /* false: conflicts on package name, true: conflicts on package provides */
50   int noupdateprovide;                  /* true: update packages needs not to provide old package */
51   
52   Rule *rules;                          /* all rules */
53   Id nrules;                            /* rpm rules */
54
55   Id jobrules;                          /* user rules */
56   Id systemrules;                       /* policy rules, e.g. keep packages installed or update. All literals > 0 */
57   Id weakrules;                         /* rules that can be autodisabled */
58   Id learntrules;                       /* learnt rules */
59
60   Id *weaksystemrules;                  /* please try to install (r->d) */
61
62   Id *watches;                          /* Array of rule offsets
63                                          * watches has nsolvables*2 entries and is addressed from the middle
64                                          * middle-solvable : decision to conflict, offset point to linked-list of rules
65                                          * middle+solvable : decision to install: offset point to linked-list of rules
66                                          */
67
68   Queue ruletojob;
69
70   /* our decisions: */
71   Queue decisionq;
72   Queue decisionq_why;                  /* index of rule, Offset into rules */
73   Id *decisionmap;                      /* map for all available solvables, > 0: level of decision when installed, < 0 level of decision when conflict */
74
75   /* learnt rule history */
76   Queue learnt_why;
77   Queue learnt_pool;
78
79   int propagate_index;
80
81   Queue problems;
82   Queue suggestions;                    /* suggested packages */
83
84   Map recommendsmap;                    /* recommended packages from decisionmap */
85   Map suggestsmap;                      /* suggested packages from decisionmap */
86   int recommends_index;                 /* recommended level */
87
88   Id *obsoletes;                        /* obsoletes for each system solvable */
89   Id *obsoletes_data;                   /* data area for obsoletes */
90
91   int rc_output;                        /* output result compatible to redcarpet/zypp testsuite, set == 2 for pure rc (will suppress architecture) */
92 } Solver;
93
94 /*
95  * queue commands
96  */
97
98 enum solvcmds {
99   SOLVCMD_NULL=0,
100   SOLVER_INSTALL_SOLVABLE,
101   SOLVER_ERASE_SOLVABLE,
102   SOLVER_INSTALL_SOLVABLE_NAME,
103   SOLVER_ERASE_SOLVABLE_NAME,
104   SOLVER_INSTALL_SOLVABLE_PROVIDES,
105   SOLVER_ERASE_SOLVABLE_PROVIDES,
106   SOLVER_INSTALL_SOLVABLE_UPDATE
107 };
108
109 extern Solver *solver_create(Pool *pool, Source *system);
110 extern void solver_free(Solver *solv);
111 extern void solve(Solver *solv, Queue *job);
112
113 extern void prune_best_version_arch(Pool *pool, Queue *plist);
114
115 void printdecisions(Solver *solv);
116
117
118 #endif /* SOLVER_H */