1.1下载gurobi求解器,https://www.gurobi.com/downloads/
下载完成后,一路next安装好,放着。然后点击academic license申请个证书,如果没账号就注册一个,用qq邮箱比用公司的邮箱会快。公司邮箱会慢点,但是也会收得到,收到验证邮件后点击进去设置密码即可。
1.2 获取学术许可成功
1.3打开gurobi的命令行窗口会提示输入许可
把刚刚那个grbgetkey复制粘贴到这个窗口就完事了
1.4 安装完成
经过以上两步已经完成了gurobi的安装,但是许多同学在安装的最后一步并不会去重启,即使它提示你需要重启。这就会导致环境变量不生效,后面会有意想不到的事情发生。
2.1 Gurobi导入idea中
打开idea,点projecstructure,module。做如下操作
2.2找到gurobi的安装路径的lib目录
添加jar包
添加完成apply,返回开始贴上官方代码。
2.3 运行MIP问题的例子
例子在这,https://www.gurobi.com/documentation/9.1/examples/mip1_java.html,代码如下:
import gurobi.*;
public class Mip1 {
public static void main(String[] args) {
try {
// Create empty environment, set options, and start
GRBEnv env = new GRBEnv(true);
env.set("logFile", "mip1.log");
env.start();
// Create empty model
GRBModel model = new GRBModel(env);
// Create variables
GRBVar x = model.addVar(0.0, 1.0, 0.0, GRB.BINARY, "x"