22#include "absl/log/check.h"
23#include "absl/status/status.h"
24#include "absl/status/statusor.h"
25#include "absl/strings/str_cat.h"
26#include "absl/strings/string_view.h"
27#include "absl/time/time.h"
28#include "absl/types/span.h"
32#include "ortools/math_opt/parameters.pb.h"
33#include "ortools/math_opt/solvers/glpk.pb.h"
34#include "ortools/math_opt/solvers/gurobi.pb.h"
35#include "ortools/math_opt/solvers/highs.pb.h"
43template <
typename EnumType>
44bool ParseEnumFlag(
const absl::string_view text, EnumType*
const value,
45 std::string*
const error) {
47 if (!enum_value.has_value()) {
48 *error =
"unknown value for enumeration";
56template <
typename EnumType>
57std::string UnparseEnumFlag(
const EnumType value) {
58 std::ostringstream oss;
95 static constexpr SolverType kSolverTypeValues[] = {
101 return absl::MakeConstSpan(kSolverTypeValues);
105 std::string*
const error) {
106 return ParseEnumFlag(text, value, error);
110 return UnparseEnumFlag(value);
117 return "primal_simplex";
119 return "dual_simplex";
123 return "first_order";
129 static constexpr LPAlgorithm kLPAlgorithmValues[] = {
135 return absl::MakeConstSpan(kLPAlgorithmValues);
139 std::string*
const error) {
140 return ParseEnumFlag(text, value, error);
144 return UnparseEnumFlag(value);
164 static constexpr Emphasis kEmphasisValues[] = {
168 return absl::MakeConstSpan(kEmphasisValues);
172 std::string*
const error) {
173 return ParseEnumFlag(text, value, error);
177 return UnparseEnumFlag(value);
181 GurobiParametersProto result;
183 GurobiParametersProto::Parameter& p = *result.add_parameters();
191 const GurobiParametersProto& proto) {
193 for (
const GurobiParametersProto::Parameter& p : proto.parameters()) {
200 GlpkParametersProto result;
202 result.set_compute_unbound_rays_if_possible(
210 if (proto.has_compute_unbound_rays_if_possible()) {
212 proto.compute_unbound_rays_if_possible();
218 SolveParametersProto result;
222 result.mutable_time_limit()));
262 *result.mutable_gscip() =
gscip;
263 *result.mutable_gurobi() =
gurobi.Proto();
264 *result.mutable_glop() =
glop;
265 *result.mutable_cp_sat() =
cp_sat;
266 *result.mutable_pdlp() =
pdlp;
267 *result.mutable_glpk() =
glpk.Proto();
268 *result.mutable_highs() =
highs;
273 const SolveParametersProto& proto) {
276 if (proto.has_time_limit()) {
279 _ <<
"invalid time_limit");
283 if (proto.has_iteration_limit()) {
286 if (proto.has_node_limit()) {
289 if (proto.has_cutoff_limit()) {
292 if (proto.has_objective_limit()) {
295 if (proto.has_best_bound_limit()) {
298 if (proto.has_solution_limit()) {
301 if (proto.has_threads()) {
302 result.
threads = proto.threads();
304 if (proto.has_random_seed()) {
307 if (proto.has_absolute_gap_tolerance()) {
310 if (proto.has_relative_gap_tolerance()) {
313 if (proto.has_solution_pool_size()) {
321 result.
gscip = proto.gscip();
323 result.
glop = proto.glop();
324 result.
cp_sat = proto.cp_sat();
325 result.
pdlp = proto.pdlp();
327 result.
highs = proto.highs();
332 std::string* error) {
333 SolveParametersProto proto;
339 *error = absl::StrCat(
340 "SolveParametersProto was invalid and could not convert to "
342 params.status().ToString());
345 *solve_parameters = *std::move(params);
An object oriented wrapper for quadratic constraints in ModelStorage.
bool AbslParseFlag(const absl::string_view text, SolverType *const value, std::string *const error)
SolverType
The solvers supported by MathOpt.
Emphasis
never give an error, and will map onto their best match.
LPAlgorithm
Selects an algorithm for solving linear programs.
std::optional< typename EnumProto< P >::Cpp > EnumFromProto(P proto_value)
std::optional< E > EnumFromString(absl::string_view str)
Enum< E >::Proto EnumToProto(std::optional< E > value)
std::string AbslUnparseFlag(const SolverType value)
In SWIG mode, we don't want anything besides these top-level includes.
std::string ProtobufTextFormatPrintToStringForFlag(const google::protobuf::Message &proto)
bool ProtobufParseTextProtoForFlag(absl::string_view text, ProtoType *message_out, std::string *error_out)
inline ::absl::StatusOr< absl::Duration > DecodeGoogleApiProto(const google::protobuf::Duration &proto)
inline ::absl::StatusOr< google::protobuf::Duration > EncodeGoogleApiProto(absl::Duration d)
static absl::Span< const E > AllValues()
Returns all possible values of the enum.
static std::optional< absl::string_view > ToOptString(E value)
std::optional< bool > compute_unbound_rays_if_possible
static GlpkParameters FromProto(const GlpkParametersProto &proto)
GlpkParametersProto Proto() const
gtl::linked_hash_map< std::string, std::string > param_values
Parameter name-value pairs to set in insertion order.
GurobiParametersProto Proto() const
static GurobiParameters FromProto(const GurobiParametersProto &proto)
std::optional< LPAlgorithm > lp_algorithm
std::optional< int64_t > node_limit
std::optional< int32_t > random_seed
absl::Duration time_limit
pdlp::PrimalDualHybridGradientParams pdlp
std::optional< double > relative_gap_tolerance
static absl::StatusOr< SolveParameters > FromProto(const SolveParametersProto &proto)
std::optional< Emphasis > heuristics
std::optional< Emphasis > scaling
std::optional< double > absolute_gap_tolerance
std::optional< Emphasis > cuts
sat::SatParameters cp_sat
std::optional< int32_t > solution_limit
std::optional< int32_t > threads
If unset, use the solver default. If set, it must be >= 1.
std::optional< int64_t > iteration_limit
std::optional< int32_t > solution_pool_size
SolveParametersProto Proto() const
std::optional< double > objective_limit
std::optional< Emphasis > presolve
std::optional< double > cutoff_limit
glop::GlopParameters glop
std::optional< double > best_bound_limit
#define OR_ASSIGN_OR_RETURN3(lhs, rexpr, error_expression)