赞
踩
如果可以通过校园网, 则直接生成。
不能的话,通过网站,发邮件申请 http://www.gurobi.cn/NewsView1.Asp?id=4
GRB_LICENSE_FILE=gurobi.lic路径
在命令提示符窗口输入 python setup.py install 安装即可。
- m = Model("min example")
- m.modelSense = GRB.MINIMIZE
-
- objFcnCoeffs = [3, 5, 6, 9]
- xVars = []
- for i in range(4):
- xVars.append(m.addVar(vtype=GRB.INTEGER, obj=objFcnCoeffs[i], name="Open%d" % i))
-
- # Update model to integrate new variables
- m.update()
-
- # Constraints
- m.addConstr(-2 * xVars[0] + 6 * xVars[1] - 3 * xVars[2] + 4 * xVars[3] >= 2, "Con1")
- m.addConstr(-5 * xVars[0] + 3 * xVars[1] + xVars[2] + 3 * xVars[3] >= -2, "Con2")
- m.addConstr(5 * xVars[0] - xVars[1] + 4 * xVars[2] - 2 * xVars[3] >= 3, "Con3")
-
- # Attempt to set an initial feasible solution (in this case to an optimal solution)
- startValues = [1, 1, 0, 0]
- for i in range(4):
- xVars[i].start = startValues[i]
-
- # Solve model
- m.optimize()
-
- # Print solution
- print('\
- TOTAL COSTS: %g' % m.objVal)
- for i in range(4):
- print('\
- xVar[%s] = %g' % i, xVars[i])
编译器可以运行gurobi,但pycharm不认识gurobi,给出红线,并且无法进行类型提示。
安装gurobipy-stubs模块就好(先进入项目环境,conda的话,就是conda activate 环境名字)
pip install gurobipy-stubs
参考文献:https://blog.csdn.net/qq_57867839/article/details/126844519
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。