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);
74 const CallbackDataProto& proto)
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)
absl::Status CheckModelStorage(const ModelStorage *const storage, const ModelStorage *const expected_storage)
An object oriented wrapper for quadratic constraints in ModelStorage.
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.
Select next search node to expand Select next item_i to add this new search node to the search Generate a new search node where item_i is not in the knapsack Check validity of this new partial solution(using propagators) - If valid
inline ::absl::StatusOr< absl::Duration > DecodeGoogleApiProto(const google::protobuf::Duration &proto)
CallbackDataProto::PresolveStats presolve_stats
Only available for event == CallbackEvent::kPresolve.
absl::Duration runtime
Time since Solve() was called. Available for all events.
CallbackDataProto::SimplexStats simplex_stats
Only available for event == CallbackEvent::kSimplex.
CallbackDataProto::BarrierStats barrier_stats
Only available for event == CallbackEvent::kBarrier.
std::optional< VariableMap< double > > solution
CallbackDataProto::MipStats mip_stats
CallbackData(CallbackEvent event, absl::Duration runtime)
Users will typically not need this function other than for testing.
CallbackEvent event
The current state of the underlying solver.
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)