简体   繁体   English

Python Gurobi:如何在目标函数中实现决策变量的最大值?

[英]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)

Gurobi documentation Gurobi 文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Gurobi Python目标函数中对`if`条件进行建模? - How can I model `if` conditionals in Gurobi Python Objective Function? 如何在 Gurobi Python 中将决策变量与矩阵相乘 - How to multiply decision variable with a matrix in Gurobi Python 我怎样才能获得gurobi变量的值? - How can I get the value of a gurobi variable? CPLEX Python API 如何将决策变量与目标函数中的虚拟变量相乘? - CPLEX Python API how to multiply a decision variable with a dummy in the objective function? 如何将 CP-SAT 公式(在 python 中)中的目标指定为所有决策变量值的最大值的最小化? - How can I specify the objective in a CP-SAT formulation (in python) to be the minimization of the max of all decision variable values? 如何在Gurobi中正确实现成本最小化目标功能? - How to implement a cost minimization objective function correctly in Gurobi? 使用gurobi我如何在一组值中约束变量的域 - With gurobi how can I constraint the domain of a variable in a set of value 如何添加目标以调度 model 以使用 CPlex Python 将当前决策变量计算为特定值? - How can I add objective for scheduling model to count the present decision variables to be specific value using CPlex Python? if 条件在 Gurobi Python 目标 Function - if condition in Gurobi Python Objective Function 在Gurobi Python界面中对决策变量的值进行排序 - Sort Decision variables' value in Gurobi Python Interface
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM