resetting valid solver run in order to get a complete solver run for the testcase
[platform/upstream/libzypp.git] / zypp / solver / detail / Resolver.h
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* Resolver.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_RESOLVER_H
23 #define ZYPP_SOLVER_DETAIL_RESOLVER_H
24
25 #include <iosfwd>
26 #include <list>
27 #include <map>
28 #include <string>
29
30 #include "zypp/base/ReferenceCounted.h"
31 #include "zypp/base/PtrTypes.h"
32
33 #include "zypp/ResPool.h"
34
35 #include "zypp/solver/detail/Types.h"
36 #include "zypp/solver/detail/ResolverQueue.h"
37 #include "zypp/solver/detail/ResolverContext.h"
38 #include "zypp/solver/detail/ContextPool.h"
39
40 #include "zypp/ProblemTypes.h"
41 #include "zypp/ResolverProblem.h"
42 #include "zypp/ProblemSolution.h"
43 #include "zypp/UpgradeStatistics.h"
44
45 #include "zypp/CapSet.h"
46
47
48 /////////////////////////////////////////////////////////////////////////
49 namespace zypp
50 { ///////////////////////////////////////////////////////////////////////
51   ///////////////////////////////////////////////////////////////////////
52   namespace solver
53   { /////////////////////////////////////////////////////////////////////
54     /////////////////////////////////////////////////////////////////////
55     namespace detail
56     { ///////////////////////////////////////////////////////////////////
57
58 ///////////////////////////////////////////////////////////////////
59 //
60 //      CLASS NAME : Resolver
61
62 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
63
64   private:
65     ResPool _pool;
66
67     unsigned _timeout_seconds;
68     unsigned _maxSolverPasses;
69     bool _verifying;
70     bool _testing;
71     
72     // In order reducing solver time we are reducing the branches
73     // by skipping resolvables which have worse architecture,edition
74     // than a resolvable which provides the same cababilities.
75     // BUT if there is no valid solution we will regard the "other"
76     // resolvables in a second solver run too.
77     bool _tryAllPossibilities; // Try ALL alternatives
78
79     // list populated by calls to addPoolItemTo*()
80     QueueItemList _initial_items;
81     PoolItemList _items_to_install;
82     PoolItemList _items_to_establish;
83     PoolItemList _items_to_remove;
84     PoolItemList _items_to_verify;
85     PoolItemList _items_to_lockUninstalled;    
86   
87     // pool of valid contexts which are "recycled" in order to fasten the solver
88     ContextPool contextPool;
89
90     // list of problematic items after doUpgrade()
91     PoolItemList _update_items;
92
93
94     CapSet _extra_caps;
95     CapSet _extra_conflicts;
96
97     //typedef std::multimap<PoolItem_Ref,Capability> IgnoreMap;
98
99     // These conflict should be ignored of the concering item
100     IgnoreMap _ignoreConflicts;
101     // These requires should be ignored of the concering item    
102     IgnoreMap _ignoreRequires;
103     // These obsoletes should be ignored of the concering item    
104     IgnoreMap _ignoreObsoletes;    
105     // Ignore architecture of the item
106     PoolItemList _ignoreArchitecture;
107     // Ignore the status "installed" of the item
108     PoolItemList _ignoreInstalledItem;
109     // Ignore the architecture of the item
110     PoolItemList _ignoreArchitectureItem;    
111     
112
113     ResolverQueueList _pending_queues;
114     ResolverQueueList _pruned_queues;
115     ResolverQueueList _complete_queues;
116     ResolverQueueList _deferred_queues;
117     ResolverQueueList _invalid_queues;
118
119     int _valid_solution_count;
120
121     ResolverContext_Ptr _best_context;
122     // Context of the last establishing call ( without any transaction )
123     ResolverContext_Ptr _establish_context;    
124     bool _timed_out;
125
126     std::set<Source_Ref> _subscribed;
127
128     Arch _architecture;
129
130     bool _forceResolve; // remove items which are conflicts with others or
131                         // have unfulfilled requirements.
132                         // This behaviour is favourited by ZMD
133     bool _upgradeMode;  // Resolver has been called with doUpgrade
134     bool _preferHighestVersion; // Prefer the result with the newest version
135                                 //if there are more solver results. 
136
137     // helpers
138     bool doesObsoleteCapability (PoolItem_Ref candidate, const Capability & cap);
139     bool doesObsoleteItem (PoolItem_Ref candidate, PoolItem_Ref installed);
140
141   public:
142
143     Resolver (const ResPool & pool);
144     virtual ~Resolver();
145
146     // ---------------------------------- I/O
147
148     virtual std::ostream & dumpOn( std::ostream & str ) const;
149     friend std::ostream& operator<<(std::ostream& str, const Resolver & obj)
150     { return obj.dumpOn (str); }
151     void dumpTaskList(const PoolItemList &install, const PoolItemList &remove );
152     
153     // ---------------------------------- accessors
154
155     QueueItemList initialItems () const { return _initial_items; }
156
157     ResolverQueueList pendingQueues () const { return _pending_queues; }
158     ResolverQueueList prunedQueues () const { return _pruned_queues; }
159     ResolverQueueList completeQueues () const { return _complete_queues; }
160     ResolverQueueList deferredQueues () const { return _deferred_queues; }
161     ResolverQueueList invalidQueues () const { return _invalid_queues; }
162
163     ResolverContext_Ptr bestContext (void) const { return _best_context; }
164
165     /** depending on the last solver result, either return bestContext()
166         of the first invalid context */
167     ResolverContext_Ptr context (void) const;
168
169     // ---------------------------------- methods
170
171     void setTimeout (int seconds) { _timeout_seconds = seconds; }
172     void setMaxSolverPasses (int count) { _maxSolverPasses = count; }
173     int timeout () { return _timeout_seconds; }
174     int maxSolverPasses () { return _maxSolverPasses; }
175
176     ResPool pool (void) const;
177     void setPool (const ResPool & pool) { _pool = pool; }
178
179     void addSubscribedSource (Source_Ref source);
180
181     void addPoolItemToInstall (PoolItem_Ref item);
182     void addPoolItemsToInstallFromList (PoolItemList & rl);
183
184     void addPoolItemToLockUninstalled (PoolItem_Ref item);
185
186     void addPoolItemToRemove (PoolItem_Ref item);
187     void addPoolItemsToRemoveFromList (PoolItemList & rl);
188
189     void addPoolItemToEstablish (PoolItem_Ref item);
190     void addPoolItemsToEstablishFromList (PoolItemList & rl);
191
192     void addPoolItemToVerify (PoolItem_Ref item);
193
194     void addExtraCapability (const Capability & capability);
195     void addExtraConflict (const Capability & capability);
196
197     void addIgnoreConflict (const PoolItem_Ref item,
198                             const Capability & capability);
199     void addIgnoreRequires (const PoolItem_Ref item,
200                             const Capability & capability);
201     void addIgnoreObsoletes (const PoolItem_Ref item,
202                              const Capability & capability);
203     void addIgnoreInstalledItem (const PoolItem_Ref item);
204     void addIgnoreArchitectureItem (const PoolItem_Ref item);    
205
206     void setForceResolve (const bool force) { _forceResolve = force; }
207     const bool forceResolve() { return _forceResolve; }
208     void setPreferHighestVersion (const bool highestVersion) { _preferHighestVersion = highestVersion; }
209     const bool preferHighestVersion() { return _preferHighestVersion; }
210
211     void setTryAllPossibilities (const bool tryAllPossibilities) { _tryAllPossibilities = tryAllPossibilities; }
212     const bool tryAllPossibilities () { return _tryAllPossibilities; };
213     
214     bool verifySystem (bool considerNewHardware = false);
215     void establishState (ResolverContext_Ptr context = NULL);
216     bool establishPool (void);
217     void freshenState( ResolverContext_Ptr context = NULL, bool resetAfterSolve = true );
218     bool freshenPool( bool resetAfterSolve = true );
219     bool resolveDependencies (const ResolverContext_Ptr context = NULL);
220     bool resolvePool( bool tryAllPossibilities = false );
221
222     bool transactResObject( ResObject::constPtr robj,
223                             bool install = true,
224                             bool recursive = false);
225     bool transactResKind( Resolvable::Kind kind );
226     void transactReset( ResStatus::TransactByValue causer );
227
228     void doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
229     PoolItemList problematicUpdateItems( void ) const { return _update_items; }
230
231
232     ResolverProblemList problems (const bool ignoreValidSolution = false) const;
233     void applySolutions (const ProblemSolutionList &solutions);
234     // returns a string list of ResolverInfo of the LAST not valid solution
235     std::list<std::string> problemDescription( void ) const;
236
237     // reset all SOLVER transaction in pool
238     void undo(void);
239
240     // only for testsuite
241     void reset (const bool resetValidResults = false);
242
243     Arch architecture() const { return _architecture; }
244     void setArchitecture( const Arch & arch) { _architecture = arch; }
245
246     bool testing(void) const { return _testing; }
247     void setTesting( bool testing ) { _testing = testing; }
248 };
249
250 ///////////////////////////////////////////////////////////////////
251     };// namespace detail
252     /////////////////////////////////////////////////////////////////////
253     /////////////////////////////////////////////////////////////////////
254   };// namespace solver
255   ///////////////////////////////////////////////////////////////////////
256   ///////////////////////////////////////////////////////////////////////
257 };// namespace zypp
258 /////////////////////////////////////////////////////////////////////////
259
260 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H