Convert Figma logo to code with AI

ERGO-Code logoHiGHS

Linear optimization software

1,030
195
1,030
108

Top Related Projects

2,259

Modeling language for Mathematical Optimization (linear, mixed-integer, conic, semidefinite, nonlinear)

11,545

Google's Operations Research tools:

Quick Overview

HiGHS is an open-source solver for linear optimization problems. It is designed to be a high-performance, easy-to-use tool for solving large-scale linear programming (LP) and mixed-integer programming (MIP) problems. HiGHS is developed by the Edinburgh Research Group in Optimization (ERGO) at the University of Edinburgh.

Pros

  • High performance: HiGHS is optimized for speed and efficiency, making it suitable for large-scale problems
  • Open-source: Free to use and modify, with an active community of contributors
  • Cross-platform: Supports Windows, Linux, and macOS
  • Multiple interfaces: Provides C, C++, Python, and Julia interfaces for flexibility

Cons

  • Limited to linear optimization: Not suitable for non-linear or quadratic programming problems
  • Learning curve: May require some understanding of optimization concepts for effective use
  • Documentation: While improving, some areas of documentation could be more comprehensive

Code Examples

  1. Solving a simple LP problem using the Python interface:
from highs import Highs
import numpy as np

h = Highs()
h.addVars(2, lb=[0, 0])
h.addConstr([1, 1], "<=", 1)
h.setObjective([1, 2])
h.run()

print("Optimal solution:", h.getSolution().col_value)
print("Optimal objective:", h.getObjective())
  1. Using the C++ interface to solve a MIP problem:
#include "Highs.h"

int main() {
    Highs highs;
    HighsLp lp;
    lp.num_col_ = 2;
    lp.num_row_ = 1;
    lp.col_cost_ = {1.0, 2.0};
    lp.col_lower_ = {0.0, 0.0};
    lp.col_upper_ = {1.0, 1.0};
    lp.row_lower_ = {0.0};
    lp.row_upper_ = {1.0};
    lp.a_matrix_.start_ = {0, 1};
    lp.a_matrix_.index_ = {0, 0};
    lp.a_matrix_.value_ = {1.0, 1.0};
    lp.integrality_ = {HighsVarType::kInteger, HighsVarType::kInteger};

    highs.passModel(lp);
    highs.run();

    const HighsSolution& solution = highs.getSolution();
    std::cout << "Optimal solution: " << solution.col_value[0] << ", " << solution.col_value[1] << std::endl;
    std::cout << "Optimal objective: " << highs.getObjectiveValue() << std::endl;

    return 0;
}
  1. Reading a problem from a file using the Julia interface:
using HiGHS

h = Highs()
read_model(h, "path/to/problem.mps")
run(h)

println("Optimal solution: ", get_col_solution(h))
println("Optimal objective: ", get_objective_value(h))

Getting Started

To get started with HiGHS, follow these steps:

  1. Install HiGHS:

    • For Python: pip install highspy
    • For C++: Build from source or use package managers (e.g., vcpkg)
    • For Julia: ] add HiGHS
  2. Import the library and create a Highs object:

from highs import Highs
h = Highs()
  1. Define your problem, solve it, and retrieve the results:
# Add variables, constraints, and objective
h.addVars(2)
h.addConstr([1, 1], "<=", 1)
h.setObjective([1, 2])

# Solve the problem
h.run()

# Get results
print(h.getSolution().col_value)
print(h.getObjective())

Competitor Comparisons

2,259

Modeling language for Mathematical Optimization (linear, mixed-integer, conic, semidefinite, nonlinear)

Pros of JuMP.jl

  • Written in Julia, offering better performance and integration with the Julia ecosystem
  • Provides a high-level modeling language for mathematical optimization problems
  • Supports a wide range of problem types and solvers

Cons of JuMP.jl

  • Requires knowledge of Julia programming language
  • May have a steeper learning curve for users unfamiliar with algebraic modeling languages

Code Comparison

