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_SAT_RESOLVER_H
23 #define ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H
30 #include "zypp/base/ReferenceCounted.h"
31 #include "zypp/base/PtrTypes.h"
32 #include "zypp/ResPool.h"
33 #include "zypp/base/SerialNumber.h"
34 #include "zypp/ProblemTypes.h"
35 #include "zypp/ResolverProblem.h"
36 #include "zypp/ProblemSolution.h"
37 #include "zypp/Capability.h"
38 #include "zypp/solver/detail/SolverQueueItem.h"
40 #include "satsolver/solver.h"
41 #include "satsolver/pool.h"
45 /////////////////////////////////////////////////////////////////////////
47 { ///////////////////////////////////////////////////////////////////////
48 ///////////////////////////////////////////////////////////////////////
50 { /////////////////////////////////////////////////////////////////////
51 /////////////////////////////////////////////////////////////////////
53 { ///////////////////////////////////////////////////////////////////
56 ///////////////////////////////////////////////////////////////////
58 // CLASS NAME : SATResolver
60 * \todo The way solver options are passed as individual booleans from Resolver
61 * via solver::detail::Resolver to SATResolver is pedestrian and error prone.
62 * Introdce a dedicated solver option structure which is passed down as a whole.
64 class SATResolver : public base::ReferenceCounted, private base::NonCopyable {
72 // list of problematic items (orphaned)
73 PoolItemList _problem_items;
75 // list populated by calls to addPoolItemTo*()
76 PoolItemList _items_to_install;
77 PoolItemList _items_to_remove;
78 PoolItemList _items_to_lock;
79 PoolItemList _items_to_keep;
82 PoolItemList _result_items_to_install;
83 PoolItemList _result_items_to_remove;
85 bool _fixsystem; // repair errors in rpm dependency graph
86 bool _allowdowngrade; // allow to downgrade installed solvable
87 bool _allowarchchange; // allow to change architecture of installed solvables
88 bool _allowvendorchange; // allow to change vendor of installed solvables
89 bool _allowuninstall; // allow removal of installed solvables
90 bool _updatesystem; // update
91 bool _allowvirtualconflicts; // false: conflicts on package name, true: conflicts on package provides
92 bool _noupdateprovide; // true: update packages needs not to provide old package
93 bool _dosplitprovides; // true: consider legacy split provides
94 bool _onlyRequires; // true: consider required packages only
95 bool _ignorealreadyrecommended; // true: ignore recommended packages that were already recommended by the installed packages
97 bool _distupgrade_removeunsupported;
98 bool _solveSrcPackages; // false: generate no job rule for source packages selected in the pool
100 // ---------------------------------- methods
101 std::string SATprobleminfoString (Id problem, std::string &detail, Id &ignoreId);
102 void resetItemTransaction (PoolItem item);
104 // Create a SAT solver and reset solver selection in the pool (Collecting
105 void solverInit(const PoolItemList & weakItems);
106 // common solver run with the _jobQueue; Save results back to pool
107 bool solving(const CapabilitySet & requires_caps = CapabilitySet(),
108 const CapabilitySet & conflict_caps = CapabilitySet());
111 // set locks for the solver
113 // set requirements for a running system
114 void setSystemRequirements();
116 // Checking if this solvable/item has a buddy which reflect the real
117 // user visible description of an item
118 // e.g. The release package has a buddy to the concerning product item.
119 // This user want's the message "Product foo conflicts with product bar" and
120 // NOT "package release-foo conflicts with package release-bar"
121 // So these functions return the concerning buddy (e.g. product item)
122 sat::Solvable mapSolvable (const Id &id);
123 PoolItem mapItem (const PoolItem &item);
127 SATResolver (const ResPool & pool, Pool *SATPool);
128 virtual ~SATResolver();
130 // ---------------------------------- I/O
132 virtual std::ostream & dumpOn( std::ostream & str ) const;
133 friend std::ostream& operator<<(std::ostream& str, const SATResolver & obj)
134 { return obj.dumpOn (str); }
136 ResPool pool (void) const;
137 void setPool (const ResPool & pool) { _pool = pool; }
139 // solver run with pool selected items
140 bool resolvePool(const CapabilitySet & requires_caps,
141 const CapabilitySet & conflict_caps,
142 const PoolItemList & weakItems
144 // solver run with the given request queue
145 bool resolveQueue(const SolverQueueItemList &requestQueue,
146 const PoolItemList & weakItems
148 // searching for new packages
151 ResolverProblemList problems ();
152 void applySolutions (const ProblemSolutionList &solutions);
154 void addPoolItemToInstall (PoolItem item);
155 void addPoolItemsToInstallFromList (PoolItemList & rl);
157 void addPoolItemToLock (PoolItem item);
158 void addPoolItemToKeep (PoolItem item);
160 void addPoolItemToRemove (PoolItem item);
161 void addPoolItemsToRemoveFromList (PoolItemList & rl);
163 bool fixsystem () const {return _fixsystem;}
164 void setFixsystem ( const bool fixsystem) { _fixsystem = fixsystem;}
166 bool ignorealreadyrecommended () const {return _ignorealreadyrecommended;}
167 void setIgnorealreadyrecommended ( const bool ignorealreadyrecommended) { _ignorealreadyrecommended = ignorealreadyrecommended;}
169 bool distupgrade () const {return _distupgrade;}
170 void setDistupgrade ( const bool distupgrade) { _distupgrade = distupgrade;}
172 bool distupgrade_removeunsupported () const {return _distupgrade_removeunsupported;}
173 void setDistupgrade_removeunsupported ( const bool distupgrade_removeunsupported) { _distupgrade_removeunsupported = distupgrade_removeunsupported;}
175 bool allowdowngrade () const {return _allowdowngrade;}
176 void setAllowdowngrade ( const bool allowdowngrade) { _allowdowngrade = allowdowngrade;}
178 bool allowarchchange () const {return _allowarchchange;}
179 void setAllowarchchange ( const bool allowarchchange) { _allowarchchange = allowarchchange;}
181 bool allowvendorchange () const {return _allowvendorchange;}
182 void setAllowvendorchange ( const bool allowvendorchange) { _allowvendorchange = allowvendorchange;}
184 bool allowuninstall () const {return _allowuninstall;}
185 void setAllowuninstall ( const bool allowuninstall) { _allowuninstall = allowuninstall;}
187 bool updatesystem () const {return _updatesystem;}
188 void setUpdatesystem ( const bool updatesystem) { _updatesystem = updatesystem;}
190 bool allowvirtualconflicts () const {return _allowvirtualconflicts;}
191 void setAllowvirtualconflicts ( const bool allowvirtualconflicts) { _allowvirtualconflicts = allowvirtualconflicts;}
193 bool noupdateprovide () const {return _noupdateprovide;}
194 void setNoupdateprovide ( const bool noupdateprovide) { _noupdateprovide = noupdateprovide;}
196 bool dosplitprovides () const {return _dosplitprovides;}
197 void setDosplitprovides ( const bool dosplitprovides) { _dosplitprovides = dosplitprovides;}
199 bool onlyRequires () const {return _onlyRequires;}
200 void setOnlyRequires ( const bool onlyRequires) { _onlyRequires = onlyRequires;}
202 bool solveSrcPackages() const { return _solveSrcPackages; }
203 void setSolveSrcPackages( bool state_r ) { _solveSrcPackages = state_r; }
205 PoolItemList problematicUpdateItems( void ) const { return _problem_items; }
207 PoolItemList resultItemsToInstall () { return _result_items_to_install; }
208 PoolItemList resultItemsToRemove () { return _result_items_to_remove; }
209 PoolItemList problematicUpdateItems() { return _problem_items; }
213 ///////////////////////////////////////////////////////////////////
214 };// namespace detail
215 /////////////////////////////////////////////////////////////////////
216 /////////////////////////////////////////////////////////////////////
217 };// namespace solver
218 ///////////////////////////////////////////////////////////////////////
219 ///////////////////////////////////////////////////////////////////////
221 /////////////////////////////////////////////////////////////////////////
223 #endif // ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H