OR-Tools  9.2
gurobi_callback.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_MATH_OPT_SOLVERS_GUROBI_CALLBACK_H_
15#define OR_TOOLS_MATH_OPT_SOLVERS_GUROBI_CALLBACK_H_
16
17#include <cstdint>
18#include <vector>
19
20#include "absl/container/flat_hash_set.h"
21#include "absl/status/status.h"
22#include "absl/time/time.h"
24#include "ortools/math_opt/callback.pb.h"
29#include "ortools/math_opt/sparse_containers.pb.h"
30
32
33namespace operations_research {
34namespace math_opt {
35
41 // events[i] indicates if we should run user_cb when Gurobi's callback is
42 // triggered with where=i. See:
43 // https://www.gurobi.com/documentation/9.1/refman/cb_codes.html
44 // For list of possible values for where. See also EventToGurobiWhere() below.
45 std::vector<bool> events;
46 const SparseVectorFilterProto& mip_solution_filter;
47 const SparseVectorFilterProto& mip_node_filter;
48 const absl::Time start;
49};
50
51// Converts a set of CallbackEventProto enums to a bit vector indicating which
52// Gurobi callback events need to run our callback.
53//
54// The returned vector will have an entry for each possible value of "where"
55// that Gurobi's callbacks can stop at, see the table here:
56// https://www.gurobi.com/documentation/9.1/refman/cb_codes.html
57std::vector<bool> EventToGurobiWhere(
58 const absl::flat_hash_set<CallbackEventProto>& events);
59
61 const GurobiCallbackInput& callback_input,
62 MessageCallbackData& message_callback_data,
63 SolveInterrupter* local_interrupter);
64
65// Makes the final calls to the message callback with any unfinished line if
66// necessary. It must be called once at the end of the solve, even when the
67// solve or one callback failed (in case the last unfinished line contains some
68// details about that).
69void GurobiCallbackImplFlush(const GurobiCallbackInput& callback_input,
70 MessageCallbackData& message_callback_data);
71
72} // namespace math_opt
73} // namespace operations_research
74#endif // OR_TOOLS_MATH_OPT_SOLVERS_GUROBI_CALLBACK_H_
std::function< void(const std::vector< std::string > &)> MessageCallback
std::function< absl::StatusOr< CallbackResultProto >(const CallbackDataProto &)> Callback
GurobiMPCallbackContext * context
void GurobiCallbackImplFlush(const GurobiCallbackInput &callback_input, MessageCallbackData &message_callback_data)
absl::Status GurobiCallbackImpl(const Gurobi::CallbackContext &context, const GurobiCallbackInput &callback_input, MessageCallbackData &message_callback_data, SolveInterrupter *const local_interrupter)
std::vector< bool > EventToGurobiWhere(const absl::flat_hash_set< CallbackEventProto > &events)
Collection of objects used to extend the Constraint Solver library.
const SparseVectorFilterProto & mip_node_filter
SolverInterface::MessageCallback message_cb
const SparseVectorFilterProto & mip_solution_filter
const gtl::linked_hash_map< int64_t, int > & variable_ids