diff --git a/CMakeLists.txt b/CMakeLists.txt
index b5692408aee5..10a7d4235313 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -483,7 +483,7 @@ set(BAZEL_CONFIGS)
option(WITH_GUROBI "Build with support for Gurobi" OFF)
if(WITH_GUROBI)
- find_package(Gurobi 9.5.1 EXACT MODULE REQUIRED)
+ find_package(Gurobi 9.5 EXACT MODULE REQUIRED)
list(APPEND BAZEL_CONFIGS --config=gurobi)
diff --git a/cmake/modules/FindGurobi.cmake b/cmake/modules/FindGurobi.cmake
index 415cfad58b04..7c51a8832e0d 100644
--- a/cmake/modules/FindGurobi.cmake
+++ b/cmake/modules/FindGurobi.cmake
@@ -1,11 +1,15 @@
# -*- mode: cmake -*-
# vi: set ft=cmake :
+file(GLOB _GUROBI_SEARCH_PATHS
+ /Library/gurobi95*/macos_universal2
+ /opt/gurobi95*/linux64
+ /opt/gurobi95*/power64
+)
+
find_path(Gurobi_INCLUDE_DIR NAMES gurobi_c.h
PATHS
- /Library/gurobi951/macos_universal2
- /opt/gurobi951/linux64
- /opt/gurobi951/power64
+ ${_GUROBI_SEARCH_PATHS}
ENV GUROBI_HOME
PATH_SUFFIXES include
)
@@ -38,14 +42,13 @@ find_library(Gurobi_LIBRARY
NAMES "gurobi${Gurobi_VERSION_MAJOR}${Gurobi_VERSION_MINOR}"
HINTS "${_GUROBI_ROOT}"
PATHS
- /Library/gurobi951/macos_universal2
- /opt/gurobi951/linux64
- /opt/gurobi951/power64
+ ${_GUROBI_SEARCH_PATHS}
ENV GUROBI_HOME
PATH_SUFFIXES lib
)
unset(_GUROBI_ROOT)
+unset(_GUROBI_SEARCH_PATHS)
include(FindPackageHandleStandardArgs)
diff --git a/doc/_pages/bazel.md b/doc/_pages/bazel.md
index d530ea23c550..ad87c654a66e 100644
--- a/doc/_pages/bazel.md
+++ b/doc/_pages/bazel.md
@@ -169,27 +169,31 @@ bazel build //tools/lint:buildifier
The Drake Bazel build currently supports the following proprietary solvers:
-* Gurobi 9.5.1
+* Gurobi 9.5
* MOSEKā¢ 10.0
* SNOPT 7.4
-## Gurobi 9.5.1
+## Gurobi 9.5
### Install on Ubuntu
1. Register for an account on [https://www.gurobi.com](https://www.gurobi.com).
2. Set up your Gurobi license file in accordance with Gurobi documentation.
3. ``export GRB_LICENSE_FILE=/path/to/gurobi.lic``.
-4. Download ``gurobi9.5.1_linux64.tar.gz``. You may need to manually edit the URL to get the correct minor version.
-5. Unzip it. We suggest that you use ``/opt/gurobi951`` to simplify working with Drake installations.
-6. If you unzipped into a location other than ``/opt/gurobi951``, then call ``export GUROBI_HOME=GUROBI_UNZIP_PATH/linux64`` to set the path you used, where in ``GUROBI_HOME`` folder you can find ``bin`` folder.
+4. Download ``gurobi9.5.2_linux64.tar.gz``. You may need to manually edit the URL to get the correct version.
+5. Unzip it. We suggest that you use ``/opt/gurobi952`` to simplify working with Drake installations.
+6. If you unzipped into a location other than ``/opt/gurobi952``, then call ``export GUROBI_HOME=GUROBI_UNZIP_PATH/linux64`` to set the path you used, where in ``GUROBI_HOME`` folder you can find ``bin`` folder.
+
+Drake supports any patch version of Gurobi 9.5. At time of writing, the most
+recent available version was 9.5.2; if using a newer patch version, the paths
+and file names above should be adjusted accordingly.
### Install on macOS
1. Register for an account on [http://www.gurobi.com](http://www.gurobi.com).
2. Set up your Gurobi license file in accordance with Gurobi documentation.
3. ``export GRB_LICENSE_FILE=/path/to/gurobi.lic``
-4. Download and install ``gurobi9.5.1_mac64.pkg``.
+4. Download and install ``gurobi9.5.2_mac64.pkg``.
To confirm that your setup was successful, run the tests that require Gurobi:
diff --git a/doc/_pages/python_bindings.md b/doc/_pages/python_bindings.md
index b03c417464af..de8293468c2d 100644
--- a/doc/_pages/python_bindings.md
+++ b/doc/_pages/python_bindings.md
@@ -42,7 +42,7 @@ python3 -c 'import pydrake.all; print(pydrake.__file__)'
```
-If you are using Gurobi, you must either have it installed in the suggested location under `/opt/...` mentioned in Gurobi 9.5.1, or you must ensure that you define the `${GUROBI_HOME}` environment variable, or specify `${GUROBI_INCLUDE_DIR}` via CMake.
+If you are using Gurobi, you must either have it installed in the suggested location under `/opt/...` mentioned in Gurobi 9.5, or you must ensure that you define the `${GUROBI_HOME}` environment variable, or specify `${GUROBI_INCLUDE_DIR}` via CMake.
diff --git a/tools/workspace/gurobi/package-macos.BUILD.bazel.in b/tools/workspace/gurobi/package-macos.BUILD.bazel.in
index 358e645c7552..1f0418c12a0c 100644
--- a/tools/workspace/gurobi/package-macos.BUILD.bazel.in
+++ b/tools/workspace/gurobi/package-macos.BUILD.bazel.in
@@ -11,7 +11,7 @@ licenses(["by_exception_only"]) # Gurobi
genrule(
name = "error-message",
outs = ["error-message.h"],
- cmd = "echo 'error: Gurobi 9.5.1 is not installed at {gurobi_home}' && false", # noqa
+ cmd = "echo 'error: Gurobi 9.5 is not installed at {gurobi_home}' && false", # noqa
visibility = ["//visibility:private"],
)
diff --git a/tools/workspace/gurobi/package-ubuntu.BUILD.bazel.in b/tools/workspace/gurobi/package-ubuntu.BUILD.bazel.in
index 6a36208c8d77..ba6d0cf44319 100644
--- a/tools/workspace/gurobi/package-ubuntu.BUILD.bazel.in
+++ b/tools/workspace/gurobi/package-ubuntu.BUILD.bazel.in
@@ -12,7 +12,7 @@ licenses(["by_exception_only"]) # Gurobi
genrule(
name = "error-message",
outs = ["error-message.h"],
- cmd = "echo 'error: Gurobi 9.5.1 is not installed at {gurobi_home}, export GUROBI_HOME to the correct value' && false", # noqa
+ cmd = "echo 'error: Gurobi 9.5 is not installed at {gurobi_home}, export GUROBI_HOME to the correct value' && false", # noqa
visibility = ["//visibility:private"],
)
@@ -25,8 +25,8 @@ GUROBI_CXX_HDRS = glob([
"gurobi-distro/include/gurobi_c++.h",
]) or [":error-message.h"]
-# In the Gurobi package, libgurobi95.so is a symlink to libgurobi.so.9.0.0.
-# However, if we use libgurobi.so.9.0.0 in srcs, executables that link this
+# In the Gurobi package, libgurobi95.so is a symlink to libgurobi.so.9.5.*.
+# However, if we use libgurobi.so.9.5.* in srcs, executables that link this
# library will be unable to find it at runtime in the Bazel sandbox,
# because the NEEDED statements in the executable will not square with the
# RPATH statements. I don't really know why this happens, but I suspect it
@@ -42,7 +42,7 @@ GUROBI_CXX_SRCS = glob([
]) or [":error-message.h"]
GUROBI_INSTALL_LIBRARIES = glob([
- "gurobi-distro/lib/libgurobi.so.9.5.1",
+ "gurobi-distro/lib/libgurobi.so.9.5.*",
"gurobi-distro/lib/libgurobi95.so",
]) or [":error-message.h"]
diff --git a/tools/workspace/gurobi/repository.bzl b/tools/workspace/gurobi/repository.bzl
index 4297598835e9..b2b8104fc96a 100644
--- a/tools/workspace/gurobi/repository.bzl
+++ b/tools/workspace/gurobi/repository.bzl
@@ -4,7 +4,24 @@
load("@drake//tools/workspace:os.bzl", "determine_os")
-# Ubuntu only: GUROBI_HOME should be the linux64 directory in the Gurobi 9.5.1
+# Finds the "latest" f'{path}/{prefix}*/{subdir}', where "latest" is determined
+# by converting the part that matched the '*' to an integer and taking the
+# match with the highest value.
+def _find_latest(repo_ctx, path, prefix, subdir):
+ best_dir = None
+ best_version = None
+ for d in repo_ctx.path(path).readdir():
+ if d.basename.startswith(prefix):
+ full_dir = d.get_child(subdir)
+ if full_dir.exists:
+ version = int(d.basename[len(prefix):])
+ if best_version == None or version > best_version:
+ best_version = version
+ best_dir = full_dir.realpath
+
+ return best_dir or (path + "/" + prefix + "-notfound/" + subdir)
+
+# Ubuntu only: GUROBI_HOME should be the linux64 directory in the Gurobi 9.5
# release.
#
def _gurobi_impl(repo_ctx):
@@ -14,17 +31,27 @@ def _gurobi_impl(repo_ctx):
if os_result.is_macos:
# Gurobi must be installed into its standard location.
- gurobi_home = "/Library/gurobi951/macos_universal2"
+ gurobi_home = _find_latest(
+ repo_ctx,
+ "/Library",
+ "gurobi95",
+ "macos_universal2",
+ )
repo_ctx.symlink(gurobi_home, "gurobi-distro")
build_flavor = "macos"
else:
# The default directory for the downloaded gurobi is
- # /opt/gurobi951/linux64. If the user does not use the default
+ # /opt/gurobi95*/linux64. If the user does not use the default
# directory, the he/she should set GUROBI_HOME environment variable to
# the gurobi file location.
gurobi_home = repo_ctx.os.environ.get("GUROBI_HOME", "")
repo_ctx.symlink(
- gurobi_home or "/opt/gurobi951/linux64",
+ gurobi_home or _find_latest(
+ repo_ctx,
+ "/opt",
+ "gurobi95",
+ "linux64",
+ ),
"gurobi-distro",
)
build_flavor = "ubuntu"