OR-Tools  8.1
rins.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_RINS_H_
15 #define OR_TOOLS_SAT_RINS_H_
16 
17 #include <vector>
18 
19 #include "absl/container/flat_hash_map.h"
20 #include "absl/synchronization/mutex.h"
21 #include "absl/types/optional.h"
22 #include "ortools/sat/integer.h"
24 #include "ortools/sat/model.h"
26 
27 namespace operations_research {
28 namespace sat {
29 
30 // Links IntegerVariable with model variable and its lp constraint if any.
31 struct LPVariable {
32  IntegerVariable positive_var = kNoIntegerVariable;
34  int model_var;
35 
36  bool operator==(const LPVariable other) const {
37  return (positive_var == other.positive_var && lp == other.lp &&
38  model_var == other.model_var);
39  }
40 };
41 
42 // This is used to "cache" in the model the set of relevant LPVariable.
43 struct LPVariables {
44  std::vector<LPVariable> vars;
45  int model_vars_size = 0;
46 };
47 
48 // A RINS Neighborhood is actually just a generic neighborhood where the domain
49 // of some variable have been reduced (fixed or restricted in [lb, ub]).
50 //
51 // Important: It might be possible that the value of the variables here are
52 // outside the domains of these variables! This happens for RENS type of
53 // neighborhood in the presence of holes in the domains because the LP
54 // relaxation ignore those.
56  // A variable will appear only once and not in both vectors.
57  std::vector<std::pair</*model_var*/ int, /*value*/ int64>> fixed_vars;
58  std::vector<std::pair</*model_var*/ int, /*domain*/ std::pair<int64, int64>>>
60 };
61 
62 // Helper method to create a RINS neighborhood by fixing variables with same
63 // values in relaxation solution and the current best solution in the
64 // response_manager. Prioritizes repositories in following order to get a
65 // relaxation solution.
66 // 1. incomplete_solutions
67 // 2. lp_solutions
68 // 3. relaxation_solutions
69 //
70 // If response_manager is not provided, this generates a RENS neighborhood by
71 // ignoring the solutions and using the relaxation values. The domain of the
72 // variables are reduced to integer values around relaxation values. If the
73 // relaxation value is integer, then we fix the domain of the variable to that
74 // value.
76  const SharedResponseManager* response_manager,
80  random_engine_t* random);
81 
82 // Adds the current LP solution to the pool.
84 
85 } // namespace sat
86 } // namespace operations_research
87 
88 #endif // OR_TOOLS_SAT_RINS_H_
synchronization.h
operations_research::sat::kNoIntegerVariable
const IntegerVariable kNoIntegerVariable(-1)
operations_research::sat::LPVariable::lp
LinearProgrammingConstraint * lp
Definition: rins.h:33
operations_research::sat::LPVariables::vars
std::vector< LPVariable > vars
Definition: rins.h:44
operations_research::sat::LPVariable
Definition: rins.h:31
model.h
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::LPVariables::model_vars_size
int model_vars_size
Definition: rins.h:45
operations_research::sat::LPVariables
Definition: rins.h:43
int64
int64_t int64
Definition: integral_types.h:34
operations_research::sat::RINSNeighborhood
Definition: rins.h:55
relaxation_solutions
SharedRelaxationSolutionRepository * relaxation_solutions
Definition: cp_model_solver.cc:2106
operations_research::sat::SharedResponseManager
Definition: synchronization.h:166
operations_research::sat::GetRINSNeighborhood
RINSNeighborhood GetRINSNeighborhood(const SharedResponseManager *response_manager, const SharedRelaxationSolutionRepository *relaxation_solutions, const SharedLPSolutionRepository *lp_solutions, SharedIncompleteSolutionManager *incomplete_solutions, random_engine_t *random)
Definition: rins.cc:99
operations_research::sat::SharedRelaxationSolutionRepository
Definition: synchronization.h:127
operations_research::sat::RINSNeighborhood::reduced_domain_vars
std::vector< std::pair< int, std::pair< int64, int64 > > > reduced_domain_vars
Definition: rins.h:59
lp_solutions
SharedLPSolutionRepository * lp_solutions
Definition: cp_model_solver.cc:2107
operations_research::sat::Model
Class that owns everything related to a particular optimization model.
Definition: sat/model.h:38
operations_research::sat::LPVariable::operator==
bool operator==(const LPVariable other) const
Definition: rins.h:36
model
GRBmodel * model
Definition: gurobi_interface.cc:269
operations_research::sat::LinearProgrammingConstraint
Definition: linear_programming_constraint.h:128
operations_research::sat::RINSNeighborhood::fixed_vars
std::vector< std::pair< int, int64 > > fixed_vars
Definition: rins.h:57
operations_research::sat::LPVariable::positive_var
IntegerVariable positive_var
Definition: rins.h:32
operations_research::sat::SharedIncompleteSolutionManager
Definition: synchronization.h:151
operations_research::sat::SharedLPSolutionRepository
Definition: synchronization.h:135
incomplete_solutions
SharedIncompleteSolutionManager * incomplete_solutions
Definition: cp_model_solver.cc:2108
integer.h
linear_programming_constraint.h
operations_research::random_engine_t
std::mt19937 random_engine_t
Definition: random_engine.h:23
operations_research::sat::RecordLPRelaxationValues
void RecordLPRelaxationValues(Model *model)
Definition: rins.cc:25
operations_research::sat::LPVariable::model_var
int model_var
Definition: rins.h:34