Skip to content

Commit

Permalink
Add empty stubs for Highs support, #3116
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Oct 3, 2022
1 parent 3a284dc commit 488211e
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 5 deletions.
8 changes: 7 additions & 1 deletion ortools/linear_solver/linear_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -214,13 +216,17 @@ 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,

// 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.
Expand Down
4 changes: 3 additions & 1 deletion ortools/linear_solver/linear_solver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions ortools/linear_solver/proto_solver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ 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",
"scip_proto_solver.cc",
],
hdrs = [
"gurobi_proto_solver.h",
"highs_proto_solver.h",
"pdlp_proto_solver.h",
"sat_proto_solver.h",
"sat_solver_utils.h",
Expand All @@ -34,6 +36,7 @@ cc_library(
copts = [
"-DUSE_PDLP",
"-DUSE_SCIP",
"-DUSE_HIGHS",
],
deps = [
"//ortools/base",
Expand Down
37 changes: 37 additions & 0 deletions ortools/linear_solver/proto_solver/highs_proto_solver.cc
Original file line number Diff line number Diff line change
@@ -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 <cmath>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

#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<MPSolutionResponse> HighsSolveProto(MPModelRequest request,
bool solve_as_a_mip) {
return absl::UnimplementedError("Highs support is not yet implemented");
}

} // namespace operations_research
31 changes: 31 additions & 0 deletions ortools/linear_solver/proto_solver/highs_proto_solver.h
Original file line number Diff line number Diff line change
@@ -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 <functional>
#include <string>

#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<MPSolutionResponse> HighsSolveProto(MPModelRequest request,
bool solve_as_a_mip = true);

} // namespace operations_research

#endif // OR_TOOLS_LINEAR_SOLVER_PROTO_SOLVER_HIGHS_PROTO_SOLVER_H_
5 changes: 3 additions & 2 deletions ortools/linear_solver/wrappers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions ortools/linear_solver/wrappers/model_builder_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ortools/linear_solver/xpress_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 488211e

Please sign in to comment.