ERGO-Code/HiGHS

GitHub: ERGO-Code/HiGHS

HiGHS 是一款开源的高性能线性优化求解器,用于解决大规模线性规划、凸二次规划和混合整数规划问题。

Stars: 1724 | Forks: 332

# HiGHS - 线性优化软件 [![Build Status](https://static.pigsec.cn/wp-content/uploads/repos/cas/21/217825f58c4e6b0d52a70ffaa18543f8573e5c90e5d69f4b0fe1332a7a01259d.svg)][fast_build_link] [![Build Status](https://static.pigsec.cn/wp-content/uploads/repos/cas/86/863047e5c31c55901ef3874da5ea6c0f3b62f828cabc6e042f05822fcf3addec.svg)][linux_build_link] [![Build Status](https://static.pigsec.cn/wp-content/uploads/repos/cas/2f/2f23e408ddac57a27dcf2fc0ddc96c8a7e4eaeae162f8d03494ee864b8b0c4d5.svg)][macos_build_link] [![Build Status](https://static.pigsec.cn/wp-content/uploads/repos/cas/ce/ce6a6d67010a2a262d063a3fa011c4597c62b386d53cef5b640f3ce9ccb4b7c4.svg)][windows_build_link] \ [![Conan Center](https://img.shields.io/conan/v/highs)](https://conan.io/center/recipes/highs) \ [![PyPi](https://img.shields.io/pypi/v/highspy.svg)](https://pypi.python.org/pypi/highspy) [![PyPi](https://img.shields.io/pypi/dm/highspy.svg)](https://pypi.python.org/pypi/highspy) \ [![NuGet version](https://img.shields.io/nuget/v/Highs.Native.svg)](https://www.nuget.org/packages/Highs.Native) [![NuGet download](https://img.shields.io/nuget/dt/Highs.Native.svg)](https://www.nuget.org/packages/Highs.Native) - [关于 HiGHS](#about-highs) - [文档](#documentation) - [安装](#installation) - [使用 CMake 从源码构建](#build-from-source-using-cmake) - [使用 Meson* 构建](#build-with-meson) - [使用 Nix* 构建](#build-with-nix) - [预编译二进制文件](#precompiled-binaries) - [运行 HiGHS](#running-highs) - [接口](#interfaces) - [Python](#python) - [C](#c) - [CSharp](#csharp) - [Fortran](#fortran) - [参考](#reference) ## 关于 HiGHS HiGHS 是一款高性能的串行和并行求解器,适用于大规模稀疏 线性优化问题,其形式为 $$ \min \quad \dfrac{1}{2}x^TQx + c^Tx \qquad \textrm{s.t.}~ \quad L \leq Ax \leq U; \quad l \leq x \leq u $$ 其中 $Q$ 必须是半正定的;如果 $Q$ 为零,可能还会要求某些变量取整数值。因此,HiGHS 可以解决线性规划 (LP) 问题、凸二次规划 (QP) 问题和混合整数规划 (MIP) 问题。它主要使用 C++ 编写,但也包含部分 C 代码。它已经在多种 Linux、MacOS 和 Windows 环境下进行了开发和测试。无需任何第三方依赖。 HiGHS 拥有原始和对偶修正单纯形求解器,最初由 Qi Huangfu 编写,并由 Julian Hall 进一步开发。它还包含由 Lukas Schork 编写的 LP 内点法求解器,由 Michael Feldmeier 编写的 QP 活动集求解器,以及由 Leona Gottwald 编写的 MIP 求解器。其他功能由 Julian Hall 和 Ivet Galabova 添加,后者负责管理 HiGHS 的软件工程以及 C、C#、FORTRAN、Julia 和 Python 的接口。 请在 https://www.highs.dev 了解更多关于 HiGHS 的信息。 尽管 HiGHS 是根据 MIT 许可证免费提供的,但我们非常乐意了解用户的使用体验,并通过发送至 highsopt@gmail.com 的邮件提供建议。 ## 文档 文档可在 https://ergo-code.github.io/HiGHS/ 获取。 ## 安装 ### 使用 CMake 从源码构建 HiGHS 使用 CMake 作为构建系统,并且要求至少为 3.15 版本。要在名为 'build' 的新子目录中生成构建文件,请运行: ``` cmake -S . -B build cmake --build build ``` 这将安装可执行文件 `bin/highs` 和库 `lib/highs`。 要测试编译是否成功,请进入 build 目录并运行 ``` ctest ``` 有关使用 CMake 构建的更多详细信息,请参见 `HiGHS/cmake/README.md`。 #### 使用 Meson 构建 作为替代方案,可以使用 `meson` 构建接口安装 HiGHS: ``` meson setup bbdir -Dwith_tests=True meson test -C bbdir ``` _meson 构建文件由社区提供,HiGHS 开发团队不作官方支持。_ **如果您使用此方法并遇到问题,请考虑查阅 [HiGHS 贡献指南](https://github.com/ERGO-Code/HiGHS/blob/master/CONTRIBUTING.md) 并贡献修复或更新。** #### 使用 Nix 构建 有一个提供 `highs` 二进制文件的 nix flake: ``` nix run . ``` 假设您已经安装了 [nix](https://nixos.org/download.html),您甚至可以[无需安装任何内容](https://determinate.systems/posts/nix-run/)直接运行它: ``` nix run github:ERGO-Code/HiGHS ``` nix flake 还提供了 Python 包: ``` nix build .#highspy tree result/ ``` 以及用于测试的 devShell: ``` nix develop .#highspy python >>> import highspy >>> highspy.Highs() ``` _nix 构建文件由社区提供,HiGHS 开发团队不作官方支持。_ ### 预编译二进制文件 预编译的静态二进制文件可在 https://github.com/ERGO-Code/HiGHS/releases 获取。 此外,还有一个包含 Windows x64 共享库的包。 `*-mit` 二进制包包含 HiGHS 并采用 MIT 许可证。 `*-apache` 二进制包包含带有 HiPO 的 HiGHS 并采用 Apache 许可证,这是由于 HiPO 依赖项的许可要求。有关更多信息,请参见 [THIRD_PARTY_NOTICES.md](https://github.com/ERGO-Code/HiGHS/blob/master/THIRD_PARTY_NOTICES.md)。 如果您对更多平台和二进制文件有任何疑问或需求,请通过 hello@highs.dev 与我们联系。 ## 运行 HiGHS HiGHS 可以读取 MPS 文件和 (CPLEX) LP 文件,以下命令 用于求解 `ml.mps` 中的模型 ``` highs ml.mps ``` #### 命令行选项 从命令行运行 HiGHS 时,可以直接指定一些基本选项值。 还可以通过文件指定更多选项。其正式用法 如下: ``` $ bin/highs --help usage: ./bin/highs [options] [file] options: --model_file file File of model to solve. --options_file file File containing HiGHS options. --read_solution_file file File of solution to read. --read_basis_file text File of initial basis to read. --write_model_file text File for writing out model. --solution_file text File for writing out solution. --write_basis_file text File for writing out final basis. --presolve text Set presolve option to: "choose" * default "on" "off" --solver text Set solver option to: "choose" * default "simplex" "ipm" --parallel text Set parallel option to: "choose" * default "on" "off" --threads int Set maximum number of threads to use: 0: automatic * default --run_crossover text Set run_crossover option to: "choose" "on" * default "off" --time_limit float Run time limit (seconds - double). --random_seed int Seed to initialize random number generation. --ranging text Compute cost, bound, RHS and basic solution ranging: "on" "off" * default -v, --version Print version. -h, --help Print help. ``` 有关选项的完整列表,请参阅文档网站的[选项页面](https://ergo-code.github.io/HiGHS/stable/options/definitions/)。 ## 接口 在 `HiGHS/highs/interfaces` 中有用于 C、C#、FORTRAN 和 Python 的 HiGHS 接口,在 `HiGHS/examples/` 中有示例驱动文件。有关语言和建模接口的更多信息,请访问 https://ergo-code.github.io/HiGHS/stable/interfaces/other/。 我们很乐意通过发送至 highsopt@gmail.com 的邮件提供合理水平的支持。 ### Python Python 包 `highspy` 是 HiGHS 的一个轻量级封装,可在 [PyPi](https://pypi.org/project/highspy/) 上获取。可以通过运行以下 `pip` 命令轻松安装 ``` $ pip install highspy ``` 或者,可以从源码构建 `highspy`。下载 HiGHS 源代码并从根目录 运行 ``` pip install . ``` Python 包 `highspy` 依赖于 `numpy` 包,如果尚未安装 `numpy`,它也会被一并安装。 可以使用小示例 `HiGHS/examples/call_highs_from_python_highspy.py` 来测试安装。 [Google Colab 示例笔记本](https://colab.research.google.com/drive/1JmHF53OYfU-0Sp9bzLw-D2TQyRABSjHb?usp=sharing) 也演示了如何调用 `highspy`。 要在 Python 中使用 HiPO,需要额外的 `highspy-extras`。它包含 HiPO 的依赖项,并采用 Apache 2.0 许可证。可以使用以下命令安装 ``` $ pip install highspy[extras] ``` 有关更多详细信息,请访问 https://ergo-code.github.io/HiGHS/ 上的 Interfaces -> Python -> HiPO in Python。 ### C C API 位于 `HiGHS/highs/interfaces/highs_c_api.h`。它包含在默认构建中。有关更多详细信息,请查阅文档网站 https://ergo-code.github.io/HiGHS/。 ### CSharp nuget 包 Highs.Native 位于 https://www.nuget.org,网址为 https://www.nuget.org/packages/Highs.Native/。 可以使用 `dotnet` 将其添加到您的 C# 项目中 ``` dotnet add package Highs.Native --version 1.15.1 ``` nuget 包包含以下平台的运行时库: * `win-x64` * `win-x86` * `linux-x64` * `linux-arm64` * `macos-x64` * `macos-arm64` 有关本地构建的详细信息可在 `nuget/README.md` 中找到。 ### Fortran Fortran API 位于 `HiGHS/highs/interfaces/highs_fortran_api.f90`。它*不*包含在默认构建中。有关更多详细信息,请查阅文档网站 https://ergo-code.github.io/HiGHS/。 ## 参考 如果您在学术环境中使用 HiGHS,请予以致谢并引用以下文章。 Parallelizing the dual revised simplex method Q. Huangfu and J. A. J. Hall Mathematical Programming Computation, 10 (1), 119-142, 2018. DOI: [10.1007/s12532-017-0130-5](https://link.springer.com/article/10.1007/s12532-017-0130-5)
标签:Bash脚本, C++, 二次规划, 数学优化, 数据擦除, 求解器, 混合整数规划, 线性规划, 逆向工具