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