"TypeError: unsupported operand type(s) for -: 'LessThan' and 'NoneType' " while using sympy equation
回答済みaddConstr does not seem to accept a sympy inequalty. If this does not work, then how get variables and constraints input from a user and then add them to a model?
m = gp.Model()
decsn_var = [x', 'y']
for i in range(n_decsn):
decsn_var[i] = sym.sympify(decsn_var[i])
for i in range(n_decsn):
decsn_var[i] = m.addVar(lb = -gp.GRB.INFINITY, ub = gp.GRB.INFINITY)
ineq_lower = ['1-x+y', 'y']
for i in range(n_ineq_lower):
ineq_lower[i] = sym.sympify(ineq_lower[i])
g = ineq_lower[0] <= 0
m.addConstr(g)
TypeError Traceback (most recent call last)
<ipython-input-58-4a83b28d925b> in <module>
----> 1 m.addConstr(g)
src\gurobipy\model.pxi in gurobipy.gurobipy.Model.addConstr()
TypeError: unsupported operand type(s) for -: 'LessThan' and 'NoneType'
0
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
You are right that gurobipy does not support sympy inequalities. Instead you should add your constraints (and variables) as follows:
x = m.addVar(lb = -gp.GRB.INFINITY, name="x")
y = m.addVar(lb = -gp.GRB.INFINITY, name="y")
m.addConstr(1-x+y <= 0)0
投稿コメントは受け付けていません。
コメント
2件のコメント