如何在cvxpy中对双变量使用warm_start

问题描述

如何在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当前不支持初始猜测,无论是原始变量还是双重变量。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...