New option for ignoring Obsoletes. This is used for installing more than
[platform/upstream/libzypp.git] / zypp / solver / detail / SATResolver.h
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* SATResolver.h
3  *
4  * Copyright (C) 2000-2002 Ximian, Inc.
5  * Copyright (C) 2005 SUSE Linux Products GmbH
6  *
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.
10  *
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.
15  *
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
19  * 02111-1307, USA.
20  */
21
22 #ifndef ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H
23 #define ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H
24
25 #include <iosfwd>
26 #include <list>
27 #include <map>
28 #include <string>
29
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"
39 extern "C" {
40 #include "satsolver/solver.h"
41 #include "satsolver/pool.h"
42 }
43
44
45 /////////////////////////////////////////////////////////////////////////
46 namespace zypp
47 { ///////////////////////////////////////////////////////////////////////
48   ///////////////////////////////////////////////////////////////////////
49   namespace solver
50   { /////////////////////////////////////////////////////////////////////
51     /////////////////////////////////////////////////////////////////////
52     namespace detail
53     { ///////////////////////////////////////////////////////////////////
54
55
56 ///////////////////////////////////////////////////////////////////
57 //
58 //      CLASS NAME : SATResolver
59
60 class SATResolver : public base::ReferenceCounted, private base::NonCopyable {
61
62   private:
63     ResPool _pool;
64     Pool *_SATPool;
65     Solver *_solv;
66     Queue _jobQueue;
67
68     // list populated by calls to addPoolItemTo*()
69     PoolItemList _items_to_install;
70     PoolItemList _items_to_remove;
71     PoolItemList _items_to_lock;
72     PoolItemList _items_to_keep;
73
74     // solve results
75     PoolItemList _result_items_to_install;
76     PoolItemList _result_items_to_remove;
77
78     bool _fixsystem;                    // repair errors in rpm dependency graph 
79     bool _allowdowngrade;               // allow to downgrade installed solvable 
80     bool _allowarchchange;              // allow to change architecture of installed solvables 
81     bool _allowvendorchange;            // allow to change vendor of installed solvables 
82     bool _allowuninstall;               // allow removal of installed solvables
83     bool _updatesystem;                 // distupgrade 
84     bool _allowvirtualconflicts;        // false: conflicts on package name, true: conflicts on package provides 
85     bool _noupdateprovide;              // true: update packages needs not to provide old package 
86     bool _dosplitprovides;              // true: consider legacy split provides 
87     bool _onlyRequires;                 // true: consider required packages only
88     bool _ignorealreadyrecommended;     // true: ignore recommended packages that were already recommended by the installed packages
89     
90     // ---------------------------------- methods
91     std::string SATprobleminfoString (Id problem, std::string &detail, Id &ignoreId);
92     void resetItemTransaction (PoolItem item);
93
94     // Create a SAT solver and reset solver selection in the pool (Collecting 
95     void solverInit(const PoolItemList & weakItems,
96                     const CapabilitySet & noObsoletesCapability,
97                     const PoolItemSet & noObsoletesItem,
98                     const ObsoleteStrings & noObsoletesString);
99     // common solver run with the _jobQueue; Save results back to pool
100     bool solving();
101     // cleanup solver
102     void solverEnd();
103     
104   public:
105
106     SATResolver (const ResPool & pool, Pool *SATPool);
107     virtual ~SATResolver();
108
109     // ---------------------------------- I/O
110
111     virtual std::ostream & dumpOn( std::ostream & str ) const;
112     friend std::ostream& operator<<(std::ostream& str, const SATResolver & obj)
113     { return obj.dumpOn (str); }
114
115     ResPool pool (void) const;
116     void setPool (const ResPool & pool) { _pool = pool; }
117
118     // solver run with pool selected items
119     bool resolvePool(const CapabilitySet & requires_caps,
120                      const CapabilitySet & conflict_caps,
121                      const PoolItemList & weakItems,
122                      const CapabilitySet & noObsoletesCapability,
123                      const PoolItemSet & noObsoletesItem,
124                      const ObsoleteStrings & noObsoletesString
125                      );
126     // solver run with the given request queue
127     bool resolveQueue(const SolverQueueItemList &requestQueue,
128                       const PoolItemList & weakItems,
129                       const CapabilitySet & noObsoletesCapability,
130                       const PoolItemSet & noObsoletesItem,
131                       const ObsoleteStrings & noObsoletesString               
132                       );
133     // searching for new packages
134     void doUpdate();
135
136     ResolverProblemList problems ();
137     void applySolutions (const ProblemSolutionList &solutions);
138
139     void addPoolItemToInstall (PoolItem item);
140     void addPoolItemsToInstallFromList (PoolItemList & rl);
141
142     void addPoolItemToLock (PoolItem item);
143     void addPoolItemToKeep (PoolItem item);    
144
145     void addPoolItemToRemove (PoolItem item);
146     void addPoolItemsToRemoveFromList (PoolItemList & rl);
147
148     bool fixsystem () const {return _fixsystem;}
149     void setFixsystem ( const bool fixsystem) { _fixsystem = fixsystem;}
150
151     bool ignorealreadyrecommended () const {return _ignorealreadyrecommended;}
152     void setIgnorealreadyrecommended ( const bool ignorealreadyrecommended) { _ignorealreadyrecommended = ignorealreadyrecommended;}
153
154     bool allowdowngrade () const {return _allowdowngrade;}
155     void setAllowdowngrade ( const bool allowdowngrade) { _allowdowngrade = allowdowngrade;}
156
157     bool allowarchchange () const {return _allowarchchange;}
158     void setAllowarchchange ( const bool allowarchchange) { _allowarchchange = allowarchchange;}
159
160     bool allowvendorchange () const {return _allowvendorchange;}
161     void setAllowvendorchange ( const bool allowvendorchange) { _allowvendorchange = allowvendorchange;}
162     
163     bool allowuninstall () const {return _allowuninstall;}
164     void setAllowuninstall ( const bool allowuninstall) { _allowuninstall = allowuninstall;}
165
166     bool updatesystem () const {return _updatesystem;}
167     void setUpdatesystem ( const bool updatesystem) { _updatesystem = updatesystem;}
168     
169     bool allowvirtualconflicts () const {return _allowvirtualconflicts;}
170     void setAllowvirtualconflicts ( const bool allowvirtualconflicts) { _allowvirtualconflicts = allowvirtualconflicts;}
171     
172     bool noupdateprovide () const {return _noupdateprovide;}
173     void setNoupdateprovide ( const bool noupdateprovide) { _noupdateprovide = noupdateprovide;}
174
175     bool dosplitprovides () const {return _dosplitprovides;}
176     void setDosplitprovides ( const bool dosplitprovides) { _dosplitprovides = dosplitprovides;}
177     
178     bool onlyRequires () const {return _onlyRequires;}
179     void setOnlyRequires ( const bool onlyRequires) { _onlyRequires = onlyRequires;}
180
181     bool doesObsoleteItem (PoolItem candidate, PoolItem installed);
182
183     PoolItemList resultItemsToInstall () { return _result_items_to_install; }
184     PoolItemList resultItemsToRemove () { return _result_items_to_remove; }
185     
186 };
187
188 ///////////////////////////////////////////////////////////////////
189     };// namespace detail
190     /////////////////////////////////////////////////////////////////////
191     /////////////////////////////////////////////////////////////////////
192   };// namespace solver
193   ///////////////////////////////////////////////////////////////////////
194   ///////////////////////////////////////////////////////////////////////
195 };// namespace zypp
196 /////////////////////////////////////////////////////////////////////////
197
198 #endif // ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H