20 #include <type_traits>
23 #include "absl/status/status.h"
24 #include "absl/status/statusor.h"
25 #include "absl/strings/string_view.h"
26 #include "absl/time/time.h"
27 #include "absl/types/span.h"
31 #include "ortools/math_opt/parameters.pb.h"
32 #include "ortools/math_opt/solvers/gurobi.pb.h"
40 template <
typename EnumType>
41 bool ParseEnumFlag(
const absl::string_view text, EnumType*
const value,
42 std::string*
const error) {
43 const std::optional<EnumType> enum_value = EnumFromString<EnumType>(text);
44 if (!enum_value.has_value()) {
45 *error =
"unknown value for enumeration";
53 template <
typename EnumType>
54 std::string UnparseEnumFlag(
const EnumType
value) {
55 std::ostringstream oss;
80 static constexpr
SolverType kSolverTypeValues[] = {
84 return absl::MakeConstSpan(kSolverTypeValues);
88 std::string*
const error) {
89 return ParseEnumFlag(text,
value, error);
93 return UnparseEnumFlag(
value);
100 return "primal_simplex";
102 return "dual_simplex";
110 static constexpr
LPAlgorithm kLPAlgorithmValues[] = {
115 return absl::MakeConstSpan(kLPAlgorithmValues);
119 std::string*
const error) {
120 return ParseEnumFlag(text,
value, error);
124 return UnparseEnumFlag(
value);
144 static constexpr
Emphasis kEmphasisValues[] = {
148 return absl::MakeConstSpan(kEmphasisValues);
152 std::string*
const error) {
153 return ParseEnumFlag(text,
value, error);
157 return UnparseEnumFlag(
value);
161 GurobiParametersProto result;
163 GurobiParametersProto::Parameter& p = *result.add_parameters();
171 const GurobiParametersProto&
proto) {
173 for (
const GurobiParametersProto::Parameter& p :
proto.parameters()) {
180 SolveParametersProto result;
184 result.mutable_time_limit()));
224 *result.mutable_gscip() =
gscip;
226 *result.mutable_glop() =
glop;
227 *result.mutable_cp_sat() =
cp_sat;
232 const SolveParametersProto&
proto) {
235 if (
proto.has_time_limit()) {
238 _ <<
"invalid time_limit");
242 if (
proto.has_iteration_limit()) {
245 if (
proto.has_node_limit()) {
248 if (
proto.has_cutoff_limit()) {
251 if (
proto.has_objective_limit()) {
254 if (
proto.has_best_bound_limit()) {
257 if (
proto.has_solution_limit()) {
260 if (
proto.has_threads()) {
263 if (
proto.has_random_seed()) {
266 if (
proto.has_absolute_gap_tolerance()) {
269 if (
proto.has_relative_gap_tolerance()) {
272 if (
proto.has_solution_pool_size()) {
288 std::string* error) {
289 SolveParametersProto
proto;
295 *error = absl::StrCat(
296 "SolveParametersProto was invalid and could not convert to "
298 params.status().ToString());
301 *solve_parameters = *std::move(params);
bool AbslParseFlag(const absl::string_view text, SolverType *const value, std::string *const error)
std::string AbslUnparseFlag(const SolverType value)
std::optional< typename EnumProto< P >::Cpp > EnumFromProto(const P proto_value)
Enum< E >::Proto EnumToProto(const std::optional< E > value)
Collection of objects used to extend the Constraint Solver library.
std::string ProtobufTextFormatPrintToString(const ProtoType 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 std::optional< absl::string_view > ToOptString(E value)
static absl::Span< const E > AllValues()
static GurobiParameters FromProto(const GurobiParametersProto &proto)
GurobiParametersProto Proto() const
gtl::linked_hash_map< std::string, std::string > param_values
std::optional< double > best_bound_limit
std::optional< Emphasis > scaling
std::optional< int32_t > solution_limit
absl::Duration time_limit
std::optional< int64_t > node_limit
std::optional< Emphasis > heuristics
std::optional< double > absolute_gap_tolerance
std::optional< double > relative_gap_tolerance
std::optional< LPAlgorithm > lp_algorithm
std::optional< Emphasis > presolve
std::optional< int32_t > random_seed
std::optional< int32_t > threads
static absl::StatusOr< SolveParameters > FromProto(const SolveParametersProto &proto)
SolveParametersProto Proto() const
sat::SatParameters cp_sat
std::optional< double > objective_limit
std::optional< Emphasis > cuts
std::optional< int64_t > iteration_limit
std::optional< double > cutoff_limit
glop::GlopParameters glop
std::optional< int32_t > solution_pool_size
#define OR_ASSIGN_OR_RETURN3(lhs, rexpr, error_expression)