OR-Tools  8.0
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) {
22  case MPCallbackEvent::kMipSolution:
23  return "MIP_SOLUTION";
24  case MPCallbackEvent::kMip:
25  return "MIP";
26  case MPCallbackEvent::kMipNode:
27  return "MIP_NODE";
28  case MPCallbackEvent::kBarrier:
29  return "BARRIER";
30  case MPCallbackEvent::kMessage:
31  return "MESSAGE";
32  case MPCallbackEvent::kPresolve:
33  return "PRESOLVE";
34  case MPCallbackEvent::kPolling:
35  return "POLLING";
37  return "MULTI_OBJ";
38  case MPCallbackEvent::kSimplex:
39  return "SIMPLEX";
40  case MPCallbackEvent::kUnknown:
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
operations_research::MPCallbackList::MPCallbackList
MPCallbackList(const std::vector< MPCallback * > &callbacks)
Definition: linear_solver_callback.cc:72
operations_research::MPCallback
Definition: linear_solver_callback.h:140
operations_research::MPCallbackContext
Definition: linear_solver_callback.h:64
logging.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::ToString
const absl::string_view ToString(MPSolver::OptimizationProblemType optimization_problem_type)
Definition: linear_solver.cc:568
context
GurobiMPCallbackContext * context
Definition: gurobi_interface.cc:439
operations_research::MPCallbackEvent::kUnknown
@ kUnknown
operations_research::MPCallback::might_add_cuts
bool might_add_cuts() const
Definition: linear_solver_callback.h:155
operations_research::MPCallbackEvent
MPCallbackEvent
Definition: linear_solver_callback.h:35
operations_research::MPCallback::might_add_lazy_constraints
bool might_add_lazy_constraints() const
Definition: linear_solver_callback.h:156
callback
MPCallback * callback
Definition: gurobi_interface.cc:440
operations_research::MPCallbackList::RunCallback
void RunCallback(MPCallbackContext *context) override
Definition: linear_solver_callback.cc:77
linear_solver_callback.h