21#include "absl/container/flat_hash_set.h"
22#include "absl/status/status.h"
23#include "absl/status/statusor.h"
24#include "absl/strings/string_view.h"
25#include "absl/time/time.h"
26#include "absl/types/span.h"
30#include "ortools/math_opt/callback.pb.h"
35#include "ortools/math_opt/sparse_containers.pb.h"
51 return "mip_solution";
66 return absl::MakeConstSpan(kCallbackEventValues);
70 const absl::Duration runtime)
71 : event(event), runtime(runtime) {}
74 const CallbackDataProto&
proto)
78 presolve_stats(
proto.presolve_stats()),
79 simplex_stats(
proto.simplex_stats()),
80 barrier_stats(
proto.barrier_stats()),
81 mip_stats(
proto.mip_stats()) {
83 if (
proto.has_primal_solution_vector()) {
88 CHECK_OK(maybe_time.status());
93 const ModelStorage*
const expected_storage)
const {
95 <<
"invalid mip_node_filter";
97 <<
"invalid mip_solution_filter";
98 return absl::OkStatus();
102 CallbackRegistrationProto result;
104 result.add_request_registration(
EnumToProto(event));
106 std::sort(result.mutable_request_registration()->begin(),
107 result.mutable_request_registration()->end());
116 const ModelStorage*
const expected_storage)
const {
121 <<
"invalid new_constraints";
124 for (
const auto& [v, _] :
solution) {
126 v.storage(), expected_storage))
127 <<
"invalid variable " << v <<
" in suggested_solutions";
130 return absl::OkStatus();
134 CallbackResultProto result;
140 CallbackResultProto::GeneratedLinearConstraint* constraint_proto =
142 constraint_proto->set_is_lazy(constraint.is_lazy);
143 constraint_proto->set_lower_bound(
144 constraint.linear_constraint.lower_bound_minus_offset());
145 constraint_proto->set_upper_bound(
146 constraint.linear_constraint.upper_bound_minus_offset());
147 *constraint_proto->mutable_linear_expression() =
#define RETURN_IF_ERROR(expr)
CpModelProto proto
The output proto.
absl::Status CheckModelStorage(const ModelStorage *const storage, const ModelStorage *const expected_storage)
absl::flat_hash_map< Variable, V > VariableMap
std::optional< typename EnumProto< P >::Cpp > EnumFromProto(P proto_value)
absl::StatusOr< VariableMap< double > > VariableValuesFromProto(const ModelStorage *const model, const SparseDoubleVectorProto &vars_proto)
CallbackEvent
The supported events during a solve for callbacks.
SparseDoubleVectorProto VariableValuesToProto(const VariableMap< double > &variable_values)
Returns the proto equivalent of variable_values.
Enum< E >::Proto EnumToProto(std::optional< E > value)
In SWIG mode, we don't want anything besides these top-level includes.
inline ::absl::StatusOr< absl::Duration > DecodeGoogleApiProto(const google::protobuf::Duration &proto)
absl::Duration runtime
Time since Solve() was called. Available for all events.
std::optional< VariableMap< double > > solution
CallbackData(CallbackEvent event, absl::Duration runtime)
Users will typically not need this function other than for testing.
absl::flat_hash_set< CallbackEvent > events
MapFilter< Variable > mip_node_filter
bool add_lazy_constraints
absl::Status CheckModelStorage(const ModelStorage *expected_storage) const
MapFilter< Variable > mip_solution_filter
CallbackRegistrationProto Proto() const
absl::Status CheckModelStorage(const ModelStorage *expected_storage) const
std::vector< GeneratedLinearConstraint > new_constraints
CallbackResultProto Proto() const
bool terminate
Stop the solve process and return early. Can be called from any event.
std::vector< VariableMap< double > > suggested_solutions
A solution or partially defined solution to give to the solver.
static absl::Span< const E > AllValues()
Returns all possible values of the enum.
static std::optional< absl::string_view > ToOptString(E value)