solve_mp_model library
This commit is contained in:
@@ -416,3 +416,14 @@ cc_binary(
|
||||
"@com_google_absl//absl/time",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "solve_mp_model",
|
||||
srcs = ["solve_mp_model.cc"],
|
||||
hdrs = ["solve_mp_model.h"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":linear_solver",
|
||||
":linear_solver_cc_proto",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -700,6 +700,7 @@ class MPSolver {
|
||||
|
||||
// Gives some brief (a few lines, at most) human-readable information about
|
||||
// the given request, suitable for debug logging.
|
||||
ABSL_DEPRECATED("Prefer MPModelRequestLoggingInfo() from solve_mp_model.h.")
|
||||
static std::string GetMPModelRequestLoggingInfo(
|
||||
const MPModelRequest& request);
|
||||
|
||||
|
||||
41
ortools/linear_solver/solve_mp_model.cc
Normal file
41
ortools/linear_solver/solve_mp_model.cc
Normal 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/linear_solver/solve_mp_model.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
|
||||
#include "ortools/linear_solver/linear_solver.h"
|
||||
#include "ortools/linear_solver/linear_solver.pb.h"
|
||||
|
||||
namespace operations_research {
|
||||
|
||||
MPSolutionResponse SolveMPModel(const MPModelRequest& model_request,
|
||||
std::atomic<bool>* interrupt) {
|
||||
// TODO(b/311704821): this function should not delegate to MPSolver, also true
|
||||
// for the functions below.
|
||||
MPSolutionResponse response;
|
||||
MPSolver::SolveWithProto(model_request, &response, interrupt);
|
||||
return response;
|
||||
}
|
||||
|
||||
bool SolverTypeSupportsInterruption(const MPModelRequest::SolverType solver) {
|
||||
return MPSolver::SolverTypeSupportsInterruption(solver);
|
||||
}
|
||||
|
||||
std::string MPModelRequestLoggingInfo(const MPModelRequest& request) {
|
||||
return MPSolver::GetMPModelRequestLoggingInfo(request);
|
||||
}
|
||||
|
||||
} // namespace operations_research
|
||||
50
ortools/linear_solver/solve_mp_model.h
Normal file
50
ortools/linear_solver/solve_mp_model.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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.
|
||||
|
||||
// Functions for solving optimization models defined by MPModelRequest.
|
||||
//
|
||||
// See linear_solver.proto for further documentation.
|
||||
|
||||
#ifndef OR_TOOLS_LINEAR_SOLVER_SOLVE_MP_MODEL_H_
|
||||
#define OR_TOOLS_LINEAR_SOLVER_SOLVE_MP_MODEL_H_
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include "ortools/linear_solver/linear_solver.pb.h"
|
||||
|
||||
namespace operations_research {
|
||||
|
||||
/**
|
||||
* Solves the model encoded by a MPModelRequest protocol buffer and returns the
|
||||
* solution encoded as a MPSolutionResponse. The solve is stopped prematurely
|
||||
* if interrupt is non-null at set to true during (or before) solving.
|
||||
* Interruption is only supported if SolverTypeSupportsInterruption() returns
|
||||
* true for the requested solver. Passing a non-null interruption with any
|
||||
* other solver type immediately returns an MPSOLVER_INCOMPATIBLE_OPTIONS
|
||||
* error.
|
||||
*/
|
||||
MPSolutionResponse SolveMPModel(
|
||||
const MPModelRequest& model_request,
|
||||
// `interrupt` is non-const because the internal
|
||||
// solver may set it to true itself, in some cases.
|
||||
std::atomic<bool>* interrupt = nullptr);
|
||||
|
||||
bool SolverTypeSupportsInterruption(MPModelRequest::SolverType solver);
|
||||
|
||||
// Gives some brief (a few lines, at most) human-readable information about
|
||||
// the given request, suitable for debug logging.
|
||||
std::string MPModelRequestLoggingInfo(const MPModelRequest& request);
|
||||
|
||||
} // namespace operations_research
|
||||
|
||||
#endif // OR_TOOLS_LINEAR_SOLVER_SOLVE_MP_MODEL_H_
|
||||
Reference in New Issue
Block a user