OR-Tools  8.0
cp_model_lns.h
Go to the documentation of this file.
1 // Copyright 2010-2018 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #ifndef OR_TOOLS_SAT_CP_MODEL_LNS_H_
15 #define OR_TOOLS_SAT_CP_MODEL_LNS_H_
16 
17 #include <vector>
18 
19 #include "absl/container/flat_hash_map.h"
20 #include "absl/synchronization/mutex.h"
21 #include "absl/types/span.h"
24 #include "ortools/sat/model.h"
25 #include "ortools/sat/subsolver.h"
29 
30 namespace operations_research {
31 namespace sat {
32 
33 // Neighborhood returned by Neighborhood generators.
34 struct Neighborhood {
35  // True if neighborhood generator was able to generate a neighborhood.
36  bool is_generated = false;
37 
38  // True if the CpModelProto below is not the same as the base model.
39  // This is not expected to happen often but allows to handle this case
40  // properly.
41  bool is_reduced = false;
42 
43  // Relaxed model. Any feasible solution to this "local" model should be a
44  // feasible solution to the base model too.
45  CpModelProto cp_model;
46 
47  // Neighborhood Id. Used to identify the neighborhood by a generator.
48  // Currently only used by WeightedRandomRelaxationNeighborhoodGenerator.
49  // TODO(user): Make sure that the id is unique for each generated
50  // neighborhood for each generator.
51  int64 id = 0;
52 
53  // Used for identifying the source of the neighborhood if it is generated
54  // using solution repositories.
55  std::string source_info = "";
56 };
57 
58 // Contains pre-computed information about a given CpModelProto that is meant
59 // to be used to generate LNS neighborhood. This class can be shared between
60 // more than one generator in order to reduce memory usage.
61 //
62 // Note that its implement the SubSolver interface to be able to Synchronize()
63 // the bounds of the base problem with the external world.
65  public:
66  NeighborhoodGeneratorHelper(CpModelProto const* model_proto,
67  SatParameters const* parameters,
69  SharedTimeLimit* shared_time_limit = nullptr,
70  SharedBoundsManager* shared_bounds = nullptr);
71 
72  // SubSolver interface.
73  bool TaskIsAvailable() override { return false; }
74  std::function<void()> GenerateTask(int64 task_id) override { return {}; }
75  void Synchronize() override;
76 
77  // Returns the LNS fragment where the given variables are fixed to the value
78  // they take in the given solution.
80  const CpSolverResponse& initial_solution,
81  const std::vector<int>& variables_to_fix) const;
82 
83  // Returns the neighborhood where the given constraints are removed.
85  const std::vector<int>& constraints_to_remove) const;
86 
87  // Returns the LNS fragment which will relax all inactive variables and all
88  // variables in relaxed_variables.
90  const CpSolverResponse& initial_solution,
91  const std::vector<int>& relaxed_variables) const;
92 
93  // Returns a trivial model by fixing all active variables to the initial
94  // solution values.
95  Neighborhood FixAllVariables(const CpSolverResponse& initial_solution) const;
96 
97  // Return a neighborhood that correspond to the full problem.
99 
100  // Indicates if the variable can be frozen. It happens if the variable is non
101  // constant, and if it is a decision variable, or if
102  // focus_on_decision_variables is false.
103  bool IsActive(int var) const;
104 
105  // Returns the list of "active" variables.
106  const std::vector<int>& ActiveVariables() const { return active_variables_; }
107 
108  // Constraints <-> Variables graph.
109  // Note that only non-constant variable are listed here.
110  const std::vector<std::vector<int>>& ConstraintToVar() const {
111  return constraint_to_var_;
112  }
113  const std::vector<std::vector<int>>& VarToConstraint() const {
114  return var_to_constraint_;
115  }
116 
117  // Returns all the constraints indices of a given type.
118  const absl::Span<const int> TypeToConstraints(
119  ConstraintProto::ConstraintCase type) const {
120  if (type >= type_to_constraints_.size()) return {};
121  return absl::MakeSpan(type_to_constraints_[type]);
122  }
123 
124  // The initial problem.
125  // Note that the domain of the variables are not updated here.
126  const CpModelProto& ModelProto() const { return model_proto_; }
127  const SatParameters& Parameters() const { return parameters_; }
128 
129  // This mutex must be acquired before calling any of the function that access
130  // data that can be updated by Synchronize().
131  //
132  // TODO(user): Refactor the class to be thread-safe instead, it should be
133  // safer and more easily maintenable. Some complication with accessing the
134  // variable<->constraint graph efficiently though.
135  absl::Mutex* MutableMutex() const { return &mutex_; }
136 
138  return *shared_response_;
139  }
140 
141  private:
142  // Recompute most of the class member. This needs to be called when the
143  // domains of the variables are updated.
144  void RecomputeHelperData();
145 
146  // Indicates if a variable is fixed in the model.
147  bool IsConstant(int var) const;
148 
149  const SatParameters& parameters_;
150  const CpModelProto& model_proto_;
151  int shared_bounds_id_;
152  SharedTimeLimit* shared_time_limit_;
153  SharedBoundsManager* shared_bounds_;
154  SharedResponseManager* shared_response_;
155  SharedRelaxationSolutionRepository* shared_relaxation_solutions_;
156 
157  // This proto will only contain the field variables() with an updated version
158  // of the domains compared to model_proto_.variables(). We do it like this to
159  // reduce the memory footprint of the helper when the model is large.
160  //
161  // TODO(user): Use custom domain repository rather than a proto?
162  CpModelProto model_proto_with_only_variables_;
163 
164  mutable absl::Mutex mutex_;
165 
166  // Constraints by types.
167  std::vector<std::vector<int>> type_to_constraints_;
168 
169  // Variable-Constraint graph.
170  std::vector<std::vector<int>> constraint_to_var_;
171  std::vector<std::vector<int>> var_to_constraint_;
172 
173  // The set of active variables, that is the list of non constant variables if
174  // parameters_.focus_on_decision_variables() is false, or the list of non
175  // constant decision variables otherwise. It is stored both as a list and as a
176  // set (using a Boolean vector).
177  std::vector<bool> active_variables_set_;
178  std::vector<int> active_variables_;
179 };
180 
181 // Base class for a CpModelProto neighborhood generator.
183  public:
184  NeighborhoodGenerator(const std::string& name,
185  NeighborhoodGeneratorHelper const* helper)
186  : name_(name), helper_(*helper), difficulty_(0.5) {}
188 
189  // Generates a "local" subproblem for the given seed.
190  //
191  // The difficulty will be in [0, 1] and is related to the asked neighborhood
192  // size (and thus local problem difficulty). A difficulty of 0.0 means empty
193  // neighborhood and a difficulty of 1.0 means the full problem. The algorithm
194  // should try to generate a neighborhood according to this difficulty which
195  // will be dynamically adjusted depending on whether or not we can solve the
196  // subproblem in a given time limit.
197  //
198  // The given initial_solution should contain a feasible solution to the
199  // initial CpModelProto given to this class. Any solution to the returned
200  // CPModelProto should also be valid solution to the same initial model.
201  //
202  // This function should be thread-safe.
203  virtual Neighborhood Generate(const CpSolverResponse& initial_solution,
204  double difficulty, random_engine_t* random) = 0;
205 
206  // Returns true if the neighborhood generator can generate a neighborhood.
207  virtual bool ReadyToGenerate() const;
208 
209  // Returns true if the neighborhood generator generates relaxation of the
210  // given problem.
211  virtual bool IsRelaxationGenerator() const { return false; }
212 
213  // Uses UCB1 algorithm to compute the score (Multi armed bandit problem).
214  // Details are at
215  // https://lilianweng.github.io/lil-log/2018/01/23/the-multi-armed-bandit-problem-and-its-solutions.html.
216  // 'total_num_calls' should be the sum of calls across all generators part of
217  // the multi armed bandit problem.
218  // If the generator is called less than 10 times then the method returns
219  // infinity as score in order to get more data about the generator
220  // performance.
221  double GetUCBScore(int64 total_num_calls) const;
222 
223  // Adds solve data about one "solved" neighborhood.
224  struct SolveData {
225  // Neighborhood Id. Used to identify the neighborhood by a generator.
226  // Currently only used by WeightedRandomRelaxationNeighborhoodGenerator.
228 
229  // The status of the sub-solve.
231 
232  // The difficulty when this neighborhood was generated.
233  double difficulty = 0.0;
234 
235  // The determinitic time limit given to the solver for this neighborhood.
236  double deterministic_limit = 0.0;
237 
238  // The time it took to solve this neighborhood.
239  double deterministic_time = 0.0;
240 
241  // Objective information. These only refer to the "internal" objective
242  // without scaling or offset so we are exact and it is always in the
243  // minimization direction.
244  // - The initial best objective is the one of the best known solution at the
245  // time the neighborhood was generated.
246  // - The base objective is the one of the base solution from which this
247  // neighborhood was generated.
248  // - The new objective is the objective of the best solution found by
249  // solving the neighborhood.
250  IntegerValue initial_best_objective = IntegerValue(0);
251  IntegerValue base_objective = IntegerValue(0);
252  IntegerValue new_objective = IntegerValue(0);
253 
254  // Bounds data is only used by relaxation neighborhoods.
255  IntegerValue initial_best_objective_bound = IntegerValue(0);
256  IntegerValue new_objective_bound = IntegerValue(0);
257 
258  // This is just used to construct a deterministic order for the updates.
259  bool operator<(const SolveData& o) const {
260  return std::tie(status, difficulty, deterministic_limit,
264  neighborhood_id) <
265  std::tie(o.status, o.difficulty, o.deterministic_limit,
269  o.neighborhood_id);
270  }
271  };
272  void AddSolveData(SolveData data) {
273  absl::MutexLock mutex_lock(&mutex_);
274  solve_data_.push_back(data);
275  }
276 
277  // Process all the recently added solve data and update this generator
278  // score and difficulty.
279  void Synchronize();
280 
281  // Returns a short description of the generator.
282  std::string name() const { return name_; }
283 
284  // Number of times this generator was called.
285  int64 num_calls() const {
286  absl::MutexLock mutex_lock(&mutex_);
287  return num_calls_;
288  }
289 
290  // Number of time the neighborhood was fully solved (OPTIMAL/INFEASIBLE).
292  absl::MutexLock mutex_lock(&mutex_);
293  return num_fully_solved_calls_;
294  }
295 
296  // The current difficulty of this generator
297  double difficulty() const {
298  absl::MutexLock mutex_lock(&mutex_);
299  return difficulty_.value();
300  }
301 
302  // The current time limit that the sub-solve should use on this generator.
303  double deterministic_limit() const {
304  absl::MutexLock mutex_lock(&mutex_);
305  return deterministic_limit_;
306  }
307 
308  // The sum of the deterministic time spent in this generator.
309  double deterministic_time() const {
310  absl::MutexLock mutex_lock(&mutex_);
311  return deterministic_time_;
312  }
313 
314  protected:
315  // Triggered with each call to Synchronize() for each recently added
316  // SolveData. This is meant to be used for processing feedbacks by specific
317  // neighborhood generators to adjust the neighborhood generation process.
318  virtual void AdditionalProcessingOnSynchronize(const SolveData& solve_data) {}
319 
320  const std::string name_;
322  mutable absl::Mutex mutex_;
323 
324  private:
325  std::vector<SolveData> solve_data_;
326 
327  // Current parameters to be used when generating/solving a neighborhood with
328  // this generator. Only updated on Synchronize().
329  AdaptiveParameterValue difficulty_;
330  double deterministic_limit_ = 0.1;
331 
332  // Current statistics of the last solved neighborhood.
333  // Only updated on Synchronize().
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;
339 };
340 
341 // Pick a random subset of variables.
343  public:
345  NeighborhoodGeneratorHelper const* helper, const std::string& name)
346  : NeighborhoodGenerator(name, helper) {}
347  Neighborhood Generate(const CpSolverResponse& initial_solution,
348  double difficulty, random_engine_t* random) final;
349 };
350 
351 // Pick a random subset of variables that are constructed by a BFS in the
352 // variable <-> constraint graph. That is, pick a random variable, then all the
353 // variable connected by some constraint to the first one, and so on. The
354 // variable of the last "level" are selected randomly.
356  public:
358  NeighborhoodGeneratorHelper const* helper, const std::string& name)
359  : NeighborhoodGenerator(name, helper) {}
360  Neighborhood Generate(const CpSolverResponse& initial_solution,
361  double difficulty, random_engine_t* random) final;
362 };
363 
364 // Pick a random subset of constraint and relax all of their variables. We are a
365 // bit smarter than this because after the first contraint is selected, we only
366 // select constraints that share at least one variable with the already selected
367 // constraints. The variable from the "last" constraint are selected randomly.
369  public:
371  NeighborhoodGeneratorHelper const* helper, const std::string& name)
372  : NeighborhoodGenerator(name, helper) {}
373  Neighborhood Generate(const CpSolverResponse& initial_solution,
374  double difficulty, random_engine_t* random) final;
375 };
376 
377 // Helper method for the scheduling neighborhood generators. Returns the model
378 // as neighborhood for the given set of intervals to relax. For each no_overlap
379 // constraints, it adds strict relation order between the non-relaxed intervals.
381  const absl::Span<const int> intervals_to_relax,
382  const CpSolverResponse& initial_solution,
383  const NeighborhoodGeneratorHelper& helper);
384 
385 // Only make sense for scheduling problem. This select a random set of interval
386 // of the problem according to the difficulty. Then, for each no_overlap
387 // constraints, it adds strict relation order between the non-relaxed intervals.
388 //
389 // TODO(user): Also deal with cumulative constraint.
391  public:
393  NeighborhoodGeneratorHelper const* helper, const std::string& name)
394  : NeighborhoodGenerator(name, helper) {}
395 
396  Neighborhood Generate(const CpSolverResponse& initial_solution,
397  double difficulty, random_engine_t* random) final;
398 };
399 
400 // Similar to SchedulingNeighborhoodGenerator except the set of intervals that
401 // are relaxed are from a specific random time interval.
403  public:
405  NeighborhoodGeneratorHelper const* helper, const std::string& name)
406  : NeighborhoodGenerator(name, helper) {}
407 
408  Neighborhood Generate(const CpSolverResponse& initial_solution,
409  double difficulty, random_engine_t* random) final;
410 };
411 
412 // Generates a neighborhood by fixing the variables to solutions reported in
413 // various repositories. This is inspired from RINS published in "Exploring
414 // relaxation induced neighborhoods to improve MIP solutions" 2004 by E. Danna
415 // et.
416 //
417 // If incomplete_solutions is provided, this generates a neighborhood by fixing
418 // the variable values to a solution in the SharedIncompleteSolutionManager and
419 // ignores the other repositories.
420 //
421 // Otherwise, if response_manager is not provided, this generates a neighborhood
422 // using only the linear/general relaxation values. The domain of the variables
423 // are reduced to the integer values around their lp solution/relaxation
424 // solution values. This was published in "RENS – The Relaxation Enforced
425 // Neighborhood" 2009 by Timo Berthold.
427  public:
429  NeighborhoodGeneratorHelper const* helper,
430  const SharedResponseManager* response_manager,
434  const std::string& name)
435  : NeighborhoodGenerator(name, helper),
436  response_manager_(response_manager),
437  relaxation_solutions_(relaxation_solutions),
438  lp_solutions_(lp_solutions),
439  incomplete_solutions_(incomplete_solutions) {
440  CHECK(lp_solutions_ != nullptr || relaxation_solutions_ != nullptr ||
441  incomplete_solutions != nullptr);
442  }
443 
444  // Both initial solution and difficulty values are ignored.
445  Neighborhood Generate(const CpSolverResponse& initial_solution,
446  double difficulty, random_engine_t* random) final;
447 
448  // Returns true if the required solutions are available.
449  bool ReadyToGenerate() const override;
450 
451  private:
452  const SharedResponseManager* response_manager_;
453  const SharedRelaxationSolutionRepository* relaxation_solutions_;
454  const SharedLPSolutionRepository* lp_solutions_;
455  SharedIncompleteSolutionManager* incomplete_solutions_;
456 };
457 
458 // Generates a relaxation of the original model by removing a consecutive span
459 // of constraints starting at a random index. The number of constraints removed
460 // is in sync with the difficulty passed to the generator.
462  : public NeighborhoodGenerator {
463  public:
465  NeighborhoodGeneratorHelper const* helper, const std::string& name)
466  : NeighborhoodGenerator(name, helper) {}
467  Neighborhood Generate(const CpSolverResponse& initial_solution,
468  double difficulty, random_engine_t* random) final;
469 
470  bool IsRelaxationGenerator() const override { return true; }
471  bool ReadyToGenerate() const override { return true; }
472 };
473 
474 // Generates a relaxation of the original model by removing some constraints
475 // randomly with a given weight for each constraint that controls the
476 // probability of constraint getting removed. The number of constraints removed
477 // is in sync with the difficulty passed to the generator. Higher weighted
478 // constraints are more likely to get removed.
480  : public NeighborhoodGenerator {
481  public:
483  NeighborhoodGeneratorHelper const* helper, const std::string& name);
484 
485  // Generates the neighborhood as described above. Also stores the removed
486  // constraints indices for adjusting the weights.
487  Neighborhood Generate(const CpSolverResponse& initial_solution,
488  double difficulty, random_engine_t* random) final;
489 
490  bool IsRelaxationGenerator() const override { return true; }
491  bool ReadyToGenerate() const override { return true; }
492 
493  private:
494  // Adjusts the weights of the constraints removed to get the neighborhood
495  // based on the solve_data.
496  void AdditionalProcessingOnSynchronize(const SolveData& solve_data) override
497  ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
498 
499  // Higher weighted constraints are more likely to get removed.
500  std::vector<double> constraint_weights_;
501  int num_removable_constraints_ = 0;
502 
503  // Indices of the removed constraints per generated neighborhood.
504  absl::flat_hash_map<int64, std::vector<int>> removed_constraints_
505  ABSL_GUARDED_BY(mutex_);
506 
507  // TODO(user): Move this to parent class if other generators start using
508  // feedbacks.
509  int64 next_available_id_ ABSL_GUARDED_BY(mutex_) = 0;
510 };
511 
512 } // namespace sat
513 } // namespace operations_research
514 
515 #endif // OR_TOOLS_SAT_CP_MODEL_LNS_H_
synchronization.h
operations_research::sat::Neighborhood::source_info
std::string source_info
Definition: cp_model_lns.h:55
var
IntVar * var
Definition: expr_array.cc:1858
operations_research::sat::NeighborhoodGeneratorHelper::GenerateTask
std::function< void()> GenerateTask(int64 task_id) override
Definition: cp_model_lns.h:74
operations_research::sat::NeighborhoodGenerator::name
std::string name() const
Definition: cp_model_lns.h:282
operations_research::sat::WeightedRandomRelaxationNeighborhoodGenerator::Generate
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
Definition: cp_model_lns.cc:842
integral_types.h
operations_research::sat::NeighborhoodGenerator::helper_
const NeighborhoodGeneratorHelper & helper_
Definition: cp_model_lns.h:321
cp_model.pb.h
subsolver.h
operations_research::sat::NeighborhoodGenerator::Synchronize
void Synchronize()
Definition: cp_model_lns.cc:256
operations_research::SharedTimeLimit
Definition: time_limit.h:338
operations_research::sat::SchedulingNeighborhoodGenerator
Definition: cp_model_lns.h:390
operations_research::sat::SimpleNeighborhoodGenerator::SimpleNeighborhoodGenerator
SimpleNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
Definition: cp_model_lns.h:344
operations_research::sat::ConsecutiveConstraintsRelaxationNeighborhoodGenerator::Generate
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
Definition: cp_model_lns.cc:713
operations_research::sat::ConsecutiveConstraintsRelaxationNeighborhoodGenerator::ConsecutiveConstraintsRelaxationNeighborhoodGenerator
ConsecutiveConstraintsRelaxationNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
Definition: cp_model_lns.h:464
operations_research::sat::NeighborhoodGenerator::deterministic_limit
double deterministic_limit() const
Definition: cp_model_lns.h:303
operations_research::sat::NeighborhoodGeneratorHelper::TaskIsAvailable
bool TaskIsAvailable() override
Definition: cp_model_lns.h:73
operations_research::sat::WeightedRandomRelaxationNeighborhoodGenerator::IsRelaxationGenerator
bool IsRelaxationGenerator() const override
Definition: cp_model_lns.h:490
operations_research::sat::ConsecutiveConstraintsRelaxationNeighborhoodGenerator::ReadyToGenerate
bool ReadyToGenerate() const override
Definition: cp_model_lns.h:471
operations_research::sat::SimpleNeighborhoodGenerator
Definition: cp_model_lns.h:342
operations_research::sat::NeighborhoodGeneratorHelper::VarToConstraint
const std::vector< std::vector< int > > & VarToConstraint() const
Definition: cp_model_lns.h:113
operations_research::sat::VariableGraphNeighborhoodGenerator
Definition: cp_model_lns.h:355
model_proto
CpModelProto const * model_proto
Definition: cp_model_solver.cc:2023
operations_research::sat::VariableGraphNeighborhoodGenerator::VariableGraphNeighborhoodGenerator
VariableGraphNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
Definition: cp_model_lns.h:357
model.h
operations_research::sat::NeighborhoodGenerator::SolveData::initial_best_objective
IntegerValue initial_best_objective
Definition: cp_model_lns.h:250
operations_research::sat::SubSolver
Definition: subsolver.h:41
operations_research
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Definition: dense_doubly_linked_list.h:21
operations_research::sat::NeighborhoodGenerator::GetUCBScore
double GetUCBScore(int64 total_num_calls) const
Definition: cp_model_lns.cc:249
operations_research::sat::NeighborhoodGeneratorHelper::TypeToConstraints
const absl::Span< const int > TypeToConstraints(ConstraintProto::ConstraintCase type) const
Definition: cp_model_lns.h:118
adaptative_parameter_value.h
operations_research::sat::NeighborhoodGeneratorHelper::Parameters
const SatParameters & Parameters() const
Definition: cp_model_lns.h:127
operations_research::sat::NeighborhoodGeneratorHelper::FixGivenVariables
Neighborhood FixGivenVariables(const CpSolverResponse &initial_solution, const std::vector< int > &variables_to_fix) const
Definition: cp_model_lns.cc:173
operations_research::sat::SchedulingNeighborhoodGenerator::Generate
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
Definition: cp_model_lns.cc:558
operations_research::sat::NeighborhoodGenerator::SolveData
Definition: cp_model_lns.h:224
operations_research::sat::UNKNOWN
@ UNKNOWN
Definition: cp_model.pb.h:228
operations_research::sat::NeighborhoodGeneratorHelper::RemoveMarkedConstraints
Neighborhood RemoveMarkedConstraints(const std::vector< int > &constraints_to_remove) const
Definition: cp_model_lns.cc:207
operations_research::sat::SharedResponseManager
Definition: synchronization.h:166
operations_research::sat::NeighborhoodGenerator::name_
const std::string name_
Definition: cp_model_lns.h:320
operations_research::sat::NeighborhoodGenerator::SolveData::difficulty
double difficulty
Definition: cp_model_lns.h:233
int64
int64_t int64
Definition: integral_types.h:34
operations_research::sat::NeighborhoodGenerator::SolveData::new_objective
IntegerValue new_objective
Definition: cp_model_lns.h:252
operations_research::sat::SchedulingTimeWindowNeighborhoodGenerator
Definition: cp_model_lns.h:402
operations_research::sat::NeighborhoodGeneratorHelper::ActiveVariables
const std::vector< int > & ActiveVariables() const
Definition: cp_model_lns.h:106
random_engine.h
relaxation_solutions
SharedRelaxationSolutionRepository * relaxation_solutions
Definition: cp_model_solver.cc:2028
operations_research::sat::NeighborhoodGeneratorHelper::ConstraintToVar
const std::vector< std::vector< int > > & ConstraintToVar() const
Definition: cp_model_lns.h:110
operations_research::sat::SharedRelaxationSolutionRepository
Definition: synchronization.h:127
operations_research::sat::GenerateSchedulingNeighborhoodForRelaxation
Neighborhood GenerateSchedulingNeighborhoodForRelaxation(const absl::Span< const int > intervals_to_relax, const CpSolverResponse &initial_solution, const NeighborhoodGeneratorHelper &helper)
Definition: cp_model_lns.cc:465
operations_research::sat::NeighborhoodGenerator::~NeighborhoodGenerator
virtual ~NeighborhoodGenerator()
Definition: cp_model_lns.h:187
operations_research::sat::NeighborhoodGeneratorHelper::shared_response
const SharedResponseManager & shared_response() const
Definition: cp_model_lns.h:137
operations_research::sat::NeighborhoodGenerator::mutex_
absl::Mutex mutex_
Definition: cp_model_lns.h:322
operations_research::sat::NeighborhoodGenerator::ReadyToGenerate
virtual bool ReadyToGenerate() const
Definition: cp_model_lns.cc:245
operations_research::sat::NeighborhoodGenerator::SolveData::deterministic_time
double deterministic_time
Definition: cp_model_lns.h:239
operations_research::sat::ConsecutiveConstraintsRelaxationNeighborhoodGenerator
Definition: cp_model_lns.h:462
operations_research::sat::NeighborhoodGenerator::SolveData::status
CpSolverStatus status
Definition: cp_model_lns.h:230
operations_research::sat::ConstraintGraphNeighborhoodGenerator::Generate
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
Definition: cp_model_lns.cc:410
operations_research::sat::SchedulingNeighborhoodGenerator::SchedulingNeighborhoodGenerator
SchedulingNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
Definition: cp_model_lns.h:392
operations_research::sat::WeightedRandomRelaxationNeighborhoodGenerator
Definition: cp_model_lns.h:480
operations_research::sat::NeighborhoodGenerator::SolveData::neighborhood_id
int64 neighborhood_id
Definition: cp_model_lns.h:227
operations_research::sat::NeighborhoodGeneratorHelper::FullNeighborhood
Neighborhood FullNeighborhood() const
Definition: cp_model_lns.cc:163
operations_research::sat::SharedBoundsManager
Definition: synchronization.h:333
operations_research::sat::SharedIncompleteSolutionManager
Definition: synchronization.h:151
operations_research::sat::NeighborhoodGenerator
Definition: cp_model_lns.h:182
operations_research::sat::NeighborhoodGenerator::SolveData::operator<
bool operator<(const SolveData &o) const
Definition: cp_model_lns.h:259
operations_research::sat::ConstraintGraphNeighborhoodGenerator
Definition: cp_model_lns.h:368
lp_solutions
SharedLPSolutionRepository * lp_solutions
Definition: cp_model_solver.cc:2029
operations_research::sat::NeighborhoodGeneratorHelper::MutableMutex
absl::Mutex * MutableMutex() const
Definition: cp_model_lns.h:135
operations_research::sat::WeightedRandomRelaxationNeighborhoodGenerator::ReadyToGenerate
bool ReadyToGenerate() const override
Definition: cp_model_lns.h:491
operations_research::sat::SchedulingTimeWindowNeighborhoodGenerator::Generate
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
Definition: cp_model_lns.cc:569
operations_research::sat::RelaxationInducedNeighborhoodGenerator::Generate
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
Definition: cp_model_lns.cc:620
operations_research::sat::NeighborhoodGenerator::SolveData::new_objective_bound
IntegerValue new_objective_bound
Definition: cp_model_lns.h:256
operations_research::sat::WeightedRandomRelaxationNeighborhoodGenerator::WeightedRandomRelaxationNeighborhoodGenerator
WeightedRandomRelaxationNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
Definition: cp_model_lns.cc:749
operations_research::sat::Neighborhood
Definition: cp_model_lns.h:34
operations_research::sat::VariableGraphNeighborhoodGenerator::Generate
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
Definition: cp_model_lns.cc:358
operations_research::sat::ConsecutiveConstraintsRelaxationNeighborhoodGenerator::IsRelaxationGenerator
bool IsRelaxationGenerator() const override
Definition: cp_model_lns.h:470
operations_research::sat::NeighborhoodGenerator::SolveData::initial_best_objective_bound
IntegerValue initial_best_objective_bound
Definition: cp_model_lns.h:255
operations_research::sat::NeighborhoodGenerator::SolveData::deterministic_limit
double deterministic_limit
Definition: cp_model_lns.h:236
operations_research::sat::NeighborhoodGenerator::difficulty
double difficulty() const
Definition: cp_model_lns.h:297
operations_research::sat::NeighborhoodGeneratorHelper::FixAllVariables
Neighborhood FixAllVariables(const CpSolverResponse &initial_solution) const
Definition: cp_model_lns.cc:236
operations_research::sat::ConstraintGraphNeighborhoodGenerator::ConstraintGraphNeighborhoodGenerator
ConstraintGraphNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
Definition: cp_model_lns.h:370
operations_research::sat::NeighborhoodGeneratorHelper::ModelProto
const CpModelProto & ModelProto() const
Definition: cp_model_lns.h:126
operations_research::sat::NeighborhoodGeneratorHelper::RelaxGivenVariables
Neighborhood RelaxGivenVariables(const CpSolverResponse &initial_solution, const std::vector< int > &relaxed_variables) const
Definition: cp_model_lns.cc:222
operations_research::sat::CpSolverStatus
CpSolverStatus
Definition: cp_model.pb.h:227
operations_research::sat::NeighborhoodGenerator::IsRelaxationGenerator
virtual bool IsRelaxationGenerator() const
Definition: cp_model_lns.h:211
operations_research::sat::Neighborhood::cp_model
CpModelProto cp_model
Definition: cp_model_lns.h:45
operations_research::sat::NeighborhoodGeneratorHelper::NeighborhoodGeneratorHelper
NeighborhoodGeneratorHelper(CpModelProto const *model_proto, SatParameters const *parameters, SharedResponseManager *shared_response, SharedTimeLimit *shared_time_limit=nullptr, SharedBoundsManager *shared_bounds=nullptr)
Definition: cp_model_lns.cc:33
operations_research::sat::Neighborhood::is_reduced
bool is_reduced
Definition: cp_model_lns.h:41
operations_research::sat::RelaxationInducedNeighborhoodGenerator::ReadyToGenerate
bool ReadyToGenerate() const override
Definition: cp_model_lns.cc:596
operations_research::sat::NeighborhoodGeneratorHelper
Definition: cp_model_lns.h:64
operations_research::sat::Neighborhood::is_generated
bool is_generated
Definition: cp_model_lns.h:36
operations_research::sat::NeighborhoodGenerator::num_fully_solved_calls
int64 num_fully_solved_calls() const
Definition: cp_model_lns.h:291
operations_research::sat::NeighborhoodGeneratorHelper::IsActive
bool IsActive(int var) const
Definition: cp_model_lns.cc:153
operations_research::sat::RelaxationInducedNeighborhoodGenerator
Definition: cp_model_lns.h:426
operations_research::sat::RelaxationInducedNeighborhoodGenerator::RelaxationInducedNeighborhoodGenerator
RelaxationInducedNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const SharedResponseManager *response_manager, const SharedRelaxationSolutionRepository *relaxation_solutions, const SharedLPSolutionRepository *lp_solutions, SharedIncompleteSolutionManager *incomplete_solutions, const std::string &name)
Definition: cp_model_lns.h:428
operations_research::sat::SchedulingTimeWindowNeighborhoodGenerator::SchedulingTimeWindowNeighborhoodGenerator
SchedulingTimeWindowNeighborhoodGenerator(NeighborhoodGeneratorHelper const *helper, const std::string &name)
Definition: cp_model_lns.h:404
operations_research::sat::NeighborhoodGenerator::AdditionalProcessingOnSynchronize
virtual void AdditionalProcessingOnSynchronize(const SolveData &solve_data)
Definition: cp_model_lns.h:318
operations_research::AdaptiveParameterValue::value
double value() const
Definition: adaptative_parameter_value.h:70
operations_research::sat::SharedLPSolutionRepository
Definition: synchronization.h:135
operations_research::sat::NeighborhoodGenerator::AddSolveData
void AddSolveData(SolveData data)
Definition: cp_model_lns.h:272
operations_research::sat::NeighborhoodGenerator::deterministic_time
double deterministic_time() const
Definition: cp_model_lns.h:309
operations_research::sat::NeighborhoodGenerator::Generate
virtual Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random)=0
operations_research::sat::SimpleNeighborhoodGenerator::Generate
Neighborhood Generate(const CpSolverResponse &initial_solution, double difficulty, random_engine_t *random) final
Definition: cp_model_lns.cc:350
operations_research::AdaptiveParameterValue
Definition: adaptative_parameter_value.h:37
operations_research::sat::NeighborhoodGenerator::num_calls
int64 num_calls() const
Definition: cp_model_lns.h:285
parameters
SatParameters parameters
Definition: cp_model_fz_solver.cc:107
incomplete_solutions
SharedIncompleteSolutionManager * incomplete_solutions
Definition: cp_model_solver.cc:2030
operations_research::sat::NeighborhoodGenerator::NeighborhoodGenerator
NeighborhoodGenerator(const std::string &name, NeighborhoodGeneratorHelper const *helper)
Definition: cp_model_lns.h:184
operations_research::random_engine_t
std::mt19937 random_engine_t
Definition: random_engine.h:23
operations_research::sat::NeighborhoodGeneratorHelper::Synchronize
void Synchronize() override
Definition: cp_model_lns.cc:53
operations_research::sat::NeighborhoodGenerator::SolveData::base_objective
IntegerValue base_objective
Definition: cp_model_lns.h:251