https://github.com/mit-drl/goop
Generalized Mixed Integer Optimization in Go
https://github.com/mit-drl/goop
golang goop gurobi ilp integer-programming mip optimization
Last synced: 26 days ago
JSON representation
Generalized Mixed Integer Optimization in Go
- Host: GitHub
- URL: https://github.com/mit-drl/goop
- Owner: mit-drl
- License: gpl-3.0
- Created: 2018-04-20T20:13:43.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-11-29T19:32:48.000Z (about 4 years ago)
- Last Synced: 2024-06-19T17:51:39.231Z (over 1 year ago)
- Topics: golang, goop, gurobi, ilp, integer-programming, mip, optimization
- Language: Go
- Homepage: https://mit-drl.github.io/goop/
- Size: 49.8 KB
- Stars: 20
- Watchers: 4
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Goop [](https://goreportcard.com/report/github.com/mit-drl/goop) [](https://travis-ci.org/mit-drl/goop) [](https://godoc.org/github.com/mit-drl/goop) [](https://codeclimate.com/github/mit-drl/goop/maintainability) [](https://codecov.io/gh/mit-drl/goop)
General Linear Optimization in Go. `goop` provides general interface for solving
mixed integer linear optimization problems using a variety of back-end solvers
including LPSolve and Gurobi.
# Quickstart
We are going to start with a simple example showing how `goop` can be used to
solve integer linear programs. The example below seeks to maximize the following
MIP:
```
maximize x + y + 2 z
subject to x + 2 y + 3 z <= 4
x + y >= 1
x, y, z binary
```
This is is the same example implemented [here](http://www.gurobi.com/documentation/7.5/examples/mip1_py.html). Below
we have implemented the model using `goop` and have optimized the model using
the supported Gurobi solver.
```go
package main
import (
"fmt"
"github.com/mit-drl/goop"
"github.com/mit-drl/goop/solvers"
)
func main() {
// Instantiate a new model
m := goop.NewModel()
// Add your variables to the model
x := m.AddBinaryVar()
y := m.AddBinaryVar()
z := m.AddBinaryVar()
// Add your constraints
m.AddConstr(goop.Sum(x, y.Mult(2), z.Mult(3)).LessEq(goop.K(4)))
m.AddConstr(goop.Sum(x, y).GreaterEq(goop.One))
// Set a linear objective using your variables
obj := goop.Sum(x, y, z.Mult(2))
m.SetObjective(obj, goop.SenseMaximize)
// Optimize the variables according to the model
sol, err := m.Optimize(solvers.NewGurobiSolver())
// Check if there is an error from the solver. No error should be returned
// for this model
if err != nil {
panic("Should not have an error")
}
// Print out the solution
fmt.Println("x =", sol.Value(x))
fmt.Println("y =", sol.Value(y))
fmt.Println("z =", sol.Value(z))
// Output:
// x = 1
// y = 0
// z = 1
}
```
# Installation
1. First get the code
```
mkdir -p $GOPATH/github.com/mit-drl && cd $GOPATH/github.com/mit-drl
git clone https://github.com/mit-drl/goop && cd goop
```
2. Next build install the dependencies
```
./install.sh
```
3. Follow the [instructions](#Solver Notes) for your solver of choice. Note,
currently only Gurobi is supported
4. Finally build the library
```
go build
```
Note that due to a quirk with Gurobi, if you are using Ubuntu < 16.04, you must
build with
```
go build -tags pre_xenial
```
5. (Optional) Test our installation
```
govendor test -v +local
```
# Solver Notes
We currently have bindings for Gurobi and LPSolve. Please follow the
instructions below for using these specific solvers.
## Gurobi
- You must have [Gurobi](http://www.gurobi.com/downloads/download-center)
installed and have a valid license.
- The `GUROBI_HOME` environment variable must be set to the home directory
of your Gurobi installation
## LPSolve
LPSolve is installed using the normal install procedure and should work out of
the box.