SATResolver.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* SATResolver.h
00003  *
00004  * Copyright (C) 2000-2002 Ximian, Inc.
00005  * Copyright (C) 2005 SUSE Linux Products GmbH
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License,
00009  * version 2, as published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019  * 02111-1307, USA.
00020  */
00021 
00022 #ifndef ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H
00023 #define ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H
00024 
00025 extern "C"
00026 {
00027 #include <satsolver/solver.h>
00028 #include <satsolver/pool.h>
00029 }
00030 
00031 #include <iosfwd>
00032 #include <list>
00033 #include <map>
00034 #include <string>
00035 
00036 #include "zypp/base/ReferenceCounted.h"
00037 #include "zypp/base/PtrTypes.h"
00038 #include "zypp/ResPool.h"
00039 #include "zypp/base/SerialNumber.h"
00040 #include "zypp/ProblemTypes.h"
00041 #include "zypp/ResolverProblem.h"
00042 #include "zypp/ProblemSolution.h"
00043 #include "zypp/Capability.h"
00044 #include "zypp/solver/detail/SolverQueueItem.h"
00045 
00046 
00048 namespace zypp
00049 { 
00050 
00051   namespace solver
00052   { 
00053 
00054     namespace detail
00055     { 
00056 
00057 
00059 //
00060 //      CLASS NAME : SATResolver
00066 class SATResolver : public base::ReferenceCounted, private base::NonCopyable {
00067 
00068   private:
00069     ResPool _pool;
00070     Pool *_SATPool;
00071     Solver *_solv;
00072     Queue _jobQueue;
00073 
00074     // list of problematic items (orphaned)
00075     PoolItemList _problem_items;
00076 
00077     // list populated by calls to addPoolItemTo*()
00078     PoolItemList _items_to_install;
00079     PoolItemList _items_to_remove;
00080     PoolItemList _items_to_lock;
00081     PoolItemList _items_to_keep;
00082 
00083     // solve results
00084     PoolItemList _result_items_to_install;
00085     PoolItemList _result_items_to_remove;
00086 
00087     bool _fixsystem;                    // repair errors in rpm dependency graph
00088     bool _allowdowngrade;               // allow to downgrade installed solvable
00089     bool _allowarchchange;              // allow to change architecture of installed solvables
00090     bool _allowvendorchange;            // allow to change vendor of installed solvables
00091     bool _allowuninstall;               // allow removal of installed solvables
00092     bool _updatesystem;                 // update
00093     bool _noupdateprovide;              // true: update packages needs not to provide old package
00094     bool _dosplitprovides;              // true: consider legacy split provides
00095     bool _onlyRequires;                 // true: consider required packages only
00096     bool _ignorealreadyrecommended;     // true: ignore recommended packages that were already recommended by the installed packages
00097     bool _distupgrade;
00098     bool _distupgrade_removeunsupported;
00099     bool _solveSrcPackages;             // false: generate no job rule for source packages selected in the pool
00100 
00101     // ---------------------------------- methods
00102     std::string SATprobleminfoString (Id problem, std::string &detail, Id &ignoreId);
00103     void resetItemTransaction (PoolItem item);
00104 
00105     // Create a SAT solver and reset solver selection in the pool (Collecting
00106     void solverInit(const PoolItemList & weakItems);
00107     // common solver run with the _jobQueue; Save results back to pool
00108     bool solving(const CapabilitySet & requires_caps = CapabilitySet(),
00109                  const CapabilitySet & conflict_caps = CapabilitySet());
00110     // cleanup solver
00111     void solverEnd();
00112     // set locks for the solver
00113     void setLocks();
00114     // set requirements for a running system
00115     void setSystemRequirements();
00116 
00117    // Checking if this solvable/item has a buddy which reflect the real
00118    // user visible description of an item
00119    // e.g. The release package has a buddy to the concerning product item.
00120    // This user want's the message "Product foo conflicts with product bar" and
00121    // NOT "package release-foo conflicts with package release-bar"
00122    // So these functions return the concerning buddy (e.g. product item)
00123     sat::Solvable mapSolvable (const Id &id);
00124     PoolItem mapItem (const PoolItem &item);
00125 
00126   public:
00127 
00128     SATResolver (const ResPool & pool, Pool *SATPool);
00129     virtual ~SATResolver();
00130 
00131     // ---------------------------------- I/O
00132 
00133     virtual std::ostream & dumpOn( std::ostream & str ) const;
00134     friend std::ostream& operator<<(std::ostream& str, const SATResolver & obj)
00135     { return obj.dumpOn (str); }
00136 
00137     ResPool pool (void) const;
00138     void setPool (const ResPool & pool) { _pool = pool; }
00139 
00140     // solver run with pool selected items
00141     bool resolvePool(const CapabilitySet & requires_caps,
00142                      const CapabilitySet & conflict_caps,
00143                      const PoolItemList & weakItems,
00144                      const std::set<Repository> & upgradeRepos
00145                      );
00146     // solver run with the given request queue
00147     bool resolveQueue(const SolverQueueItemList &requestQueue,
00148                       const PoolItemList & weakItems
00149                       );
00150     // searching for new packages
00151     void doUpdate();
00152 
00153     ResolverProblemList problems ();
00154     void applySolutions (const ProblemSolutionList &solutions);
00155 
00156     void addPoolItemToInstall (PoolItem item);
00157     void addPoolItemsToInstallFromList (PoolItemList & rl);
00158 
00159     void addPoolItemToLock (PoolItem item);
00160     void addPoolItemToKeep (PoolItem item);
00161 
00162     void addPoolItemToRemove (PoolItem item);
00163     void addPoolItemsToRemoveFromList (PoolItemList & rl);
00164 
00165     bool fixsystem () const {return _fixsystem;}
00166     void setFixsystem ( const bool fixsystem) { _fixsystem = fixsystem;}
00167 
00168     bool ignorealreadyrecommended () const {return _ignorealreadyrecommended;}
00169     void setIgnorealreadyrecommended ( const bool ignorealreadyrecommended) { _ignorealreadyrecommended = ignorealreadyrecommended;}
00170 
00171     bool distupgrade () const {return _distupgrade;}
00172     void setDistupgrade ( const bool distupgrade) { _distupgrade = distupgrade;}
00173 
00174     bool distupgrade_removeunsupported () const {return _distupgrade_removeunsupported;}
00175     void setDistupgrade_removeunsupported ( const bool distupgrade_removeunsupported) { _distupgrade_removeunsupported = distupgrade_removeunsupported;}
00176 
00177     bool allowdowngrade () const {return _allowdowngrade;}
00178     void setAllowdowngrade ( const bool allowdowngrade) { _allowdowngrade = allowdowngrade;}
00179 
00180     bool allowarchchange () const {return _allowarchchange;}
00181     void setAllowarchchange ( const bool allowarchchange) { _allowarchchange = allowarchchange;}
00182 
00183     bool allowvendorchange () const {return _allowvendorchange;}
00184     void setAllowvendorchange ( const bool allowvendorchange) { _allowvendorchange = allowvendorchange;}
00185 
00186     bool allowuninstall () const {return _allowuninstall;}
00187     void setAllowuninstall ( const bool allowuninstall) { _allowuninstall = allowuninstall;}
00188 
00189     bool updatesystem () const {return _updatesystem;}
00190     void setUpdatesystem ( const bool updatesystem) { _updatesystem = updatesystem;}
00191 
00192     bool noupdateprovide () const {return _noupdateprovide;}
00193     void setNoupdateprovide ( const bool noupdateprovide) { _noupdateprovide = noupdateprovide;}
00194 
00195     bool dosplitprovides () const {return _dosplitprovides;}
00196     void setDosplitprovides ( const bool dosplitprovides) { _dosplitprovides = dosplitprovides;}
00197 
00198     bool onlyRequires () const {return _onlyRequires;}
00199     void setOnlyRequires ( const bool onlyRequires) { _onlyRequires = onlyRequires;}
00200 
00201     bool solveSrcPackages() const               { return _solveSrcPackages; }
00202     void setSolveSrcPackages( bool state_r )    { _solveSrcPackages = state_r; }
00203 
00204     PoolItemList problematicUpdateItems( void ) const { return _problem_items; }
00205 
00206     PoolItemList resultItemsToInstall () { return _result_items_to_install; }
00207     PoolItemList resultItemsToRemove () { return _result_items_to_remove; }
00208     PoolItemList problematicUpdateItems() { return _problem_items; }
00209 
00210 };
00211 
00213     };// namespace detail
00216   };// namespace solver
00219 };// namespace zypp
00221 
00222 #endif // ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H

doxygen