summaryrefslogtreecommitdiff
path: root/apt-pkg/solver3.h
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2025-12-29 18:47:15 +0100
committerJulian Andres Klode <jak@debian.org>2026-01-31 17:30:20 +0100
commit1fbb857b6b2cbddcea9e8b03aa0c766c72e91f34 (patch)
tree120116a10a15504e3776591c264aef5c1c31c356 /apt-pkg/solver3.h
parent267fd0117a057afd88bc15bfb4f4d688804a9ab4 (diff)
solver3: Use classical watchers for propagation
Instead of tracking dependencies and reverse dependencies, install classical watchers. This vastly streamlines the propagation code and allows us to easily switch to literals in the next step. This implementation watches _all_ solutions rather than using the modern 2-watched literals scheme or the intermediate head/tail watchers. Ultimately a more effective watcher scheme would be interesting but not a significant priority seeing as most of the solver runtime is spent not in propagation but in problem translation. decision trees -------------- The new watchers produce slightly different decision trees, sometimes subtly changing solutions. Notably in various observed examples in Ubuntu 25.04, courier was installed as an MTA instead of postfix: The old decision tree was: apcupsd:amd64 -> mailutils:amd64=1:3.18-1 -> mailutils:amd64 -> postfix:amd64=3.9.1-10ubuntu1 The new decision tree is: lsb:amd64 -> lsb-core:amd64 -> courier-mta:amd64=1.3.13-1 The difference here being that lsb-core declares a mail-transport-agent dependency whereas mailutils depends on `default-mta | mail-transport-agency`; but both are effectively subject to selection at similar time. Further work is needed to optimize selection. A notable choice may also be to deal with broken packages like lsb-core that declare dependencies solely on a virtual package by reconstructing the default provider for that package utilizing default-* dependencies or similar notions. Likewise in the test suite, explanations are different in some uninstallable cases. backtracking ~~~~~~~~~~~~ The following major changes were observed in the 25.04 test suite: -tmp/regression-remove/07f0a068-36c2-11f0-b7c1-fa163e171f02:18 +tmp/regression-remove/07f0a068-36c2-11f0-b7c1-fa163e171f02:3 -tmp/regression-remove/32078f70-3734-11f0-a75a-fa163ec8ca8c:64 +tmp/regression-remove/32078f70-3734-11f0-a75a-fa163ec8ca8c:19 Other test cases showed little deviation, +/- 1, generally the same amount of backtracking. performance ~~~~~~~~~~~ Running Ubuntu's regression test suite resulted in no significant performance difference being observable. Before: 290s user time; 16.66% solver After: 299s user time; 17.36% solver Tests where run with make -j 8 and solver performance extracted perf report --symbol-filter=ResolveExternal --stdio
Diffstat (limited to 'apt-pkg/solver3.h')
-rw-r--r--apt-pkg/solver3.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/apt-pkg/solver3.h b/apt-pkg/solver3.h
index a3ec859bb..af1d749eb 100644
--- a/apt-pkg/solver3.h
+++ b/apt-pkg/solver3.h
@@ -200,6 +200,7 @@ struct Lit
int32_t value;
public:
+ constexpr Lit() : value{0} {}
// SAFETY: value must be 31 bit, one bit is needed for the sign.
constexpr Lit(Var var) : value{static_cast<int32_t>(var.value)} {}
@@ -328,6 +329,8 @@ class Solver
inline State &operator[](Var r);
inline const State &operator[](Var r) const;
+ inline std::vector<const Clause *> &watches(Lit lit);
+
// \brief Heap of the remaining work.
//
// In contrast to MiniSAT which picks undecided literals and decides them,
@@ -364,6 +367,8 @@ class Solver
virtual void Discover(Var var) = 0;
// \brief Propagate all pending propagations
[[nodiscard]] bool Propagate();
+ // \brief Propagate all pending propagations
+ [[nodiscard]] bool Propagate(const Clause *clause, Lit lit);
// \brief Return the current level (.size() with casting)
level_type decisionLevel()
@@ -553,8 +558,8 @@ struct APT::Solver::Solver::State
// \brief Clauses owned by this package/version
std::vector<std::unique_ptr<Clause>> clauses;
- // \brief Reverse clauses, that is dependencies (or conflicts) from other packages on this one
- std::vector<const Clause *> rclauses;
+ // \brief Watches watching a clause by sign
+ std::vector<const Clause *> watches[2];
};
/**
@@ -606,3 +611,8 @@ struct std::hash<APT::Solver::Lit>
std::hash<decltype(APT::Solver::Lit::value)> hash_value;
std::size_t operator()(const APT::Solver::Lit &v) const noexcept { return hash_value(v.value); }
};
+
+inline std::vector<const APT::Solver::Clause *> &APT::Solver::Solver::watches(Lit lit)
+{
+ return (*this)[lit.var()].watches[lit.sign()];
+}