14#ifndef OR_TOOLS_SAT_LINEAR_CONSTRAINT_MANAGER_H_
15#define OR_TOOLS_SAT_LINEAR_CONSTRAINT_MANAGER_H_
24#include "absl/container/btree_map.h"
25#include "absl/container/flat_hash_map.h"
26#include "absl/container/flat_hash_set.h"
27#include "absl/strings/string_view.h"
33#include "ortools/sat/sat_parameters.pb.h"
76 : sat_parameters_(*
model->GetOrCreate<SatParameters>()),
97 std::string extra_info =
"");
125 return constraint_infos_;
131 return lp_constraints_;
136 return num_shortened_constraints_;
169 void ComputeObjectiveParallelism(
const ConstraintIndex ct_index);
174 void RescaleActiveCounts(
double scaling_factor);
178 void PermanentlyRemoveSomeConstraints();
180 const SatParameters& sat_parameters_;
184 bool current_lp_is_changed_ =
false;
187 int64_t last_simplification_timestamp_ = 0;
192 std::vector<ConstraintIndex> lp_constraints_;
199 absl::flat_hash_map<size_t, ConstraintIndex> equiv_constraints_;
201 int64_t num_simplifications_ = 0;
202 int64_t num_merged_constraints_ = 0;
203 int64_t num_shortened_constraints_ = 0;
204 int64_t num_splitted_constraints_ = 0;
205 int64_t num_coeff_strenghtening_ = 0;
207 int64_t num_cuts_ = 0;
208 int64_t num_add_cut_calls_ = 0;
209 absl::btree_map<std::string, int> type_to_num_cuts_;
211 bool objective_is_defined_ =
false;
212 bool objective_norm_computed_ =
false;
213 double objective_l2_norm_ = 0.0;
222 double sum_of_squared_objective_coeffs_ = 0.0;
223 absl::flat_hash_map<IntegerVariable, double> objective_map_;
236 double constraint_active_count_increase_ = 1.0;
238 int32_t num_deletable_constraints_ = 0;
246template <
typename Element>
249 explicit TopN(
int n) : n_(n) {}
256 void Add(Element e,
double score) {
257 if (heap_.size() < n_) {
258 const int index = elements_.size();
259 heap_.push_back({
index, score});
260 elements_.push_back(std::move(e));
261 if (heap_.size() == n_) {
263 std::make_heap(heap_.begin(), heap_.end());
266 if (score <= heap_.front().score)
return;
267 const int index_to_replace = heap_.front().index;
268 elements_[index_to_replace] = std::move(e);
271 std::pop_heap(heap_.begin(), heap_.end());
272 heap_.back() = {index_to_replace, score};
273 std::push_heap(heap_.begin(), heap_.end());
286 const double operator<(
const HeapElement& other)
const {
287 return score > other.score;
290 std::vector<HeapElement> heap_;
291 std::vector<Element> elements_;
315 struct CutCandidate {
319 TopN<CutCandidate> cuts_;
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
int64_t num_coeff_strenghtening() const
bool ChangeLp(const absl::StrongVector< IntegerVariable, double > &lp_solution, glop::BasisState *solution_state)
bool DebugCheckConstraint(const LinearConstraint &cut)
void SetObjectiveCoefficient(IntegerVariable var, IntegerValue coeff)
ConstraintIndex Add(LinearConstraint ct, bool *added=nullptr)
int64_t num_shortened_constraints() const
DEFINE_STRONG_INDEX_TYPE(ConstraintIndex)
const std::vector< ConstraintIndex > & LpConstraints() const
std::string Statistics() const
void AddAllConstraintsToLp()
bool AddCut(LinearConstraint ct, std::string type_name, const absl::StrongVector< IntegerVariable, double > &lp_solution, std::string extra_info="")
const absl::StrongVector< ConstraintIndex, ConstraintInfo > & AllConstraints() const
LinearConstraintManager(Model *model)
Class that owns everything related to a particular optimization model.
void AddCut(LinearConstraint ct, const std::string &name, const absl::StrongVector< IntegerVariable, double > &lp_solution)
void TransferToManager(const absl::StrongVector< IntegerVariable, double > &lp_solution, LinearConstraintManager *manager)
const std::vector< Element > & UnorderedElements() const
void Add(Element e, double score)
Collection of objects used to extend the Constraint Solver library.
LinearConstraint constraint
double objective_parallelism
bool objective_parallelism_computed