我正在尝试在gurobi中设置目标函数,并且需要有关pythonic方法的一些指导以实现此目标。我有一个带有16个值的numpy数组“ A”,我需要将该数组的每个值减去列表中的决策变量x1。对正值求和并将其乘以成本。
A1 = [123, 12, 15, 16, 17, 18, ....20]
A2 = [45, 77, 87, 20, 56, .....30]
X = [40, 50]
Cost = [35, 22]
m = Model("test")
x[1] = m.addvar(lb=30.0,ub=100,vtype=GRB.INTEGER, name="tobuypeak1")
x[2] = m.addvar(lb=30.0,ub=300,vtype=GRB.INTEGER, name="tobuypeak2")
obj = ((123-40)+(12-40)..+(20-40) as long as the subtracted value is +ve otherwise 0)*cost1 + ((45-50)+(77-50)...as long as subtracted value is +ve else 0)*Cost2
我是gurobi的新手,一定会感谢您的指导。
谢谢!