diff options
| author | Julian Andres Klode <jak@debian.org> | 2025-05-20 11:42:34 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2025-05-26 12:08:29 +0200 |
| commit | 4f5b0fe1d6af3a5cce15636b9c5307438a9c2d9f (patch) | |
| tree | d070825c55b40dead2f75dadbdfd69756b07943c /apt-pkg | |
| parent | c6f49402c2f8aed20b538263d80ecb6fed179b18 (diff) | |
solver3: Remove Work::choice
Instead of having the historic choice here, follow MiniSAT and
use the assigned variable from the tail. This should also make
the Assume() function work now, albeit we still need to actually
migrate to it.
This is a first step towards refactoring the Solve() loop to use
a propagate/find next literal/assume it kind of loop, albeit there
is a bit more to prepare there as we need to also reinsert work
items when backtracking.
Diffstat (limited to 'apt-pkg')
| -rw-r--r-- | apt-pkg/solver3.cc | 9 | ||||
| -rw-r--r-- | apt-pkg/solver3.h | 13 |
2 files changed, 7 insertions, 15 deletions
diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc index abc0af314..b97e3b694 100644 --- a/apt-pkg/solver3.cc +++ b/apt-pkg/solver3.cc @@ -901,13 +901,13 @@ APT::Solver::Clause APT::Solver::TranslateOrGroup(pkgCache::DepIterator start, p return clause; } -void APT::Solver::Push(Work work) +void APT::Solver::Push(Var var, Work work) { if (unlikely(debug >= 2)) std::cerr << "Trying choice for " << work.toString(cache) << std::endl; choices.push_back(solved.size()); - solved.push_back(Solved{Var(), std::move(work)}); + solved.push_back(Solved{var, std::move(work)}); } void APT::Solver::UndoOne() @@ -958,7 +958,7 @@ bool APT::Solver::Pop() assert(choices.back() < solved.size()); int itemsToUndo = solved.size() - choices.back(); - auto choice = solved[choices.back()].work->choice; + auto choice = solved[choices.back()].assigned; for (; itemsToUndo; --itemsToUndo) UndoOne(); @@ -1059,8 +1059,7 @@ bool APT::Solver::Solve() } if (item.size > 1 || item.clause->optional) { - item.choice = sol; - Push(item); + Push(sol, item); } if (unlikely(debug >= 3)) std::cerr << "(try it: " << sol.toString(cache) << ")\n"; diff --git a/apt-pkg/solver3.h b/apt-pkg/solver3.h index 43f6ec3a7..eb589d2bd 100644 --- a/apt-pkg/solver3.h +++ b/apt-pkg/solver3.h @@ -277,7 +277,7 @@ class Solver public: // \brief Create a new decision level. - void Push(Work work); + void Push(Var var, Work work); // \brief Revert to the previous decision level. [[nodiscard]] bool Pop(); // \brief Undo a single assignment / solved work item @@ -426,15 +426,8 @@ struct APT::Solver::Work // \brief The depth at which the item has been added depth_type depth; - // This is a union because we only need to store the choice we made when adding - // to the choice vector, and we don't need the size of valid choices in there. - union - { - // The choice we took - Var choice; - // Number of valid choices - size_t size{0}; - }; + // Number of valid choices + size_t size{0}; // \brief This item should be removed from the queue. bool erased{false}; |
