Unofficial Gurobi Torch bindings.
Lua C CMake
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
cmake
.gitignore
.travis.yml
CMakeLists.txt
LICENSE
README.md
gurobi-scm-1.rockspec
init.c
init.lua
test.lua

README.md

gurobi.torch • [ ![Build Status] travis-image ] travis [ License license-image ] license

Unofficial Gurobi Torch bindings.


You may also be interested in:

Installation

  1. Set GUROBI_HOME in your shell's current session (with export GUROBI_HOME=..) and initialization file (.bashrc or .zshrc).
  2. luarocks make

Usage

The following solves the linear program

min  c'*x s.t. G*x <= h

Linear Program

local gurobi = require 'gurobi'

local G = torch.Tensor{{-1, 1}, {-1, -1}, {0, -1}, {1, -2}}
local h = torch.Tensor{1.0, -2.0, 0.0, 4.0}
local c = torch.Tensor{2.0, 1.0}

local env = gurobi.loadenv("")
local model = gurobi.newmodel(env, "", c)
gurobi.addconstrs(model, G, 'LE', h)
local status, x = gurobi.solve(model)
print(x) -- Optimal x is [0.5, 1.5]

gurobi.free(env, model)

Linear Program with Incrementally Added Constraints

local gurobi = require 'gurobi'

-- minimize y
-- subject to y >= x
--            y >= -x
--            y >= x + 1
local c = torch.Tensor{0.0, 1.0}
local G = torch.Tensor{{1, -1}, {-1, -1}, {1, -1}}
local h = torch.Tensor{0.0, 0.0, -1.0}

local env = gurobi.loadenv("")
local model = gurobi.newmodel(env, "", c)

local I = {{1,2}}
gurobi.addconstrs(model, G[I], 'LE', h[I])

local status, x = gurobi.solve(model)
print(x) -- Optimal at this point is [0, 0]

gurobi.addconstr(model, G[3], 'LE', h[3])
status, x = gurobi.solve(model)
print(x) -- Optimal at this point is [-0.5, 0.5]

gurobi.free(env, model)

OpenMP Parallel Solves

local env = gurobi.loadenv("")
local model1 = gurobi.newmodel(env, "", c)
gurobi.addconstrs(model1, G, 'LE', h)

local model2 = gurobi.newmodel(env, "", c)
gurobi.addconstrs(model2, G, 'LE', h)

local status, xs = gurobi.solvePar({model1, model2})

Tests

After installing the library with luarocks, our tests in test.lua can be run with th test.lua.

Licensing

  • Gurobi is proprietary software.
  • The original code in this repository (the Gurobi bindings) is Apache-licensed.