OR-Tools  9.6
linear_solver_callback.cc
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 
15 
16 #include <string>
17 #include <vector>
18 
19 #include "ortools/base/logging.h"
20 
21 namespace operations_research {
22 
23 std::string ToString(MPCallbackEvent event) {
24  switch (event) {
26  return "MIP_SOLUTION";
28  return "MIP";
30  return "MIP_NODE";
32  return "BARRIER";
34  return "MESSAGE";
36  return "PRESOLVE";
38  return "POLLING";
40  return "MULTI_OBJ";
42  return "SIMPLEX";
44  return "UNKNOWN";
45  default:
46  LOG(FATAL) << "Unrecognized callback event: " << static_cast<int>(event);
47  }
48 }
49 
50 namespace {
51 
52 // Returns true if any of the callbacks in a list might add cuts.
53 bool CallbacksMightAddCuts(const std::vector<MPCallback*>& callbacks) {
54  for (MPCallback* callback : callbacks) {
55  if (callback->might_add_cuts()) {
56  return true;
57  }
58  }
59  return false;
60 }
61 
62 // Returns true if any of the callbacks in a list might add lazy constraints.
63 bool CallbacksMightAddLazyConstraints(
64  const std::vector<MPCallback*>& callbacks) {
65  for (MPCallback* callback : callbacks) {
67  return true;
68  }
69  }
70  return false;
71 }
72 
73 } // namespace
74 
75 MPCallbackList::MPCallbackList(const std::vector<MPCallback*>& callbacks)
76  : MPCallback(CallbacksMightAddCuts(callbacks),
77  CallbacksMightAddLazyConstraints(callbacks)),
78  callbacks_(callbacks) {}
79 
81  for (MPCallback* callback : callbacks_) {
82  callback->RunCallback(context);
83  }
84 }
85 
86 } // namespace operations_research
void RunCallback(MPCallbackContext *context) override
MPCallbackList(const std::vector< MPCallback * > &callbacks)
GurobiMPCallbackContext * context
MPCallback * callback
Collection of objects used to extend the Constraint Solver library.
const absl::string_view ToString(MPSolver::OptimizationProblemType optimization_problem_type)