19#include "absl/status/statusor.h"
35#if defined(PROTOBUF_INTERNAL_IMPL)
36using google::protobuf::Message;
38using google::protobuf::Message;
45constexpr bool kProtoLiteSatParameters =
70 std::function<
void(
const std::string&)> logging_callback,
71 std::function<
void(
const MPSolution&)> solution_callback) {
76 if (kProtoLiteSatParameters) {
78 return absl::InvalidArgumentError(
79 "solver_specific_parameters is not a valid binary stream of the "
80 "SatParameters proto");
85 return absl::InvalidArgumentError(
86 "solver_specific_parameters is not a valid textual representation "
87 "of the SatParameters proto");
103 if (logging_callback !=
nullptr) {
125 std::vector<std::unique_ptr<glop::Preprocessor>> for_postsolve;
137 response.set_status_str(
"Problem proven infeasible during MIP presolve");
146 SOLVER_LOG(&logger,
"Scaling to pure integer problem.");
149 std::vector<double> var_scaling(num_variables, 1.0);
156 for (
int i = 0; i < var_scaling.size(); ++i) {
157 var_scaling[i] *= other_scaling[i];
171 response.set_status_str(
"Failed to convert model into CP-SAT model");
181 for (
int i = 0; i < size; ++i) {
183 if (
var >= var_scaling.size())
continue;
194 cp_model_hint->add_vars(
var);
195 cp_model_hint->add_values(
static_cast<int64_t
>(std::round(
value)));
200 const int old_num_variables = mp_model->
variable().size();
201 const int old_num_constraints = mp_model->
constraint().size();
208 if (interrupt_solve !=
nullptr) {
218 (glop::ColIndex(old_num_variables)));
221 static_cast<double>(cp_response.solution(v)) / var_scaling[v];
223 for (
int i = for_postsolve.size(); --i >= 0;) {
224 for_postsolve[i]->RecoverSolution(&glop_solution);
233 if (solution_callback !=
nullptr) {
236 solution_callback(post_solve(cp_response));
253 MPSolution post_solved_solution = post_solve(cp_response);
254 *
response.mutable_variable_value() =
262 if (kProtoLiteSatParameters) {
#define DCHECK_EQ(val1, val2)
const ::operations_research::MPConstraintProto & constraint(int index) const
int variable_size() const
const ::operations_research::MPVariableProto & variable(int index) const
const ::operations_research::PartialVariableAssignment & solution_hint() const
bool has_solution_hint() const
double solver_time_limit_seconds() const
::operations_research::MPModelProto * mutable_model()
bool enable_internal_solver_output() const
const std::string & solver_specific_parameters() const
bool has_solver_specific_parameters() const
bool has_solver_time_limit_seconds() const
PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final
const ::operations_research::MPModelProto & model() const
void add_variable_value(double value)
::PROTOBUF_NAMESPACE_ID::RepeatedField< double > * mutable_variable_value()
void set_objective_value(double value)
double var_value(int index) const
::PROTOBUF_NAMESPACE_ID::int32 var_index(int index) const
void SetLogToStdOut(bool enable)
bool LoggingIsEnabled() const
void AddInfoLoggingCallback(std::function< void(const std::string &message)> callback)
void EnableLogging(bool enable)
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
const ::operations_research::sat::IntegerVariableProto & variables(int index) const
bool has_objective() const
::operations_research::sat::PartialVariableAssignment * mutable_solution_hint()
double best_objective_bound() const
void set_status(::operations_research::sat::CpSolverStatus value)
double objective_value() const
::operations_research::sat::CpSolverStatus status() const
Class that owns everything related to a particular optimization model.
T Add(std::function< T(Model *)> f)
This makes it possible to have a nicer API on the client side, and it allows both of these forms:
void Register(T *non_owned_class)
Register a non-owned class that will be "singleton" in the model.
T * GetOrCreate()
Returns an object of type T that is unique to this model (like a "local" singleton).
bool log_search_progress() const
bool enumerate_all_solutions() const
void set_linearization_level(::PROTOBUF_NAMESPACE_ID::int32 value)
bool mip_automatically_scale_variables() const
double mip_var_scaling() const
void set_log_search_progress(bool value)
double mip_max_bound() const
void set_max_time_in_seconds(double value)
bool log_to_stdout() const
SharedResponseManager * response
std::function< void(Model *)> NewFeasibleSolutionObserver(const std::function< void(const CpSolverResponse &response)> &observer)
Creates a solution observer with the model with model.Add(NewFeasibleSolutionObserver([](response){....
std::function< SatParameters(Model *)> NewSatParameters(const std::string ¶ms)
Creates parameters for the solver, which you can add to the model with.
std::string CpSolverResponseStats(const CpSolverResponse &response, bool has_objective)
Returns a string with some statistics on the solver response.
void RemoveNearZeroTerms(const SatParameters ¶ms, MPModelProto *mp_model, SolverLogger *logger)
bool ConvertMPModelProtoToCpModelProto(const SatParameters ¶ms, const MPModelProto &mp_model, CpModelProto *cp_model, SolverLogger *logger)
CpSolverResponse SolveCpModel(const CpModelProto &model_proto, Model *model)
Solves the given CpModelProto.
std::vector< double > ScaleContinuousVariables(double scaling, double max_bound, MPModelProto *mp_model)
std::vector< double > DetectImpliedIntegers(MPModelProto *mp_model, SolverLogger *logger)
Collection of objects used to extend the Constraint Solver library.
bool ExtractValidMPModelInPlaceOrPopulateResponseStatus(MPModelRequest *request, MPSolutionResponse *response)
Like ExtractValidMPModelOrPopulateResponseStatus(), but works in-place: if the MPModel needed extract...
MPSolverResponseStatus ApplyMipPresolveSteps(const glop::GlopParameters &glop_params, MPModelProto *model, std::vector< std::unique_ptr< glop::Preprocessor > > *for_postsolve, SolverLogger *logger)
bool ProtobufTextFormatMergeFromString(const std::string &proto_text_string, ProtoType *proto)
absl::StatusOr< MPSolutionResponse > SatSolveProto(MPModelRequest request, std::atomic< bool > *interrupt_solve, std::function< void(const std::string &)> logging_callback, std::function< void(const MPSolution &)> solution_callback)
std::string EncodeSatParametersAsString(const sat::SatParameters ¶meters)
#define SOLVER_LOG(logger,...)