Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
cp_model_solver_logging.h
Go to the documentation of this file.
1// Copyright 2010-2025 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14#ifndef ORTOOLS_SAT_CP_MODEL_SOLVER_LOGGING_H_
15#define ORTOOLS_SAT_CP_MODEL_SOLVER_LOGGING_H_
16
17#include <string>
18
19#include "absl/container/btree_map.h"
20#include "ortools/base/timer.h"
21#include "ortools/sat/model.h"
24
25namespace operations_research {
26namespace sat {
27
28// This class implements the standard logging of the solver progress to the
29// SolverLogger object in the model, typically enabled by setting
30// SatParameters.log_search_progress to true.
32 public:
33 explicit SolverProgressLogger(Model* model)
34 : wall_timer_(*model->GetOrCreate<WallTimer>()),
35 logger_(model->GetOrCreate<SolverLogger>()) {
36 bounds_logging_id_ = logger_->GetNewThrottledId();
37 }
38
39 void UpdateProgress(const SolverStatusChangeInfo& info);
40
41 void SetIsOptimization(bool is_optimization) {
42 is_optimization_ = is_optimization;
43 }
44
46
47 private:
48 void RegisterSolutionFound(const std::string& improvement_info,
49 int solution_number);
50 void RegisterObjectiveBoundImprovement(const std::string& improvement_info);
51
52 const WallTimer& wall_timer_;
53 SolverLogger* logger_;
54 bool is_optimization_ = false;
55 int bounds_logging_id_;
56
57 int num_solutions_ = 0;
58
59 absl::btree_map<std::string, int> primal_improvements_count_;
60 absl::btree_map<std::string, int> primal_improvements_min_rank_;
61 absl::btree_map<std::string, int> primal_improvements_max_rank_;
62 absl::btree_map<std::string, int> dual_improvements_count_;
63};
64
65} // namespace sat
66} // namespace operations_research
67
68#endif // ORTOOLS_SAT_CP_MODEL_SOLVER_LOGGING_H_
void UpdateProgress(const SolverStatusChangeInfo &info)
void DisplayImprovementStatistics(SolverLogger *logger) const
OR-Tools root namespace.