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"
26 #include "ortools/sat/sat_parameters.pb.h"
67 : sat_parameters_(*
model->GetOrCreate<SatParameters>()),
88 std::string extra_info =
"");
116 return constraint_infos_;
122 return lp_constraints_;
155 void ComputeObjectiveParallelism(
const ConstraintIndex ct_index);
160 void RescaleActiveCounts(
double scaling_factor);
164 void PermanentlyRemoveSomeConstraints();
166 const SatParameters& sat_parameters_;
170 bool current_lp_is_changed_ =
false;
173 int64 last_simplification_timestamp_ = 0;
178 std::vector<ConstraintIndex> lp_constraints_;
185 absl::flat_hash_map<size_t, ConstraintIndex> equiv_constraints_;
187 int64 num_simplifications_ = 0;
188 int64 num_merged_constraints_ = 0;
189 int64 num_shortened_constraints_ = 0;
190 int64 num_splitted_constraints_ = 0;
191 int64 num_coeff_strenghtening_ = 0;
194 int64 num_add_cut_calls_ = 0;
195 std::map<std::string, int> type_to_num_cuts_;
197 bool objective_is_defined_ =
false;
198 bool objective_norm_computed_ =
false;
199 double objective_l2_norm_ = 0.0;
208 double sum_of_squared_objective_coeffs_ = 0.0;
209 absl::flat_hash_map<IntegerVariable, double> objective_map_;
221 double constraint_active_count_increase_ = 1.0;
223 int32 num_deletable_constraints_ = 0;
231 template <
typename Element>
234 explicit TopN(
int n) : n_(n) {}
241 void Add(Element e,
double score) {
242 if (heap_.size() < n_) {
243 const int index = elements_.size();
244 heap_.push_back({
index, score});
245 elements_.push_back(std::move(e));
246 if (heap_.size() == n_) {
248 std::make_heap(heap_.begin(), heap_.end());
251 if (score <= heap_.front().score)
return;
252 const int index_to_replace = heap_.front().index;
253 elements_[index_to_replace] = std::move(e);
256 std::pop_heap(heap_.begin(), heap_.end());
257 heap_.back() = {index_to_replace, score};
258 std::push_heap(heap_.begin(), heap_.end());
271 const double operator<(
const HeapElement& other)
const {
272 return score > other.score;
275 std::vector<HeapElement> heap_;
276 std::vector<Element> elements_;
300 struct CutCandidate {
304 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