Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
solver_resources.cc
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
15
16#include <string>
17#include <utility>
18
19#include "absl/status/statusor.h"
20#include "absl/strings/str_cat.h"
21#include "absl/strings/string_view.h"
23
25
26SolverResourcesProto SolverResources::Proto() const {
27 SolverResourcesProto ret;
28 if (cpu.has_value()) {
29 ret.set_cpu(cpu.value());
30 }
31 if (ram.has_value()) {
32 ret.set_ram(ram.value());
33 }
34 return ret;
35}
36
37absl::StatusOr<SolverResources> SolverResources::FromProto(
38 const SolverResourcesProto& proto) {
40 if (proto.has_cpu()) {
41 ret.cpu = proto.cpu();
42 }
43 if (proto.has_ram()) {
44 ret.ram = proto.ram();
45 }
46 return ret;
47}
48
49bool AbslParseFlag(const absl::string_view text,
50 SolverResources* const solver_resources,
51 std::string* const error) {
52 SolverResourcesProto proto;
53 if (!ProtobufParseTextProtoForFlag(text, &proto, error)) {
54 return false;
55 }
56 absl::StatusOr<SolverResources> resources = SolverResources::FromProto(proto);
57 if (!resources.ok()) {
58 *error = absl::StrCat(
59 "SolverResourcesProto was invalid and could not convert to "
60 "SolverResources: ",
61 resources.status().ToString());
62 return false;
63 }
64 *solver_resources = *std::move(resources);
65 return true;
66}
67
68std::string AbslUnparseFlag(const SolverResources& solver_resources) {
69 return ProtobufTextFormatPrintToStringForFlag(solver_resources.Proto());
70}
71
72} // namespace operations_research::math_opt
CpModelProto proto
The output proto.
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition gurobi_isv.cc:28
bool AbslParseFlag(const absl::string_view text, SolverType *const value, std::string *const error)
std::string AbslUnparseFlag(const SolverType value)
std::string ProtobufTextFormatPrintToStringForFlag(const google::protobuf::Message &proto)
bool ProtobufParseTextProtoForFlag(absl::string_view text, ProtoType *message_out, std::string *error_out)
Definition proto_utils.h:86
static absl::StatusOr< SolverResources > FromProto(const SolverResourcesProto &proto)