np.random.seed(0)
weights = np.random.normal(0, 1, size=(6, 8))
weights[weights<0] = 0
weights_self = np.random.normal(0, 1, size=(6, 6))
weights_self[weights_self<0] = 0
fixed_x = np.random.uniform(-1, 1, size=(8, 2))
weights_cp = cp.Parameter((6, 8), value=weights)
weights_self_cp = cp.Parameter((6, 6), value=weights_self)
fixed_x_cp = cp.Parameter((8, 2), value=fixed_x)
var_x = cp.Variable((6, 2))
cost = 0
for i in range(6):
for j in range(8):
if i != j:
cost += weights_cp[i, j] * cp.norm(var_x[i] - fixed_x_cp[j])
for i in range(6):
for j in range(6):
if i != j:
cost += weights_self_cp[i, j] * cp.norm(var_x[i] - var_x[j])
objective = cp.Minimize(cost)
problem = cp.Problem(objective)
problem.solve()
It is giving DCP error, is there another way to write this? I am trying to minimize the sum of distances (weighted) of 6 variable points from 8 fixed points.
New contributor
Soham Gosavi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.