Closed lvjiamei closed 2 years ago
因为没有实现,这个问题我好久前就问过了,你可以看看源代码,。
谢谢谢谢回答!我搞了一个其他的方法搞定。 原因解释链接: https://www.codenong.com/3431676/ 下面是现在成功的代码:
constraint_ueq = [] def gene_constraint1(j): constraint_ueq.append(lambda var : sum(np.array(var)[(1 + j) user_num: (j + 2) user_num]) - 1) for j in range(0,3): gene_constraint1(j)
约束:33的矩阵,每一行的和小于等于1 方式1: constraint_ueq = [\ lambda var: sum(np.array(var)[user_num: 2 user_num]) - 1, lambda var: sum(np.array(var)[user_num + 1 user_num: user_num + 2 user_num]) - 1, lambda var: sum(np.array(var)[user_num + 2 user_num: user_num + 3 user_num]) - 1 ] 输出:[0. 1. 0. 0. 1. 0. 0. 1. 0.]
方式2: for j in range(0, 3): constraint_ueq.append(lambda var: sum(np.array(var)[(1 + j) user_num: (j + 2) user_num]) - 1) 输出:[0. 1. 1. 1. 1. 1. 0. 1. 0.] 请问这是为什么呢?