diff --git a/ortools/linear_solver/proto_solver/BUILD.bazel b/ortools/linear_solver/proto_solver/BUILD.bazel index 4a2d2f8950..9162959482 100644 --- a/ortools/linear_solver/proto_solver/BUILD.bazel +++ b/ortools/linear_solver/proto_solver/BUILD.bazel @@ -167,3 +167,26 @@ cc_library( "@com_google_absl//absl/status:statusor", ], ) + +cc_library( + name = "xpress_proto_solver", + srcs = ["xpress_proto_solver.cc"], + hdrs = ["xpress_proto_solver.h"], + deps = [ + "//ortools/base:timer", + "//ortools/xpress:environment", + "//ortools/linear_solver:linear_solver_cc_proto", + "//ortools/linear_solver:model_validator", + "//ortools/util:lazy_mutable_copy", + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/cleanup", + "@com_google_absl//absl/log", + "@com_google_absl//absl/log:check", + "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/time", + "@com_google_absl//absl/types:optional", + ], +) \ No newline at end of file diff --git a/ortools/linear_solver/proto_solver/xpress_proto_solver.cc b/ortools/linear_solver/proto_solver/xpress_proto_solver.cc new file mode 100644 index 0000000000..beab59228c --- /dev/null +++ b/ortools/linear_solver/proto_solver/xpress_proto_solver.cc @@ -0,0 +1,56 @@ +// 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 +#include +#include +#include +#include +#include +#include +#include + +#include "absl/base/attributes.h" +#include "absl/cleanup/cleanup.h" +#include "absl/log/check.h" +#include "absl/status/status.h" +#include "absl/status/statusor.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/str_format.h" +#include "absl/strings/str_join.h" +#include "absl/strings/str_split.h" +#include "absl/strings/string_view.h" +#include "absl/time/clock.h" +#include "absl/time/time.h" +#include "absl/types/optional.h" +#include "ortools/base/logging.h" +#include "ortools/base/status_macros.h" +#include "ortools/base/timer.h" +#include "ortools/linear_solver/linear_solver.pb.h" +#include "ortools/linear_solver/model_validator.h" +#include "ortools/linear_solver/proto_solver/xpress_proto_solver.h" +#include "ortools/util/lazy_mutable_copy.h" +#include "ortools/xpress/environment.h" + +namespace operations_research { + +absl::StatusOr XpressSolveProto( + const MPModelRequest& request) { + MPSolutionResponse response; + response.set_status(MPSOLVER_SOLVER_TYPE_UNAVAILABLE); + response.set_status_str(std::string("XPressMP not supported")); // NOLINT + + return response; +} + +} // namespace operations_research diff --git a/ortools/linear_solver/proto_solver/xpress_proto_solver.h b/ortools/linear_solver/proto_solver/xpress_proto_solver.h new file mode 100644 index 0000000000..dd9819354d --- /dev/null +++ b/ortools/linear_solver/proto_solver/xpress_proto_solver.h @@ -0,0 +1,32 @@ +// 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. + +#ifndef OR_TOOLS_LINEAR_SOLVER_PROTO_SOLVER_XPRESS_PROTO_SOLVER_H_ +#define OR_TOOLS_LINEAR_SOLVER_PROTO_SOLVER_XPRESS_PROTO_SOLVER_H_ + +#include + +#include "absl/status/status.h" +#include "absl/status/statusor.h" +#include "absl/strings/string_view.h" +#include "ortools/xpress/environment.h" +#include "ortools/linear_solver/linear_solver.pb.h" + +namespace operations_research { + +// Solves the input request. +absl::StatusOr XpressSolveProto( + const MPModelRequest& request); + +} // namespace operations_research +#endif // OR_TOOLS_LINEAR_SOLVER_PROTO_SOLVER_XPRESS_PROTO_SOLVER_H_ diff --git a/ortools/linear_solver/wrappers/BUILD.bazel b/ortools/linear_solver/wrappers/BUILD.bazel index 48fa1d8435..90d38351d6 100644 --- a/ortools/linear_solver/wrappers/BUILD.bazel +++ b/ortools/linear_solver/wrappers/BUILD.bazel @@ -45,8 +45,10 @@ cc_library( "//ortools/linear_solver/proto_solver:pdlp_proto_solver", "//ortools/linear_solver/proto_solver:sat_proto_solver", "//ortools/linear_solver/proto_solver:scip_proto_solver", + "//ortools/linear_solver/proto_solver:xpress_proto_solver", "//ortools/lp_data:lp_parser", "//ortools/lp_data:mps_reader", "//ortools/util:logging", + "//ortools/xpress:environment", ], ) diff --git a/ortools/linear_solver/wrappers/model_builder_helper.cc b/ortools/linear_solver/wrappers/model_builder_helper.cc index 02227c6af7..91c9844221 100644 --- a/ortools/linear_solver/wrappers/model_builder_helper.cc +++ b/ortools/linear_solver/wrappers/model_builder_helper.cc @@ -26,11 +26,14 @@ #include "ortools/base/helpers.h" #include "ortools/base/logging.h" #include "ortools/base/options.h" +#include "ortools/gurobi/environment.h" #include "ortools/linear_solver/linear_solver.h" #include "ortools/linear_solver/linear_solver.pb.h" #include "ortools/linear_solver/model_exporter.h" #include "ortools/linear_solver/proto_solver/glop_proto_solver.h" +#include "ortools/linear_solver/proto_solver/gurobi_proto_solver.h" #include "ortools/linear_solver/proto_solver/sat_proto_solver.h" +#include "ortools/linear_solver/proto_solver/xpress_proto_solver.h" #include "ortools/linear_solver/solve_mp_model.h" #if defined(USE_SCIP) #include "ortools/linear_solver/proto_solver/scip_proto_solver.h" @@ -42,6 +45,7 @@ #include "ortools/lp_data/lp_parser.h" #endif // defined(USE_LP_PARSER) #include "ortools/lp_data/mps_reader.h" +#include "ortools/xpress/environment.h" namespace operations_research { @@ -530,6 +534,16 @@ bool ModelSolverHelper::SolverIsSupported() const { return true; } #endif // USE_SCIP + if (solver_type_.value() == + MPModelRequest::GUROBI_MIXED_INTEGER_PROGRAMMING || + solver_type_.value() == MPModelRequest::GUROBI_LINEAR_PROGRAMMING) { + return GurobiIsCorrectlyInstalled(); + } + if (solver_type_.value() == + MPModelRequest::XPRESS_MIXED_INTEGER_PROGRAMMING || + solver_type_.value() == MPModelRequest::XPRESS_LINEAR_PROGRAMMING) { + return XpressIsCorrectlyInstalled(); + } return false; } @@ -581,6 +595,23 @@ void ModelSolverHelper::Solve(const ModelBuilderHelper& model) { break; } #endif // defined(USE_PDLP) + case MPModelRequest:: + GUROBI_LINEAR_PROGRAMMING: // ABSL_FALLTHROUGH_INTENDED + case MPModelRequest::GUROBI_MIXED_INTEGER_PROGRAMMING: { + const auto temp = GurobiSolveProto(request); + if (temp.ok()) { + response_ = std::move(temp.value()); + } + } + case MPModelRequest:: + XPRESS_LINEAR_PROGRAMMING: // ABSL_FALLTHROUGH_INTENDED + case MPModelRequest::XPRESS_MIXED_INTEGER_PROGRAMMING: { + const auto temp = XpressSolveProto(request); + if (temp.ok()) { + response_ = std::move(temp.value()); + } + } + default: { response_->set_status( MPSolverResponseStatus::MPSOLVER_SOLVER_TYPE_UNAVAILABLE);