HiGHS Ruby

HiGHS - linear optimization software - for Ruby

Build Status

Installation

Add this line to your application’s Gemfile:

gem "highs"

Getting Started

The API is fairly low-level at the moment

Load a linear program

model =
  Highs.lp(
    sense: :minimize,
    col_cost: [8, 10],
    col_lower: [0, 0],
    col_upper: [1e30, 1e30],
    row_lower: [7, 12, 6],
    row_upper: [1e30, 1e30, 1e30],
    a_format: :colwise,
    a_start: [0, 3],
    a_index: [0, 1, 2, 0, 1, 2],
    a_value: [2, 3, 2, 2, 4, 1]
  )

Load a mixed-integer program

model =
  Highs.mip(
    sense: :minimize,
    col_cost: [8, 10],
    col_lower: [0, 0],
    col_upper: [1e30, 1e30],
    row_lower: [7, 12, 6],
    row_upper: [1e30, 1e30, 1e30],
    a_format: :colwise,
    a_start: [0, 3],
    a_index: [0, 1, 2, 0, 1, 2],
    a_value: [2, 3, 2, 2, 4, 1],
    integrality: [:integer, :continuous]
  )

Load a quadratic program

model =
  Highs.qp(
    sense: :minimize,
    col_cost: [0, -1, 0],
    col_lower: [0, 0, 0],
    col_upper: [1e30, 1e30, 1e30],
    row_lower: [1, -1e30],
    row_upper: [1e30, 1e30],
    a_format: :colwise,
    a_start: [0, 1, 2],
    a_index: [0, 0, 0],
    a_value: [1, 1, 1],
    q_format: :colwise,
    q_start: [0, 2, 3],
    q_index: [0, 2, 1, 0, 2],
    q_value: [2, -1, 0.2, -1, 2]
  )

Solve

model.solve

Write the program to an MPS file

model.write("model.mps")

Read a program from an MPS file

model = Highs.read("model.mps")

Reference

Enable verbose logging

model.solve(verbose: true)

Set the time limit in seconds

model.solve(time_limit: 30)

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/highs-ruby.git
cd highs-ruby
bundle install
bundle exec rake vendor:all
bundle exec rake test