OR-Tools  8.2
scip_helper_macros.h
Go to the documentation of this file.
1 // Copyright 2010-2018 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 
14 #ifndef OR_TOOLS_LINEAR_SOLVER_SCIP_HELPER_MACROS_H_
15 #define OR_TOOLS_LINEAR_SOLVER_SCIP_HELPER_MACROS_H_
16 
17 #include "absl/status/status.h"
18 #include "absl/strings/str_format.h"
20 
21 namespace operations_research {
22 namespace internal {
23 // Our own version of SCIP_CALL to do error management.
24 // NOTE(user): There are so many SCIP error codes, in so many different
25 // situations. We don't try to match them perfectly to google3 error codes.
26 // Instead, we use the most likely/generic code "invalid argument" and surface
27 // the internal SCIP error code to the user.
28 inline absl::Status ScipCodeToUtilStatus(/*SCIP_Retcode*/ int retcode,
29  const char* source_file,
30  int source_line,
31  const char* scip_statement) {
32  if (retcode == /*SCIP_OKAY*/ 1) return absl::OkStatus();
33  return absl::InvalidArgumentError(
34  absl::StrFormat("SCIP error code %d (file '%s', line %d) on '%s'",
35  retcode, source_file, source_line, scip_statement));
36 }
37 } // namespace internal
38 
39 #define SCIP_TO_STATUS(x) \
40  ::operations_research::internal::ScipCodeToUtilStatus(x, __FILE__, __LINE__, \
41  #x)
42 
43 #define RETURN_IF_SCIP_ERROR(x) RETURN_IF_ERROR(SCIP_TO_STATUS(x));
44 
45 } // namespace operations_research
46 
47 #endif // OR_TOOLS_LINEAR_SOLVER_SCIP_HELPER_MACROS_H_
absl::Status ScipCodeToUtilStatus(int retcode, const char *source_file, int source_line, const char *scip_statement)
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...