25#include "absl/log/check.h"
26#include "absl/log/log.h"
27#include "absl/strings/str_cat.h"
46 std::string message) {
47 SOLVER_LOG(&logger,
"Invalid model in glop_solve_proto.\n", message);
51 response.set_status_str(message);
56 std::string message) {
57 SOLVER_LOG(&logger,
"Invalid parameters in glop_solve_proto.\n", message);
62 response.set_status_str(message);
101 LOG(DFATAL) <<
"Invalid glop::ProblemStatus " << s;
109 std::function<
void(
const std::string&)> logging_callback) {
120 if (logging_callback !=
nullptr) {
127 if (request->has_solver_specific_parameters()) {
129 if (!std::is_base_of<Message, glop::GlopParameters>::value) {
130 if (!params.MergeFromString(request->solver_specific_parameters())) {
131 return ModelInvalidParametersResponse(
133 "solver_specific_parameters is not a valid binary stream of the "
134 "GLOPParameters proto");
138 request->solver_specific_parameters(), ¶ms)) {
139 return ModelInvalidParametersResponse(
141 "solver_specific_parameters is not a valid textual representation "
142 "of the GlopParameters proto");
146 if (request->has_solver_time_limit_seconds()) {
152 if (!error.empty()) {
153 return ModelInvalidParametersResponse(
154 logger, absl::StrCat(
"Invalid Glop parameters: ", error));
163 std::optional<LazyMutableCopy<MPModelProto>> optional_model =
165 if (!optional_model)
return response;
169 return ModelInvalidResponse(logger,
170 "GLOP does not support general constraints");
174 MPModelProtoToLinearProgram(mp_model, &linear_program);
175 std::move(request).dispose();
184 if (interrupt_solve !=
nullptr) {
185 if (interrupt_solve->load()) {
188 "Solve not started, because the user set the atomic<bool> in "
189 "MPSolver::SolveWithProto() to true before solving could "
193 time_limit->RegisterExternalBooleanAsLimit(interrupt_solve);
208 for (
int var_id = 0; var_id < num_vars; ++var_id) {
220 interrupt_solve->load()) {
225 for (
int ct_id = 0; ct_id < num_constraints; ++ct_id) {
const ::operations_research::MPGeneralConstraintProto & general_constraint(int index) const
void add_variable_value(double value)
void add_reduced_cost(double value)
void set_objective_value(double value)
void set_status_str(Arg_ &&arg, Args_... args)
void add_dual_value(double value)
void set_status(::operations_research::MPSolverResponseStatus value)
void EnableLogging(bool enable)
void SetLogToStdOut(bool enable)
Should all messages be displayed on stdout ?
void AddInfoLoggingCallback(std::function< void(const std::string &message)> callback)
static std::unique_ptr< TimeLimit > FromParameters(const Parameters ¶meters)
bool log_to_stdout() const
void set_max_time_in_seconds(double value)
bool log_search_progress() const
void set_log_search_progress(bool value)
A full-fledged linear programming solver.
const GlopParameters & GetParameters() const
static std::string GlopVersion()
Returns a string that describes the version of the solver.
const DenseRow & reduced_costs() const
Fractional GetObjectiveValue() const
Returns the objective value of the solution with its offset and scaling.
const DenseRow & variable_values() const
Accessors to information related to variables.
ABSL_MUST_USE_RESULT ProblemStatus SolveWithTimeLimit(const LinearProgram &lp, TimeLimit *time_limit)
const DenseColumn & dual_values() const
void SetParameters(const GlopParameters ¶meters)
ColIndex num_variables() const
Returns the number of variables.
RowIndex num_constraints() const
Returns the number of constraints.
std::string ValidateParameters(const GlopParameters ¶ms)
ProblemStatus
Different statuses for a given problem.
@ INFEASIBLE_OR_UNBOUNDED
@ ABNORMAL
An error occurred during the solving process.
@ INVALID_PROBLEM
The input problem was invalid (see LinearProgram.IsValid()).
@ INIT
The solver didn't had a chance to prove anything.
In SWIG mode, we don't want anything besides these top-level includes.
std::string GlopSolverVersion()
Returns a string that describes the version of the GLOP solver.
MPSolutionResponse GlopSolveProto(LazyMutableCopy< MPModelRequest > request, std::atomic< bool > *interrupt_solve, std::function< void(const std::string &)> logging_callback)
@ MPSOLVER_CANCELLED_BY_USER
@ MPSOLVER_UNKNOWN_STATUS
@ MPSOLVER_MODEL_INVALID_SOLVER_PARAMETERS
std::optional< LazyMutableCopy< MPModelProto > > GetMPModelOrPopulateResponse(LazyMutableCopy< MPModelRequest > &request, MPSolutionResponse *response)
bool ProtobufTextFormatMergeFromString(absl::string_view proto_text_string, ProtoType *proto)
#define SOLVER_LOG(logger,...)