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"
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"
40 #include "zypp/ProblemTypes.h"
41 #include "zypp/ResolverProblem.h"
42 #include "zypp/ProblemSolution.h"
43 #include "zypp/UpgradeStatistics.h"
45 #include "zypp/CapSet.h"
48 /////////////////////////////////////////////////////////////////////////
50 { ///////////////////////////////////////////////////////////////////////
51 ///////////////////////////////////////////////////////////////////////
53 { /////////////////////////////////////////////////////////////////////
54 /////////////////////////////////////////////////////////////////////
56 { ///////////////////////////////////////////////////////////////////
58 ///////////////////////////////////////////////////////////////////
60 // CLASS NAME : Resolver
62 class Resolver : public base::ReferenceCounted, private base::NonCopyable {
67 unsigned _timeout_seconds;
68 unsigned _maxSolverPasses;
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
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;
87 // pool of valid contexts which are "recycled" in order to fasten the solver
88 ContextPool contextPool;
90 // list of problematic items after doUpgrade()
91 PoolItemList _update_items;
95 CapSet _extra_conflicts;
97 //typedef std::multimap<PoolItem_Ref,Capability> IgnoreMap;
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;
113 ResolverQueueList _pending_queues;
114 ResolverQueueList _pruned_queues;
115 ResolverQueueList _complete_queues;
116 ResolverQueueList _deferred_queues;
117 ResolverQueueList _invalid_queues;
119 int _valid_solution_count;
121 ResolverContext_Ptr _best_context;
122 // Context of the last establishing call ( without any transaction )
123 ResolverContext_Ptr _establish_context;
126 std::set<Source_Ref> _subscribed;
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.
138 bool doesObsoleteCapability (PoolItem_Ref candidate, const Capability & cap);
139 bool doesObsoleteItem (PoolItem_Ref candidate, PoolItem_Ref installed);
143 Resolver (const ResPool & pool);
146 // ---------------------------------- I/O
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 );
153 // ---------------------------------- accessors
155 QueueItemList initialItems () const { return _initial_items; }
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; }
163 ResolverContext_Ptr bestContext (void) const { return _best_context; }
165 /** depending on the last solver result, either return bestContext()
166 of the first invalid context */
167 ResolverContext_Ptr context (void) const;
169 // ---------------------------------- methods
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; }
176 ResPool pool (void) const;
177 void setPool (const ResPool & pool) { _pool = pool; }
179 void addSubscribedSource (Source_Ref source);
181 void addPoolItemToInstall (PoolItem_Ref item);
182 void addPoolItemsToInstallFromList (PoolItemList & rl);
184 void addPoolItemToLockUninstalled (PoolItem_Ref item);
186 void addPoolItemToRemove (PoolItem_Ref item);
187 void addPoolItemsToRemoveFromList (PoolItemList & rl);
189 void addPoolItemToEstablish (PoolItem_Ref item);
190 void addPoolItemsToEstablishFromList (PoolItemList & rl);
192 void addPoolItemToVerify (PoolItem_Ref item);
194 void addExtraCapability (const Capability & capability);
195 void addExtraConflict (const Capability & capability);
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);
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; }
211 void setTryAllPossibilities (const bool tryAllPossibilities) { _tryAllPossibilities = tryAllPossibilities; }
212 const bool tryAllPossibilities () { return _tryAllPossibilities; };
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 );
222 bool transactResObject( ResObject::constPtr robj,
224 bool recursive = false);
225 bool transactResKind( Resolvable::Kind kind );
226 void transactReset( ResStatus::TransactByValue causer );
228 void doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
229 PoolItemList problematicUpdateItems( void ) const { return _update_items; }
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;
237 // reset all SOLVER transaction in pool
240 // only for testsuite
241 void reset (const bool resetValidResults = false);
243 Arch architecture() const { return _architecture; }
244 void setArchitecture( const Arch & arch) { _architecture = arch; }
246 bool testing(void) const { return _testing; }
247 void setTesting( bool testing ) { _testing = testing; }
250 ///////////////////////////////////////////////////////////////////
251 };// namespace detail
252 /////////////////////////////////////////////////////////////////////
253 /////////////////////////////////////////////////////////////////////
254 };// namespace solver
255 ///////////////////////////////////////////////////////////////////////
256 ///////////////////////////////////////////////////////////////////////
258 /////////////////////////////////////////////////////////////////////////
260 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H