 |
OR-Tools
8.0
|
Go to the documentation of this file.
14 #ifndef OR_TOOLS_SAT_CP_MODEL_LNS_H_
15 #define OR_TOOLS_SAT_CP_MODEL_LNS_H_
19 #include "absl/container/flat_hash_map.h"
20 #include "absl/synchronization/mutex.h"
21 #include "absl/types/span.h"
80 const CpSolverResponse& initial_solution,
81 const std::vector<int>& variables_to_fix)
const;
85 const std::vector<int>& constraints_to_remove)
const;
90 const CpSolverResponse& initial_solution,
91 const std::vector<int>& relaxed_variables)
const;
111 return constraint_to_var_;
114 return var_to_constraint_;
119 ConstraintProto::ConstraintCase type)
const {
120 if (type >= type_to_constraints_.size())
return {};
121 return absl::MakeSpan(type_to_constraints_[type]);
126 const CpModelProto&
ModelProto()
const {
return model_proto_; }
127 const SatParameters&
Parameters()
const {
return parameters_; }
138 return *shared_response_;
144 void RecomputeHelperData();
147 bool IsConstant(
int var)
const;
149 const SatParameters& parameters_;
150 const CpModelProto& model_proto_;
151 int shared_bounds_id_;
162 CpModelProto model_proto_with_only_variables_;
164 mutable absl::Mutex mutex_;
167 std::vector<std::vector<int>> type_to_constraints_;
170 std::vector<std::vector<int>> constraint_to_var_;
171 std::vector<std::vector<int>> var_to_constraint_;
177 std::vector<bool> active_variables_set_;
178 std::vector<int> active_variables_;
273 absl::MutexLock mutex_lock(&
mutex_);
274 solve_data_.push_back(data);
286 absl::MutexLock mutex_lock(&
mutex_);
292 absl::MutexLock mutex_lock(&
mutex_);
293 return num_fully_solved_calls_;
298 absl::MutexLock mutex_lock(&
mutex_);
299 return difficulty_.
value();
304 absl::MutexLock mutex_lock(&
mutex_);
305 return deterministic_limit_;
310 absl::MutexLock mutex_lock(&
mutex_);
311 return deterministic_time_;
325 std::vector<SolveData> solve_data_;
330 double deterministic_limit_ = 0.1;
334 int64 num_calls_ = 0;
335 int64 num_fully_solved_calls_ = 0;
336 int64 num_consecutive_non_improving_calls_ = 0;
337 double deterministic_time_ = 0.0;
338 double current_average_ = 0.0;
381 const absl::Span<const int> intervals_to_relax,
382 const CpSolverResponse& initial_solution,
383 const NeighborhoodGeneratorHelper& helper);
434 const std::string&
name)
436 response_manager_(response_manager),
440 CHECK(lp_solutions_ !=
nullptr || relaxation_solutions_ !=
nullptr ||
496 void AdditionalProcessingOnSynchronize(
const SolveData& solve_data)
override
497 ABSL_EXCLUSIVE_LOCKS_REQUIRED(
mutex_);
500 std::vector<double> constraint_weights_;
501 int num_removable_constraints_ = 0;
504 absl::flat_hash_map<int64, std::vector<int>> removed_constraints_
509 int64 next_available_id_ ABSL_GUARDED_BY(
mutex_) = 0;
515 #endif // OR_TOOLS_SAT_CP_MODEL_LNS_H_
std::function< void()> GenerateTask(int64 task_id) override
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
const NeighborhoodGeneratorHelper & helper_
SimpleNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
ConsecutiveConstraintsRelaxationNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
double deterministic_limit() const
bool TaskIsAvailable() override
bool IsRelaxationGenerator() const override
bool ReadyToGenerate() const override
const std::vector< std::vector< int > > & VarToConstraint() const
CpModelProto const * model_proto
VariableGraphNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
IntegerValue initial_best_objective
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
double GetUCBScore(int64 total_num_calls) const
const absl::Span< const int > TypeToConstraints(ConstraintProto::ConstraintCase type) const
const SatParameters & Parameters() const
Neighborhood FixGivenVariables(const CpSolverResponse &initial_solution, const std::vector< int > &variables_to_fix) const
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
Neighborhood RemoveMarkedConstraints(const std::vector< int > &constraints_to_remove) const
IntegerValue new_objective
const std::vector< int > & ActiveVariables() const
SharedRelaxationSolutionRepository * relaxation_solutions
const std::vector< std::vector< int > > & ConstraintToVar() const
Neighborhood GenerateSchedulingNeighborhoodForRelaxation(const absl::Span< const int > intervals_to_relax, const CpSolverResponse &initial_solution, const NeighborhoodGeneratorHelper &helper)
virtual ~NeighborhoodGenerator()
const SharedResponseManager & shared_response() const
virtual bool ReadyToGenerate() const
double deterministic_time
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
SchedulingNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
Neighborhood FullNeighborhood() const
bool operator<(const SolveData &o) const
SharedLPSolutionRepository * lp_solutions
absl::Mutex * MutableMutex() const
bool ReadyToGenerate() const override
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
IntegerValue new_objective_bound
WeightedRandomRelaxationNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
bool IsRelaxationGenerator() const override
IntegerValue initial_best_objective_bound
double deterministic_limit
double difficulty() const
Neighborhood FixAllVariables(const CpSolverResponse &initial_solution) const
ConstraintGraphNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
const CpModelProto & ModelProto() const
Neighborhood RelaxGivenVariables(const CpSolverResponse &initial_solution, const std::vector< int > &relaxed_variables) const
virtual bool IsRelaxationGenerator() const
NeighborhoodGeneratorHelper(CpModelProto const *model_proto, SatParameters const *parameters, SharedResponseManager *shared_response, SharedTimeLimit *shared_time_limit=nullptr, SharedBoundsManager *shared_bounds=nullptr)
bool ReadyToGenerate() const override
int64 num_fully_solved_calls() const
bool IsActive(int var) const
RelaxationInducedNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const SharedResponseManager *response_manager, const SharedRelaxationSolutionRepository *relaxation_solutions, const SharedLPSolutionRepository *lp_solutions, SharedIncompleteSolutionManager *incomplete_solutions, const std::string &name)
SchedulingTimeWindowNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
virtual void AdditionalProcessingOnSynchronize(const SolveData &solve_data)
void AddSolveData(SolveData data)
double deterministic_time() const
virtual Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random)=0
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
SharedIncompleteSolutionManager * incomplete_solutions
NeighborhoodGenerator(const std::string &name, NeighborhoodGeneratorHelper const *helper)
std::mt19937 random_engine_t
void Synchronize() override
IntegerValue base_objective