Crate gurobi [−] [src]
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 x = model.add_var("x", Binary).unwrap(); let y = model.add_var("y", Continuous(-10.0, 10.0)).unwrap(); let z = model.add_var("z", Continuous(-INFINITY, INFINITY)).unwrap(); // integrate all the variables into the model. model.update().unwrap(); // add a linear constraint model.add_constr("c0", &x - &y + 2.0 * &z, Equal, 0.0).unwrap(); // ... model.set_objective(&x, Maximize).unwrap(); // optimize the model. model.optimize().unwrap(); assert_eq!(model.status().unwrap(), Status::Optimal); assert_eq!(model.get(attr::ObjVal).unwrap() , 0.0); let val = model.get_values(attr::X, &[x, y, z]).unwrap(); assert_eq!(val, [0.0, -10.0, -5.0]); }
Modules
attr |
Defines the name of attributes |
param |
Defines the name of parameters |
Structs
Callback |
The context object for Gurobi callback. |
Constr |
Proxy object of a linear constraint |
Env |
Gurobi environment object |
LinExpr |
Linear expression of variables |
Model |
Gurobi model object associated with certain environment. |
QConstr |
Proxy object of a quadratic constraint |
QuadExpr |
Quadratic expression of variables |
SOS |
Proxy object of a Special Order Set (SOS) constraint |
Var |
Proxy object of a variables |
Enums
ConstrSense |
Sense for new linear/quadratic constraint |
Error |
The error type for operations in Gurobi Rust API |
ModelSense |
Sense of new objective function |
RelaxType |
Type of cost function at feasibility relaxation |
SOSType |
Type of new SOS constraint |
Status |
Status of a model |
VarType |
Type for new variable |
Where |
Location where the callback called |
Constants
INFINITY |
Large number used in C API |
Traits
Proxy |
Provides methods to query/modify attributes associated with certain element. |
Functions
version |
Returns the version number of Gurobi |
Type Definitions
Result |
A specialized
|