Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 添加x<;=y==z作为Gurobi中的约束_Python_Gurobi - Fatal编程技术网

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变量,这也是可能的吗?