diff --git a/ortools/linear_solver/linear_solver.h b/ortools/linear_solver/linear_solver.h index 733c075a47..5fccc2cb3e 100644 --- a/ortools/linear_solver/linear_solver.h +++ b/ortools/linear_solver/linear_solver.h @@ -199,10 +199,12 @@ class MPSolver { // gradient method. Sometimes faster than Glop for medium-size problems and // scales to much larger problems than Glop. PDLP_LINEAR_PROGRAMMING = 8, + HIGHS_LINEAR_PROGRAMMING = 15, // Integer programming problems. // ----------------------------- - SCIP_MIXED_INTEGER_PROGRAMMING = 3, // Recommended default value. + // Recommended default value for MIP problems. + SCIP_MIXED_INTEGER_PROGRAMMING = 3, GLPK_MIXED_INTEGER_PROGRAMMING = 4, CBC_MIXED_INTEGER_PROGRAMMING = 5, @@ -214,6 +216,8 @@ class MPSolver { XPRESS_LINEAR_PROGRAMMING = 101, XPRESS_MIXED_INTEGER_PROGRAMMING = 102, + HIGHS_MIXED_INTEGER_PROGRAMMING = 16, + // Boolean optimization problem (requires only integer variables and works // best with only Boolean variables). BOP_INTEGER_PROGRAMMING = 12, @@ -221,6 +225,8 @@ class MPSolver { // SAT based solver (requires only integer and Boolean variables). // If you pass it mixed integer problems, it will scale coefficients to // integer values, and solver continuous variables as integral variables. + // + // Recommended default value for pure integral problems problems. SAT_INTEGER_PROGRAMMING = 14, // Dedicated knapsack solvers. diff --git a/ortools/linear_solver/linear_solver.proto b/ortools/linear_solver/linear_solver.proto index a7999bbc1b..6b63c1f824 100644 --- a/ortools/linear_solver/linear_solver.proto +++ b/ortools/linear_solver/linear_solver.proto @@ -425,6 +425,7 @@ message MPModelRequest { XPRESS_LINEAR_PROGRAMMING = 101; // Commercial, needs a valid license. NOLINT CPLEX_LINEAR_PROGRAMMING = 10; // Commercial, needs a valid license. NOLINT + HIGHS_LINEAR_PROGRAMMING = 15; SCIP_MIXED_INTEGER_PROGRAMMING = 3; // Recommended default for MIP models. GLPK_MIXED_INTEGER_PROGRAMMING = 4; @@ -434,13 +435,14 @@ message MPModelRequest { 102; // Commercial, needs a valid license. NOLINT CPLEX_MIXED_INTEGER_PROGRAMMING = 11; // Commercial, needs a valid license. NOLINT + HIGHS_MIXED_INTEGER_PROGRAMMING = 16; BOP_INTEGER_PROGRAMMING = 12; // WARNING: This solver will currently interpret all variables as integer, // so any solution you get will be valid, but the optimal might be far away // for the real one (when you authorise non-integer value for continuous // variables). - SAT_INTEGER_PROGRAMMING = 14; + SAT_INTEGER_PROGRAMMING = 14; // Recommended for pure integer problems. // In-house linear programming solver based on the primal-dual hybrid // gradient method. Sometimes faster than Glop for medium-size problems and diff --git a/ortools/linear_solver/proto_solver/BUILD.bazel b/ortools/linear_solver/proto_solver/BUILD.bazel index 45091505b6..2eba856333 100644 --- a/ortools/linear_solver/proto_solver/BUILD.bazel +++ b/ortools/linear_solver/proto_solver/BUILD.bazel @@ -19,6 +19,7 @@ cc_library( name = "proto_solver", srcs = [ "gurobi_proto_solver.cc", + "highs_proto_solver.cc", "pdlp_proto_solver.cc", "sat_proto_solver.cc", "sat_solver_utils.cc", @@ -26,6 +27,7 @@ cc_library( ], hdrs = [ "gurobi_proto_solver.h", + "highs_proto_solver.h", "pdlp_proto_solver.h", "sat_proto_solver.h", "sat_solver_utils.h", @@ -34,6 +36,7 @@ cc_library( copts = [ "-DUSE_PDLP", "-DUSE_SCIP", + "-DUSE_HIGHS", ], deps = [ "//ortools/base", diff --git a/ortools/linear_solver/proto_solver/highs_proto_solver.cc b/ortools/linear_solver/proto_solver/highs_proto_solver.cc new file mode 100644 index 0000000000..4f74ce7ff2 --- /dev/null +++ b/ortools/linear_solver/proto_solver/highs_proto_solver.cc @@ -0,0 +1,37 @@ +// 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/proto_solver/highs_proto_solver.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "absl/status/statusor.h" +#include "ortools/linear_solver/linear_solver.pb.h" +#include "ortools/linear_solver/model_validator.h" +#include "ortools/port/proto_utils.h" + +namespace operations_research { + +absl::StatusOr HighsSolveProto(MPModelRequest request, + bool solve_as_a_mip) { + return absl::UnimplementedError("Highs support is not yet implemented"); +} + +} // namespace operations_research diff --git a/ortools/linear_solver/proto_solver/highs_proto_solver.h b/ortools/linear_solver/proto_solver/highs_proto_solver.h new file mode 100644 index 0000000000..67d7684d29 --- /dev/null +++ b/ortools/linear_solver/proto_solver/highs_proto_solver.h @@ -0,0 +1,31 @@ +// 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_HIGHS_PROTO_SOLVER_H_ +#define OR_TOOLS_LINEAR_SOLVER_PROTO_SOLVER_HIGHS_PROTO_SOLVER_H_ + +#include +#include + +#include "absl/status/statusor.h" +#include "ortools/linear_solver/linear_solver.pb.h" + +namespace operations_research { + +// Solve the input MIP model with the HIGHS solver. +absl::StatusOr HighsSolveProto(MPModelRequest request, + bool solve_as_a_mip = true); + +} // namespace operations_research + +#endif // OR_TOOLS_LINEAR_SOLVER_PROTO_SOLVER_HIGHS_PROTO_SOLVER_H_ diff --git a/ortools/linear_solver/wrappers/BUILD.bazel b/ortools/linear_solver/wrappers/BUILD.bazel index 9612478812..8dec5305b2 100644 --- a/ortools/linear_solver/wrappers/BUILD.bazel +++ b/ortools/linear_solver/wrappers/BUILD.bazel @@ -30,8 +30,9 @@ cc_library( srcs = ["model_builder_helper.cc"], hdrs = ["model_builder_helper.h"], copts = [ - "-DUSE_SCIP", - ], + "-DUSE_HIGHS", + "-DUSE_PDLP", + "-DUSE_SCIP", ], visibility = ["//visibility:public"], deps = [ "//ortools/linear_solver", diff --git a/ortools/linear_solver/wrappers/model_builder_helper.cc b/ortools/linear_solver/wrappers/model_builder_helper.cc index eb16f0b0e2..e870088f32 100644 --- a/ortools/linear_solver/wrappers/model_builder_helper.cc +++ b/ortools/linear_solver/wrappers/model_builder_helper.cc @@ -21,6 +21,7 @@ #include "ortools/linear_solver/linear_solver.h" #include "ortools/linear_solver/linear_solver.pb.h" +#include "ortools/linear_solver/proto_solver/highs_proto_solver.h" #include "ortools/linear_solver/proto_solver/sat_proto_solver.h" #if defined(USE_SCIP) #include "ortools/linear_solver/proto_solver/scip_proto_solver.h" @@ -324,6 +325,22 @@ void ModelSolverHelper::Solve(const ModelBuilderHelper& model) { break; } #endif // defined(USE_SCIP) +#if defined(USE_HIGHS) + case MPModelRequest::HIGHS_MIXED_INTEGER_PROGRAMMING: { + const auto temp = HighsSolveProto(request, true); + if (temp.ok()) { + response_ = std::move(temp.value()); + } + break; + } + case MPModelRequest::HIGHS_LINEAR_PROGRAMMING: { + const auto temp = HighsSolveProto(request, false); + if (temp.ok()) { + response_ = std::move(temp.value()); + } + break; + } +#endif // defined(USE_HIGHS) default: { response_->set_status( MPSolverResponseStatus::MPSOLVER_SOLVER_TYPE_UNAVAILABLE); diff --git a/ortools/linear_solver/xpress_interface.cc b/ortools/linear_solver/xpress_interface.cc index 3c5fb70523..e982cefd03 100644 --- a/ortools/linear_solver/xpress_interface.cc +++ b/ortools/linear_solver/xpress_interface.cc @@ -177,7 +177,7 @@ class XpressInterface : public MPSolverInterface { return 0.0; } - // TODO(user,user): Not yet working. + // TODO(user): Not yet working. LOG(DFATAL) << "ComputeExactConditionNumber not implemented for" << " XPRESS_LINEAR_PROGRAMMING"; return 0.0;