Project

opt-rb

0.01
No release in over a year
Convex optimization for Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Opt

πŸ”₯ Convex optimization for Ruby

Supports Cbc, Clp, GLOP, GLPK, HiGHS, OSQP, and SCS

Build Status

Installation

Add this line to your application’s Gemfile:

gem "opt-rb"

And install one or more solvers based on your problem types:

Solver LP QP MIP License
Cbc βœ“ βœ“ EPL-2.0
Clp βœ“ EPL-2.0
GLOP βœ“ Apache-2.0
GLPK βœ“ βœ“ GPL-3.0-or-later
HiGHS βœ“ βœ“ βœ“ MIT
OSQP βœ“ βœ“ Apache-2.0
SCS βœ“ * MIT

* supports, but not implemented yet

Getting Started

Create and solve a problem

x1 = Opt::Variable.new(0.., "x1")
x2 = Opt::Variable.new(0.., "x2")

prob = Opt::Problem.new
prob.add(2 * x1 + 2 * x2 >= 7)
prob.add(3 * x1 + 4 * x2 >= 12)
prob.add(2 * x1 + x2 >= 6)
prob.minimize(8 * x1 + 10 * x2)
prob.solve

Get the value of a variable

x1.value

QP

prob.minimize(x1 * x1)

MIP

x1 = Opt::Integer.new(0.., "x1")
x2 = Opt::Binary.new("x2")

MIP with semi-continuous variables - HiGHS only at the moment

x1 = Opt::SemiContinuous.new(2.., "x1")
x2 = Opt::SemiInteger.new(2.., "x2")

Reference

Specify the solver

prob.solve(solver: :cbc)

Enable verbose logging

prob.solve(verbose: true)

Set the time limit in seconds

prob.solve(time_limit: 30)

Credits

This project was inspired by CVXPY and OR-Tools.

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/opt.git
cd opt
bundle install
bundle exec rake test