以下是我的代码:
import cvxpy as cp
alpha = 0.3
lamda_1 = 0.5
lamda_2 = 1.2
mu1 = cp.Variable(pos=True)
mu2 = cp.Variable(pos=True)
p_ev_max = 50
eps = 0.05
S1 = cp.Variable(pos=True)
S2 = cp.Variable(pos=True)
S = cp.Parameter(pos=True)
S.value = 200
# time resolution is 15 mins
obj = cp.Minimize(1/(mu1 - lamda_1)+1/(mu2 - lamda_2))
constraints = [
mu1 == cp.min(p_ev_max, (1+eps)*S1),
mu2 == cp.min(p_ev_max, (1+eps)*S2),
S == S1 + S2,
]
prob = cp.Problem(objective= obj, constraints = constraints)
prob.solve(gp=True, requires_grad=True)使用cp.min函数时会出现以下错误:
Traceback (most recent call last):
File "<input>", line 32, in <module>
File "~/Library/Python/3.8/lib/python/site-packages/cvxpy/expressions/expression.py", line 661, in __lt__
raise NotImplementedError("Strict inequalities are not allowed.")
NotImplementedError: Strict inequalities are not allowed.我想知道我该如何使用cvxpy min max function。我搜索错误,但它们与在约束中使用cp.min无关。
发布于 2022-08-21 11:15:28
您可以在cvxpy中使用v堆栈()来解决这个问题:
mu1 == cp.min(cp.vstack([p_ev_max, (1+eps)*S1])),
mu2 == cp.min(cp.vstack([p_ev_max, (1+eps)*S2])),我认为vstack()将多个独立变量组合成一个符合cp.min要求的变量。
https://stackoverflow.com/questions/71274747
复制相似问题