JuMP.jl:

using JuMP, HiGHS
model = Model(HiGHS.Optimizer)
@variable(model, x >= 0)
@variable(model, y >= 0)
@objective(model, Max, 5x + 3y)
@constraint(model, 1x + 5y <= 3)
optimize!(model)

HiGHS:

#include "Highs.h"
HighsModel model;
model.lp_.colCost_ = {5.0, 3.0};
model.lp_.colLower_ = {0.0, 0.0};
model.lp_.colUpper_ = {kHighsInf, kHighsInf};
model.lp_.rowLower_ = {-kHighsInf};
model.lp_.rowUpper_ = {3.0};
model.lp_.aMatrix_.start_ = {0, 1};
model.lp_.aMatrix_.index_ = {0, 0};
model.lp_.aMatrix_.value_ = {1.0, 5.0};
Highs highs;
highs.passModel(model);
highs.run();
11,545

Google's Operations Research tools:

Pros of OR-Tools

  • Broader scope: Covers a wide range of optimization problems beyond linear programming
  • Extensive documentation and examples
  • Supports multiple programming languages (C++, Python, Java, C#)

Cons of OR-Tools

  • Larger and more complex codebase
  • Steeper learning curve for beginners
  • May have higher computational overhead for simpler problems

Code Comparison

HiGHS (C++):

#include "Highs.h"
Highs highs;
HighsStatus status = highs.readModel("model.mps");
status = highs.run();

OR-Tools (Python):

from ortools.linear_solver import pywraplp
solver = pywraplp.Solver.CreateSolver('GLOP')
x = solver.NumVar(0, 1, 'x')
solver.Add(x <= 1)
solver.Maximize(x)
status = solver.Solve()

Key Differences

  • HiGHS focuses on high-performance linear programming solvers
  • OR-Tools provides a more comprehensive suite of optimization tools
  • HiGHS may be more suitable for specialized linear programming tasks
  • OR-Tools offers greater flexibility for various optimization problems

Both projects are open-source and actively maintained, with HiGHS being more focused and OR-Tools offering a broader range of optimization capabilities.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

HiGHS - Linear optimization software

Build Status Build Status Build Status Build Status
Conan Center
PyPi PyPi
NuGet version NuGet download

About HiGHS

HiGHS is a high performance serial and parallel solver for large scale sparse linear optimization problems of the form

$$ \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 $$

where Q must be positive semi-definite and, if Q is zero, there may be a requirement that some of the variables take integer values. Thus HiGHS can solve linear programming (LP) problems, convex quadratic programming (QP) problems, and mixed integer programming (MIP) problems. It is mainly written in C++, but also has some C. It has been developed and tested on various Linux, MacOS and Windows installations. No third-party dependencies are required.

HiGHS has primal and dual revised simplex solvers, originally written by Qi Huangfu and further developed by Julian Hall. It also has an interior point solver for LP written by Lukas Schork, an active set solver for QP written by Michael Feldmeier, and a MIP solver written by Leona Gottwald. Other features have been added by Julian Hall and Ivet Galabova, who manages the software engineering of HiGHS and interfaces to C, C#, FORTRAN, Julia and Python.

Find out more about HiGHS at https://www.highs.dev.

Although HiGHS is freely available under the MIT license, we would be pleased to learn about users' experience and give advice via email sent to highsopt@gmail.com.

Documentation

Documentation is available at https://ergo-code.github.io/HiGHS/.

Installation

Build from source using CMake

HiGHS uses CMake as build system, and requires at least version 3.15. To generate build files in a new subdirectory called 'build', run:

    cmake -S . -B build
    cmake --build build

This installs the executable bin/highs and the library lib/highs.

To test whether the compilation was successful, change into the build directory and run

    ctest

More details on building with CMake can be found in HiGHS/cmake/README.md.

Build with Meson

As an alternative, HiGHS can be installed using the meson build interface:

meson setup bbdir -Dwith_tests=True
meson test -C bbdir

The meson build files are provided by the community and are not officially supported by the HiGHS development team.

Build with Nix

There is a nix flake that provides the highs binary:

nix run .

You can even run without installing anything, supposing you have installed nix:

nix run github:ERGO-Code/HiGHS

The nix flake also provides the python package:

nix build .#highspy
tree result/

And a devShell for testing it:

nix develop .#highspy
python
>>> import highspy
>>> highspy.Highs()

The nix build files are provided by the community and are not officially supported by the HiGHS development team.

Precompiled binaries

Precompiled static executables are available for a variety of platforms at https://github.com/JuliaBinaryWrappers/HiGHSstatic_jll.jl/releases

These binaries are provided by the Julia community and are not officially supported by the HiGHS development team. If you have trouble using these libraries, please open a GitHub issue and tag @odow in your question.

See https://ergo-code.github.io/HiGHS/stable/installation/#Precompiled-Binaries.

Running HiGHS

HiGHS can read MPS files and (CPLEX) LP files, and the following command solves the model in ml.mps

    highs ml.mps

Command line options

When HiGHS is run from the command line, some fundamental option values may be specified directly. Many more may be specified via a file. Formally, the usage is:

$ bin/highs --help
HiGHS options
Usage:
  bin/highs [OPTION...] [file]

      --model_file arg          File of model to solve.
      --read_solution_file arg  File of solution to read.
      --options_file arg        File containing HiGHS options.
      --presolve arg            Presolve: "choose" by default - "on"/"off"
                                are alternatives.
      --solver arg              Solver: "choose" by default - "simplex"/"ipm"
                                are alternatives.
      --parallel arg            Parallel solve: "choose" by default -
                                "on"/"off" are alternatives.
      --run_crossover arg       Run crossover: "on" by default -
                                "choose"/"off" are alternatives.
      --time_limit arg          Run time limit (seconds - double).
      --solution_file arg       File for writing out model solution.
      --write_model_file arg    File for writing out model.
      --random_seed arg         Seed to initialize random number generation.
      --ranging arg             Compute cost, bound, RHS and basic solution
                                ranging.
      --version                 Print version.
  -h, --help                    Print help.

For a full list of options, see the options page of the documentation website.

Interfaces

There are HiGHS interfaces for C, C#, FORTRAN, and Python in HiGHS/src/interfaces, with example driver files in HiGHS/examples/. More on language and modelling interfaces can be found at https://ergo-code.github.io/HiGHS/stable/interfaces/other/.

We are happy to give a reasonable level of support via email sent to highsopt@gmail.com.

Python

The python package highspy is a thin wrapper around HiGHS and is available on PyPi. It can be easily installed via pip by running

$ pip install highspy

Alternatively, highspy can be built from source. Download the HiGHS source code and run

pip install .

from the root directory.

The HiGHS C++ library no longer needs to be separately installed. The python package highspy depends on the numpy package and numpy will be installed as well, if it is not already present.

The installation can be tested using the small example HiGHS/examples/call_highs_from_python_highspy.py.

The Google Colab Example Notebook also demonstrates how to call highspy.

C

The C API is in HiGHS/src/interfaces/highs_c_api.h. It is included in the default build. For more details, check out the documentation website https://ergo-code.github.io/HiGHS/.

CSharp

The nuget package Highs.Native is on https://www.nuget.org, at https://www.nuget.org/packages/Highs.Native/.

It can be added to your C# project with dotnet

dotnet add package Highs.Native --version 1.9.0

The nuget package contains runtime libraries for

  • win-x64
  • win-x32
  • linux-x64
  • linux-arm64
  • macos-x64
  • macos-arm64

Details for building locally can be found in nuget/README.md.

Fortran

The Fortran API is in HiGHS/src/interfaces/highs_fortran_api.f90. It is not included in the default build. For more details, check out the documentation website https://ergo-code.github.io/HiGHS/.

Reference

If you use HiGHS in an academic context, please acknowledge this and cite the following article.

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