122 int MaxLevel()
const {
return decision_indexes_.size(); }
127 CHECK_LE(level, decision_indexes_.size());
128 return literals_[decision_indexes_[level - 1]];
132 absl::Span<const int>
NodeIds(
int level)
const;
136 absl::Span<const ProtoLiteral>
Implications(
int level)
const;
138 auto it = implication_level_.find(implication);
139 if (it != implication_level_.end() && it->second <= level)
return;
140 MutableImplications(level).push_back(implication);
141 implication_level_[implication] = level;
146 return level_to_objective_lbs_[level - 1];
149 absl::Span<const ProtoLiteral>
Literals()
const {
return literals_; }
151 const std::vector<ProtoLiteral>&
TargetPhase()
const {
return target_phase_; }
155 if (target_phase_.size() >= kMaxPhaseSize)
return false;
156 if (!implication_level_.contains(lit)) {
157 target_phase_.push_back(lit);
170 static constexpr int kMaxPhaseSize = 256;
172 std::vector<ProtoLiteral>& MutableImplications(
int level) {
173 return implications_[level - 1];
176 std::vector<ProtoLiteral> literals_;
177 std::vector<int> node_ids_;
181 std::vector<std::vector<ProtoLiteral>> implications_;
182 absl::flat_hash_map<ProtoLiteral, int> implication_level_;
185 std::vector<int> decision_indexes_;
188 std::vector<IntegerValue> level_to_objective_lbs_;
190 std::vector<ProtoLiteral> target_phase_;
206 int NumNodes() const ABSL_LOCKS_EXCLUDED(mu_);
225 absl::MutexLock l(&mu_);
234 struct NodeTrailInfo {
236 absl::flat_hash_map<int, IntegerValue> implications;
239 std::vector<ProtoLiteral> phase;
242 ProtoLiteral literal;
244 Node* parent =
nullptr;
245 std::array<Node*, 2> children = {
nullptr,
nullptr};
249 bool implied =
false;
251 std::unique_ptr<NodeTrailInfo> trail_info;
253 bool IsValid(
const ProtoTrail& path)
const ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
254 Node* GetSibling(Node* node) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
257 NodeTrailInfo* GetTrailInfo(Node* node);
258 void Split(std::vector<std::pair<Node*, int>>& nodes, ProtoLiteral lit)
259 ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
260 Node* MakeSubtree(Node* parent, ProtoLiteral literal)
261 ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
262 void ProcessNodeChanges() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
263 std::vector<std::pair<Node*,
int>> GetAssignedNodes(const ProtoTrail& path)
264 ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
265 void AssignLeaf(ProtoTrail& path, Node* leaf)
266 ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
267 void RestartLockHeld() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
268 std::
string ShortStatus() const ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
270 mutable absl::Mutex mu_;
271 const SatParameters& params_;
272 const
int num_workers_;
273 SharedResponseManager* const shared_response_manager_;
276 int node_id_offset_ ABSL_GUARDED_BY(mu_) = 0;
279 std::deque<Node> nodes_ ABSL_GUARDED_BY(mu_);
280 std::vector<Node*> unassigned_leaves_ ABSL_GUARDED_BY(mu_);
284 int num_splits_wanted_ ABSL_GUARDED_BY(mu_);
289 const
int max_nodes_;
290 int num_leaves_assigned_ ABSL_GUARDED_BY(mu_) = 0;
294 std::vector<Node*> to_close_ ABSL_GUARDED_BY(mu_);
295 std::vector<Node*> to_update_ ABSL_GUARDED_BY(mu_);
297 int64_t num_restarts_ ABSL_GUARDED_BY(mu_) = 0;
298 int64_t num_syncs_since_restart_ ABSL_GUARDED_BY(mu_) = 0;
299 int num_closed_nodes_ ABSL_GUARDED_BY(mu_) = 0;
309 const std::function<
void()>& feasible_solution_observer);
315 bool SyncWithLocalTrail();
316 bool SyncWithSharedTree();
318 std::optional<ProtoLiteral> EncodeDecision(
Literal decision);
319 bool NextDecision(LiteralIndex* decision_index);
320 void MaybeProposeSplit();
321 bool ShouldReplaceSubtree();
322 bool FinishedMinRestarts()
const {
323 return assigned_tree_.MaxLevel() > 0 &&
324 restart_policy_->NumRestarts() >=
325 parameters_->shared_tree_worker_min_restarts_per_subtree();
330 bool AddImplications();
331 bool AddDecisionImplication(
Literal literal,
int level);
333 const std::vector<Literal>& DecisionReason(
int level);
335 SatParameters* parameters_;
353 int64_t num_trees_ = 0;
356 std::vector<Literal> assigned_tree_literals_;
357 std::vector<std::vector<Literal>> assigned_tree_implications_;
363 bool new_split_available_ =
false;
365 std::vector<Literal> reason_;
371 double earliest_replacement_dtime_ = 0;
374 int reversible_trail_index_ = 0;
377 std::deque<int> rev_num_processed_implications_;