如何在 cvxpy 中将 warm_start 与双变量一起使用
How to use warm_start with Dual variables in cvxpy
如何在 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 目前不支持初始猜测,无论是原始变量还是对偶变量。
如何在 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 目前不支持初始猜测,无论是原始变量还是对偶变量。