diff --git a/ortools/math_opt/cpp/BUILD.bazel b/ortools/math_opt/cpp/BUILD.bazel index 715f1ecb7a..4e4b887731 100644 --- a/ortools/math_opt/cpp/BUILD.bazel +++ b/ortools/math_opt/cpp/BUILD.bazel @@ -313,6 +313,7 @@ cc_library( cc_library( name = "solve_arguments", + srcs = ["solve_arguments.cc"], hdrs = [ "solve_arguments.h", ], diff --git a/ortools/math_opt/cpp/solve_arguments.cc b/ortools/math_opt/cpp/solve_arguments.cc new file mode 100644 index 0000000000..8914b27959 --- /dev/null +++ b/ortools/math_opt/cpp/solve_arguments.cc @@ -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 + +#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