From 4f5b0fe1d6af3a5cce15636b9c5307438a9c2d9f Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 20 May 2025 11:42:34 +0200 Subject: 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. --- apt-pkg/solver3.h | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'apt-pkg/solver3.h') 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}; -- cgit v1.2.3-70-g09d2 From 6c3196950acb6a1351c221c74edd9c3ba691b7e5 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 26 May 2025 12:42:58 +0200 Subject: solver3: Initialize startTime if not set in Pop() If the user pushes Assumptions that fail, we could inadvertently timeout during the Pop() as the variable was not initialized. Always initialize it to 0, and if we haven't set an actual time by the time we Pop() set it there. --- apt-pkg/solver3.cc | 2 ++ apt-pkg/solver3.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'apt-pkg/solver3.h') diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc index 489d4081b..eeac6f177 100644 --- a/apt-pkg/solver3.cc +++ b/apt-pkg/solver3.cc @@ -947,6 +947,8 @@ bool APT::Solver::Pop() return false; time_t now = time(nullptr); + if (startTime == 0) + startTime = now; if (now - startTime >= Timeout) return _error->Error("Solver timed out."); diff --git a/apt-pkg/solver3.h b/apt-pkg/solver3.h index eb589d2bd..590b187cc 100644 --- a/apt-pkg/solver3.h +++ b/apt-pkg/solver3.h @@ -222,7 +222,7 @@ class Solver std::vector choices{}; // \brief The time we called Solve() - time_t startTime; + time_t startTime{}; EDSP::Request::Flags requestFlags; /// Various configuration options -- cgit v1.2.3-70-g09d2