6 releases
Uses old Rust 2015
0.3.4 | Apr 4, 2020 |
---|---|
0.3.3 | Jun 14, 2018 |
0.3.2 | Sep 4, 2016 |
0.3.1 | Aug 29, 2016 |
0.1.1 |
|
#2121 in Algorithms
Used in generic-bnp
115KB
2.5K
SLoC
rust-gurobi
An unofficial Rust API for Gurobi optimizer.
- Documentation - master / 0.3 (latest)
Notices
- This wrapper library is not officially supported by Gurobi.
- Too many works have not finished yet.
License
Copyright (c) 2016, Yusuke Sasaki
This software is released under the MIT license, see LICENSE.
lib.rs
:
This crate provides primitive Rust APIs for Gurobi Optimizer.
It supports some types of mathematical programming problems (e.g. Linear programming; LP, Mixed Integer Linear Programming; MILP, and so on).
Notices
-
Before using this crate, you should install Gurobi and obtain a license. The instruction can be found here.
-
Make sure that the environment variable
GUROBI_HOME
is set to the installation path of Gurobi (likeC:\gurobi652\win64
,/opt/gurobi652/linux64
). -
On Windows, the toolchain should be MSVC ABI (it also requires Visual Studio or Visual C++ Build Tools). If you want to use GNU ABI with MinGW-w64/MSYS2 toolchain, you should create the import library for Gurobi runtime DLL (e.g.
gurobi65.dll
) and put it intoGUROBI_HOME/lib
. Procedure of creating import library is as follows:$ pacman -S mingw-w64-x86_64-tools-git $ gendef - $(cygpath $GUROBI_HOME)/bin/gurobi65.dll > gurobi65.def $ dlltool --dllname gurobi65.dll --def gurobi65.def --output-lib $(cygpath $GUROBI}HOME)/lib/libgurobi65.dll.a
Examples
extern crate gurobi;
use gurobi::*;
fn main() {
let env = Env::new("logfile.log").unwrap();
// create an empty model which associated with `env`:
let mut model = env.new_model("model1").unwrap();
// add decision variables.
let x1 = model.add_var("x1", Continuous, 0.0, -INFINITY, INFINITY, &[], &[]).unwrap();
let x2 = model.add_var("x2", Integer, 0.0, -INFINITY, INFINITY, &[], &[]).unwrap();
// integrate all of the variables into the model.
model.update().unwrap();
// add a linear constraint
model.add_constr("c0", &x1 + 2.0 * &x2, Greater, -14.0).unwrap();
model.add_constr("c1", -4.0 * &x1 - 1.0 * &x2, Less, -33.0).unwrap();
model.add_constr("c2", 2.0 * &x1 + &x2, Less, 20.0).unwrap();
// integrate all of the constraints into the model.
model.update().unwrap();
// set the expression of objective function.
model.set_objective(8.0 * &x1 + &x2, Minimize).unwrap();
assert_eq!(model.get(attr::IsMIP).unwrap(), 1, "Model is not a MIP.");
// write constructed model to the file.
model.write("logfile.lp").unwrap();
// optimize the model.
model.optimize().unwrap();
assert_eq!(model.status().unwrap(), Status::Optimal);
assert_eq!(model.get(attr::ObjVal).unwrap() , 59.0);
let val = model.get_values(attr::X, &[x1, x2]).unwrap();
assert_eq!(val, [6.5, 7.0]);
}
Dependencies
~420KB