确保环境变量设置为 Gurobi 的安装路径 (如 , )。GUROBI_HOMEC:gurobi652win64/opt/gurobi652/linux64
在 Windows 上,工具链应为 MSVC ABI(还需要 Visual Studio 或 Visual C++ 生成工具)。 如果要将 GNU ABI 与 MinGW-w64/MSYS2 工具链一起使用,则应创建导入 库,并将其放入 . 创建导入库的过程如下:gurobi65.dllGUROBI_HOME/lib
$ 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
列子
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]);
}
转口
pub use model::VarType::*;
pub use model::ConstrSense::*;
pub use model::ModelSense::*;
pub use model::SOSType::*;
pub use model::RelaxType::*;
模块
阿特尔定义属性的名称
参数定义参数的名称
结构体
回调Gurobi 回调的上下文对象。
Constr线性约束的代理对象
环境Gurobi 环境对象
LinExpr的变量的线性表达式
型与特定环境关联的 Gurobi 模型对象。
代理提供查询/修改与特定元素关联的属性的方法。
QConstr二次约束的代理对象
四倍频变量的二次表达式
求救特殊订单集 (SOS) 约束的代理对象
变量变量的代理对象
枚举
ConstrSense的感应新的线性/二次约束
错误Gurobi Rust API 中操作的错误类型
模型感知新目标函数的意义
RelaxType可行性放宽时的成本函数类型
SOSType新 SOS 约束的类型
地位模型的状态
VarType新变量的类型
哪里回调调用的位置
常数
无限C API 中使用的大量
功能
版本返回 Gurobi 的版本号
类型定义
结果Gurobi Rust API 中操作的专用结果类型
上一条:Gurobi求解器
下一条:postman干嘛用