Python 添加x<;=y==z作为Gurobi中的约束
我想做一些类似的事情:Python 添加x<;=y==z作为Gurobi中的约束,python,gurobi,Python,Gurobi,我想做一些类似的事情: model.addConstr((x这里是在x和y是完全连续的GurobiVar实例的情况下如何实现的。这是解决此类问题的一种行之有效的方法 一个简单的例子: from gurobipy import Model, GRB m = Model() x = m.addVar(lb=-GRB.INFINITY) y = m.addVar(lb=-GRB.INFINITY) z = m.addVar(vtype=GRB.BINARY) # To be numerically
model.addConstr((x这里是在x和y是完全连续的GurobiVar实例的情况下如何实现的。这是解决此类问题的一种行之有效的方法
一个简单的例子:
from gurobipy import Model, GRB
m = Model()
x = m.addVar(lb=-GRB.INFINITY)
y = m.addVar(lb=-GRB.INFINITY)
z = m.addVar(vtype=GRB.BINARY)
# To be numerically stable, the big M has to be
# a similar order of magnitude as the absolute value
# of the difference between x and y
BIG_M = 10000
# Force z to become 1 if y is larger than x
m.addConstr(BIG_M * z >= y - x)
# Force z to be zero if y is smaller than x
m.addConstr(BIG_M * (1 - z) >= x - y)
True
和False
分别具有数值1
和0
。model.addConstr(如果x和y是gurobi变量,这也是可能的吗?