[英]Python Gurobi: How can I implement a maximum value of a decision variable in the objective function?
Hopefully someone can help me out.希望有人可以帮助我。 I am developing an optimization model where I minimize electricity costs over time ( t ) and over different transactions ( s ).
我正在开发一个优化模型,在该模型中,我将随着时间 ( t ) 和不同交易 ( s ) 的电力成本最小化。 (where: standard power( p )*costs of electricity ( c ) = electricity costs).
(其中:标准功率( p )*电力成本( c )=电力成本)。
Now I am trying to implement a cost component in the objective function that is based on the maximum power consumption that occurred (some alike: max(P[s,t]) ).现在我试图在目标函数中实现一个基于发生的最大功耗的成本组件(有些类似: max(P[s,t]) )。 However, np.max() returns an error because P[s,t] is an unsupported class for np.max().
但是, np.max() 返回错误,因为 P[s,t] 是 np.max() 不受支持的类。 Also the Gurobi function gp.max_(P[s,t]) also gives an unsupported class error.
此外,Gurobi 函数 gp.max_(P[s,t]) 也给出了不受支持的类错误。 Is there someone who has a solution?
有人有解决方案吗?
Code:代码:
obj = gp.quicksum(p[s, t] * Cost_elect[t]e for t in range(T) for s in range(S)) + gp.max_(p_batt_ch[s,t]*fixed_cost for t in range(T) for s in range(S))
You need to assign the max
constraint to a new auxiliary variable and the put this variable into the objective instead of the actual constraint.您需要将
max
约束分配给新的辅助变量,并将此变量放入目标而不是实际约束。
maxobj = model.addVar()
max_constr = model.addConstr(maxobj == gp.max_(p_batt_ch[s,t] * fixed_cost
for t in range(T) for s in range(S)))
obj = gp.quicksum(p[s,t] * Cost_elect[t] for t in range(T) for s in range(S)) + maxobj)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.