我有一个大小为VxV的矩阵S
。我想对它施加以下形式的约束:。我尝试这样做,但是这段代码遇到了问题ValueError: Atoms must be at most 2D.
我整理了一个关于我的问题的简化示例:
def ILP_example(scores):
V = scores.shape[0]
u, v, w = np.meshgrid(range(V), range(V), range(V))
arr = cp.Variable(scores.shape)
objective = cp.Maximize(
cp.sum(cp.multiply(scores, arr))
)
constraints = [
arr[u, v] + arr[v, w] - arr[u, w] <= 1,
]
prob = cp.Problem(objective, constraints)
prob.solve()
return
例如尝试运行ILP_example(np.random.rand(5, 5))
会导致错误ValueError: Atoms must be at most 2D.
,该如何解决?