OR-Tools  8.2
linear_solver_callback.cc
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 
15 
16 #include "ortools/base/logging.h"
17 
18 namespace operations_research {
19 
20 std::string ToString(MPCallbackEvent event) {
21  switch (event) {
23  return "MIP_SOLUTION";
25  return "MIP";
27  return "MIP_NODE";
29  return "BARRIER";
31  return "MESSAGE";
33  return "PRESOLVE";
35  return "POLLING";
37  return "MULTI_OBJ";
39  return "SIMPLEX";
41  return "UNKNOWN";
42  default:
43  LOG(FATAL) << "Unrecognized callback event: " << static_cast<int>(event);
44  }
45 }
46 
47 namespace {
48 
49 // Returns true if any of the callbacks in a list might add cuts.
50 bool CallbacksMightAddCuts(const std::vector<MPCallback*>& callbacks) {
51  for (MPCallback* callback : callbacks) {
52  if (callback->might_add_cuts()) {
53  return true;
54  }
55  }
56  return false;
57 }
58 
59 // Returns true if any of the callbacks in a list might add lazy constraints.
60 bool CallbacksMightAddLazyConstraints(
61  const std::vector<MPCallback*>& callbacks) {
62  for (MPCallback* callback : callbacks) {
64  return true;
65  }
66  }
67  return false;
68 }
69 
70 } // namespace
71 
72 MPCallbackList::MPCallbackList(const std::vector<MPCallback*>& callbacks)
73  : MPCallback(CallbacksMightAddCuts(callbacks),
74  CallbacksMightAddLazyConstraints(callbacks)),
75  callbacks_(callbacks) {}
76 
78  for (MPCallback* callback : callbacks_) {
79  callback->RunCallback(context);
80  }
81 }
82 
83 } // namespace operations_research
#define LOG(severity)
Definition: base/logging.h:420
void RunCallback(MPCallbackContext *context) override
MPCallbackList(const std::vector< MPCallback * > &callbacks)
GurobiMPCallbackContext * context
MPCallback * callback
const int FATAL
Definition: log_severity.h:32
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
const absl::string_view ToString(MPSolver::OptimizationProblemType optimization_problem_type)