Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / solver / detail / SATResolver.h
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* SATResolver.h
3  *
4  * Copyright (C) 2000-2002 Ximian, Inc.
5  * Copyright (C) 2005 SUSE Linux Products GmbH
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License,
9  * version 2, as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19  * 02111-1307, USA.
20  */
21
22 #ifndef ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H
23 #define ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H
24
25 extern "C"
26 {
27 #include <solv/solver.h>
28 #include <solv/pool.h>
29 }
30
31 #include <iosfwd>
32 #include <list>
33 #include <map>
34 #include <string>
35
36 #include "zypp/base/ReferenceCounted.h"
37 #include "zypp/base/PtrTypes.h"
38 #include "zypp/ResPool.h"
39 #include "zypp/base/SerialNumber.h"
40 #include "zypp/ProblemTypes.h"
41 #include "zypp/ResolverProblem.h"
42 #include "zypp/ProblemSolution.h"
43 #include "zypp/Capability.h"
44 #include "zypp/solver/detail/SolverQueueItem.h"
45
46 /////////////////////////////////////////////////////////////////////////
47 namespace zypp
48 { ///////////////////////////////////////////////////////////////////////
49
50   namespace sat
51   {
52     class Transaction;
53   }
54
55   ///////////////////////////////////////////////////////////////////////
56   namespace solver
57   { /////////////////////////////////////////////////////////////////////
58     /////////////////////////////////////////////////////////////////////
59     namespace detail
60     { ///////////////////////////////////////////////////////////////////
61
62
63 ///////////////////////////////////////////////////////////////////
64 //
65 //      CLASS NAME : SATResolver
66 /**
67  * \todo The way solver options are passed as individual booleans from Resolver
68  * via solver::detail::Resolver to SATResolver is pedestrian and error prone.
69  * Introdce a dedicated solver option structure which is passed down as a whole.
70 */
71 class SATResolver : public base::ReferenceCounted, private base::NonCopyable {
72
73   private:
74     ResPool _pool;
75     Pool *_SATPool;
76     Solver *_solv;
77     Queue _jobQueue;
78
79     // list of problematic items (orphaned)
80     PoolItemList _problem_items;
81
82     // list populated by calls to addPoolItemTo*()
83     PoolItemList _items_to_install;
84     PoolItemList _items_to_remove;
85     PoolItemList _items_to_lock;
86     PoolItemList _items_to_keep;
87
88     // solve results
89     PoolItemList _result_items_to_install;
90     PoolItemList _result_items_to_remove;
91   public:
92     bool _fixsystem:1;                  // repair errors in rpm dependency graph
93     bool _allowdowngrade:1;             // allow to downgrade installed solvable
94     bool _allowarchchange:1;            // allow to change architecture of installed solvables
95     bool _allowvendorchange:1;          // allow to change vendor of installed solvables
96     bool _allowuninstall:1;             // allow removal of installed solvables
97     bool _updatesystem:1;               // update
98     bool _noupdateprovide:1;            // true: update packages needs not to provide old package
99     bool _dosplitprovides:1;            // true: consider legacy split provides
100     bool _onlyRequires:1;               // true: consider required packages only
101     bool _ignorealreadyrecommended:1;   // true: ignore recommended packages that were already recommended by the installed packages
102     bool _distupgrade:1;
103     bool _distupgrade_removeunsupported:1;
104     bool _dup_allowdowngrade:1;         // dup mode: allow to downgrade installed solvable
105     bool _dup_allownamechange:1;        // dup mode: allow to change name of installed solvable
106     bool _dup_allowarchchange:1;        // dup mode: allow to change architecture of installed solvables
107     bool _dup_allowvendorchange:1;      // dup mode: allow to change vendor of installed solvables
108     bool _solveSrcPackages:1;           // false: generate no job rule for source packages selected in the pool
109     bool _cleandepsOnRemove:1;          // whether removing a package should also remove no longer needed requirements
110
111   private:
112     // ---------------------------------- methods
113     std::string SATprobleminfoString (Id problem, std::string &detail, Id &ignoreId);
114     void resetItemTransaction (PoolItem item);
115
116     // Create a SAT solver and reset solver selection in the pool (Collecting
117     void solverInit(const PoolItemList & weakItems);
118     // common solver run with the _jobQueue; Save results back to pool
119     bool solving(const CapabilitySet & requires_caps = CapabilitySet(),
120                  const CapabilitySet & conflict_caps = CapabilitySet());
121     // cleanup solver
122     void solverEnd();
123     // set locks for the solver
124     void setLocks();
125     // set requirements for a running system
126     void setSystemRequirements();
127
128    // Checking if this solvable/item has a buddy which reflect the real
129    // user visible description of an item
130    // e.g. The release package has a buddy to the concerning product item.
131    // This user want's the message "Product foo conflicts with product bar" and
132    // NOT "package release-foo conflicts with package release-bar"
133    // So these functions return the concerning buddy (e.g. product item)
134     sat::Solvable mapSolvable (const Id &id);
135     PoolItem mapItem (const PoolItem &item);
136
137   public:
138
139     SATResolver (const ResPool & pool, Pool *SATPool);
140     virtual ~SATResolver();
141
142     // ---------------------------------- I/O
143
144     virtual std::ostream & dumpOn( std::ostream & str ) const;
145     friend std::ostream& operator<<(std::ostream& str, const SATResolver & obj)
146     { return obj.dumpOn (str); }
147
148     ResPool pool (void) const;
149     void setPool (const ResPool & pool) { _pool = pool; }
150
151     // solver run with pool selected items
152     bool resolvePool(const CapabilitySet & requires_caps,
153                      const CapabilitySet & conflict_caps,
154                      const PoolItemList & weakItems,
155                      const std::set<Repository> & upgradeRepos
156                      );
157     // solver run with the given request queue
158     bool resolveQueue(const SolverQueueItemList &requestQueue,
159                       const PoolItemList & weakItems
160                       );
161     // searching for new packages
162     void doUpdate();
163
164     ResolverProblemList problems ();
165     void applySolutions (const ProblemSolutionList &solutions);
166
167     void addPoolItemToInstall (PoolItem item);
168     void addPoolItemsToInstallFromList (PoolItemList & rl);
169
170     void addPoolItemToLock (PoolItem item);
171     void addPoolItemToKeep (PoolItem item);
172
173     void addPoolItemToRemove (PoolItem item);
174     void addPoolItemsToRemoveFromList (PoolItemList & rl);
175
176     bool fixsystem () const {return _fixsystem;}
177     void setFixsystem ( const bool fixsystem) { _fixsystem = fixsystem;}
178
179     bool ignorealreadyrecommended () const {return _ignorealreadyrecommended;}
180     void setIgnorealreadyrecommended ( const bool ignorealreadyrecommended) { _ignorealreadyrecommended = ignorealreadyrecommended;}
181
182     bool distupgrade () const {return _distupgrade;}
183     void setDistupgrade ( const bool distupgrade) { _distupgrade = distupgrade;}
184
185     bool distupgrade_removeunsupported () const {return _distupgrade_removeunsupported;}
186     void setDistupgrade_removeunsupported ( const bool distupgrade_removeunsupported) { _distupgrade_removeunsupported = distupgrade_removeunsupported;}
187
188     bool allowdowngrade () const {return _allowdowngrade;}
189     void setAllowdowngrade ( const bool allowdowngrade) { _allowdowngrade = allowdowngrade;}
190
191     bool allowarchchange () const {return _allowarchchange;}
192     void setAllowarchchange ( const bool allowarchchange) { _allowarchchange = allowarchchange;}
193
194     bool allowvendorchange () const {return _allowvendorchange;}
195     void setAllowvendorchange ( const bool allowvendorchange) { _allowvendorchange = allowvendorchange;}
196
197     bool allowuninstall () const {return _allowuninstall;}
198     void setAllowuninstall ( const bool allowuninstall) { _allowuninstall = allowuninstall;}
199
200     bool updatesystem () const {return _updatesystem;}
201     void setUpdatesystem ( const bool updatesystem) { _updatesystem = updatesystem;}
202
203     bool noupdateprovide () const {return _noupdateprovide;}
204     void setNoupdateprovide ( const bool noupdateprovide) { _noupdateprovide = noupdateprovide;}
205
206     bool dosplitprovides () const {return _dosplitprovides;}
207     void setDosplitprovides ( const bool dosplitprovides) { _dosplitprovides = dosplitprovides;}
208
209     bool onlyRequires () const {return _onlyRequires;}
210     void setOnlyRequires ( const bool onlyRequires) { _onlyRequires = onlyRequires;}
211
212     bool solveSrcPackages() const               { return _solveSrcPackages; }
213     void setSolveSrcPackages( bool state_r )    { _solveSrcPackages = state_r; }
214
215     bool cleandepsOnRemove() const              { return _cleandepsOnRemove; }
216     void setCleandepsOnRemove( bool state_r )   { _cleandepsOnRemove = state_r; }
217
218     PoolItemList problematicUpdateItems( void ) const { return _problem_items; }
219
220     PoolItemList resultItemsToInstall () { return _result_items_to_install; }
221     PoolItemList resultItemsToRemove () { return _result_items_to_remove; }
222     PoolItemList problematicUpdateItems() { return _problem_items; }
223
224     sat::StringQueue autoInstalled() const;
225     sat::StringQueue userInstalled() const;
226 };
227
228 ///////////////////////////////////////////////////////////////////
229     };// namespace detail
230     /////////////////////////////////////////////////////////////////////
231     /////////////////////////////////////////////////////////////////////
232   };// namespace solver
233   ///////////////////////////////////////////////////////////////////////
234   ///////////////////////////////////////////////////////////////////////
235 };// namespace zypp
236 /////////////////////////////////////////////////////////////////////////
237
238 #endif // ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H