在Python 3中使用Gurobi包的自然日志

时间:2018-02-18 02:26:58

标签: python gurobi

from gurobipy import *
from math import *

def main():

    # Create a new model

    m = Model()

    # Create variables

    lb = 0.0
    ub = 1.0

    x = m.addVar(lb, ub, name='x')
    y = m.addVar(lb, ub, name='y')

    # Set objective for y

    m.setObjective(y)


    m.addConstr(log(x) + 2 * y + 3 <= 4, 'c0')

    # Add constraint: x + y >= 1

    m.addConstr(x + y >= 1, 'c1')

    # Optimize model as an LP

    m.optimize()

main()

我正在尝试解决实用程序优化问题,但它会一直产生错误

Traceback (most recent call last):
  File "C:/python36/gur.py", line 48, in <module>
    main()
  File "C:/python36/gur.py", line 38, in main
    m.addConstr(log(x) + 2 * y + 3 <= 4, 'c0')
TypeError: must be real number, not Var

我一直在搜索和阅读几个网站,但我找不到一个明确的解决方案。

任何人都可以帮我解决这个问题吗? 谢谢!

0 个答案:

没有答案