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