Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
linear_solver_callback.cc
Go to the documentation of this file.
1// Copyright 2010-2024 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
20
21namespace operations_research {
22
23std::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
50namespace {
51
52// Returns true if any of the callbacks in a list might add cuts.
53bool 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.
63bool 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
75MPCallbackList::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
Runs all callbacks from the list given at construction, in sequence.
MPCallbackList(const std::vector< MPCallback * > &callbacks)
GurobiMPCallbackContext * context
MPCallback * callback
In SWIG mode, we don't want anything besides these top-level includes.
@ kMultiObj
The solver is in multi-objective optimization.
@ kMipSolution
Called every time a new MIP incumbent is found.
@ kMessage
The solver is about to log out a message, use this callback to capture it.
@ kPresolve
The solver is currently running presolve.
@ kSimplex
The solver is currently running the simplex method.
@ kMipNode
Called once per pass of the cut loop inside each MIP node.
@ kBarrier
Called in each iterate of IPM/barrier method.
absl::string_view ToString(MPSolver::OptimizationProblemType optimization_problem_type)