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( PoolItem i, Capability c, Dep k, bool initial)
77 , initialInstallation( initial )
80 typedef std::multimap<PoolItem_Ref,ItemCapKind> ItemCapKindMap;
81 typedef std::list<ItemCapKind> ItemCapKindList;
83 ///////////////////////////////////////////////////////////////////
85 // CLASS NAME : Resolver
87 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
91 SerialNumberWatcher _poolchanged;
93 unsigned _timeout_seconds;
94 unsigned _maxSolverPasses;
98 // In order reducing solver time we are reducing the branches
99 // by skipping resolvables which have worse architecture,edition
100 // than a resolvable which provides the same cababilities.
101 // BUT if there is no valid solution we will regard the "other"
102 // resolvables in a second solver run too.
103 bool _tryAllPossibilities; // Try ALL alternatives
105 // list populated by calls to addPoolItemTo*()
106 QueueItemList _initial_items;
107 PoolItemList _items_to_install;
108 PoolItemList _items_to_establish;
109 PoolItemList _items_to_remove;
110 PoolItemList _items_to_verify;
111 PoolItemList _items_to_lockUninstalled;
113 // pool of valid contexts which are "recycled" in order to fasten the solver
114 ContextPool contextPool;
116 // list of problematic items after doUpgrade()
117 PoolItemList _update_items;
119 // Additional information about the solverrun
120 ItemCapKindMap _isInstalledBy;
121 ItemCapKindMap _installs;
124 CapSet _extra_conflicts;
126 //typedef std::multimap<PoolItem_Ref,Capability> IgnoreMap;
128 // These conflict should be ignored of the concering item
129 IgnoreMap _ignoreConflicts;
130 // These requires should be ignored of the concering item
131 IgnoreMap _ignoreRequires;
132 // These obsoletes should be ignored of the concering item
133 IgnoreMap _ignoreObsoletes;
134 // Ignore architecture of the item
135 PoolItemList _ignoreArchitecture;
136 // Ignore the status "installed" of the item
137 PoolItemList _ignoreInstalledItem;
138 // Ignore the architecture of the item
139 PoolItemList _ignoreArchitectureItem;
140 // Ignore the vendor of the item
141 PoolItemList _ignoreVendorItem;
143 ResolverQueueList _pending_queues;
144 ResolverQueueList _pruned_queues;
145 ResolverQueueList _complete_queues;
146 ResolverQueueList _deferred_queues;
147 ResolverQueueList _invalid_queues;
149 int _valid_solution_count;
151 ResolverContext_Ptr _best_context;
152 // Context of the last establishing call ( without any transaction )
153 ResolverContext_Ptr _establish_context;
156 std::set<Repository> _subscribed;
160 bool _forceResolve; // remove items which are conflicts with others or
161 // have unfulfilled requirements.
162 // This behaviour is favourited by ZMD
163 bool _upgradeMode; // Resolver has been called with doUpgrade
164 bool _preferHighestVersion; // Prefer the result with the newest version
165 //if there are more solver results.
168 bool doesObsoleteCapability (PoolItem_Ref candidate, const Capability & cap);
169 bool doesObsoleteItem (PoolItem_Ref candidate, PoolItem_Ref installed);
171 void collectResolverInfo (void);
176 Resolver (const ResPool & pool);
179 // ---------------------------------- I/O
181 virtual std::ostream & dumpOn( std::ostream & str ) const;
182 friend std::ostream& operator<<(std::ostream& str, const Resolver & obj)
183 { return obj.dumpOn (str); }
184 void dumpTaskList(const PoolItemList &install, const PoolItemList &remove );
186 // ---------------------------------- accessors
188 QueueItemList initialItems () const { return _initial_items; }
190 ResolverQueueList pendingQueues () const { return _pending_queues; }
191 ResolverQueueList prunedQueues () const { return _pruned_queues; }
192 ResolverQueueList completeQueues () const { return _complete_queues; }
193 ResolverQueueList deferredQueues () const { return _deferred_queues; }
194 ResolverQueueList invalidQueues () const { return _invalid_queues; }
196 ResolverContext_Ptr bestContext (void) const { return _best_context; }
198 /** depending on the last solver result, either return bestContext()
199 of the first invalid context */
200 ResolverContext_Ptr context (void) const;
202 // ---------------------------------- methods
204 void setTimeout (int seconds) { _timeout_seconds = seconds; }
205 void setMaxSolverPasses (int count) { _maxSolverPasses = count; }
206 int timeout () { return _timeout_seconds; }
207 int maxSolverPasses () { return _maxSolverPasses; }
209 ResPool pool (void) const;
210 void setPool (const ResPool & pool) { _pool = pool; }
212 void addSubscribedSource (Repository source);
214 void addPoolItemToInstall (PoolItem_Ref item);
215 void addPoolItemsToInstallFromList (PoolItemList & rl);
217 void addPoolItemToLockUninstalled (PoolItem_Ref item);
219 void addPoolItemToRemove (PoolItem_Ref item);
220 void addPoolItemsToRemoveFromList (PoolItemList & rl);
222 void addPoolItemToEstablish (PoolItem_Ref item);
223 void addPoolItemsToEstablishFromList (PoolItemList & rl);
225 void addPoolItemToVerify (PoolItem_Ref item);
227 void addExtraCapability (const Capability & capability);
228 void addExtraConflict (const Capability & capability);
230 const CapSet extraCapability () { return _extra_caps; }
231 const CapSet extraConflicts () { return _extra_conflicts; }
233 void addIgnoreConflict (const PoolItem_Ref item,
234 const Capability & capability);
235 void addIgnoreRequires (const PoolItem_Ref item,
236 const Capability & capability);
237 void addIgnoreObsoletes (const PoolItem_Ref item,
238 const Capability & capability);
239 void addIgnoreInstalledItem (const PoolItem_Ref item);
240 void addIgnoreArchitectureItem (const PoolItem_Ref item);
241 void addIgnoreVendorItem (const PoolItem_Ref item);
243 void setForceResolve (const bool force) { _forceResolve = force; }
244 const bool forceResolve() { return _forceResolve; }
245 void setPreferHighestVersion (const bool highestVersion) { _preferHighestVersion = highestVersion; }
246 const bool preferHighestVersion() { return _preferHighestVersion; }
248 void setTryAllPossibilities (const bool tryAllPossibilities) { _tryAllPossibilities = tryAllPossibilities; }
249 const bool tryAllPossibilities () { return _tryAllPossibilities; };
251 bool verifySystem (bool considerNewHardware = false);
252 void establishState (ResolverContext_Ptr context = NULL);
253 bool establishPool (void);
254 void freshenState( ResolverContext_Ptr context = NULL, bool resetAfterSolve = true );
255 bool freshenPool( bool resetAfterSolve = true );
256 bool resolveDependencies (const ResolverContext_Ptr context = NULL);
257 bool resolvePool( bool tryAllPossibilities = false);
259 bool transactResObject( ResObject::constPtr robj,
261 bool recursive = false);
262 bool transactResKind( Resolvable::Kind kind );
263 void transactReset( ResStatus::TransactByValue causer );
265 void doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
266 PoolItemList problematicUpdateItems( void ) const { return _update_items; }
269 ResolverProblemList problems (const bool ignoreValidSolution = false) const;
270 void applySolutions (const ProblemSolutionList &solutions);
271 // returns a string list of ResolverInfo of the LAST not valid solution
272 std::list<std::string> problemDescription( void ) const;
274 // reset all SOLVER transaction in pool
277 // Get more information about the solverrun
278 // Which item will be installed by another item or triggers an item for
280 const ItemCapKindList isInstalledBy (const PoolItem_Ref item);
281 const ItemCapKindList installs (const PoolItem_Ref item);
283 void reset (bool resetValidResults = false, bool keepExtras = false );
285 Arch architecture() const { return _architecture; }
286 void setArchitecture( const Arch & arch) { _architecture = arch; }
288 bool testing(void) const { return _testing; }
289 void setTesting( bool testing ) { _testing = testing; }
292 ///////////////////////////////////////////////////////////////////
293 };// namespace detail
294 /////////////////////////////////////////////////////////////////////
295 /////////////////////////////////////////////////////////////////////
296 };// namespace solver
297 ///////////////////////////////////////////////////////////////////////
298 ///////////////////////////////////////////////////////////////////////
300 /////////////////////////////////////////////////////////////////////////
302 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H