Skip to content

Commit 718ccba

Browse files
committed
or-tools: add Highs support
1 parent a88a621 commit 718ccba

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Formula/o/or-tools.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class OrTools < Formula
4040
depends_on "clp"
4141
depends_on "coinutils"
4242
depends_on "eigen"
43+
depends_on "highs"
4344
depends_on "openblas"
4445
depends_on "osi"
4546
depends_on "protobuf"
@@ -52,9 +53,8 @@ class OrTools < Formula
5253
patch :DATA
5354

5455
def install
55-
# FIXME: Upstream enabled Highs support in their binary distribution, but our build fails with it.
5656
args = %w[
57-
-DUSE_HIGHS=OFF
57+
-DUSE_HIGHS=ON
5858
-DBUILD_DEPS=OFF
5959
-DBUILD_SAMPLES=OFF
6060
-DBUILD_EXAMPLES=OFF
@@ -112,6 +112,28 @@ def install
112112
*shell_output("pkg-config --cflags --libs #{absl_libs.join(" ")}").chomp.split,
113113
"-o", "simple_sat_program"
114114
system "./simple_sat_program"
115+
116+
# Highs backend
117+
(testpath/"highs_test.cc").write <<~EOS
118+
#include "ortools/linear_solver/linear_solver.h"
119+
using operations_research::MPSolver;
120+
int main() {
121+
if (!MPSolver::SupportsProblemType(MPSolver::HIGHS_LINEAR_PROGRAMMING)) return 1;
122+
MPSolver solver("t", MPSolver::HIGHS_LINEAR_PROGRAMMING);
123+
auto* x = solver.MakeNumVar(0.0, 1.0, "x");
124+
auto* obj = solver.MutableObjective();
125+
obj->SetCoefficient(x, 1.0);
126+
obj->SetMaximization();
127+
if (solver.Solve() != MPSolver::OPTIMAL) return 2;
128+
return x->solution_value() > 0.99 ? 0 : 3;
129+
}
130+
EOS
131+
system ENV.cxx, "-std=c++17", "highs_test.cc",
132+
"-I#{include}", "-L#{lib}", "-lortools",
133+
"-DOR_PROTO_DLL=", "-DPROTOBUF_USE_DLLS",
134+
*shell_output("pkg-config --cflags --libs #{absl_libs.join(" ")}").chomp.split,
135+
"-o", "highs_test"
136+
system "./highs_test"
115137
end
116138
end
117139

0 commit comments

Comments
 (0)