Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
solve_stats_validator.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 "absl/status/status.h"
17#include "absl/status/statusor.h"
18#include "absl/strings/str_cat.h"
19#include "absl/time/time.h"
21#include "ortools/math_opt/result.pb.h"
22
23namespace operations_research {
24namespace math_opt {
25
26absl::Status ValidateSolveStats(const SolveStatsProto& solve_stats) {
27 const absl::StatusOr<absl::Duration> solve_time =
28 util_time::DecodeGoogleApiProto(solve_stats.solve_time());
29 if (!solve_time.ok()) {
30 return absl::InvalidArgumentError(
31 absl::StrCat("invalid solve_time, ", solve_time.status().message()));
32 }
33 if (solve_time.value() < absl::ZeroDuration()) {
34 return absl::InvalidArgumentError("solve_time must be non-negative");
35 }
36 if (solve_stats.simplex_iterations() < 0) {
37 return absl::InvalidArgumentError(
38 "simplex_iterations must be non-negative");
39 }
40 if (solve_stats.barrier_iterations() < 0) {
41 return absl::InvalidArgumentError(
42 "barrier_iterations must be non-negative");
43 }
44 if (solve_stats.node_count() < 0) {
45 return absl::InvalidArgumentError("node_count must be non-negative");
46 }
47 return absl::OkStatus();
48}
49
50} // namespace math_opt
51} // namespace operations_research
absl::Status ValidateSolveStats(const SolveStatsProto &solve_stats)
In SWIG mode, we don't want anything besides these top-level includes.
inline ::absl::StatusOr< absl::Duration > DecodeGoogleApiProto(const google::protobuf::Duration &proto)
Definition protoutil.h:42