Skip to content

Nonlinear optimization for Ruby

License

Notifications You must be signed in to change notification settings

ankane/nlopt-ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NLopt Ruby

NLopt - nonlinear optimization - for Ruby

Build Status

Installation

First, install NLopt. For Homebrew, use:

brew install nlopt

And for Ubuntu 22.04+, use:

sudo apt-get install libnlopt0

Then add this line to your application’s Gemfile:

gem "nlopt"

Getting Started

Create an optimization

opt = NLopt::Opt.new("LN_COBYLA", 2)

Set the objective function

f = lambda do |x, grad|
  x[0] + x[1]
end
opt.set_min_objective(f)

Set constraints

opt.set_lower_bounds([1, 2])
opt.set_upper_bounds([3, 4])

Perform the optimization

xopt = opt.optimize([2, 3])

API

This library follows the NLopt Python API. You can follow Python tutorials and convert the code to Ruby in many cases. Feel free to open an issue if you run into problems.

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

About

Nonlinear optimization for Ruby

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages