1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * Copyright (C) 2000-2002 Ximian, Inc.
5 * Copyright (C) 2005 SUSE Linux Products GmbH
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.
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.
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
22 #ifndef ZYPP_SOLVER_DETAIL_RESOLVER_H
23 #define ZYPP_SOLVER_DETAIL_RESOLVER_H
30 #include "zypp/base/ReferenceCounted.h"
31 #include "zypp/base/PtrTypes.h"
33 #include "zypp/ResPool.h"
34 #include "zypp/base/SerialNumber.h"
36 #include "zypp/solver/detail/Types.h"
37 #include "zypp/solver/detail/ResolverQueue.h"
38 #include "zypp/solver/detail/ResolverContext.h"
39 #include "zypp/solver/detail/ContextPool.h"
41 #include "zypp/ProblemTypes.h"
42 #include "zypp/ResolverProblem.h"
43 #include "zypp/ProblemSolution.h"
44 #include "zypp/UpgradeStatistics.h"
46 #include "zypp/CapSet.h"
49 /////////////////////////////////////////////////////////////////////////
51 { ///////////////////////////////////////////////////////////////////////
52 ///////////////////////////////////////////////////////////////////////
54 { /////////////////////////////////////////////////////////////////////
55 /////////////////////////////////////////////////////////////////////
57 { ///////////////////////////////////////////////////////////////////
59 ///////////////////////////////////////////////////////////////////
61 // CLASS NAME : ItemCapKind
67 Capability cap; //Capability which has triggerd this selection
68 Dep capKind; //Kind of that capability
69 PoolItem_Ref item; //Item which has triggered this selection
70 bool initialInstallation; //This item has triggered the installation
71 //Not already fullfilled requierement only.
73 ItemCapKind() : capKind("FRESHENS") {}
74 ItemCapKind( PoolItem i, Capability c, Dep k, bool initial)
78 , initialInstallation( initial )
81 typedef std::multimap<PoolItem_Ref,ItemCapKind> ItemCapKindMap;
82 typedef std::list<ItemCapKind> ItemCapKindList;
84 ///////////////////////////////////////////////////////////////////
86 // CLASS NAME : Resolver
88 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
92 SerialNumberWatcher _poolchanged;
94 unsigned _timeout_seconds;
95 unsigned _maxSolverPasses;
99 // In order reducing solver time we are reducing the branches
100 // by skipping resolvables which have worse architecture,edition
101 // than a resolvable which provides the same cababilities.
102 // BUT if there is no valid solution we will regard the "other"
103 // resolvables in a second solver run too.
104 bool _tryAllPossibilities; // Try ALL alternatives
106 // list populated by calls to addPoolItemTo*()
107 QueueItemList _initial_items;
108 PoolItemList _items_to_install;
109 PoolItemList _items_to_establish;
110 PoolItemList _items_to_remove;
111 PoolItemList _items_to_verify;
112 PoolItemList _items_to_lockUninstalled;
113 PoolItemList _items_to_keep;
115 // pool of valid contexts which are "recycled" in order to fasten the solver
116 ContextPool contextPool;
118 // list of problematic items after doUpgrade()
119 PoolItemList _update_items;
121 // Additional information about the solverrun
122 ItemCapKindMap _isInstalledBy;
123 ItemCapKindMap _installs;
126 CapSet _extra_conflicts;
128 //typedef std::multimap<PoolItem_Ref,Capability> IgnoreMap;
130 // These conflict should be ignored of the concering item
131 IgnoreMap _ignoreConflicts;
132 // These requires should be ignored of the concering item
133 IgnoreMap _ignoreRequires;
134 // These obsoletes should be ignored of the concering item
135 IgnoreMap _ignoreObsoletes;
136 // Ignore architecture of the item
137 PoolItemList _ignoreArchitecture;
138 // Ignore the status "installed" of the item
139 PoolItemList _ignoreInstalledItem;
140 // Ignore the architecture of the item
141 PoolItemList _ignoreArchitectureItem;
142 // Ignore the vendor of the item
143 PoolItemList _ignoreVendorItem;
145 ResolverQueueList _pending_queues;
146 ResolverQueueList _pruned_queues;
147 ResolverQueueList _complete_queues;
148 ResolverQueueList _deferred_queues;
149 ResolverQueueList _invalid_queues;
151 int _valid_solution_count;
153 ResolverContext_Ptr _best_context;
154 // Context of the last establishing call ( without any transaction )
155 ResolverContext_Ptr _establish_context;
158 std::set<Repository> _subscribed;
162 bool _forceResolve; // remove items which are conflicts with others or
163 // have unfulfilled requirements.
164 // This behaviour is favourited by ZMD
165 bool _upgradeMode; // Resolver has been called with doUpgrade
166 bool _preferHighestVersion; // Prefer the result with the newest version
167 //if there are more solver results.
170 bool doesObsoleteCapability (PoolItem_Ref candidate, const Capability & cap);
171 bool doesObsoleteItem (PoolItem_Ref candidate, PoolItem_Ref installed);
173 void collectResolverInfo (void);
178 Resolver (const ResPool & pool);
181 // ---------------------------------- I/O
183 virtual std::ostream & dumpOn( std::ostream & str ) const;
184 friend std::ostream& operator<<(std::ostream& str, const Resolver & obj)
185 { return obj.dumpOn (str); }
186 void dumpTaskList(const PoolItemList &install, const PoolItemList &remove );
188 // ---------------------------------- accessors
190 QueueItemList initialItems () const { return _initial_items; }
192 ResolverQueueList pendingQueues () const { return _pending_queues; }
193 ResolverQueueList prunedQueues () const { return _pruned_queues; }
194 ResolverQueueList completeQueues () const { return _complete_queues; }
195 ResolverQueueList deferredQueues () const { return _deferred_queues; }
196 ResolverQueueList invalidQueues () const { return _invalid_queues; }
198 ResolverContext_Ptr bestContext (void) const { return _best_context; }
200 /** depending on the last solver result, either return bestContext()
201 of the first invalid context */
202 ResolverContext_Ptr context (void) const;
204 // ---------------------------------- methods
206 void setTimeout (int seconds) { _timeout_seconds = seconds; }
207 void setMaxSolverPasses (int count) { _maxSolverPasses = count; }
208 int timeout () const { return _timeout_seconds; }
209 int maxSolverPasses () const { return _maxSolverPasses; }
211 ResPool pool (void) const;
212 void setPool (const ResPool & pool) { _pool = pool; }
214 void addSubscribedSource (Repository source);
216 void addPoolItemToInstall (PoolItem_Ref item);
217 void addPoolItemsToInstallFromList (PoolItemList & rl);
219 void addPoolItemToLockUninstalled (PoolItem_Ref item);
220 void addPoolItemToKepp (PoolItem_Ref item);
222 void addPoolItemToRemove (PoolItem_Ref item);
223 void addPoolItemsToRemoveFromList (PoolItemList & rl);
225 void addPoolItemToEstablish (PoolItem_Ref item);
226 void addPoolItemsToEstablishFromList (PoolItemList & rl);
228 void addPoolItemToVerify (PoolItem_Ref item);
230 void addExtraCapability (const Capability & capability);
231 void removeExtraCapability (const Capability & capability);
232 void addExtraConflict (const Capability & capability);
234 const CapSet extraCapability () { return _extra_caps; }
235 const CapSet extraConflicts () { return _extra_conflicts; }
237 void addIgnoreConflict (const PoolItem_Ref item,
238 const Capability & capability);
239 void addIgnoreRequires (const PoolItem_Ref item,
240 const Capability & capability);
241 void addIgnoreObsoletes (const PoolItem_Ref item,
242 const Capability & capability);
243 void addIgnoreInstalledItem (const PoolItem_Ref item);
244 void addIgnoreArchitectureItem (const PoolItem_Ref item);
245 void addIgnoreVendorItem (const PoolItem_Ref item);
247 void setForceResolve (const bool force) { _forceResolve = force; }
248 bool forceResolve() { return _forceResolve; }
249 void setPreferHighestVersion (const bool highestVersion) { _preferHighestVersion = highestVersion; }
250 bool preferHighestVersion() { return _preferHighestVersion; }
252 void setTryAllPossibilities (const bool tryAllPossibilities) { _tryAllPossibilities = tryAllPossibilities; }
253 bool tryAllPossibilities () const { return _tryAllPossibilities; };
255 bool verifySystem (bool considerNewHardware = false);
256 void establishState (ResolverContext_Ptr context = NULL);
257 bool establishPool (void);
258 void freshenState( ResolverContext_Ptr context = NULL, bool resetAfterSolve = true );
259 bool freshenPool( bool resetAfterSolve = true );
260 bool resolveDependencies (const ResolverContext_Ptr context = NULL);
261 bool resolvePool( bool tryAllPossibilities = false);
263 bool transactResObject( ResObject::constPtr robj,
265 bool recursive = false);
266 bool transactResKind( Resolvable::Kind kind );
267 void transactReset( ResStatus::TransactByValue causer );
269 void doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
270 PoolItemList problematicUpdateItems( void ) const { return _update_items; }
273 ResolverProblemList problems (const bool ignoreValidSolution = false) const;
274 void applySolutions (const ProblemSolutionList &solutions);
275 // returns a string list of ResolverInfo of the LAST not valid solution
276 std::list<std::string> problemDescription( void ) const;
278 // reset all SOLVER transaction in pool
281 // Get more information about the solverrun
282 // Which item will be installed by another item or triggers an item for
284 const ItemCapKindList isInstalledBy (const PoolItem_Ref item);
285 const ItemCapKindList installs (const PoolItem_Ref item);
287 void reset (bool resetValidResults = false, bool keepExtras = false );
289 Arch architecture() const { return _architecture; }
290 void setArchitecture( const Arch & arch) { _architecture = arch; }
292 bool testing(void) const { return _testing; }
293 void setTesting( bool testing ) { _testing = testing; }
296 ///////////////////////////////////////////////////////////////////
297 };// namespace detail
298 /////////////////////////////////////////////////////////////////////
299 /////////////////////////////////////////////////////////////////////
300 };// namespace solver
301 ///////////////////////////////////////////////////////////////////////
302 ///////////////////////////////////////////////////////////////////////
304 /////////////////////////////////////////////////////////////////////////
306 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H