math_opt: Add solve_arguments.cc

This commit is contained in:
Corentin Le Molgat
2022-12-19 10:09:00 +01:00
parent b36e2cb18b
commit c73e32a43b
2 changed files with 42 additions and 0 deletions

View File

@@ -313,6 +313,7 @@ cc_library(
cc_library(
name = "solve_arguments",
srcs = ["solve_arguments.cc"],
hdrs = [
"solve_arguments.h",
],

View File

@@ -0,0 +1,41 @@
// Copyright 2010-2022 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "ortools/math_opt/cpp/solve_arguments.h"
#include <functional>
#include "absl/container/flat_hash_set.h"
#include "absl/status/status.h"
#include "ortools/base/status_macros.h"
#include "ortools/math_opt/cpp/callback.h"
#include "ortools/math_opt/cpp/model_solve_parameters.h"
#include "ortools/math_opt/storage/model_storage.h"
namespace operations_research::math_opt {
absl::Status SolveArguments::CheckModelStorageAndCallback(
const ModelStorage* const expected_storage) const {
RETURN_IF_ERROR(model_parameters.CheckModelStorage(expected_storage))
<< "invalid model_parameters";
RETURN_IF_ERROR(callback_registration.CheckModelStorage(expected_storage))
<< "invalid callback_registration";
if (callback == nullptr && !callback_registration.events.empty()) {
return absl::InvalidArgumentError(
"no callback was provided to run, but callback events were registered");
}
return absl::OkStatus();
}
} // namespace operations_research::math_opt