14 #ifndef OR_TOOLS_SAT_LINEAR_CONSTRAINT_MANAGER_H_
15 #define OR_TOOLS_SAT_LINEAR_CONSTRAINT_MANAGER_H_
20 #include "absl/container/flat_hash_map.h"
21 #include "absl/container/flat_hash_set.h"
67 : sat_parameters_(*
model->GetOrCreate<SatParameters>()),
88 std::string extra_info =
"");
113 return constraint_infos_;
119 return lp_constraints_;
152 void ComputeObjectiveParallelism(
const ConstraintIndex ct_index);
157 void RescaleActiveCounts(
double scaling_factor);
161 void PermanentlyRemoveSomeConstraints();
163 const SatParameters& sat_parameters_;
167 bool current_lp_is_changed_ =
false;
170 int64 last_simplification_timestamp_ = 0;
175 std::vector<ConstraintIndex> lp_constraints_;
182 absl::flat_hash_map<size_t, ConstraintIndex> equiv_constraints_;
184 int64 num_simplifications_ = 0;
185 int64 num_merged_constraints_ = 0;
186 int64 num_shortened_constraints_ = 0;
187 int64 num_splitted_constraints_ = 0;
188 int64 num_coeff_strenghtening_ = 0;
191 int64 num_add_cut_calls_ = 0;
192 std::map<std::string, int> type_to_num_cuts_;
194 bool objective_is_defined_ =
false;
195 bool objective_norm_computed_ =
false;
196 double objective_l2_norm_ = 0.0;
216 double constraint_active_count_increase_ = 1.0;
218 int32 num_deletable_constraints_ = 0;
226 template <
typename Element>
229 explicit TopN(
int n) : n_(n) {}
236 void Add(Element e,
double score) {
237 if (heap_.size() < n_) {
238 const int index = elements_.size();
239 heap_.push_back({
index, score});
240 elements_.push_back(std::move(e));
241 if (heap_.size() == n_) {
243 std::make_heap(heap_.begin(), heap_.end());
246 if (score <= heap_.front().score)
return;
247 const int index_to_replace = heap_.front().index;
248 elements_[index_to_replace] = std::move(e);
251 std::pop_heap(heap_.begin(), heap_.end());
252 heap_.back() = {index_to_replace, score};
253 std::push_heap(heap_.begin(), heap_.end());
266 const double operator<(
const HeapElement& other)
const {
267 return score > other.score;
270 std::vector<HeapElement> heap_;
271 std::vector<Element> elements_;
295 struct CutCandidate {
299 TopN<CutCandidate> cuts_;
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
~LinearConstraintManager()
bool ChangeLp(const absl::StrongVector< IntegerVariable, double > &lp_solution, glop::BasisState *solution_state)
bool DebugCheckConstraint(const LinearConstraint &cut)
DEFINE_INT_TYPE(ConstraintIndex, int32)
int64 num_shortened_constraints() const
int64 num_coeff_strenghtening() const
void SetObjectiveCoefficient(IntegerVariable var, IntegerValue coeff)
ConstraintIndex Add(LinearConstraint ct, bool *added=nullptr)
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)
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
LinearConstraint constraint
double objective_parallelism
bool objective_parallelism_computed