1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
// Copyright (c) 2016 Yusuke Sasaki // // This software is released under the MIT License. // See http://opensource.org/licenses/mit-license.php or <LICENSE>. //! 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](http://www.gurobi.com/downloads/licenses/license-center). //! //! * Make sure that the environment variable `GUROBI_HOME` is set to the installation path of Gurobi //! (like `C:\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 into `GUROBI_HOME/lib`. //! Procedure of creating import library is as follows: //! //! ```shell-session //! $ 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]); //! } //! ``` extern crate gurobi_sys as ffi; extern crate itertools; mod env; mod error; mod model; mod util; // re-exports pub use error::{Error, Result}; pub use env::Env; pub use model::{Model, Var, Constr, QConstr, SOS, LinExpr, QuadExpr, Proxy}; pub use model::{VarType, ConstrSense, ModelSense, SOSType, Status, RelaxType}; pub use model::callback::{Callback, Where}; pub use model::VarType::*; pub use model::ConstrSense::*; pub use model::ModelSense::*; pub use model::SOSType::*; pub use model::RelaxType::*; pub use model::attr::exports as attr; pub use env::param::exports as param; /// Large number used in C API pub const INFINITY: f64 = 1e100; /// Returns the version number of Gurobi pub fn version() -> (i32, i32, i32) { let (mut major, mut minor, mut technical) = (0, 0, 0); unsafe { ffi::GRBversion(&mut major, &mut minor, &mut technical) }; (major, minor, technical) }