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;
93 static constexpr SolverType kSolverTypeValues[] = {
99 return absl::MakeConstSpan(kSolverTypeValues);
103 std::string*
const error) {
104 return ParseEnumFlag(text,
value, error);
108 return UnparseEnumFlag(
value);
115 return "primal_simplex";
117 return "dual_simplex";
121 return "first_order";
127 static constexpr LPAlgorithm kLPAlgorithmValues[] = {
133 return absl::MakeConstSpan(kLPAlgorithmValues);
137 std::string*
const error) {
138 return ParseEnumFlag(text,
value, error);
142 return UnparseEnumFlag(
value);
162 static constexpr Emphasis kEmphasisValues[] = {
166 return absl::MakeConstSpan(kEmphasisValues);
170 std::string*
const error) {
171 return ParseEnumFlag(text,
value, error);
175 return UnparseEnumFlag(
value);
179 GurobiParametersProto result;
181 GurobiParametersProto::Parameter& p = *result.add_parameters();
189 const GurobiParametersProto&
proto) {
191 for (
const GurobiParametersProto::Parameter& p :
proto.parameters()) {
198 GlpkParametersProto result;
200 result.set_compute_unbound_rays_if_possible(
208 if (
proto.has_compute_unbound_rays_if_possible()) {
210 proto.compute_unbound_rays_if_possible();
216 SolveParametersProto result;
220 result.mutable_time_limit()));
260 *result.mutable_gscip() =
gscip;
262 *result.mutable_glop() =
glop;
263 *result.mutable_cp_sat() =
cp_sat;
264 *result.mutable_pdlp() =
pdlp;
266 *result.mutable_highs() =
highs;
271 const SolveParametersProto&
proto) {
274 if (
proto.has_time_limit()) {
277 _ <<
"invalid time_limit");
281 if (
proto.has_iteration_limit()) {
284 if (
proto.has_node_limit()) {
287 if (
proto.has_cutoff_limit()) {
290 if (
proto.has_objective_limit()) {
293 if (
proto.has_best_bound_limit()) {
296 if (
proto.has_solution_limit()) {
299 if (
proto.has_threads()) {
302 if (
proto.has_random_seed()) {
305 if (
proto.has_absolute_gap_tolerance()) {
308 if (
proto.has_relative_gap_tolerance()) {
311 if (
proto.has_solution_pool_size()) {
330 std::string* error) {
331 SolveParametersProto
proto;
337 *error = absl::StrCat(
338 "SolveParametersProto was invalid and could not convert to "
340 params.status().ToString());
343 *solve_parameters = *std::move(params);
CpModelProto proto
The output proto.
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)