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
24 #ifndef ZYPP_USE_RESOLVER_INTERNALS
25 #error Do not directly include this file!
29 #include <solv/solver.h>
30 #include <solv/pool.h>
38 #include "zypp/base/ReferenceCounted.h"
39 #include "zypp/base/PtrTypes.h"
40 #include "zypp/ResPool.h"
41 #include "zypp/base/SerialNumber.h"
42 #include "zypp/ProblemTypes.h"
43 #include "zypp/ResolverProblem.h"
44 #include "zypp/ProblemSolution.h"
45 #include "zypp/Capability.h"
46 #include "zypp/solver/detail/SolverQueueItem.h"
48 #include "zypp/sat/detail/PoolMember.h"
50 /////////////////////////////////////////////////////////////////////////
52 { ///////////////////////////////////////////////////////////////////////
59 ///////////////////////////////////////////////////////////////////////
61 { /////////////////////////////////////////////////////////////////////
62 /////////////////////////////////////////////////////////////////////
64 { ///////////////////////////////////////////////////////////////////
67 ///////////////////////////////////////////////////////////////////
69 // CLASS NAME : SATResolver
71 * \todo The way solver options are passed as individual booleans from Resolver
72 * via solver::detail::Resolver to SATResolver is pedestrian and error prone.
73 * Introdce a dedicated solver option structure which is passed down as a whole.
75 class SATResolver : public base::ReferenceCounted, private base::NonCopyable, private sat::detail::PoolMember
80 sat::detail::CPool *_satPool;
81 sat::detail::CSolver *_satSolver;
82 sat::detail::CQueue _jobQueue;
84 // list of problematic items (orphaned)
85 PoolItemList _problem_items;
87 // list populated by calls to addPoolItemTo*()
88 PoolItemList _items_to_install;
89 PoolItemList _items_to_remove;
90 PoolItemList _items_to_lock;
91 PoolItemList _items_to_keep;
94 PoolItemList _result_items_to_install;
95 PoolItemList _result_items_to_remove;
97 bool _fixsystem:1; // repair errors in rpm dependency graph
98 bool _allowdowngrade:1; // allow to downgrade installed solvable
99 bool _allowarchchange:1; // allow to change architecture of installed solvables
100 bool _allowvendorchange:1; // allow to change vendor of installed solvables
101 bool _allowuninstall:1; // allow removal of installed solvables
102 bool _updatesystem:1; // update
103 bool _noupdateprovide:1; // true: update packages needs not to provide old package
104 bool _dosplitprovides:1; // true: consider legacy split provides
105 bool _onlyRequires:1; // true: consider required packages only
106 bool _ignorealreadyrecommended:1; // true: ignore recommended packages that were already recommended by the installed packages
108 bool _distupgrade_removeunsupported:1;
109 bool _dup_allowdowngrade:1; // dup mode: allow to downgrade installed solvable
110 bool _dup_allownamechange:1; // dup mode: allow to change name of installed solvable
111 bool _dup_allowarchchange:1; // dup mode: allow to change architecture of installed solvables
112 bool _dup_allowvendorchange:1; // dup mode: allow to change vendor of installed solvables
113 bool _solveSrcPackages:1; // false: generate no job rule for source packages selected in the pool
114 bool _cleandepsOnRemove:1; // whether removing a package should also remove no longer needed requirements
117 // ---------------------------------- methods
118 std::string SATprobleminfoString (Id problem, std::string &detail, Id &ignoreId);
119 void resetItemTransaction (PoolItem item);
121 // Create a SAT solver and reset solver selection in the pool (Collecting
122 void solverInit(const PoolItemList & weakItems);
123 // common solver run with the _jobQueue; Save results back to pool
124 bool solving(const CapabilitySet & requires_caps = CapabilitySet(),
125 const CapabilitySet & conflict_caps = CapabilitySet());
128 // set locks for the solver
130 // set requirements for a running system
131 void setSystemRequirements();
133 // Checking if this solvable/item has a buddy which reflect the real
134 // user visible description of an item
135 // e.g. The release package has a buddy to the concerning product item.
136 // This user want's the message "Product foo conflicts with product bar" and
137 // NOT "package release-foo conflicts with package release-bar"
138 // So these functions return the concerning buddy (e.g. product item)
139 sat::Solvable mapSolvable (const Id &id);
140 PoolItem mapItem (const PoolItem &item);
144 SATResolver (const ResPool & pool, sat::detail::CPool *satPool);
145 virtual ~SATResolver();
147 // ---------------------------------- I/O
149 virtual std::ostream & dumpOn( std::ostream & str ) const;
150 friend std::ostream& operator<<(std::ostream& str, const SATResolver & obj)
151 { return obj.dumpOn (str); }
153 ResPool pool (void) const;
154 void setPool (const ResPool & pool) { _pool = pool; }
156 // solver run with pool selected items
157 bool resolvePool(const CapabilitySet & requires_caps,
158 const CapabilitySet & conflict_caps,
159 const PoolItemList & weakItems,
160 const std::set<Repository> & upgradeRepos
162 // solver run with the given request queue
163 bool resolveQueue(const SolverQueueItemList &requestQueue,
164 const PoolItemList & weakItems
166 // searching for new packages
169 ResolverProblemList problems ();
170 void applySolutions (const ProblemSolutionList &solutions);
172 bool fixsystem () const {return _fixsystem;}
173 void setFixsystem ( const bool fixsystem) { _fixsystem = fixsystem;}
175 bool ignorealreadyrecommended () const {return _ignorealreadyrecommended;}
176 void setIgnorealreadyrecommended ( const bool ignorealreadyrecommended) { _ignorealreadyrecommended = ignorealreadyrecommended;}
178 bool distupgrade () const {return _distupgrade;}
179 void setDistupgrade ( const bool distupgrade) { _distupgrade = distupgrade;}
181 bool distupgrade_removeunsupported () const {return _distupgrade_removeunsupported;}
182 void setDistupgrade_removeunsupported ( const bool distupgrade_removeunsupported) { _distupgrade_removeunsupported = distupgrade_removeunsupported;}
184 bool allowdowngrade () const {return _allowdowngrade;}
185 void setAllowdowngrade ( const bool allowdowngrade) { _allowdowngrade = allowdowngrade;}
187 bool allowarchchange () const {return _allowarchchange;}
188 void setAllowarchchange ( const bool allowarchchange) { _allowarchchange = allowarchchange;}
190 bool allowvendorchange () const {return _allowvendorchange;}
191 void setAllowvendorchange ( const bool allowvendorchange) { _allowvendorchange = allowvendorchange;}
193 bool allowuninstall () const {return _allowuninstall;}
194 void setAllowuninstall ( const bool allowuninstall) { _allowuninstall = allowuninstall;}
196 bool updatesystem () const {return _updatesystem;}
197 void setUpdatesystem ( const bool updatesystem) { _updatesystem = updatesystem;}
199 bool noupdateprovide () const {return _noupdateprovide;}
200 void setNoupdateprovide ( const bool noupdateprovide) { _noupdateprovide = noupdateprovide;}
202 bool dosplitprovides () const {return _dosplitprovides;}
203 void setDosplitprovides ( const bool dosplitprovides) { _dosplitprovides = dosplitprovides;}
205 bool onlyRequires () const {return _onlyRequires;}
206 void setOnlyRequires ( const bool onlyRequires) { _onlyRequires = onlyRequires;}
208 bool solveSrcPackages() const { return _solveSrcPackages; }
209 void setSolveSrcPackages( bool state_r ) { _solveSrcPackages = state_r; }
211 bool cleandepsOnRemove() const { return _cleandepsOnRemove; }
212 void setCleandepsOnRemove( bool state_r ) { _cleandepsOnRemove = state_r; }
214 PoolItemList problematicUpdateItems( void ) const { return _problem_items; }
215 PoolItemList problematicUpdateItems() { return _problem_items; }
217 PoolItemList resultItemsToInstall () { return _result_items_to_install; }
218 PoolItemList resultItemsToRemove () { return _result_items_to_remove; }
220 sat::StringQueue autoInstalled() const;
221 sat::StringQueue userInstalled() const;
224 ///////////////////////////////////////////////////////////////////
225 };// namespace detail
226 /////////////////////////////////////////////////////////////////////
227 /////////////////////////////////////////////////////////////////////
228 };// namespace solver
229 ///////////////////////////////////////////////////////////////////////
230 ///////////////////////////////////////////////////////////////////////
232 /////////////////////////////////////////////////////////////////////////
233 #endif // ZYPP_USE_RESOLVER_INTERNALS
234 #endif // ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H