14 #ifndef OR_TOOLS_SAT_LINEAR_CONSTRAINT_MANAGER_H_
15 #define OR_TOOLS_SAT_LINEAR_CONSTRAINT_MANAGER_H_
21 #include "absl/container/flat_hash_map.h"
22 #include "absl/container/flat_hash_set.h"
69 : sat_parameters_(*
model->GetOrCreate<SatParameters>()),
91 std::string extra_info =
"");
119 return constraint_infos_;
125 return lp_constraints_;
130 return num_shortened_constraints_;
160 void ComputeObjectiveParallelism(
const ConstraintIndex ct_index);
165 void RescaleActiveCounts(
double scaling_factor);
169 void PermanentlyRemoveSomeConstraints();
171 const SatParameters& sat_parameters_;
175 bool current_lp_is_changed_ =
false;
178 int64_t last_simplification_timestamp_ = 0;
183 std::vector<ConstraintIndex> lp_constraints_;
190 absl::flat_hash_map<size_t, ConstraintIndex> equiv_constraints_;
192 int64_t num_simplifications_ = 0;
193 int64_t num_merged_constraints_ = 0;
194 int64_t num_shortened_constraints_ = 0;
195 int64_t num_splitted_constraints_ = 0;
196 int64_t num_coeff_strenghtening_ = 0;
198 int64_t num_cuts_ = 0;
199 int64_t num_add_cut_calls_ = 0;
200 std::map<std::string, int> type_to_num_cuts_;
202 bool objective_is_defined_ =
false;
203 bool objective_norm_computed_ =
false;
204 double objective_l2_norm_ = 0.0;
213 double sum_of_squared_objective_coeffs_ = 0.0;
214 absl::flat_hash_map<IntegerVariable, double> objective_map_;
227 double constraint_active_count_increase_ = 1.0;
229 int32_t num_deletable_constraints_ = 0;
237 template <
typename Element>
240 explicit TopN(
int n) : n_(n) {}
247 void Add(Element e,
double score) {
248 if (heap_.size() < n_) {
249 const int index = elements_.size();
250 heap_.push_back({
index, score});
251 elements_.push_back(std::move(e));
252 if (heap_.size() == n_) {
254 std::make_heap(heap_.begin(), heap_.end());
257 if (score <= heap_.front().score)
return;
258 const int index_to_replace = heap_.front().index;
259 elements_[index_to_replace] = std::move(e);
262 std::pop_heap(heap_.begin(), heap_.end());
263 heap_.back() = {index_to_replace, score};
264 std::push_heap(heap_.begin(), heap_.end());
277 const double operator<(
const HeapElement& other)
const {
278 return score > other.score;
281 std::vector<HeapElement> heap_;
282 std::vector<Element> elements_;
306 struct CutCandidate {
310 TopN<CutCandidate> cuts_;
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
~LinearConstraintManager()
int64_t num_coeff_strenghtening() const
DEFINE_INT_TYPE(ConstraintIndex, int32_t)
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
const absl::StrongVector< ConstraintIndex, ConstraintInfo > & AllConstraints() const
const std::vector< ConstraintIndex > & LpConstraints() const
void AddAllConstraintsToLp()
bool AddCut(LinearConstraint ct, std::string type_name, const absl::StrongVector< IntegerVariable, double > &lp_solution, std::string extra_info="")
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