问题描述
如何在cvxpy中为双变量设置开始猜测?对于正常的单值问题,解决方案是
x.value = 1/2
如何解决双重变量问题?
代码示例
import cvxpy as cp
# Create two scalar optimization variables.
x = cp.Variable()
y = cp.Variable()
# Create two constraints.
constraints = [x + y == 1,x - y >= 1]
# Form objective.
obj = cp.Minimize((x - y)**2)
# Form and solve problem.
prob = cp.Problem(obj,constraints)
# This is the way I amagine but it does not work
constraints[0].dual_value = 3
prob.solve()
# The optimal dual variable (Lagrange multiplier) for
# a constraint is stored in constraint.dual_value.
print("optimal (x + y == 1) dual variable",constraints[0].dual_value)
print("optimal (x - y >= 1) dual variable",constraints[1].dual_value)
print("x - y value:",(x - y).value)
解决方法
CVXPY当前不支持初始猜测,无论是原始变量还是双重变量。